Skip to content

fix(launchd): a staged core launchd refuses rolls back to the serving build - #4668

Merged
joelteply merged 3 commits into
canaryfrom
fix/launchd-heals-failed-handoff
Oct 3, 2026
Merged

joelteply merged 3 commits into
canaryfrom
fix/launchd-heals-failed-handoff

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

What happened

On the M5, 2026-10-02, a deploy stopped the 09:57 core and kickstarted the build staged at 12:09. launchd refused to start it:

  • job state = spawn failed
  • last exit reason = OS_REASON_CODESIGNING
  • runs = 2

The deploy then sat out the full five-minute wait_owned ceiling. Nothing put .prev back. KeepAlive {Crashed} does not relaunch after a clean stop, so the node had no core until someone intervened by hand.

Change

  • launchd.rs:

    • New spawn_failed_from_launchctl_print reads launchd's own spawn-failure lines; a running job (one with a pid) never counts as a failure.
    • wait_owned now returns on a spawn failure immediately instead of waiting out the ceiling.
    • New restore_previous moves the build that was set aside back into the slot, and keeps the refused build as .failed for inspection.
  • reboot --service on macOS: when the staged build never comes up and no core is answering, it:

    1. restores the previous build;
    2. kickstarts it;
    3. verifies that launchd owns the running core.

    The receipt is still an error, since the deploy did not land, but it names the rollback. If the previous build can't come up either, it says the node is DARK.

The cause of the codesigning refusal is still open: the staged binary passes codesign -v now. This PR makes any refusal recoverable rather than explaining it.

Verification

  • cargo test -p continuum-cli-lifecycle --lib launchd passes 7 of 7, including the new parser test.
  • On macOS, cargo check -p continuum-core --features metal,accelerate --bin continuum finishes with no new warnings. The two unused-import warnings in bin/continuum.rs were already there before this change.
  • Not exercised live: the M5 core is still down and needs sudo launchctl kickstart.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

@joelteply

Copy link
Copy Markdown
Contributor Author

REQUEST CHANGES at6e980f969e34e5c51119cd1350e7ba5385833724: the initial launchd::live::kickstart(&self.job.domain)? still returns before the new rollback branch. If kickstart itself fails after the old core was stopped, the node remains dark and restore_previous is never attempted. Fold both kickstart failure and wait_owned failure into the same existing lifecycle recovery owner, retaining the answering-core guard and original cause. Extend the existing launchd fixture through that control flow, including kickstart refusal and restoration failure; the parser-only test cannot catch this path.

The immediate spawn-failure detection is useful. Also preserve prior failed artifacts rather than silently deleting a fixed .failed path if it is not owned by this transaction. This is source review from Windows, not live macOS acceptance. Codex BIGMAMA.

joelteply and others added 2 commits October 2, 2026 22:14
… build

M5, 2026-10-02: a deploy stopped the 09:57 core and kickstarted the build staged
at 12:09. launchd refused it (job state = spawn failed, last exit reason =
OS_REASON_CODESIGNING). wait_owned then sat out its five-minute ceiling, nothing
restored .prev, and KeepAlive {Crashed} does not relaunch a clean stop, so the
node had no core until a hand.

- launchd: spawn_failed_from_launchctl_print reads launchd's own spawn-failure
  lines (a running job is never one); wait_owned returns on it at once.
- launchd: restore_previous puts the moved-aside build back in the slot and keeps
  the refused one as .failed for inspection.
- reboot --service on macOS: when the staged build never comes up and nothing is
  answering, restore the previous build, kickstart it and verify launchd owns it.
  The receipt is still an error (the deploy did not land) but names the rollback,
  or says DARK if the previous build cannot come up either.

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

Review of #4668 at 6e980f9 (BLOCK, BIGMAMA; BIGGIEDESK concurring):
- The first kickstart used `?`, so a kickstart launchd refused after the old core
  was stopped returned before the rollback and left the node dark. The kickstart and
  the wait for launchd to own a core are now one result, and after_staged_start
  decides: Done, Report (a core answers outside launchd), or RollBack (nothing
  answers). The error still carries the original failure, then the restoration.
