flybrain/services/flysim/crates/fly-legacy-session/examples/reward_bearing.rs
acamilo 12f361436f fly-legacy-session: the shadow run, its comparator and verdict (SHADOW-01)
shadow::run follows the live service's per-process trace files: each
segment boots a session from that process's startup save (a fresh start
powers on instead), replays the transition's admissions, runs it, takes
the live captures in the live order around a deferred rollback, and
compares its own trace line field by field, the ledger digest, and the
FLYSIM01 bytes of every live save (host-fields and archive-order
substituted). The first difference stops it with a diverged verdict and
divergence.json. A spool copies live generations as they appear; a lag
guard backs off while the live fly loses real time.

verdict.json is fly-shadow-verdict-v1, the contract CUT-01 reads;
fly-shadow check applies the cutover rule. trace::compare_line is shared
with trace::compare. tests/shadow.rs runs the real service through a
restart under a shadow and plants four differences, each caught with the
right kind, field and step.
2026-09-30 01:39:42 +00:00

39 lines
1.8 KiB
Rust

//! `reward_bearing IN OUT`: a copy of a FLYSIM01 checkpoint with its adapter ledger thinned so the
//! real brain earns rewards where the fly already stands -- the current map unvisited (an `AREA`
//! payout on the first sample), its exits unfound (`boundary`), its ground unwalked
//! (`exploration`), no wild win a replay (`battle`). TASK-01's brain arm
//! (`tests/session_trace.rs`), as a file for SHADOW-01's rehearsal (`tools/shadow-rehearsal.sh`),
//! where the real service restores it. A test fixture, never a stream checkpoint.
fn main() {
let args: Vec<String> = std::env::args().skip(1).collect();
let [input, output] = args.as_slice() else {
eprintln!("usage: reward_bearing IN OUT");
std::process::exit(2);
};
let bytes = std::fs::read(input).expect("the checkpoint reads");
let mut checkpoint = flysim::store::decode(&bytes).expect("FLYSIM01");
let reward = &mut checkpoint.runtime.reward;
let map = reward["location"]
.as_str()
.and_then(|l| l.split(':').next())
.unwrap_or("0")
.to_owned();
if let Some(seen) = reward["seen"].as_array_mut() {
seen.retain(|key| {
let key = key.as_str().unwrap_or("");
key != format!("map:{map}") && !key.starts_with(&format!("boundary:{map}:"))
});
}
if let Some(tiles) = reward["tiles"].as_array_mut() {
tiles.retain(|tile| !tile.as_str().unwrap_or("").starts_with(&format!("{map}:")));
}
if let Some(counts) = reward["tileCounts"].as_object_mut() {
counts.remove(&map);
}
reward["wildWins"] = serde_json::json!({});
reward["replayBlocked"] = serde_json::json!([]);
let out = flysim::store::encode(&checkpoint.agent, &checkpoint.runtime).expect("encodes");
std::fs::write(output, out).expect("the copy writes");
eprintln!("thinned map {map}: {output}");
}