Skip to content

fix(launchd): the rollback waits for the restored core; a stale spawn failure is not this start's - #4681

Merged
joelteply merged 4 commits into
canaryfrom
fix/rollback-waits-for-the-restored-core
Oct 3, 2026
Merged

joelteply merged 4 commits into
canaryfrom
fix/rollback-waits-for-the-restored-core

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

What happened (first live #4668 rollback, M5, 2026-10-03)

  • The tracker deployed c839ac6 using the c01065c CLI.
  • launchd refused the staged build (OS_REASON_CODESIGNING, job state = spawn failed).
  • fix(launchd): a staged core launchd refuses rolls back to the serving build #4668 caught it straight away: it kept the refused binary (continuum-core-server.failed-1791022074399), restored c01065c and kickstarted it.
  • kickstart -k returned an error, so the CLI reported "restored the previous build but the node is DARK" at 10:08:02Z.
  • In that same second launchd started the restored core, and it answered about 30 s later. The node wasn't dark; the verdict was wrong.

Fixes

  1. After restoring, a kickstart error doesn't end the attempt. launchd's KeepAlive may start the restored build anyway, so only the wait for an answering, launchd-owned core decides.
  2. A stale spawn failure no longer counts. Right after a refusal, launchctl print still shows job state = spawn failed from the previous attempt. wait_owned now records launchd's runs count when the wait begins, and treats a spawn failure as final only once runs has moved. An unreadable count isn't evidence, so the wait falls back to its 5-minute ceiling.

Tests

  • New: a_spawn_failure_counts_only_after_launchd_spawned_again (same count, moved count, no baseline, unreadable now).
  • continuum-cli-lifecycle passes 50/50.
  • The CLI change (3 lines in continuum.rs) is left to CI to compile.

Still open

Why launchd refuses a byte-identical, validly signed build at one moment and accepts it at another.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

… failure is not this start's

First live #4668 rollback, M5 2026-10-03 (deploy of c839ac6 by the c01065c CLI):
launchd refused the staged build (OS_REASON_CODESIGNING, spawn failed); the rollback
detected it, kept the refused binary, restored c01065c and kickstarted it. `kickstart -k`
returned an error, and the CLI reported "restored the previous build but the node is DARK"
at 10:08:02Z. In that same second launchd started the restored core, which answered about
30 s later. The verdict was wrong, not the node.

Two causes, two fixes:
- After restoring, a kickstart error no longer ends the attempt: launchd's KeepAlive may
  start the restored build anyway, so only the wait decides.
- wait_owned read `job state = spawn failed` as this start's refusal, but right after a
  refusal that line is the PREVIOUS attempt's. It now records launchd's `runs` at the
  start of the wait and counts a spawn failure only once runs has moved
  (fresh_spawn_attempt). An unreadable count is not evidence; the wait falls back to its
  ceiling.

Test: a_spawn_failure_counts_only_after_launchd_spawned_again. continuum-cli-lifecycle 50/50.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…ild's identity proven

BIGGIEDESK on #4681: answering under launchd is not yet "restored" (#194). After the
restored core answers, restored_build_identity reads the slot binary's embedded build SHA
(binary_build_sha) and the answering core's `ping` buildSha (bounded at 30 s, like
deploy-verify), and the receipt names the SHA only when sha_matches; otherwise it says
the restored core's identity is unproven and why.

cargo check of the continuum bin: clean for this change (the unused install_cli import
warning at line 47 is pre-existing on canary).

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

@joelteply joelteply left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source review of 0bb013e (not a macOS execution): continuing through a restored kickstart error and checking the restored slot SHA against ping are the right corrections.

[P2] Capture the runs baseline before issuing kickstart. wait_owned currently samples runs after kickstart has returned, on both the new-artifact and restored-artifact paths. If the requested spawn is immediately rejected, its incremented runs count becomes the baseline. The new refusal is then treated as stale and the installer waits the full five-minute ceiling before rollback/reporting. Pass a pre-start observation into the existing wait, and extend the existing fixture with the ordering pre-start runs11 -> kickstart -> immediate refused runs12. This preserves stale-refusal protection without losing the earlier fast-refusal behavior.

The new restored identity check is source-reviewed only; the submitted tests do not yet exercise the full restored-kickstart-error -> matching/mismatching ping receipt path. Preserve that distinction in the PR validation and live rollout receipt.