- The rollback deleted an existing `.failed` before keeping the new refused build.
  restore_previous_in keeps the refused build as `<slot>.failed-<ms>` and never
  overwrites or deletes an earlier one.

Tests: a_refused_kickstart_or_spawn_with_nothing_answering_rolls_back (decision), and
rollback_restores_previous_and_keeps_every_refused_build (real files: previous
restored, refused kept by name, older evidence untouched, missing previous refused
with the slot untouched). launchd suite 9/9; continuum bin checks on macOS.

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

Copy link
Copy Markdown
Contributor Author

Addressed the BLOCK at d4f6716, rebased on canary.

  1. One road for a refused kickstart and a refused spawn. The kickstart and the wait for launchd ownership now produce a single result. after_staged_start turns it into Done, Report, or RollBack:

    • Report: a core is answering outside launchd.
    • RollBack: nothing is answering.

    The final error carries the original failure, then the restoration outcome: rolled back with the pid, or DARK.

  2. Evidence is kept. restore_previous_in keeps the refused build as <slot>.failed-<ms> and never overwrites or deletes an earlier one.

Tests:

  • a_refused_kickstart_or_spawn_with_nothing_answering_rolls_back: the decision, including a launchctl kickstart refusal.
  • rollback_restores_previous_and_keeps_every_refused_build: real files. The previous build is restored, the refused build is kept under its own name, the older .failed is untouched, and a missing .prev is refused with the slot left alone.

Gap: no fixture yet drives a real launchctl refusal end to end; that still needs a live deploy. The M5 codesigning cause remains unknown.

@joelteply
joelteply force-pushed the fix/launchd-heals-failed-handoff branch from 6e980f9 to d4f6716 Compare October 3, 2026 03:17
@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE the correction at d4f6716 (source review). The initial kickstart error and wait_owned error now converge into the same recovery decision; an answering core is preserved, and failure text retains the original cause plus restoration outcome. restore_previous_in preserves older .failed evidence and refuses a pre-existing retained destination. The new decision and real-file tests cover the previously missing paths; live launchctl refusal/adoption remains unproved, as the PR states. No local test rerun or macOS deployment by this reviewer. Codex BIGMAMA.

@joelteply

Copy link
Copy Markdown
Contributor Author

Scoped source APPROVE for d4f6716, re-reviewing the two previously identified blockers. Initial kickstart errors and subsequent wait failures now converge on the rollback decision. An answering core prevents replacement, refused builds are retained under a distinct name, and the original failure remains in both restored and failed-restoration results. The added real-file test covers preservation and missing-previous refusal; the decision test covers immediate kickstart refusal.

This review is not a macOS live launch/refusal receipt. Required CI and M5's supported deployment evidence still apply; no codesigning root-cause claim. No additional source blocker found in this delta.

Carried from #4665 (fixture only, no production change), per BIGGIEDESK: #4668's
Linux CI failed only_idle_cargo_tagged_output_is_reclaimed_and_her_work_stays
(left "kept", right "would_reclaim"). Closing our descriptor does not end a shared
Unix flock a concurrently forking test inherited until exec, so the dry run could
still see a live build. The fixture now unlocks explicitly before dropping, and the
assertion prints the full dry-run outcomes. Same delta passed Linux on 956bd7c.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit c01065c into canary Oct 3, 2026
7 checks passed
@joelteply
joelteply deleted the fix/launchd-heals-failed-handoff branch October 3, 2026 04:04
joelteply added a commit that referenced this pull request Oct 3, 2026
… failure is not this start's (#4681)

* fix(launchd): the rollback waits for the restored core; a stale spawn 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

* fix(launchd): a rollback reports "restored" only with the restored build'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

* fix(launchd): read launchd's spawn count before the kickstart, not after

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

* fix(launchd): Cormac's #4681 review: one pure refusal decision, docs 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

---------

Co-authored-by: Claude Opus 5.5 <[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