flybrain/services/flysim/crates/fly-session/src/lib.rs
acamilo 52ad46ecb0 refactor(session): build the session slice on the shared fly-session-types crate
CONTRACT-01 landed its crate, so the local stand-in module goes away and the domain
scalars, method payloads, their validation, the canonical digests and the trace format
all come from the contract. `src/types.rs` is a facade over that crate plus the few
things a coordinator needs that are not part of the type contract: a session-side
DomainError, the synthetic composition's schema and event-id derivations, and the
coordinator-local ControllerIntent, PortBinding and AgentOutcome that never cross the
bus.

Consequences worth naming:

- Payloads are read and written through DomainType::from_json / to_json instead of
  serde derives, so a misspelled required field fails where the contract says it
  should. serde, sha2 and ryu-js leave this crate's dependencies with them.
- The step-v1 section 8 trace is the contract's TransitionTrace, with behaviour and
  operational metadata already separated; the dispatch-order comparison now runs over
  the contract's own behaviour encoding.
- Two things the migration found. IN_PROGRESS is raised strictly before any mutation,
  so its certainty is "none", not "unknown"; the local module had it wrong.
  WorldObservation::validate_against checks the views a result carries but does not
  require every declared view to be present, so requiring them is made explicit in the
  coordinator's phase C check, where step-v1 puts it.
- The lost-Advance-result injection now waits for the worker to report the operation
  before abandoning the call, so the case it injects really is a loss after dispatch
  rather than a cancellation before it.

Gates: cargo test -p fly-session (61 tests, both transports), cargo clippy
--all-targets clean, and the runnable example produces the same behaviour trace over
both transports.
2026-09-22 12:30:41 +00:00

41 lines
1.7 KiB
Rust

//! `fly-session`: the lockstep session coordinator and a synthetic composition over Flybus.
//!
//! This crate is the SESSION-01 slice of the session-framework implementation guide: the
//! sequential transaction of [`step-v1`], driven over the [`flybus`] router, with small fake
//! workers standing in for a brain and an emulator.
//!
//! ```text
//! Coordinator ── Agent.Prepare ──> agent workers (fake model + fixed readout stub)
//! ── Environment.Advance ──> environment (a counter arena, no emulator)
//! ── task.evaluate_transition (once)
//! ── Agent.Commit ──> agent workers
//! ── committed snapshot ──> session.<id>.snapshots
//! ```
//!
//! Every arrow is a Flybus RPC to an incarnation-pinned service, with domain request ids and
//! the result caches of `ipc-v1` section 5 in front of every mutation. Nothing here contains a
//! public controller API, an implicit best-effort retry, a real emulator or a real brain.
//!
//! The domain types come from the CONTRACT-01 crate [`fly_session_types`]; [`types`] is a
//! facade over it plus the few session-side additions a coordinator needs.
//!
//! [`step-v1`]: https://example.invalid/step-v1
pub mod agent;
pub mod clock;
pub mod coordinator;
pub mod dedup;
pub mod environment;
pub mod harness;
pub mod phase;
pub mod rpc;
pub mod task;
pub mod worker;
// CONTRACT-01 owns the domain types; `types` is a facade over its crate plus the few
// session-side additions a coordinator needs.
pub mod types;
pub use fly_session_types;
pub use coordinator::{Coordinator, DispatchOrder, Injections, SessionFailure, StepReport};
pub use phase::{Phase, PhaseMachine};