iter embedding-abi-m5.3 (DONE 3/3): time-shard boundary-invisibility proof + friction harvest

Final functional M5 iteration (spec ae905de, plan 67027ab; on
green m5.1 204c171 + m5.2 b724cd1 whose leak-proof resolved via
dbd76e5). Proves the chunk/window-boundary-invisibility claim the
M4 retirement rests on:

- adapter::fold_window — purely additive windowed sibling of
  fold_symbol (same MidPriceStream+Kernel path; stream_tick_windowed).
  fold_symbol/MidPriceStream/Kernel byte-untouched.
- chrono as a DEV-dep only — the time-shard test derives
  (y,m)->Unix-ms bounds (data-server's own precedent) and passes
  raw ms to the bin; the bin is date-math-free; Invariant 1
  unaffected.
- new single-responsibility [[bin]] timeshard_runner — one thread
  per disjoint window, each owning its Kernel (Ctx:!Send =>
  compile-time per-thread-ctx).
- tests/timeshard.rs — spec §3 strength-ordered: (a) per-shard
  (acc,n) BIT-EXACT vs single-thread host fold of that exact window
  in stream order (THE boundary-invisibility proof); (b) Σ partials
  bit-exact by construction; (c) whole-window within REL_TOL=1e-6
  only (cross-shard f64 reassociation is host arithmetic, never a
  kernel property — bit-exact there would be the bug; tolerance
  derived from the recursive-summation error bound). Plus the
  now-deterministic leak-Σ + a journal-only friction timing capture
  (no bench gate, no timing assertion).

Concrete pin: EURUSD 2017-03/04/05 (recon-verified present,
contiguous, no gaps; data-server has no month-listing API). RED was
a genuine deterministic compile failure (declared-but-absent bin
source; Cargo missing-source error vs the plan's predicted env!
error — same cause, no false-green; benign plan-text imprecision in
Concerns).

Boss-verified independently: timeshard determinism 5/5 (no jitter);
full ail-embed suite 0 failed AND 0 ignored across all binaries
(m5.2 symbol_fan_swarm_leak_free stays un-ignored & green — the
saga's resolution intact); isolated embed_rc_global_stats_race
still green; AILang workspace data-server count 0; compiler-surface
diff empty (zero diff to crates/ailang-*, crates/ail/, runtime/,
examples/*.ail, root Cargo.toml, DESIGN.md).

Friction-harvest deliverable (P2 flat-array-decision input):
host-per-tick-FFI ~= 658 ms / 3,192,562 ticks ~= ~206 ns/tick at
real EURUSD volume.

M5 functional work complete; milestone closes next via the
mandatory audit (which also handles the pre-existing
DESIGN.md:2358-2360 "additive M4 concern" drift, out of m5.3 scope).
Includes the per-iter journal, stats, and the INDEX.md line.
This commit is contained in:
2026-05-19 02:40:16 +02:00
parent 67027ab0f9
commit 0900f3f413
8 changed files with 451 additions and 0 deletions
+19
View File
@@ -68,6 +68,25 @@ pub fn fold_symbol(
Some(Kernel::new().run(MidPriceStream::new(it).take(max_ticks)))
}
/// Fold the mid-price stream of `symbol` restricted to the inclusive
/// Unix-millisecond window `[from_ms, to_ms]` through the M3 kernel.
/// `None` if the symbol has no tick stream in that window. The window
/// is the bound (no tick cap): the result is `(Σ mid, count)` over
/// exactly the records data-server yields for that window, in stream
/// order — identical f64-add sequence to a single-thread host fold of
/// the same window, hence bit-exact against it. The windowed sibling
/// of `fold_symbol`; same `MidPriceStream` + `Kernel` path, only the
/// data-server entry differs (`stream_tick_windowed`).
pub fn fold_window(
server: &Arc<DataServer>,
symbol: &str,
from_ms: i64,
to_ms: i64,
) -> Option<(f64, i64)> {
let it = server.stream_tick_windowed(symbol, Some(from_ms), Some(to_ms))?;
Some(Kernel::new().run(MidPriceStream::new(it)))
}
#[cfg(test)]
mod tests {
use super::tick_to_px;
+73
View File
@@ -0,0 +1,73 @@
//! Time-shard swarm harness (spec §3). Run as a subprocess by
//! `tests/timeshard.rs` under `AILANG_RC_STATS=1`.
//!
//! argv: `<data_dir> <symbol> <from:to> [<from:to> ...]` — one
//! inclusive Unix-ms window per shard. Date math lives in the test
//! (chrono); this bin is date-math-free. Spawns one thread per
//! window, each building its OWN `Kernel` (`Ctx: !Send` forces
//! one-ctx-per-thread — a shared-ctx design is `error[E0277]`).
//! Prints, in shard order, `RESULT <idx> <from> <to> <accbits:016x>
//! <n>`, then one `TIMING total_ticks=<Σn> elapsed_ms=<wall>` line
//! (the friction-harvest observation; the test records it in the
//! close-out journal, it is not asserted).
use std::sync::Arc;
use std::time::Instant;
use ail_embed::adapter::fold_window;
use data_server::DataServer;
fn main() {
let mut args = std::env::args().skip(1);
let data_dir = args.next().expect("argv[1] = data dir");
let symbol = args.next().expect("argv[2] = symbol");
let windows: Vec<(i64, i64)> = args
.map(|a| {
let (f, t) = a.split_once(':').expect("window arg is from:to");
(
f.parse::<i64>().expect("from_ms i64"),
t.parse::<i64>().expect("to_ms i64"),
)
})
.collect();
assert!(
windows.len() >= 2,
"need >= 2 disjoint windows for a time-shard, got {}",
windows.len()
);
let server = Arc::new(DataServer::new(&data_dir));
let started = Instant::now();
let handles: Vec<_> = windows
.iter()
.copied()
.enumerate()
.map(|(idx, (from, to))| {
let srv = Arc::clone(&server);
let sym = symbol.clone();
// Each thread builds its own Kernel inside the closure —
// Kernel/Ctx are !Send, so this is the ONLY shape that
// compiles (one ctx per thread, type-enforced).
std::thread::spawn(move || {
let (acc, n) = fold_window(&srv, &sym, from, to)
.expect("window has a tick stream");
(idx, from, to, acc, n)
})
})
.collect();
let mut results: Vec<(usize, i64, i64, f64, i64)> = handles
.into_iter()
.map(|h| h.join().expect("shard thread panicked"))
.collect();
let elapsed_ms = started.elapsed().as_millis();
results.sort_by_key(|r| r.0);
let mut total_ticks: i64 = 0;
for (idx, from, to, acc, n) in &results {
total_ticks += *n;
println!("RESULT {idx} {from} {to} {:016x} {n}", acc.to_bits());
}
println!("TIMING total_ticks={total_ticks} elapsed_ms={elapsed_ms}");
}