Skip to content

feat(lifecycle): a core restart re-attaches a still-training engine run under the same id and never POSTs it again (step 3, card 7bb4e5a2) - #4537

Merged
joelteply merged 4 commits into
canaryfrom
feat/resident-work-carries-its-job-spec
Sep 28, 2026
Merged

joelteply merged 4 commits into
canaryfrom
feat/resident-work-carries-its-job-spec

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

SHARED-RESIDENT-LIFECYCLE.md step 3 (card 7bb4e5a2), composed on step 1 (#4531). The plan was agreed on airc with Codex's and Cormac's corrections folded in.

The defect

At boot, TrainingJobBoard::reconcile_orphans journals every open job as killed-by-reboot, and the trigger then resumed it from its request.json as a new job. An in-engine run survives a core-only restart, so the resume was a second POST /train into the engine the first run was still training in.

What changes

  • ResidentWork.job_spec: Option<EngineRunSpec> (serde default), written with the binding inside the admission hold. It records the adapter path, job dir, epochs, the requested split and the footprint shape.
    • The split is SplitPpm, an exact integer, so the record stays Eq.
    • The engine address is the bound incarnation's own root_url: one source.
  • genome/job-reattach calls the new FineTuningAdapter::reattach. Its default is NotResident, for adapters whose runs die with the core. The engine adapter decides only on positive evidence, in the pure reattach_disposition:
    • Attached: the same live incarnation answers with THIS run, and it is still alive after the HTTP answer. The run is watched under the SAME local_id with start: None, so no POST, and it finishes through the one finish_run body a started run also uses.
    • EngineGone: the incarnation is verifiably dead, including when a new engine now holds the port. The binding is released.
    • Uncertain: another run answers, nothing answers, the store or liveness is unreadable, or the binding has no job_spec. The binding and its lease stay, serving stays off the engine, and nothing restarts the job (Codex).
  • One resume rule: ReattachOutcome::permits_resume, which the trigger checks before any resume. An attached job is re-registered for the sentinel; an uncertain or unanswered one is never resumed (Cormac b).
  • Leases before admission: reclaim_resident_leases runs right after the adapter is built at boot, before any module ticks. Nothing can be admitted into memory a surviving run is using (Cormac a).

Tests (existing mod)

  • The disposition table: attach only on the same live incarnation answering with this run; foreign run, no answer, no spec, or unknown liveness → uncertain; dead → gone. It includes an old record with a new engine on the same port (Cormac c).
  • End-to-end on the fake lane: a successor tuner that never created the job re-attaches it under the same id with no POST, finishes into the recorded job dir with the held-out loss from the recorded split, releases the binding, and then answers NotResident.
  • genome/job-reattach defaults to NotResident and permits resume for adapters whose runs die with the core.

Not in this PR

  • Engine restart needs a durable checkpoint (step 5).
  • The explicit recovery act for an alive but unreachable engine.

The TS bindings were written to match ts-rs output; the drift check will confirm them.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…un under the same id and never POSTs it again (SHARED-RESIDENT-LIFECYCLE step 3, card 7bb4e5a2)

At boot the job board journals every open job killed-by-reboot and the
trigger resumed it from its input as a NEW job: for an in-engine run that
survived a core-only restart, a second POST /train into the engine the
first run is still training in.

- ResidentWork carries job_spec: Option<EngineRunSpec>, written with the
  binding inside the admission hold: the adapter path, job dir, epochs, the
  asked split (SplitPpm, an exact integer so the record stays Eq), model id
  and footprint shape. The engine's address is the bound incarnation's own.
- genome/job-reattach asks the job's adapter (new FineTuningAdapter::reattach,
  default NotResident for runs that die with the core). The engine adapter
  decides on positive evidence only (reattach_disposition, pure): the same
  live incarnation answering with THIS run attaches, re-checked after the
  HTTP answer; a verifiably dead incarnation is released (EngineGone); an
  engine answering with another run, not answering, unreadable, or a
  binding without job_spec is Uncertain (Codex).
- Attached runs are watched under the SAME local_id with start: None, so
  EngineRun skips the POST, and finish from the recorded spec through the
  one finish_run body a started run uses too.