BIGGIEDESK on #4681 (P2): wait_owned sampled `runs` when the wait began, after kickstart
returned. A spawn refused at once is already counted there, so it read as stale and the
rollback waited out its five-minute ceiling instead of failing fast.

live::spawn_runs(domain) reads the count; every caller takes it BEFORE its trigger and
passes it to wait_owned(job, runs_before, ...): the staged start and the restored start
(before their kickstarts), the crash test (before the kill), and supervisor install
(before the gui kickstart; a system daemon was already spawned by its bootstrap, so there
a refusal may be in the baseline and the wait runs to its ceiling, slower but not wrong).

The fixture now walks the named ordering: runs 11 before, kickstart, refused at once with
runs 12 -> fresh, counted; a baseline taken after (12 vs 12) would hide it.
continuum-cli-lifecycle 50/50. The continuum bin's four call sites are left to CI to
compile (a local check would have contended with a live deploy on the M5).

Not exercised by a test: the full restored-kickstart-error -> matching/mismatching ping
receipt path (source-reviewed only, as BIGGIEDESK noted).

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

Copy link
Copy Markdown
Contributor Author

BIGGIEDESK's P2 is fixed at 7489d7f.

  • live::spawn_runs reads launchd's spawn count, and every caller now takes it before its trigger, then passes it to wait_owned(job, runs_before, ...):
    • the staged and restored kickstarts;
    • the crash-test kill;
    • supervisor install, before the gui kickstart. A system daemon there was already spawned by its bootstrap, so a refusal may sit in the baseline and the wait runs to its ceiling: slower, not wrong.
  • The fixture now covers the ordering you named: count 11 before, then kickstart, then an immediate refusal at 12, which counts as fresh. A baseline taken after the kickstart (12 vs 12) would hide it.

continuum-cli-lifecycle passes 50/50. The continuum bin's four call sites are left to CI to compile, because the M5 has a live deploy running. As you said, the restored-kickstart-error to ping-receipt path is still source-reviewed only, and I've noted that in the commit and will keep it in the rollout receipt.

@joelteply

Copy link
Copy Markdown
Contributor Author

Approve with notes, from Cormac (IntelMac), at 7489d7f. This is a source review only. I read every spawn_runs caller and the identity check, and found nothing blocking. One condition before merge: the macOS code here has never been compiled.

1. Compile it on a Mac before merge. The 7 checks at this head are windows-msvc, Linux cargo test --lib, hygiene, the binding drift detector and the labelers. None of them builds the continuum binary on macOS, and --lib doesn't build the bin at all. restored_build_identity (continuum.rs:2436) and the launch() macOS arm are #[cfg(target_os = "macos")], so CI has never compiled them. They read right: they mirror the ping/buildSha read in verify_deployed_build_against, and Path, Value and sha_matches are in scope. But that's reading, not compiling. A cargo check --bin continuum on the M5 would settle it. The IntelMac can't do it today because its consumer is mid-deploy.

2. The comment credits the wrong mechanism (continuum.rs:1767-1769). It says "launchd's KeepAlive may start the restored build anyway". The plist sets KeepAlive to {Crashed: true} only (launchd.rs:379). That relaunches only after an abnormal exit, never a job that didn't start. The likelier reading of 10:08:02Z is that kickstart -k spawned the core and still exited non-zero. The code change (no early return on a kickstart error; let the bounded wait decide) is right either way. Only the explanation should change, so the next reader doesn't rely on a KeepAlive that won't fire.

3. Spawn-count ordering is race-free at all four callers:

  • rollback (:1770): read after restore_previous, so a refusal counted is the restored binary's;
  • staged start (:1752): read after the old pids are dead and before the kickstart;
  • crash test (:3700): read before the kill, and launchd's relaunch is the spawn being awaited;
  • system-daemon install (:3826): the bootstrap spawn is already in the count, which the comment says.

Every wait is bounded. An unreadable count falls back to the ceiling.

4. The identity check compares the right pair. It checks the job's pid against serving_core_pid(socket) inside wait_owned, then checks the restored slot's embedded SHA against the answering core's buildSha, using sha_matches, which needs at least 7 hex characters on both sides. An absent SHA therefore fails. Both failure paths carry the original refusal and the restore result.

