Fix serve-agent reinstall race in schedule:weekly - #7
Merged
Conversation
installAgent() booted out the old LaunchAgent and immediately bootstrapped the new one. launchctl bootout returns before launchd finishes tearing the job down, so bootstrapping into a domain that still holds the (KeepAlive) label reliably failed with "Bootstrap failed: 5: Input/output error". The installer then exited, and because serve is reinstalled last and had already been booted out, every re-run left the resident receiver DOWN — captures silently 401'd until a manual bootstrap. - bootoutAndWait(): after bootout, poll `launchctl print` until the label is actually gone (bounded ~3s) before bootstrapping. - installAgent(): retry bootstrap a few times on the transient EIO, clearing half-registered state between tries; still fail loudly on a real error. - sleepMs via Atomics.wait (no sleep binary, no async needed here). Verified: `npm run schedule:weekly` now reinstalls all three agents cleanly and idempotently; the receiver stays up (/health 200, /capture gate intact). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #6. Re-running
npm run schedule:weeklyreliably left the resident receiver down.Cause
installAgent()boots out the old LaunchAgent then immediately bootstraps the new one.launchctl bootoutreturns before launchd finishes teardown, so bootstrapping into a domain that still holds the (KeepAlive) label fails withBootstrap failed: 5: Input/output error. The installer exits on that failure — and sinceserveis reinstalled last and was already booted out, the receiver stayed down and captures silently returned 401 until a manuallaunchctl bootstrap.Reproduced deterministically: it failed on two consecutive
schedule:weeklyruns.Fix
bootoutAndWait(): after bootout, polllaunchctl printuntil the label is actually gone (bounded ~3s) before bootstrapping.installAgent(): retry bootstrap a few times on the transient EIO, clearing half-registered state between attempts; still fails loudly on a genuine error.sleepMsviaAtomics.wait(no sleep binary / async needed in this flow).Verification
After the fix,
npm run schedule:weeklyreinstalls all three agents cleanly and idempotently; receiver stays up (/health200), and the/capturegate is intact (no token → 401, correct token +{}→ 400). serve runs compileddist/server.jsunder Node 22 via the wrapper.🤖 Generated with Claude Code