flybrain/services/flysim/crates/fly-legacy-session/src/bin/flysim-session.rs
acamilo b2fd148f52 session: the live composition's participants on the router (BUS-01)
FLY_SESSION_TRANSPORT=bus (flysim-session --transport bus) runs the
agent and the world as socket clients of the session's router, one
process each by default (FLY_SESSION_MODE=thread and in-process too);
local, the PERF-01 lane, stays the default. Results, traces, checkpoints
and the compatibility string are the same in every arm (SessionArm:
local, bus/in-process, bus/thread, bus/process; FLY_PARITY_ARMS picks
them for the parity suites).

- process-mode placement: the service splits its cpuset as PERF-02 does
  and hands each process its CPUs (--host-cpus, --sweep-cpus;
  Launcher::place_process; pool::apply_placement); FLY_SESSION_AUX_CPUS
  moves the service and the world
- the launcher's own clients in memory in thread and process modes
- participants on a one-worker runtime; long handlers under
  block_in_place, which fixes a process-mode boot that failed when
  Agent.Initialize outlived the 2 s probe on a loaded box
- writers allocated ahead (WriterPool); a worker's own seals cached by
  clone, not a second hold
- over the bus the agent's Commit attaches its feed status, which the
  host reads instead of calling Legacy.FeedStatus at every publish
- fly-shadow --mode / FLY_SHADOW_MODE names the topology, forwarded to a
  remote box; the verdict records candidate.transport; fly-shadow check
  --require-arm

legacy-gameboy-v1 section 12 and 18 carry the dated amendments.
2026-10-02 00:09:41 +00:00

110 lines
4.4 KiB
Rust

//! `flysim-session`: the live fly on the session runtime, as a drop-in for `flysim` (SERVE-01).
//!
//! ```sh
//! flysim-session # what flysim.service runs after `fly-runtime session`
//! flysim-session --print-compatibility
//! ```
//!
//! It reads exactly `flysim`'s configuration (`/etc/fly/fly.env` through the unit, or
//! `--config flysim.toml`), writes the same checkpoint stores, event log, sugar journal and chat
//! sidecar, and serves the same feed, control API and metrics. These variables are its own:
//! `FLY_SESSION_DIR` (the session's router store and sockets, default `/run/fly/session`),
//! `FLY_SESSION_TRANSPORT` (`local`, the default, or `bus`; `--transport`), `FLY_SESSION_MODE`
//! (`in-process`, `thread` or `process`; `process` by default on the bus), `FLY_SESSION_PIN`,
//! `FLY_SESSION_AUX_CPUS` and `FLY_SESSION_PROFILE` (`production`, or `toy` for tests).
//!
//! The one-shot flags are `flysim`'s: `--check-config`, `--print-compatibility` (the session's
//! own string, which must equal `flysim`'s), `--print-state-compatibility` and
//! `--reset-to-milestone` (the store is shared, so these are `flysim`'s own functions).
use anyhow::Result;
use clap::Parser;
use flysim::config::Config;
#[derive(Debug, Parser)]
#[command(
name = "flysim-session",
about = "The fly brain and its Game Boy on the session runtime: flysim's feed, control API and checkpoints.",
version
)]
struct Args {
/// Path to `flysim.toml`. Without it, defaults plus `FLY_*` / `FLYSIM_*` environment
/// overrides are used, exactly as for `flysim`.
#[arg(long, value_name = "PATH")]
config: Option<std::path::PathBuf>,
/// Print the resolved configuration and exit.
#[arg(long)]
check_config: bool,
/// Print the checkpoint compatibility string this build would write, and exit.
#[arg(long)]
print_compatibility: bool,
/// Print the compatibility string the checkpoints in this directory carry, and exit.
#[arg(long, value_name = "DIR")]
print_state_compatibility: Option<std::path::PathBuf>,
/// Restart the run from the milestone archive for this ladder rung, and exit (with the
/// service stopped; `flysim --reset-to-milestone`, the same store).
#[arg(long, value_name = "RANK")]
reset_to_milestone: Option<u32>,
/// `local` (in-process over the local lane) or `bus` (every participant a socket client of
/// the session's router, one process each unless `FLY_SESSION_MODE` says otherwise).
/// Overrides `FLY_SESSION_TRANSPORT`.
#[arg(long, value_name = "local|bus")]
transport: Option<String>,
}
fn main() -> Result<()> {
let args = Args::parse();
init_tracing();
let config = Config::load(args.config.as_deref())?;
let options =
fly_legacy_session::service::ServiceOptions::from_env_with(args.transport.as_deref())?;
tracing::info!(config = ?config, options = ?options, "resolved configuration");
if args.check_config {
println!("{}", toml::to_string_pretty(&config)?);
return Ok(());
}
if args.print_compatibility {
println!(
"{}",
fly_legacy_session::service::compatibility_string(&config, &options)?
);
return Ok(());
}
if let Some(dir) = args.print_state_compatibility.as_deref() {
if let Some(found) = flysim::store::state_compatibility(dir) {
println!("{found}");
}
return Ok(());
}
if let Some(rank) = args.reset_to_milestone {
let stamp = flysim::reset::utc_stamp(flysim::eventlog::now_wall_ms());
let durable = config.paths.save_dir.clone();
let hot = config.paths.hot_dir.clone();
let archive = flysim::reset::default_archive_dir(&durable, &stamp);
for line in flysim::reset::reset_to_milestone(&durable, &hot, rank, &archive)? {
println!("{line}");
}
return Ok(());
}
fly_legacy_session::service::run(config, options)
}
/// Logs go to stderr, as `flysim`'s do (binjgb prints the cartridge header to stdout).
fn init_tracing() {
use tracing_subscriber::EnvFilter;
let filter = EnvFilter::try_from_env("FLYSIM_LOG")
.or_else(|_| EnvFilter::try_from_default_env())
.unwrap_or_else(|_| EnvFilter::new("info"));
tracing_subscriber::fmt()
.with_env_filter(filter)
.with_writer(std::io::stderr)
.with_target(false)
.init();
}