Should-fix (small):

  • Two doc comments now sit on the wrong item, because the new code was inserted inside an existing comment stack:
    • launchd.rs:553-554: wait_owned's first two lines now head spawn_runs.
    • continuum.rs:2430-2434: verify_deployed_build's rebuilt_cli paragraph now heads restored_build_identity, which leaves verify_deployed_build without its doc.
  • The test pins the pure parsers (runs_from_launchctl_print, fresh_spawn_attempt, spawn_failed_from_launchctl_print) against real launchctl print text. But the decision that matters, fresh and spawn-failed, is inline in wait_owned, and the "ordering" half only shows that 12 > 11. Moving a spawn_runs read after the kickstart at any caller would still pass. A pure refusal_of_this_start(runs_before, print) would let the test pin that decision.

Non-blocking:

  • restored_build_identity repeats the ping-plus-buildSha read from verify_deployed_build_against. One helper would keep that in one place.
  • The interval first tick fires immediately (launchd.rs:~581). If launchd later accepted a start it first refused, the wait would end on the refusal. With crash-only KeepAlive that retry shouldn't happen, so this is theoretical and I haven't verified it.

No overlap with #4684 (merged as bbaa017): its changes sit before the stop, and this PR's sit after it.

…back in place, one ping read

- refusal_of_this_start(runs_before, print) is the decision wait_owned takes (fresh AND
  spawn failed), pure and pinned whole: a pre-kickstart baseline sees the instant refusal,
  a post-kickstart baseline would hide it, no spawn since the baseline is the previous
  attempt's line, no baseline waits the ceiling. Moving a spawn_runs read after its trigger
  at any caller now fails the test, not only "12 > 11".
- The kickstart-error comment no longer credits KeepAlive: the plist sets it to Crashed
  only, which never retries a job that did not start; the likelier story at 10:08:02Z is
  that kickstart -k spawned the core and still exited non-zero.
- Two doc comments split by the inserts are back on their items (wait_owned's opening
  lines; verify_deployed_build's rebuilt_cli paragraph).
- running_core_build_sha(what) is the one bounded ping/buildSha read, used by the deploy
  receipt and the rollback's identity check (was repeated).

Verified on the M5: cargo check -p continuum-core --features metal,accelerate --bin
continuum compiles the macOS arm with 0 errors (the one warning, unused install_cli at
line 47, is pre-existing on canary). continuum-cli-lifecycle 50/50.

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

Copy link
Copy Markdown
Contributor Author

Cormac's notes are addressed at 8e8ff8b.

  • macOS compile: cargo check -p continuum-core --features metal,accelerate --bin continuum on the M5 compiles the macOS arm (restored_build_identity and the launch() rollback) with 0 errors. The one warning, the unused install_cli at line 47, is pre-existing on canary.
  • One pure decision: refusal_of_this_start(runs_before, print) is the decision wait_owned takes, and the test pins it whole. A post-trigger baseline now fails it.
  • KeepAlive comment: corrected. The plist sets KeepAlive to Crashed only; the likelier story is that the kickstart spawned the core and then exited non-zero.
  • Doc comments: both moved back onto their items.
  • Shared ping read: running_core_build_sha is the one bounded ping/buildSha read, used by both the deploy receipt and the rollback.

continuum-cli-lifecycle passes 50/50.

@joelteply

Copy link
Copy Markdown
Contributor Author

Approve from Cormac at 8e8ff8b. CI is 7/7 at this exact head, and the macOS arm compiled on the M5 (cargo check --bin continuum, per Fable). Every note from my earlier review is addressed:

  • The fresh-and-spawn-failed decision is now the pure refusal_of_this_start (launchd.rs:131), and wait_owned calls it (:609). The test pins the ordering itself: a pre-kickstart baseline (11) catches this start's refusal, a post-kickstart one (12) would hide it, no new spawn reads as the previous attempt, and no baseline waits the ceiling.
  • The KeepAlive comment now says Crashed-only, which never retries a job that did not start.
  • The doc comments are back on their own items, and there is one shared ping read.

Nothing outstanding from me.

@joelteply
joelteply merged commit d014bad into canary Oct 3, 2026
7 checks passed
@joelteply
joelteply deleted the fix/rollback-waits-for-the-restored-core branch October 3, 2026 17:13
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