fly-session: the launcher starts the legacy Game Boy environment in-process, on a thread or as a process
This commit is contained in:
parent
e28b0d8999
commit
4819f6ccd9
3 changed files with 167 additions and 2 deletions
|
|
@ -47,6 +47,8 @@ Ready(k) ─ Prepare all agents concurrently ───────────
|
|||
| `cli` | The binary's subcommands: `agent`, `environment`, `measure` |
|
||||
| `state` | The durable checkpoint store over `FLYSESS1`: compatibility, generations, the bounded writer |
|
||||
| `harness` | The runnable composition: router, the flies, one arena, one coordinator |
|
||||
| `legacy_env` | ENV-01: the legacy Game Boy environment worker over binjgb -- the one-frame setup scaffold, the joypad batch, `f32le` audio, the per-boundary memory image, `gameboy-slots-v1`, the capture payload and the world's half of `FLYSIM01` |
|
||||
| `legacy_env_parity` | ENV-01's parity harness: the toy cartridge, recorded scripts, the emulator driven directly in `LegacyFrame` order, the worker driven over the bus, and the replay of the service's own `FLY_TRACE` |
|
||||
|
||||
## Execution modes and the launcher
|
||||
|
||||
|
|
@ -88,6 +90,7 @@ A separate-process participant is a subcommand of this crate's one binary, which
|
|||
```sh
|
||||
fly-session agent --socket S --store-root D --client-id C --service N --threads T ...
|
||||
fly-session environment --socket S --store-root D --client-id C --service N --threads T ...
|
||||
fly-session legacy-environment ... --worker ID --port p1 --rom PATH --rom-digest SHA256 --slots best
|
||||
fly-session measure --steps 300 --agents 1,2,4
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,10 @@ use std::process::ExitCode;
|
|||
use crate::agent::AgentFaults;
|
||||
use crate::environment::EnvironmentFaults;
|
||||
use crate::launcher::{
|
||||
AgentLaunch, EnvironmentLaunch, ExecutionMode, Started, flags, serve_one,
|
||||
AgentLaunch, EnvironmentLaunch, ExecutionMode, LegacyEnvironmentLaunch, Started, flags,
|
||||
serve_one,
|
||||
};
|
||||
use crate::legacy_env::BackendConfig;
|
||||
use crate::types::*;
|
||||
|
||||
const USAGE: &str = "\
|
||||
|
|
@ -31,6 +33,8 @@ fly-session <command> [options]
|
|||
|
||||
agent serve one agent worker on a launcher-created endpoint
|
||||
environment serve the environment worker on a launcher-created endpoint
|
||||
legacy-environment
|
||||
serve the legacy Game Boy environment (ENV-01) on a launcher endpoint
|
||||
measure compare the execution modes and print the measurement table
|
||||
measure-row measure one row and print it as JSON (one child per row)
|
||||
|
||||
|
|
@ -50,6 +54,9 @@ Worker options (agent and environment):
|
|||
environment: --worker ID --ports p1,p2 --step-numerator N --step-denominator N
|
||||
[--advance-delay-ms N] [--omit-view-at-boundary N]
|
||||
[--fail-stage-restore 0|1] [--fail-activate-restore 0|1]
|
||||
legacy-environment:
|
||||
--worker ID --port ID --rom PATH --rom-digest SHA256 --slots best
|
||||
--audio-rate 48000 --audio-buffer-frames 4096 --setup-frames 1
|
||||
|
||||
Measure options:
|
||||
--steps N transitions per run (default 200)
|
||||
|
|
@ -77,6 +84,10 @@ pub fn main() -> ExitCode {
|
|||
.and_then(|o| serve(&command, &o)),
|
||||
"environment" => Options::parse(&rest, &[flags::COMMON, flags::ENVIRONMENT_ONLY])
|
||||
.and_then(|o| serve(&command, &o)),
|
||||
"legacy-environment" => {
|
||||
Options::parse(&rest, &[flags::COMMON, flags::LEGACY_ENVIRONMENT_ONLY])
|
||||
.and_then(|o| serve(&command, &o))
|
||||
}
|
||||
"measure" => Options::parse(&rest, &[flags::MEASURE]).and_then(|o| measure(&o)),
|
||||
"measure-row" => Options::parse(&rest, &[flags::MEASURE]).and_then(|o| measure_row(&o)),
|
||||
"--help" | "-h" | "help" => {
|
||||
|
|
@ -220,6 +231,23 @@ fn serve(role: &str, options: &Options) -> Result<(), String> {
|
|||
client_id: client_id.clone(),
|
||||
service: service.clone(),
|
||||
}),
|
||||
"legacy-environment" => Started::LegacyEnvironment(LegacyEnvironmentLaunch {
|
||||
session_id,
|
||||
worker_id: options.id(flags::WORKER)?,
|
||||
incarnation_id,
|
||||
worker_threads: threads,
|
||||
rom_path: options.path(flags::ROM)?,
|
||||
backend: BackendConfig {
|
||||
rom_digest: options.required(flags::ROM_DIGEST)?.to_owned(),
|
||||
port_id: options.id(flags::PORT)?,
|
||||
slots: parse_ids(options.required(flags::SLOTS)?, flags::SLOTS)?,
|
||||
audio_sample_rate: options.u64(flags::AUDIO_RATE, 0)?,
|
||||
audio_buffer_frames: options.u64(flags::AUDIO_BUFFER_FRAMES, 0)?,
|
||||
setup_frames: options.u64(flags::SETUP_FRAMES, 0)?,
|
||||
},
|
||||
client_id: client_id.clone(),
|
||||
service: service.clone(),
|
||||
}),
|
||||
_ => Started::Environment(EnvironmentLaunch {
|
||||
session_id,
|
||||
worker_id: options.id(flags::WORKER)?,
|
||||
|
|
@ -260,10 +288,14 @@ fn serve(role: &str, options: &Options) -> Result<(), String> {
|
|||
}
|
||||
|
||||
fn parse_ports(value: &str) -> Result<Vec<Id>, String> {
|
||||
parse_ids(value, flags::PORTS)
|
||||
}
|
||||
|
||||
fn parse_ids(value: &str, flag: &str) -> Result<Vec<Id>, String> {
|
||||
value
|
||||
.split(',')
|
||||
.filter(|part| !part.is_empty())
|
||||
.map(|part| parse_id(part).map_err(|e| format!("--ports: {e}")))
|
||||
.map(|part| parse_id(part).map_err(|e| format!("--{flag}: {e}")))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ use flybus::{Client, ClientConfig, Router, ServiceConfig, Transport, UnixListene
|
|||
|
||||
use crate::agent::{AgentConfig, AgentFaults, FakeAgentWorker};
|
||||
use crate::environment::{CounterEnvironment, EnvironmentConfig, EnvironmentFaults};
|
||||
use crate::legacy_env::{BackendConfig, LegacyEnvironmentConfig, LegacyGameboyEnvironment};
|
||||
use crate::rpc::WorkerRef;
|
||||
use crate::types::*;
|
||||
use crate::worker::{StatusCell, WorkerHandle, serve};
|
||||
|
|
@ -257,6 +258,24 @@ pub struct EnvironmentLaunch {
|
|||
pub service: String,
|
||||
}
|
||||
|
||||
/// What the legacy Game Boy environment participant (ENV-01) is started with.
|
||||
///
|
||||
/// Everything crosses a process boundary as argv: the cartridge's path (read-only, outside the
|
||||
/// checkout, never identity) and the backend configuration it must be -- the cartridge digest,
|
||||
/// the port, the declared slots and the audio configuration. `Environment.Initialize` must name
|
||||
/// exactly that configuration's `AssetRef`.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LegacyEnvironmentLaunch {
|
||||
pub session_id: Id,
|
||||
pub worker_id: Id,
|
||||
pub incarnation_id: Id,
|
||||
pub worker_threads: usize,
|
||||
pub rom_path: PathBuf,
|
||||
pub backend: BackendConfig,
|
||||
pub client_id: String,
|
||||
pub service: String,
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------------
|
||||
// A launched participant
|
||||
|
||||
|
|
@ -613,6 +632,39 @@ impl Launcher {
|
|||
}
|
||||
}
|
||||
|
||||
/// Starts the legacy Game Boy environment (ENV-01), in the launcher's configured mode, and
|
||||
/// identifies it.
|
||||
pub async fn launch_legacy_environment(
|
||||
&mut self,
|
||||
spec: LegacyEnvironmentLaunch,
|
||||
) -> Result<WorkerIdentity, DomainError> {
|
||||
let threads = self.budget.allocate(&spec.worker_id, spec.worker_threads)?;
|
||||
let identity = WorkerIdentity {
|
||||
session_id: spec.session_id.clone(),
|
||||
client_id: spec.client_id.clone(),
|
||||
service: spec.service.clone(),
|
||||
worker_id: spec.worker_id.clone(),
|
||||
incarnation_id: spec.incarnation_id.clone(),
|
||||
role: Role::Environment,
|
||||
port_id: None,
|
||||
worker_threads: threads,
|
||||
};
|
||||
let started = self
|
||||
.start_participant(&identity, Started::LegacyEnvironment(spec.clone()), threads)
|
||||
.await;
|
||||
match started {
|
||||
Ok(worker) => {
|
||||
let identity = worker.identity.clone();
|
||||
self.workers.insert(spec.worker_id.clone(), worker);
|
||||
Ok(identity)
|
||||
}
|
||||
Err(e) => {
|
||||
self.budget.release(&spec.worker_id);
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn start_participant(
|
||||
&mut self,
|
||||
identity: &WorkerIdentity,
|
||||
|
|
@ -695,6 +747,14 @@ impl Launcher {
|
|||
let status = endpoint.status();
|
||||
(serve(client, service, endpoint), status)
|
||||
}
|
||||
Started::LegacyEnvironment(spec) => {
|
||||
let endpoint = LegacyGameboyEnvironment::new(legacy_environment_config(
|
||||
spec,
|
||||
identity.worker_threads,
|
||||
));
|
||||
let status = endpoint.status();
|
||||
(serve(client, service, endpoint), status)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -1250,6 +1310,13 @@ pub(crate) mod flags {
|
|||
pub const OMIT_AUDIO_AT_BOUNDARY: &str = "omit-audio-at-boundary";
|
||||
pub const OVERLAPPING_AUDIO_AT_BOUNDARY: &str = "overlapping-audio-at-boundary";
|
||||
|
||||
pub const ROM: &str = "rom";
|
||||
pub const ROM_DIGEST: &str = "rom-digest";
|
||||
pub const SLOTS: &str = "slots";
|
||||
pub const AUDIO_RATE: &str = "audio-rate";
|
||||
pub const AUDIO_BUFFER_FRAMES: &str = "audio-buffer-frames";
|
||||
pub const SETUP_FRAMES: &str = "setup-frames";
|
||||
|
||||
pub const MODE: &str = "mode";
|
||||
pub const AGENTS: &str = "agents";
|
||||
pub const STEPS: &str = "steps";
|
||||
|
|
@ -1297,6 +1364,17 @@ pub(crate) mod flags {
|
|||
FAIL_STAGE_RESTORE,
|
||||
FAIL_ACTIVATE_RESTORE,
|
||||
];
|
||||
/// What only the legacy Game Boy environment (ENV-01) is given.
|
||||
pub const LEGACY_ENVIRONMENT_ONLY: &[&str] = &[
|
||||
WORKER,
|
||||
PORT,
|
||||
ROM,
|
||||
ROM_DIGEST,
|
||||
SLOTS,
|
||||
AUDIO_RATE,
|
||||
AUDIO_BUFFER_FRAMES,
|
||||
SETUP_FRAMES,
|
||||
];
|
||||
/// What a measurement run or one of its row children is given.
|
||||
pub const MEASURE: &[&str] = &[MODE, AGENTS, STEPS, WARMUP_STEPS, WORKER_THREADS, MODES];
|
||||
}
|
||||
|
|
@ -1314,6 +1392,7 @@ fn arg(name: &str, value: impl std::fmt::Display) -> (String, String) {
|
|||
pub(crate) enum Started {
|
||||
Agent(AgentLaunch),
|
||||
Environment(EnvironmentLaunch),
|
||||
LegacyEnvironment(LegacyEnvironmentLaunch),
|
||||
}
|
||||
|
||||
impl Started {
|
||||
|
|
@ -1321,6 +1400,7 @@ impl Started {
|
|||
match self {
|
||||
Started::Agent(_) => "agent",
|
||||
Started::Environment(_) => "environment",
|
||||
Started::LegacyEnvironment(_) => "legacy-environment",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1387,6 +1467,18 @@ impl Started {
|
|||
}
|
||||
args
|
||||
}
|
||||
Started::LegacyEnvironment(spec) => vec![
|
||||
arg(flags::SESSION, &spec.session_id),
|
||||
arg(flags::WORKER, &spec.worker_id),
|
||||
arg(flags::INCARNATION, &spec.incarnation_id),
|
||||
arg(flags::PORT, &spec.backend.port_id),
|
||||
arg(flags::ROM, spec.rom_path.display()),
|
||||
arg(flags::ROM_DIGEST, &spec.backend.rom_digest),
|
||||
arg(flags::SLOTS, spec.backend.slots.join(",")),
|
||||
arg(flags::AUDIO_RATE, spec.backend.audio_sample_rate),
|
||||
arg(flags::AUDIO_BUFFER_FRAMES, spec.backend.audio_buffer_frames),
|
||||
arg(flags::SETUP_FRAMES, spec.backend.setup_frames),
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1419,6 +1511,20 @@ pub(crate) fn environment_config(spec: &EnvironmentLaunch) -> EnvironmentConfig
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn legacy_environment_config(
|
||||
spec: &LegacyEnvironmentLaunch,
|
||||
worker_threads: usize,
|
||||
) -> LegacyEnvironmentConfig {
|
||||
LegacyEnvironmentConfig {
|
||||
session_id: spec.session_id.clone(),
|
||||
worker_id: spec.worker_id.clone(),
|
||||
incarnation_id: spec.incarnation_id.clone(),
|
||||
worker_threads,
|
||||
rom_path: spec.rom_path.clone(),
|
||||
backend: spec.backend.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Connects, registers and serves one participant. Used by a thread with its own runtime and,
|
||||
/// through the worker subcommand, by a separate process.
|
||||
pub(crate) async fn serve_one(
|
||||
|
|
@ -1444,6 +1550,11 @@ pub(crate) async fn serve_one(
|
|||
Started::Environment(spec) => {
|
||||
serve(client, service, CounterEnvironment::new(environment_config(spec)))
|
||||
}
|
||||
Started::LegacyEnvironment(spec) => serve(
|
||||
client,
|
||||
service,
|
||||
LegacyGameboyEnvironment::new(legacy_environment_config(spec, worker_threads)),
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -1528,6 +1639,21 @@ mod flag_tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn legacy_environment_launch() -> LegacyEnvironmentLaunch {
|
||||
let mut backend = BackendConfig::legacy(&"ab".repeat(32));
|
||||
backend.slots = vec![id("best"), id("spare")];
|
||||
LegacyEnvironmentLaunch {
|
||||
session_id: id("demo"),
|
||||
worker_id: id("world"),
|
||||
incarnation_id: id("world-inc-1"),
|
||||
worker_threads: 1,
|
||||
rom_path: PathBuf::from("/nonexistent/cartridge"),
|
||||
backend,
|
||||
client_id: "environment".to_owned(),
|
||||
service: "env.world".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Both halves of the command line name the same constants, and this proves it for every
|
||||
/// argument a launch can produce: a flag the launcher writes that the parser does not
|
||||
/// accept would be a silently ignored option, which is what the parser now refuses.
|
||||
|
|
@ -1539,6 +1665,10 @@ mod flag_tests {
|
|||
[flags::COMMON, flags::ENVIRONMENT_ONLY],
|
||||
),
|
||||
(Started::Agent(agent_launch()), [flags::COMMON, flags::AGENT_ONLY]),
|
||||
(
|
||||
Started::LegacyEnvironment(legacy_environment_launch()),
|
||||
[flags::COMMON, flags::LEGACY_ENVIRONMENT_ONLY],
|
||||
),
|
||||
] {
|
||||
let arguments = started.arguments();
|
||||
assert!(!arguments.is_empty());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue