Skip to content

An engine's stderr is read by a relay in its own process group, so a core restart keeps its log and fault watchers (card 1d7d6d4c, part b) - #5536

Merged
joelteply merged 6 commits into
canaryfrom
68914f75/an-engine-s-stderr-relay-in-its-own-proc
Oct 27, 2026
Merged

joelteply merged 6 commits into
canaryfrom
68914f75/an-engine-s-stderr-relay-in-its-own-proc

Conversation

@joelteply

@joelteply joelteply commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Why this serves the minds

An engine adopted across a core restart had no reader for its stderr. On enrico on 2026-10-27, engine-c ran from 03:35Z to 10:44Z with no log, and its stall at 08:27Z could not be read. The wedge, offload-placement and debug-build watchers were blind to every adopted engine, and its silence clock read as unknown. This advances plan line 3b (one live engine, never relaunched to be understood) and the S2 detector's evidence (#5528).

Part (a), the relay and its socket protocol, merged as #5533. This is part (b): launch switches to the relay.

What changes

Spawn order (plan agreed with Codex on airc, 10-27):

  1. The engine spawns as today with process_group(0). PGID stays the engine pid, so every existing stop, reap and orphan-sweep path is unchanged. The one group signal on an engine is kill_pid_tree's kill(-pid) (bin/continuum/processes.rs:428), and it now also takes the engine's relay.
  2. The relay spawns second, inside the engine's group, with the engine's stderr as its stdin. The relay is the core binary in --log-relay <port> <pid> <start_s> mode, dispatched first in main before config, tracing or sockets.
  3. The relay names the engine from those arguments, so the merged control-handle bind (read_bind, binds_refused) is deleted.

Followers:

  • The core follows each engine's relay (stderr_relay::follow), whether it spawned the engine or adopted it. ensure_model_serving_if_current calls follow_engine_log on every AlreadyServing; following is deduplicated per incarnation.
  • Lines go through the same watch chain as before (wedge, offload banner, debug build). The chain moved from launch into stderr_sink::stderr_watch, its one owner.
  • The relay's heartbeats keep child_log's per-pid silence clock, which exists only while a current heartbeat names that incarnation. A drop guard retires the clock when the follower ends, including on abort, so engine_stall is unchanged.

