Repository navigation
fix: prevent LaunchAgent reinstall from leaving gateway down - #120699
Conversation
|
Codex review: found issues before merge. Reviewed August 8, 2026, 5:37 PM ET / 21:37 UTC. ClawSweeper reviewWhat this changesThis PR guards against in-band macOS LaunchAgent mutations and adds rollback for failed external Gateway LaunchAgent reinstalls. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked by patch quality or review findings - 6 items remain Keep open: the rollback path can still leave a previously loaded cached-label Gateway unsupervised after a failed reinstall. The PR is maintainer-authored and protected by the Priority: P1 Review scores
Verification
How this fits togetherThe macOS daemon manager writes Gateway LaunchAgent artifacts, asks launchd to activate them, and thereby controls whether the Gateway remains supervised. Its rollback path must preserve both service files and launchd’s actual loaded state when activation fails. flowchart LR
A[Gateway install command] --> B[LaunchAgent lifecycle manager]
B --> C[Snapshot prior artifacts and state]
C --> D[Publish and activate replacement]
D --> E{Activation succeeds?}
E -->|Yes| F[Gateway remains supervised]
E -->|No| G[Restore prior service]
G --> H[Prior launchd state restored]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +249, Tests +270, Docs +1. Total +520 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Probe cached labels before any mutation and abort when a loaded job lacks a restorable definition, then add canonical and legacy failure-path coverage for that state. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: a loaded cached launchd label with no plist followed by candidate activation failure reaches the uncovered snapshot-and-rollback path. Is this the best way to solve the issue? No: the lifecycle-owner transaction is the right layer, but its missing-plist snapshot must not equate absence of a file with absence of a loaded launchd job. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 909509a5db8d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…w#120699) * fix(daemon): restore launchd install failures * style: format launchd regression tests * fix(daemon): guard cached launchd installs * chore: leave changelog to release flow
What Problem This Solves
Fixes an issue where macOS Gateway service installation could leave the Gateway unsupervised when
gateway install --forcewas invoked from inside that same LaunchAgent, or when external activation failed after the existing job was booted out.Related operational evidence came from a clawstudio ownership incident, although that incident's direct outage path was the separate built-in mutable-update handoff. Review of the sibling LaunchAgent lifecycle exposed this independently reproducible defect.
Why This Change Was Made
LaunchAgent install now refuses install or uninstall from its own launchd ancestry before any filesystem or launchctl mutation. External install treats the plist, generated environment file, generated wrapper, legacy definitions, and their loaded states as one transaction: it snapshots them before publication, activates the candidate, and restores the exact previous artifacts and supervision if any mutation fails. Staging remains definition-only and does not retire a live legacy job.
The activation owner now rejects ambiguous
launchctl printstate and checks real bootout/unload failures instead of proceeding with an unprovable prior state.Production LOC: +276/-27 (net +249) | Tests: +272/-0
The production growth implements the missing lifecycle ownership transaction and removes the service-loss class across canonical and legacy LaunchAgent paths.
Provenance: the inline activation path was introduced by commit
5c9e4cd30a1ee9189f5f7d9d6dfa75b9a3a98ad8on 2026-03-23 by Peter Steinberger; no associated PR is recorded by GitHub.User Impact
Operators can no longer accidentally self-terminate the Gateway by reinstalling or uninstalling its LaunchAgent from an in-band agent/tool command. Failed external reinstalls restore the prior runnable service instead of leaving launchd with no job to respawn.
Evidence
f500a7e7ae1135240ce60df775532d9aa46c21fctbx_01kzhhjg7xbpnbgd4v8f9perwy(swift-barnacle), run 31277382157pnpm test src/daemon/launchd.test.tstbx_01kzhg1sy73gdajptc0gyzehtk, run 31276315535, same 121/24 resultgit diff --check origin/main...HEADRegression coverage includes canonical and configured-old-label in-band refusal, in-band uninstall refusal, stage non-mutation, ambiguous launchd state, loaded and unloaded rollback, fresh-install artifact cleanup, generated env/wrapper restoration, and legacy supervision restoration.
ClawSweeper was explicitly waived for this repair.