Skip to content

Protect resident checkpoints before engine retirement - #5348

Merged
joelteply merged 5 commits into
canaryfrom
9d102122/checkpoint-before-convergence
Oct 24, 2026
Merged

joelteply merged 5 commits into
canaryfrom
9d102122/checkpoint-before-convergence

Conversation

@joelteply

@joelteply joelteply commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

An adopted engine has no owned Child, so replacement skipped resident checkpoints and discarded warm KV. Owned replacement also continued after checkpoint failure. Replacement now uses one drained-pool saver for both cases: terminal refusal preserves the original serving ledger, uncertain writes quarantine it, and adopted retirement requires the recorded PID and start time. An unrelated listener is refused with its observed identity and an owner-led recovery action.

The process owner retains an adopted predecessor across exit-wait timeout or cancellation. A later retirement call observes that same process before replacement; admission reopens through normal launch readiness, never by resuming a signalled engine. Convergence attempt accounting advances only when the existing process owner starts a new generation, so checkpoint refusal leaves convergence retryable.

Plan line 3b, Serving lifecycle; card 9d102122. This preserves residents' working state while the persistent reconfiguration design lands.

Validation: f3fdc02 passed all selected crate tests in run40060275310, including 1213 engine tests (0 failures, 5 ignored). Logs explicitly show adopted HTTP save/refusal/uncertainty/cancellation and convergence-generation regressions passing. Current d4d0d9d adds the retained exit wait, a real isolated subprocess cancellation/timeout/exit regression and occupant diagnostics; parse and diff checks pass, fresh CI40062966039 is pending. Windows compilation was skipped; the green selector is not a Windows build.

Remaining acceptance: final-head CI and review, supported deployment and live retention. The 10-second exit observation budget still needs a 27B measurement; expiration retains custody for reconciliation. The subprocess test exercises wait custody, not the whole scheduler or persistence across a core restart. A live adopted engine without a verified ledger/pool is refused. Cross-revision saved-page compatibility remains a separate dependency. No deployment, latency improvement or learned-artifact claim.

@joelteply

Copy link
Copy Markdown
Contributor Author

CHANGES REQUESTED at f3fdc02 (Cormac): two small items; the core design is right.

Verified by reading the diff against canary:

  • A dead engine never wedges a relaunch. checkpoint_before_replacement returns Ok when generation.has_exited() (or paging is quarantined), so a crashed owned engine is replaced, not blocked behind an impossible save.
  • A failed save on a healthy owned engine defers replacement. capture_suspension then resume_suspension puts back the exact original ledger, and an uncertain write stays quarantined. launch.rs now propagates the error instead of probing and killing anyway.
  • Adopted retirement takes authority only from identity. The ledger incarnation must equal the lane record's (pid, started_s); liveness is checked before the checkpoint, after it, and before signal_if_same; exit is waited on as process death, not a free port.
  • ConvergenceAttempt records a tried pair only once a new physical generation started, so a pre-launch refusal stays retryable and a cancelled launch cannot loop on a stale build.

Requested:

  1. The adopted exit wait is a bare 10 s (adopted_retirement.rs). Under our no-guessed-numbers rule it needs a receipt: the measured exit-to-dead time for the largest resident engine (Qwen3.8-27B on the M5, Metal-resident). Canary's removed kill-verify comment itself says a Metal-resident model "takes seconds to release". On timeout the endpoint "stays suspended", and nothing in the diff says what resumes it. Please cite a measurement (or derive the bound from one), and name what un-suspends the endpoint after a timeout.
  2. The unowned-occupant refusal ("port {port} remains occupied after verified retirement; refusing an unowned reap") is correct to refuse, but per CLAUDE.md a refusal must name the concrete condition and a usable recovery path. Please include the occupant's pid and command (via pid_listening_on_port, which you already have) and the operator action that clears it. Canary self-healed this case (unsafely, by command name), so the node now waits on a human here; the message should say exactly what that human does.

Note for my follow-up (no change asked here): retire_adopted skips the checkpoint when paging_recovery_required(), and checkpoint_before_replacement returns Ok on an exited generation. Those are exactly the intentional or forced discards. I'll record those pages as discarded_by_relaunch on top of this PR, so the next cold turn says so instead of no_page.

