Skip to main content

Module session_setup

Module session_setup 

Source
Expand description

Shared bootstrap for outrig run and (future) outrig mcp. Lifts the sequence of “load + merge config -> resolve container -> ensure image -> start + bootstrap container -> session row + log dir” out of run so both subcommands hit the same code path.

Three pieces:

  • setup – everything from config-load through “container started + bootstrapped + session row + log dir created”, returning a populated SessionSetup. Stops before MCP children connect.
  • merged_mcp + connect_mcp_clients – reads any image-embedded MCP config, applies repo-config overrides, and spawns one McpClient per merged backing MCP in BTreeMap (key-sorted, deterministic) iteration order. Adapter construction stays in the caller because only the REPL path consumes adapters.
  • teardown – mirror of the cleanup tail: graceful MCP shutdowns (drop adapters first so Arc::try_unwrap succeeds), then stop the container, then finalize the session row. Errors are logged and never override the caller’s outcome.

The MCP children are podman exec processes whose stdio rides through the container; tearing the container down before shutting them down races their pipes, so the order in teardown is load-bearing.

Structs§

SessionSetup
Output of setup: every long-lived value the post-setup pipeline needs (REPL build, MCP children, teardown). The container is already started + bootstrapped; the session row is already on disk.
SessionSetupArgs
Inputs to setup. Borrowed to keep the call site cheap; the lifetime is the caller’s stack frame.

Functions§

connect_mcp_clients
Spawn one McpClient per backing MCP declared in mcp, in key-sorted (BTreeMap) iteration order. cli_env provides any --env overlay entries to merge per server. Adapter construction is the caller’s job because only the REPL path consumes adapters.
merged_mcp
Read image-embedded MCP config and overlay explicit config.toml entries.
setup
Run the shared bootstrap. Returns once the container is up, the runtime user is bootstrapped, and the session directory + log dir exist.
teardown
Cleanup tail. Order: MCP shutdowns (so their podman exec pipes drain before the container goes away) -> container stop -> session finalize. Each step’s failure is logged but never propagated; the caller’s outcome owns the process exit code.