Skip to content

A KV page switch the engine never answers is sampled before the engine is replaced (card 3913621a) - #5528

Merged
joelteply merged 3 commits into
canaryfrom
cormac/engine-stall-sample
Oct 27, 2026
Merged

joelteply merged 3 commits into
canaryfrom
cormac/engine-stall-sample

Conversation

@joelteply

@joelteply joelteply commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Why

An engine that stops answering a KV page switch is quarantined and replaced. That's a full cold start for every mind on the node (cache reuse on enrico dropped from 0.80 to about 0.42 after restarts, 2026-10-27). Twice that day, nothing explained why the engine stopped. Plan path step 1 (Fast) and line 6 (every fast-path miss loud): the next hang should name its own cause.

The two hangs on enrico, 2026-10-27, both read from inference.kv_page.action:

  • 08:27Z: mind 18c04c5b, status 0, 90053 ms, on 7d8bff696;
  • 11:25:33Z: mind cf6b4df6, status 0, 90039 ms, on 741b0175b.

Both pins hang, so it isn't the engine version. The 11:25Z engine's own log (llama-server-58057.log) is silent from about 11:15:06Z: task 25's prefill progress stopped at 34%, and task 320 had just launched. Nothing more was written until the replacement at 11:36Z, and serving.llama.log_sink_ended never fired. Whether it was blocked writing its log, waiting on a lock, or still computing, nothing captured.

What

  • continuum_host::stack_sample: the per-OS sampler, chosen at the module boundary and never branched on in logic:
    • macOS: sample <pid> <s> -file <out>;
    • Linux: eu-stack -p <pid>;
    • Windows: none, named as such.
  • inference::engine_stall::capture(root):
    • verifies that the live lane's recorded pid is still llama-server (a dead or reused pid is named, never sampled);
    • samples it for 2 s through bounded_command, so no new spawn site;
    • writes the sample beside the engine's log, keeping the newest 4;
    • reads how long the engine's stderr has been silent.
  • child_log: records each sink's last-line time (silent_ms) and now owns the engine's log path (llama_server_log). launch.rs and process.rs built that path by hand, and both move to it. process.rs's hand-rolled port parse moves to the existing port_of_base_url.
  • turn_admission: an Uncertain page outcome raises inference.kv_page.stall_evidence (silent_ms, the sample path or why there is none) before returning, so before the caller quarantines.

Verified (enrico, 2026-10-27, head 3e875cb)

  • cargo test -p continuum-host --lib stack_sample: 1 passed. Run locally because continuum-host is a leaf crate (-j 1, niced).
  • The macOS sampler with exactly these arguments, by hand: sample <pid of a sleep> 2 -file <out> exited 0 and wrote a full report (process, path, threads).
  • Ratchets against origin/canary: exit 0, all 68 pass. The two new constants carry their derived-or-floor: reasons.
  • Not built locally: continuum-engine (the capture, the prune test, the call site). enrico is serving and IntelMac's builds go to CI, so CI is that compile. I'll post its receipt at this head.

New tests:

  • engine_stall::only_the_newest_samples_are_kept;
  • engine_stall::an_endpoint_with_no_engine_is_named_not_sampled;
  • stack_sample::a_sampler_names_its_process_and_where_the_sample_goes.

Measured after deploy

Owner Cormac: the next status 0 page switch on any node carries inference.kv_page.stall_evidence with a sample file, plus the frame where the engine's threads sit.

Seen, not changed here

child_log's module doc says the drain keeps reading and discards on a write failure, but pump returns on the first write error, which drops the reader. That doesn't stall the engine (it gets EPIPE), but its log and silent_ms would go dark. I'll card it under me rather than widen this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

joelteply added a commit that referenced this pull request Oct 27, 2026
…each child starts its own silence clock (Codex on #5528)

engine_of(root, records, liveness, is_engine), pure: only a lane this node
launched whose record names the root, alive as that exact incarnation (pid and
OS start time) and still an engine, is sampled. A remote or secondary endpoint,
a replaced engine, a reused pid, a legacy record with no start time, or two
live claimants is refused with the reason. A sample is discarded if the
incarnation changed while it ran. child_log keys the last-line clock by the
child's pid and starts a fresh clock per sink, so an engine never inherits a
predecessor's timing and an adopted (undrained) engine reads as unknown.

Fixtures: only_the_engine_that_serves_the_endpoint_is_sampled (remote, other
port, replaced, non-engine pid, legacy record, stale beside live, two live);
a_new_sink_starts_its_own_silence_clock.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@github-actions github-actions Bot added size: L and removed size: M labels Oct 27, 2026
joelteply added a commit that referenced this pull request Oct 27, 2026
…; a sink's clock is retired only if it is still its own (Codex on #5528)

settle(): a sampler that fails, times out or truncates removes its attempt
file (macOS sample writes as it goes), and the directory is pruned on every
outcome, so KEEP bounds failed captures too. child_log retires a pid's clock
when its sink ends, only if the map still holds that sink's clock (Arc
identity), so a replacement that reused the pid keeps its own.

Fixtures: a_failed_sample_leaves_nothing_and_every_attempt_prunes; the clock
test now retires the old clock (replacement kept) and the fresh one (gone).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply and others added 3 commits October 27, 2026 08:58
…e is replaced (card 3913621a)

enrico, 2026-10-27: a page restore got no answer for 90 s twice (08:27Z on
7d8bff696, 11:25Z on 741b0175b). Each ended in quarantine and a cold start for
every mind, with nothing captured, so neither hang could say why. The 11:25Z
engine's own log was silent from about 11:15Z.

- continuum_host::stack_sample: the per-OS sampler, chosen at the module boundary
  (macOS `sample <pid> <s> -file <out>`, Linux `eu-stack -p <pid>`, Windows none).
- inference::engine_stall::capture: verifies the live lane's recorded pid is
  still llama-server, samples it for 2 s through bounded_command (the kernel's one
  spawn path), writes the sample beside the engine's log keeping the newest 4, and
  reads how long the engine's stderr has been silent.
- child_log records each sink's last-line time (silent_ms), and owns the engine's
  log path (llama_server_log); launch.rs and process.rs move to it, and
  process.rs's hand-rolled port parse moves to port_of_base_url.
- turn_admission: an Uncertain page outcome raises inference.kv_page.stall_evidence
  (silent_ms, sample path or why none) before it returns, so before quarantine.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…each child starts its own silence clock (Codex on #5528)

engine_of(root, records, liveness, is_engine), pure: only a lane this node
launched whose record names the root, alive as that exact incarnation (pid and
OS start time) and still an engine, is sampled. A remote or secondary endpoint,
a replaced engine, a reused pid, a legacy record with no start time, or two
live claimants is refused with the reason. A sample is discarded if the
incarnation changed while it ran. child_log keys the last-line clock by the
child's pid and starts a fresh clock per sink, so an engine never inherits a
predecessor's timing and an adopted (undrained) engine reads as unknown.

Fixtures: only_the_engine_that_serves_the_endpoint_is_sampled (remote, other
port, replaced, non-engine pid, legacy record, stale beside live, two live);
a_new_sink_starts_its_own_silence_clock.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…; a sink's clock is retired only if it is still its own (Codex on #5528)

settle(): a sampler that fails, times out or truncates removes its attempt
file (macOS sample writes as it goes), and the directory is pruned on every
outcome, so KEEP bounds failed captures too. child_log retires a pid's clock
when its sink ends, only if the map still holds that sink's clock (Arc
identity), so a replacement that reused the pid keeps its own.

Fixtures: a_failed_sample_leaves_nothing_and_every_attempt_prunes; the clock
test now retires the old clock (replacement kept) and the fresh one (gone).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply force-pushed the cormac/engine-stall-sample branch from a0c73d2 to f3e3da1 Compare October 27, 2026 13:58
@joelteply

Copy link
Copy Markdown
Contributor Author

PASS at f3e3da1. Final rebase changes only the already-reviewed #5530 test synchronization; sampler implementation matches reviewed a0c73d2. Endpoint selection now requires one live recorded engine incarnation, checks identity again after sampling, starts a fresh stderr clock per child and retires it without removing a replacement clock. Failed/partial samples are cleaned and retention is pruned on both outcomes. Regression fixtures cover endpoint mismatch, clock replacement and failed capture retention. Independently verified all checks pass or intentionally skip, including engine, core and grid. This adds bounded diagnostic evidence; it does not establish root-cause resolution of restore stalls or live adoption. Windows has no stack sampler on this path.

@joelteply
joelteply merged commit 29d5090 into canary Oct 27, 2026
31 checks passed
@joelteply
joelteply deleted the cormac/engine-stall-sample branch October 27, 2026 14:38
joelteply added a commit that referenced this pull request Oct 27, 2026
…n or a line is not UTF-8 (card a6481313) (#5532)

* An engine's stderr sink keeps draining when its file cannot be written or a line is not UTF-8 (card a6481313)

child_log's own contract: "If the file cannot be written we keep draining and
discard, and say so once". But pump() returned on the first write or open
error, and lines() returned on the first line that was not UTF-8; either
dropped the engine's stderr reader, so its log and the stall evidence's
silent_ms (#5528) went dark for the rest of its life.

- pump reads lines as bytes and decodes them lossily; only a read error (the
  child's stderr closing) ends it.
- A failed open, write or rotation drops the file, says so once
  (serving.llama.log_sink_degraded), and keeps draining and discarding; it
  tries the file again every REOPEN_AFTER_LINES discarded lines and says when it
  recovers (serving.llama.log_sink_recovered).

Tests (unix): a child writing 4000 non-UTF-8 lines into an unwritable sink runs
to completion and the drain ends with it; non-UTF-8 output is logged with
replacement characters and the lines after it are logged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* A reopened engine log counts the bytes it already holds; an unreadable length counts as full (Codex on #5532)

Reopening after a failure (and after a rotation) set written=0, so repeated
failures and reopens could grow one file past MAX_BYTES. open_counted reads the
file's length on every open; an unreadable length is treated as full, so the
next line rotates. Test: the directory is missing at first, a near-full log
appears while the child pauses, the reopen counts it and rotates, and neither
generation passes the cap.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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