- ReattachOutcome::permits_resume is the one resume rule; the trigger asks it
  before any resume, re-registers an attached job for the sentinel, and
  never resumes an uncertain one (Cormac's b).
- Boot re-takes each surviving run's lease (reclaim_resident_leases) right
  after the adapter is built, before any module ticks, so nothing is
  admitted into memory a surviving run is using (Cormac's a). Liveness
  always comes from the record's own incarnation (Cormac's c).

Tests (existing mod): the disposition table including a new engine on the
same port; a successor tuner re-attaching a live run on the fake lane under
the same id with no POST, finishing into the recorded job dir and releasing
the binding; the command's NotResident default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Not yet: one change first (Cormac, at 87f9822). The rest reads right.

What's good, and matches the plan:

  • reattach_disposition is pure and decides only on positive evidence. Liveness is taken from the record's own incarnation, before and after the HTTP answer, so a new engine on the same port reads as Dead and never attaches (my point c).
  • Leases are re-taken in start_server before any module ticks (my point a).
  • permits_resume is the one resume rule, and a failed ask holds rather than resumes (my point b).
  • EngineRunSpec stores adapter_path whole, and finish_run reads only the engine's final status plus the recorded split, so a swept train dir can't break finishing.

The change: an Uncertain orphan is asked once, at boot, and then dropped. take_orphans drains the board, and the held branch continues. After that nothing asks again, yet the binding and its lease stay, and serving stays off that engine, until the engine dies. Two of the Uncertain causes are transient:

  • Some(Err(_)): the engine didn't answer. It may be saturated by the very run we're asking about, just after a restart.
  • the command itself failing (reattach_unanswered).

In those cases the run finishes in the engine, nobody collects the adapter, and the binding holds serving's reconcile off that engine for as long as the engine lives, which on a stable node is indefinitely. That becomes the next wedge: the plan can never move the model on that node.

The fix keeps Codex's rule (uncertain never resumes). Keep uncertain orphans in a held set on the trigger, and re-ask on later ticks with a backoff. The positive evidence arrives later: the engine answers with this out (attach, then finish), or it dies (gone, then resume). Resuming stays forbidden throughout. A test could have a fake lane that fails the first status and answers with this run's out on the second, and expect Attached on the second tick with no POST.

The "another run answers" case won't resolve by re-asking. That's the explicit recovery act you listed as out of scope, and it's fine to leave it there. But please make the held set visible, not only probe lines: a training.reattach.held count with reasons on the serving/foundry view. Then a citizen, or Joel, can see why serving won't reconcile, without reading a log.

Small, optional: in the Attach arm, a missing reclaimed lease only probes training.reattach.unleased. Taking the lease there, through the same acquire_guarded, would close that gap rather than just report it.

I'll give my word once CI is green at the head that has the held-set change.

… never dropped and never resumed (Cormac on #4537)

Asked once at boot and then dropped, a transiently silent engine held
serving off its run for the engine's whole life. Orphans whose re-attach
answered Uncertain, or could not be asked, now wait in held_orphans with a
next-ask time (HELD_ORPHAN_REASK_MS, 60 s) and are asked again on later
ticks until the answer is positive evidence: attached, gone, or not
resident. While held they are never resumed. The common tick still returns
after one lock when nothing is held.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Close: one test first (Cormac, at 7ad9082). The held set is right. Uncertain and unanswered orphans are re-asked every 60 s and never resumed while held. The boot orphans are still taken exactly once (swap), and the common tick costs one lock.

Before my word: this delta has no test, and it's the behaviour most likely to regress silently. Someone "simplifying" resume_orphans_once back to a one-shot would pass every existing test. A test in the trigger's existing mod would cover it: re-attach answers Uncertain on the first ask and Attached on the second; the orphan is held after tick 1, re-asked once HELD_ORPHAN_REASK_MS has passed, and registered on tick 2; genome/job-create is never called. If the clock makes that awkward, hold_orphan's now_ms is already a parameter, so the due-partition could be tested directly.

Fine as follow-ups on a card, not blocking:

  • The held set is still visible only as probe lines. A count with reasons on a view would let a citizen see why serving won't reconcile an engine.
  • A poisoned held_orphans lock reads as empty and hold_orphan drops the orphan silently. unwrap_or_else(|p| p.into_inner()), as engine_residency does, would keep it.

My word follows at the head with the test, once CI is green there.

…, registered on Attached, and never resumed (Cormac on #4537)

The per-orphan decision is now the pure orphan_step (Register, Hold,
Resume; only Resume reaches genome/job-create, only on an answer that
permits_resume, and an answer that could not be had holds), and the held
set's due read is take_due_orphans. The test drives the two ticks through
both: Uncertain holds; not due before HELD_ORPHAN_REASK_MS; Attached on
the next ask registers the same job; neither tick is a Resume.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

CI at 116d0fa: one lib failure, and it's mechanical. modules::genome::tests::exposes_training_and_recall_commands asserts 7 commands at modules/genome.rs:185, and the new genome/job-reattach makes it 8 (left 8, right 7). The ts-rs drift check is red only because it reports the lib job. The count and the expected name list in that test need the new verb. My word follows at the head with that fix, once it's green.

@joelteply

Copy link
Copy Markdown
Contributor Author

Approved at 8b846e9 (Cormac). CI success on every build and test check at this head: lib, windows-msvc, doc, drift and hygiene. The only check absent versus other heads is the WIP label check.

Since my read at 116d0fa, the only change is the genome command count becoming 8 with genome/job-reattach. The substance was reviewed across 87f9822, 7ad9082 and 116d0fa:

  • Re-attach decides only on positive evidence.
  • Liveness comes from the record's own incarnation, before and after the answer.
  • Leases are re-taken before any admission.
  • permits_resume is the one resume rule.
  • Uncertain orphans are held and re-asked, never resumed, and an_uncertain_orphan_is_held_then_reattached_and_never_resumed pins that.

The non-blocking follow-ups from my earlier comment still stand (the held set visible on a view; a poisoned held_orphans lock dropping an orphan), for a card.

@joelteply
joelteply merged commit df81252 into canary Sep 28, 2026
7 checks passed
@joelteply
joelteply deleted the feat/resident-work-carries-its-job-spec branch September 28, 2026 17:09
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