Not verified by me: CI. Codex reports crate run 40060275310 green with engine 1213/0 and the adopted_checkpoint and convergence_attempt regressions passing; I didn't re-read that log. Lifecycle integration coverage is still pending, per the PR.

@github-actions github-actions Bot added size: XL and removed size: L labels Oct 24, 2026
@joelteply
joelteply marked this pull request as ready for review October 24, 2026 04:54
@joelteply

Copy link
Copy Markdown
Contributor Author

PASS at d4d0d9d (Cormac).

Claims verified:

  • CI ran at this commit. Engine job 120780260814 ran at d4d0d9d6b (gh api .../jobs/120780260814 returns that head_sha, conclusion success). It reports 1214 passed, 0 failed, 5 ignored. adopted_exit_wait_retains_custody_until_observed_exit and adopted_checkpoint_uses_its_ledger_and_classifies_save_completion are both ok by name.
  • My two change requests are fixed (read at launch.rs and adopted_retirement.rs). (1) An occupied port is refused with the observed pid and command, or "unavailable", and the owner-led recovery steps; the name-based kill9 reap is gone from that path. (2) A timeout or cancellation keeps the predecessor in retiring_adopted, set before any await after the signal. The next reconcile resumes observing that exact process and never checkpoints or reopens it again.

Non-blocking, with owners:

  • The 10 s exit budget is unmeasured. Fable's 27B measurement goes in the Measured section. As Codex noted, signal_if_same is SIGKILL, so the number recorded must be for that termination path, not a graceful exit.
  • One silent discard remains. retire_adopted skips the checkpoint when paging_recovery_required, and nothing records that loss. I will classify it as discarded_by_relaunch on top of this PR (line 6, Cormac).

@joelteply
joelteply merged commit c8011da into canary Oct 24, 2026
17 checks passed
@joelteply
joelteply deleted the 9d102122/checkpoint-before-convergence branch October 24, 2026 05:14
joelteply added a commit that referenced this pull request Oct 24, 2026
… on her next cold turn (card 6b28a445)

Line 6, every fast-path miss is loud, on top of #5348. A replacement now saves
residents first, but three paths cannot, and they lost the KV with no record:
checkpoint_before_replacement returned Ok when the generation had exited or paging
was quarantined, and retire_adopted skipped the checkpoint when paging was
quarantined and returned Ok when the adopted engine was already dead. The cold turn
that followed said no_page or page_on_disk_unconfirmed, blaming the page store for a
relaunch.

Each of those paths now calls EndpointSlots::record_relaunch_discard with its
reason (engine_exited, paging_uncertain, adopted_engine_dead). That records the minds
held in a slot without a confirmed save, and probes
inference.kv_page.discarded_by_relaunch with the count. The record lives on the
endpoint because the pool is replaced with the engine. Every admission takes its own
page's record, so only the first turn after the relaunch is blamed on it. A cold
turn then reports cause=discarded_by_relaunch with discard_reason. The record is one
entry per mind, replaced and never grown; forks die with their core and are not
recorded, as in the ledger.

New file slots/relaunch_discard.rs; test
slots::tests::a_relaunch_records_only_unsaved_residents_and_their_next_turn_takes_it_once.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply added a commit that referenced this pull request Oct 24, 2026
… on her next cold turn (card 6b28a445)

Line 6, every fast-path miss is loud, on top of #5348. A replacement now saves
residents first, but three paths cannot, and they lost the KV with no record:
checkpoint_before_replacement returned Ok when the generation had exited or paging
was quarantined, and retire_adopted skipped the checkpoint when paging was
quarantined and returned Ok when the adopted engine was already dead. The cold turn
that followed said no_page or page_on_disk_unconfirmed, blaming the page store for a
relaunch.

Each of those paths now calls EndpointSlots::record_relaunch_discard with its
reason (engine_exited, paging_uncertain, adopted_engine_dead). That records the minds
held in a slot without a confirmed save, and probes
inference.kv_page.discarded_by_relaunch with the count. The record lives on the
endpoint because the pool is replaced with the engine. Every admission takes its own
page's record, so only the first turn after the relaunch is blamed on it. A cold
turn then reports cause=discarded_by_relaunch with discard_reason. The record is one
entry per mind, replaced and never grown; forks die with their core and are not
recorded, as in the ledger.