Startup lines: the relay holds the lines from before its first subscriber (bounded by Config::queue, overflow counted) and delivers them once to that subscriber, the spawning core. Without this, the offload banner (#441 readback) and the debug-build announcement would be printed before anyone subscribed, and both gates would go blind. Later subscribers start at the next line and never get a replay.

Failure is loud, with no fallback (readiness added after Codex's review of 9ef5cf0):

  • A relay counts only once it serves this engine. The spawning core waits, within a 10 s ceiling, for a connection whose opening heartbeat names this incarnation (follow::ready). That connection is also the relay's first subscription, so the held startup lines go to it and the follower keeps reading it.
  • The launch fails when:
    • the relay exits first (a failed bind, a path it cannot own);
    • the endpoint answers for another engine;
    • the time passes;
    • the start time is unreadable;
    • the spawn or setpgid fails.
  • On failure the relay is killed and reaped, and the engine is killed and reaped through the existing retire path (kill_child → retire_page_owner → collect_exited).
  • A launch cancelled during that wait still reaps and follows the relay through a drop guard (Pending), since the engine it reads is owned and may serve on.
  • A host with no home directory now fails the launch where it used to serve unlogged.

OS seam: new continuum-host::output_handoff. On unix it hands the pipe to a reader in the writer's group. On Windows it returns the stderr (Handoff::Kept), and launch drains it with the in-core pump as before. Launch holds no OS branch. stderr_relay::Incarnation is replaced by engine_residency::EngineIncarnation, so there is one owner of the type.

Spawn ratchet: the relay's Command::new lives in continuum-host, which the hygiene scan does not cover. Spawning the reader is that seam's capability, so it belongs there. I'm stating this so a reviewer can judge it; it is not a reduction in spawn sites.

Tests (worktree, macOS x86_64, at 9ef5cf0's tree)

  • continuum-host: the_reader_joins_the_writers_group_reads_every_line_and_ends_with_it. A real sh writer and cat reader: ps -o pgid= of the reader equals the writer pid, every line arrives, and the reader exits on EOF once the writer exits.
  • stderr_relay::follow::a_restarted_follower_picks_up_the_relay_and_its_silence_lives_only_with_it:
    • one follower per incarnation;
    • an aborted follower takes its clock with it;
    • a restarted follower gets only lines after it;
    • the clock goes when the relay ends.
  • This fixture caught a real self-deadlock before commit: then_some built the claim guard eagerly, and the guard's Drop re-took the lock it was dropped under. A process sample showed the thread parked at follow.rs:50 → :56. Fixed with then, with the lock released first.
  • stderr_relay::follow::a_relay_that_exits_before_serving_is_refused and an_endpoint_answering_for_another_engine_is_refused_and_a_matching_one_is_followed (the readiness handshake; 87 passed at b3fdabd).
  • stderr_relay::tests::the_first_subscriber_gets_the_banner_and_later_ones_never_a_replay (replaces the old nobody-connected test), plus the existing relay tests adapted. stderr_relay::process: the arguments round-trip and malformed ones are refused.
  • Run: cargo test -j 1 -p continuum-engine --features metal --lib -- stderr_relay child_log llama_server::tests gave 85 passed, 0 failed. The host run gave 1 passed. cargo check --lib of host and engine raised no new warnings. ratchets -- origin/canary passed 68/68, exit 0.
  • Not run locally: continuum-core (main.rs dispatch) and the Windows build. CI compiles both.

Measured after deploy (owner: Cormac, deadline: the first enrico deploy carrying this)

On enrico after deploy:

  • ps -o pid,pgid,command shows each llama-server with a continuum-core-server --log-relay in its group;
  • after a continuum reboot that adopts the engine, new engine lines still reach ~/.continuum/logs/llama-server-<port>.log, and the adopting core's child_log::silent_ms is Some;
  • no serving.llama.relay_ended probe in the 15 minutes after deploy.

Card 68914f75 stays open until that receipt is posted.

Removed / added

17 files, +583 / −154. Removed: the control-handle bind and binds_refused, launch's inline watch chain and drain match, and the duplicate Incarnation type.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

…core restart keeps its log and fault watchers (card 1d7d6d4c, part b)

The engine is spawned first, as before (process_group(0)); its relay, the core
binary in `--log-relay` mode, is spawned second, inside the engine's group, with
the engine's stderr as its stdin. PGID stays the engine pid, so every existing
stop, reap and orphan-sweep path is unchanged; a group kill of the engine takes
its relay. The relay names the engine from arguments the spawning core passes,
so the merged control-handle bind is deleted.

The core follows each engine's relay, spawned or adopted alike: every line goes
through the same watch chain (wedge, offload banner, debug build), and its
heartbeats keep the engine's silence clock, which exists only while a current
heartbeat names that incarnation. The relay holds the lines from before its
first subscriber (the spawning core) so the load banner still reaches the
placement and debug-build gates; later subscribers never get a replay.

A relay that cannot start fails the launch and the engine is killed and reaped
through the existing retire path: no in-core fallback. Windows keeps the
in-core pump; the choice lives in continuum-host::output_handoff, so launch
holds no OS branch. The relay's stderr::Incarnation is replaced by
engine_residency::EngineIncarnation (one owner).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply and others added 5 commits October 27, 2026 13:57
…matched readiness before launch accepts it (Codex on #5536)

attach took a successful OS spawn as readiness, so a relay that failed its bind
left the engine serving with nobody reading it. Now the spawning core waits,
within a 10 s ceiling, for a connection whose opening heartbeat names this
engine's incarnation. That connection is the relay's first subscription, so it
is also where the held startup lines go, and the follower keeps reading it. A
relay that exits first, an endpoint answering for another engine, or the time
passing fails the launch; the relay is killed and reaped, and launch kills and
reaps the engine as before. A launch cancelled while it waits still reaps and
follows the relay through a drop guard, since the engine it reads is owned.

Tests: a relay exiting before it serves is refused; an endpoint for another
incarnation is refused, and a matching one delivers the held banner to the
follower.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…the connect too; custody never waits (Codex on #5536)

- reap awaited a relay's exit on a spawn_blocking thread, and a runtime drop waits
  for running blocking tasks: with any engine alive the core could not shut down.
  The relay is now a tokio child (continuum-host::output_handoff hands one back)
  whose exit is an ordinary task, dropped at shutdown; the relay outlives the core
  by design and is then init's to reap. Test: a runtime with a live, reaped relay
  shuts down within 5 s (proven by mutation: the blocking reap fails it at 5.02 s).
- follow::ready awaited the connect outside its deadline; the connect and the
  opening heartbeat now share it. Test: an endpoint that accepts into its backlog
  and never speaks is refused at a 300 ms bound.
- local_stream custody took a blocking lock(); it now try_locks and refuses
  AddrInUse at once when another binder holds it.
- Tests that spawn processes are unix-only, and each live-engine test runs its own
  stand-in engine process, so silence clocks keyed by pid never cross tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…o the engine's group, readiness, core exit and re-follow (Codex's gate on #5536)

continuum-core/tests/log_relay_e2e.rs drives `continuum-core-server --log-relay`
(CARGO_BIN_EXE) for a stand-in engine (sh writing a banner then a line every
100 ms, in its own process group):
- the relay's pgid is the engine's pid;
- follow::ready proves it serves this incarnation, and the spawning core's
  follower gets the held banner first, then lines, and keeps the silence clock;
- the core exits (its follower task ends): the clock goes with it;
- a restarted core follows the same relay through the adoption path
  (follow::follow): new lines and a clock, never the banner replayed;
- the archive under HOME holds the engine's lines from the first;
- the engine is killed and the relay ends cleanly within 10 s.

CI runs it in the existing core integration step beside capability_grant_e2e,
one cargo invocation sharing that build. follow_ready returns its follower's task
(as follow_at does) so a test can end it the way a core exit does.

Not run locally: continuum-core is CI's on this node (a resident host).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…or custody, then is refused (Linux CI on #5536)

The immediate try_lock refusal (ac5d370) dropped the serialization #5533's
concurrent_binders_of_a_stale_endpoint_leave_exactly_one_owner pins: on Linux CI
all 8 concurrent binders of a stale endpoint were refused and none owned it
(job 122423021477). Codex's ask was a bounded wait, not no wait: custody now
polls try_lock every 2 ms until a 2 s ceiling, so binders of one stale endpoint
still take turns (exactly one reclaims), and a holder that never releases leaves
the binder refused AddrInUse rather than blocked.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…nother test's socket into the child (14/60 host lib runs)

a_live_owner_is_refused_and_an_old_cleanup_spares_its_successor failed on Linux
CI (job 122427234721) and locally in 14 of 60 runs of the continuum-host lib
tests, always "a stale endpoint ... is served by a live owner": its dropped
listener still answered. Without the output-handoff test (which forks sh and
cat) it failed 0 of 60, and 0 of 60 single-threaded: a fork landing while
another test creates a socket carries it into the child (on macOS close-on-exec
is set after the socket exists), so a gone server's endpoint stays served for
the child's life. Production is not exposed this way: only the relay binds
these listeners, and it forks nothing.

The fork test moves to continuum-host/tests/output_handoff.rs (its own process),
and CI runs it in a continuum-host step. After the move: lib tests 0/60, the
moved test passes; the engine's relay tests, whose forks share a binary with
their listeners, failed 0 of 40 stress runs.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply merged commit d85388c into canary Oct 27, 2026
33 checks passed
@joelteply
joelteply deleted the 68914f75/an-engine-s-stderr-relay-in-its-own-proc branch October 27, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant