The lockstep coordinator, its phase machine and a synthetic composition, as a new workspace member. Every worker method is a Flybus RPC to an incarnation-pinned service; the domain request ids and result caches of ipc-v1 section 5 sit in front of every mutation. - coordinator: the step-v1 section 3 transaction in order -- prepare every agent concurrently, run one executor per agent in sorted agent-id order, assemble all port controls in descriptor order, send exactly one Environment.Advance, evaluate the task once, commit every agent concurrently, and move the committed boundary only when all of them succeeded. Sequential, concurrent and reversed dispatch are selectable and must agree. - phase: the section 2 machine as an explicit edge table, Paused and Failed included, with a committed-boundary predicate that gates pauses, captures and publication. - clock: checked rational accumulation. A 60 Hz world with a 1 ms model tick runs 16, 17, 17 ticks and comes back to a remainder of exactly zero. - dedup: operation keys, the cached reply with its own artifact holds, CONFLICT, IN_PROGRESS, RESULT_EXPIRED, STALE_STEP, the lifecycle bound and Worker.Acknowledge. - worker: the dispatch shell. Admission order and the result cache live here; the endpoint mutex is the worker's simulation lock, so one mutation runs at a time while Worker.Status answers from a separate cell. - agent, environment, task: a fake model with an explicit seed and a mutation counter the tests read, a fixed readout stub, a counter arena that seals one immutable frame per boundary, a deterministic task and the identity executor. - fly_session_types: the CONTRACT-01 domain types as a local stand-in, reconciled with the shared crate in a following commit. Tests run twice, over the in-memory transport and over a Unix socket, through the same router: the SESSION-01 acceptance bullets and every section 4 failure-injection row that applies to this slice.
53 lines
2.2 KiB
Rust
53 lines
2.2 KiB
Rust
//! The synthetic sequential transaction, run over both transports and printed.
|
|
//!
|
|
//! ```text
|
|
//! cargo run -p fly-session --example session
|
|
//! ```
|
|
//!
|
|
//! Two fake agents, one counter arena, one coordinator, one router. Nothing here needs a ROM,
|
|
//! a dataset, a GPU or a network.
|
|
|
|
use fly_session::harness::{HarnessConfig, SessionHarness, Via};
|
|
|
|
#[tokio::main(flavor = "multi_thread", worker_threads = 4)]
|
|
async fn main() {
|
|
for via in [Via::Memory, Via::Unix] {
|
|
let dir = tempfile::tempdir().expect("a temporary directory");
|
|
let mut harness = SessionHarness::start(via, dir.path(), HarnessConfig::default())
|
|
.await
|
|
.expect("the session starts");
|
|
harness.coordinator.bootstrap().await.expect("bootstrap");
|
|
println!("--- {via:?}: Ready(0) with the world stopped at boundary 0");
|
|
let reports = harness.coordinator.run(3).await.expect("three transitions");
|
|
|
|
for (k, transition) in harness.coordinator.trace.transitions.iter().enumerate() {
|
|
let ticks: Vec<String> = transition
|
|
.agents
|
|
.iter()
|
|
.map(|a| format!("{}={} ticks", a.agent_id, a.ticks_advanced))
|
|
.collect();
|
|
println!(
|
|
"step {k}: {} batch={} boundary={} events={}",
|
|
ticks.join(" "),
|
|
transition.batch_id,
|
|
transition.acknowledged_boundary,
|
|
transition.task_event_ids.len()
|
|
);
|
|
}
|
|
let progress = harness.coordinator.task_progress();
|
|
println!(
|
|
"{via:?}: {} advances, counter {}, reward {}, {} publications, last boundary {}",
|
|
harness.coordinator.stats().advances,
|
|
progress.integer("counter").unwrap_or_default(),
|
|
progress.number("totalReward").unwrap_or_default(),
|
|
harness.coordinator.stats().publications,
|
|
reports.last().map(|r| r.boundary).unwrap_or_default(),
|
|
);
|
|
// The behaviour trace is what two runs in different dispatch orders must agree on.
|
|
for line in harness.coordinator.trace.behavior() {
|
|
println!(" behaviour: {line}");
|
|
}
|
|
harness.shutdown().await;
|
|
drop(dir);
|
|
}
|
|
}
|