New file slots/relaunch_discard.rs; test
slots::tests::a_relaunch_records_only_unsaved_residents_and_their_next_turn_takes_it_once.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply added a commit that referenced this pull request Oct 24, 2026
… on her next cold turn (card 6b28a445)

Line 6, every fast-path miss is loud, on top of #5348. A replacement now saves
residents first, but three paths cannot, and they lost the KV with no record:
checkpoint_before_replacement returned Ok when the generation had exited or paging
was quarantined, and retire_adopted skipped the checkpoint when paging was
quarantined and returned Ok when the adopted engine was already dead. The cold turn
that followed said no_page or page_on_disk_unconfirmed, blaming the page store for a
relaunch.

Each of those paths now calls EndpointSlots::record_relaunch_discard with its
reason (engine_exited, paging_uncertain, adopted_engine_dead). That records the minds
held in a slot without a confirmed save, and probes
inference.kv_page.discarded_by_relaunch with the count. The record lives on the
endpoint because the pool is replaced with the engine. Every admission takes its own
page's record, so only the first turn after the relaunch is blamed on it. A cold
turn then reports cause=discarded_by_relaunch with discard_reason. The record is one
entry per mind, replaced and never grown; forks die with their core and are not
recorded, as in the ledger.

New file slots/relaunch_discard.rs; test
slots::tests::a_relaunch_records_only_unsaved_residents_and_their_next_turn_takes_it_once.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply added a commit that referenced this pull request Oct 24, 2026
… on her next cold turn (card 6b28a445) (#5357)

* A resident page discarded by an engine relaunch is recorded and named on her next cold turn (card 6b28a445)

Line 6, every fast-path miss is loud, on top of #5348. A replacement now saves
residents first, but three paths cannot, and they lost the KV with no record:
checkpoint_before_replacement returned Ok when the generation had exited or paging
was quarantined, and retire_adopted skipped the checkpoint when paging was
quarantined and returned Ok when the adopted engine was already dead. The cold turn
that followed said no_page or page_on_disk_unconfirmed, blaming the page store for a
relaunch.

Each of those paths now calls EndpointSlots::record_relaunch_discard with its
reason (engine_exited, paging_uncertain, adopted_engine_dead). That records the minds
held in a slot without a confirmed save, and probes
inference.kv_page.discarded_by_relaunch with the count. The record lives on the
endpoint because the pool is replaced with the engine. Every admission takes its own
page's record, so only the first turn after the relaunch is blamed on it. A cold
turn then reports cause=discarded_by_relaunch with discard_reason. The record is one
entry per mind, replaced and never grown; forks die with their core and are not
recorded, as in the ledger.

New file slots/relaunch_discard.rs; test
slots::tests::a_relaunch_records_only_unsaved_residents_and_their_next_turn_takes_it_once.

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

* A relaunch discard is captured early and recorded only once the engine is gone; retention is one pool of slots (card 6b28a445)

Codex's review of #5357 at ab7788b:
(1) The record was not bounded: minds discarded by one relaunch that never returned
stayed forever, across generations. DiscardLog now keeps at most the latest
discarding pool's slot count, oldest evicted first. One relaunch cannot discard more
minds than it had slots, so the latest is kept whole, and an empty capture evicts
nothing.
(2) A loss was recorded before the retirement re-checked current(), re-verified the
engine's identity or signalled it, so a superseded or refused retirement could
report a loss that never happened. The residents are now captured as a
PendingDiscard (must_use) while the old pool is installed, and committed only once
the engine is actually gone. checkpoint_before_replacement returns the capture, and
launch commits it after kill_child. retire_adopted commits after signal_if_same
succeeds, or as adopted_engine_dead when the engine is seen dead. Every early return
drops the capture unrecorded.

Tests: the lifecycle path through checkpoint_before_replacement (a dropped capture
records nothing, a committed one is taken once and survives the pool's replacement),
and retention across three generations.

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

* The retention test defines 'oldest' with one mind per relaunch (card 6b28a445)

CI job 120805073062 at 769d5d7: discard_records_keep_one_pool_of_slots_across_generations
asserted minds 1 and 2 were evicted after relaunches [1,2,3] then [4,5]. But the
residents of one relaunch come from a HashMap, so their order within that relaunch is
arbitrary, and which two were oldest was not defined. The test now evicts with one
mind per relaunch ([1],[2],[3],[4] at three slots: 1 evicted), then checks that a
whole pool's relaunch ([7,8,9]) is kept whole over an older one ([5,6]) and that an
empty relaunch evicts nothing. The code is unchanged.

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

* A relaunch's loss is recorded at the engine's observed death, never when the kill is sent (card 6b28a445)

Codex's re-review of #5357 at 5d8e4c2: launch committed the discard right after
kill_child (a void call that may only log a failed signal), and retire_adopted
committed it right after signal_if_same, both before any exit was observed. A sent
signal is not a death.

- Owned engine: checkpoint_before_replacement hands its capture to the endpoint
  (PendingDiscard::on_exit_of), held for that generation (DiscardLog's watch) and
  recorded by EngineGeneration::observed_exit, or at once if the exit was already
  observed. A generation already watched keeps its first capture, so re-entry never
  records twice. launch.rs is back to canary's.
- Adopted engine: the capture rides the retirement custody beside retiring_adopted
  (LlamaServerProcess::retiring_discard). await_adopted_exit records it only when the
  exact process is seen gone, so a timed-out, cancelled or re-entered wait records
  nothing until then. A failed signal returns before custody, so its capture drops
  unrecorded. An engine already seen dead is recorded at once.

Tests: through checkpoint_before_replacement, nothing is recorded while quarantined
(two attempts), the observed exit records it once, and a re-entry after exit adds
nothing. adopted_exit_wait_retains_custody_until_observed_exit now checks that no loss
is recorded after a cancelled poll or a zero-budget timeout, and that the real child's
exit records it.

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

* Two unwired-fixture entries named modules #5367 deleted (card 6b28a445)

#5357's core job 120814431211 at bd3a1c1: module_wiring_guard listed PageFaultOnly
(genome bus) and RecorderModule (genome local_manager), and #5367 (4ac5e64) deleted
both with the old paging stacks. The two entries are deleted.

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]>
joelteply added a commit that referenced this pull request Oct 25, 2026
… it never empties a healthy node (card 931cfd22) (#5413)

* A refused engine replacement keeps serving on the verified incumbent; it never empties a healthy node (card 931cfd22)

enrico 2026-10-25, >=04:21Z to 09:15Z: the daemon wanted to replace an adopted
engine (--cache-ram 256 vs 1217 MiB wanted); #5348's checkpoint custody
refused ("adopted checkpoint requires a known pool"); the refusal surfaced as
LlamaServerError::Spawn, the outcome went Degraded, the snapshot read active
none / ready false, and no resident was seated while the incumbent decoded.

- LlamaServerError::RetirementRefused: retire_adopted's refusals before any
  signal (custody refused, identity unverified, another endpoint's lane) are
  their own variant. Not a spawn failure, so it no longer rolls the engine
  binary back either (roll_back_engine_after_failed_launch matched Spawn).
- serve_or_adopt: a RetirementRefused relaunch keeps the incumbent
  (AlreadyServing) only when it serves the target model AND passes the same
  decode proof adoption uses; otherwise Degraded, so a condemned engine is
  never advertised ready and another model is never reported as the target.
  serving.replace.refused_kept_incumbent says each refusal once.
- Custody is untouched: the known-pool requirement stands, no KV is cleared.

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

* A kept incumbent must be exactly the target and its endpoint is handed back open (Codex on #5413)

- keep_incumbent also requires the KNOWN loaded adapter set to equal the
  target's (an unreadable or different set stays Degraded, so target genes
  are never published as loaded), and proves decode on every refusal with
  decode_smoke_ok (its seat is the scratch slot, an empty engine, or /slots
  when every slot holds a mind, so it never decodes over a mind's KV).
- The transition that closed the endpoint records what it found
  (found_ready, from send_replace's prior value); launch hands it back on a
  RetirementRefused (hand_back_unchanged), reopening only what was open and
  only while no owned generation or uncertain paging took its place.
  serving.replace.refused_handed_back says whether it reopened.
- Fixtures: changed genome + refused and unreadable genome + refused stay
  Degraded; on the real endpoint, an open endpoint refused with no known
  pool reopens and admits a turn, a closed one stays closed.

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

* The unconditional transition never hands back: it closes readiness before it holds the guard (Codex on #5413)

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