fix(server): retain the runtime used by the service launcher #23250
main fromrefs/pull/23250/head·opened View on GitHubProblem#
After installing the service from runtime A and remotely updating through B to C, the unit still starts its launcher from A, but service-state.json names only C and B. Deleting runtimes based on that state deletes A and the next systemd restart fails with 203/EXEC.
Change#
Record launcherVersion when installing the service, preserve it through launcher update transitions, and retain it during runtime pruning. A CLI install that repoints the unit while its launcher keeps running supplies the version preserved by subsequent state writes.
Existing installations must run t3 service install using the fixed CLI and restart into the fixed launcher before relying on this field. Remote updating alone does not migrate an older launcher, which discards the field when writing state. After an install aborts because a remote update overlapped it, retry installation after that update settles; state alone is not authoritative in that case.
Scope and approval#
Fixes #17490 GitCafe: https://git.cafe/pingdotgg/t3code/issues/17490 Triaged bug via the automated issue flow: #17490. This implements the report's option of recording the installed launcher's runtime. It does not change the service's executable path on remote updates.
Verification#
- Three focused regression assertions fail before the implementation: install omits the launcher runtime, an update drops it, and pruning removes it. Red test output.
- The three changed test files pass, 63/63, including a CLI-repointed unit's version winning over stale launcher memory. Green test output.
- Before: a real, isolated Ubuntu/systemd service installed A, remotely updated to B and C, then failed restart with
203/EXECafter A was removed. Runtime transcript. - Targeted lint on the seven changed files and the server
tsc-rs --noEmitcheck pass after merging current main. - After: fixed A installed and started, then real server RPC updates to B and C retained launcher A. With the service stopped, production cleanup deleted an unrelated aged runtime and retained A/B/C. Restart through unit A succeeded; the live descriptor returned HTTP 200 and version C, and
server.probesucceeded. Runtime transcript with exact commands. - Runtime binaries were built from 00024c7f87, before the integration merge; that merge changed none of the seven affected files. Build logs.
- Server-only change; visual fixture matrix is empty. No client render paths changed. macOS launchd remains unverified on this Linux VM.
Models: Claude Opus 5.5 and GPT-6.1-Sol, through the Claude Agent and Codex harnesses in T3 Code.
Takeover#
Credit to @juliusmarminge for the original fix. No code changes; evidence and verification added below. The original description and historical captures above are preserved. The new runs use the exact final head 0df1ba9.
Evidence#
Server-only change; no client render paths changed. These timestamped command/output recordings replace visual captures for runtime behavior. Fixture matrix.
| Fixture | Before | Exact-head after | Result |
|---|---|---|---|
| Sequential A→B→C, stopped/aged prune, restart through A | Existing 203/EXEC transcript | Row 1 recording | Control removed; A/B/C retained; restart serves C; probe succeeds |
| Successful unit repoint to B while launcher A stays alive; update C→D | Existing regression tests only; no earlier runtime pair | Row 2 recording | Same launcher PID; B neither active nor rollback; prune removes A/control, retains B/C/D; restart through B serves D |
| Candidate-start failure, prune, restart | Existing failure tests only; no earlier runtime pair | Row 3 + restart continuation | Failed state retains launcher A; C serves/probes before and after restart; isolated systemd start-limit counter reset required |
Reproduction scripts and raw logs · Build/artifact provenance · Bundle checksum.
Environment: Linux x86_64/systemd user service in a disposable account; real Node 26.8.2 SEA, production installer, launcher, authenticated RPC and pruner. Release HTTP transport alone is mocked. All source files remain unchanged; distinct fixture versions modify only the generated bundle's package-version declaration. No client assets/UI were exercised; viewport/theme/pixel diffs do not apply.
What else changed: no implementation changes. Evidence includes an external executable-availability fault to trigger the failed candidate, and a unit-local reset-failed after six rapid starts hit systemd's unmodified five-start/300-second limit. Neither operation repairs persisted application state.
Verification log
- Fresh final-head scoped tests: 63/63 across the same three files, unchanged. Test output.
- Independent proof pass 1 inspected the full seven-file diff and existing evidence; pass 2: SUFFICIENT for bounded Linux/systemd claims. Independently rebuilt/repeated row 2: terminal recording.
- Blocker: the source-confirmed concurrent successful install/state-write race remains unresolved. A stale launcher-A read can overwrite installed B after a successful repoint. Sequential row 2 does not establish concurrency safety; the warning above about an aborted overlapping install does not cover this successful-install interleaving.
- Unverified: concurrent-install safety, legacy-launcher migration, macOS launchd, Windows-specific behavior, relay/tunnel. No browser/mobile/desktop render paths changed. The failed-candidate fixture establishes launcher-reference persistence, not general rollback/data-integrity guarantees.
- CI snapshot: 34 successful, zero failing/pending at the unchanged head; current-base conflict readiness remains pending. No code pushed, branch integration, claim comment, or merge performed in evidence-only mode.
- All owned runtime services/accounts/listeners removed; lead removes worktree and scratch after independent audit.
- Model/harness: GPT-6.1-Sol through Codex in T3 Code, with separate capture and independent proof-audit tasks.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -557,3 +557,7 @@557557 this.#timer = undefined;558558 }559559560+ async #writeState(next: ServiceState): Promise<void> {561+ // `t3 update` without a restart repoints the unit and records its launcher562+ // runtime while this launcher keeps running, so what the file says wins.563+ const current = await NodeFSP.readFile(this.#statePath, "utf8").then(
🟠 High
src/serviceLauncher.ts:563A concurrent successful
install({ start: false })can have its newlauncherVersionoverwritten with the old value, leaving service state pointing at launcher A and allowing pruning to remove launcher B even though the unit was repointed to B.#writeStatereads the state before the installer writes B, then atomically writes its stale merged state afterward; coordinate this merge and write with the install/repoint operation so the installed version is preserved.🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @apps/server/src/serviceLauncher.ts around line 563: A concurrent successful `install({ start: false })` can have its new `launcherVersion` overwritten with the old value, leaving service state pointing at launcher A and allowing pruning to remove launcher B even though the unit was repointed to B. `#writeState` reads the state before the installer writes B, then atomically writes its stale merged state afterward; coordinate this merge and write with the install/repoint operation so the installed version is preserved. Approvability#
Verdict: Would Approve
Macroscope's review found this PR approvable — This is a focused, backward-compatible service-state bug fix that preserves the launcher runtime through installation, updates, and pruning, with targeted regression coverage. An unresolved high-severity concurrency finding indicates that concurrent installation and launcher state writes can still lose the recorded runtime and should be addressed separately.
Needs human approval because:
- 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅ Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅ Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅ Codex Live turn messages 2 2 0 (0.0%) 8 ✅ Claude Total thread wire 5.0 KiB 5.0 KiB +7 B (+0.1%) 6.8 KiB ✅ Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅ Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB +7 B (+0.6%) 2.0 KiB ✅ Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅ Claude Live turn messages 2 2 0 (0.0%) 8 ✅ Baseline:
6318bfc· PR result:0df1ba9· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 108.5 KiB
- Claude decoded thread snapshot: 108.8 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
6f012c5a-1c67-456f-8d93-47ca29de3d0a
📥 Commits
-
Reviewing files that changed from the base of the PR and between 6318bfc597e544679848c4ed816606bacd32a175 and 0df1ba9eaefa23c18c535514cbf0ece4a67aae75.
📒 Files selected for processing: 7
-
apps/server/src/cloud/bootService.test.tsapps/server/src/cloud/bootService.tsapps/server/src/cloud/pinnedRuntime.test.tsapps/server/src/cloud/pinnedRuntime.tsapps/server/src/cloud/serviceProtocol.tsapps/server/src/serviceLauncher.test.tsapps/server/src/serviceLauncher.ts
Limit details: You’ve used all 10 included reviews currently available.
-
📝 Walkthrough
-
Service state now records an optional launcher version. Launcher state writes preserve that version, and runtime pruning retains the corresponding runtime even when it differs from the active version.
Changes: Launcher runtime state
Layer / File(s) Summary Record and decode launcher version
apps/server/src/cloud/serviceProtocol.ts,apps/server/src/cloud/bootService.ts,apps/server/src/cloud/bootService.test.tsServiceStateaccepts an optional exact-formatlauncherVersion. Installation records the CLI version, and install-state tests check the recorded value.Preserve launcher version in state writes
apps/server/src/serviceLauncher.ts,apps/server/src/serviceLauncher.test.tsLauncher state writes preserve the existing launcherVersionduring update acceptance, trial commitment, failure, and rollback. Tests cover an unchanged launcher unit and one repointed to another version.Retain the launcher runtime
apps/server/src/cloud/pinnedRuntime.ts,apps/server/src/cloud/pinnedRuntime.test.tsRuntime pruning protects the version recorded as launcherVersion, even when it differs fromactiveVersion. The pruning documentation and test reflect this behavior.Priority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix
Suggested reviewers:
maria-rcks
Merge Risk: ⚪ Minimal · up to
0df1b-
This change records the launcher runtime version in service state and keeps that runtime from being pruned. No blocking risk remains. A rare concurrent install and launcher write could leave the recorded version stale, but existing prune safeguards still protect the runtime the unit points to.
Pre-merge checks:
4-
Check name Status Explanation Title check The title clearly and concisely describes the main change: retaining the runtime used by the service launcher. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Description check The description includes all required sections. It clearly explains the problem, implementation, scope, issue reference, focused verification, observed results, limitations, and unverified cases. It a… Full details: Description check
-
Explanation
The description includes all required sections. It clearly explains the problem, implementation, scope, issue reference, focused verification, observed results, limitations, and unverified cases. It also identifies the models and harness used. No material description gaps prevent review.
-
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
juliusmarminge added labelsbugfix
juliusmarminge added labelspr:needs-julius
juliusmarminge added labelspr:gate-failed
juliusmarminge removed labelspr:needs-julius
juliusmarminge removed labelspr:gate-failed
juliusmarminge added labelspr:in-progress
juliusmarminge removed labelspr:in-progress
juliusmarminge added labelspr:needs-julius
Follow-up verification found a remaining installer/recovery race. At local follow-up a1f69baf32, recovery can overwrite a concurrent successful no-restart install’s launcherVersion and remove its restart marker. Later updates can leave the unit runtime absent from state-based retention. The third review round ended MERGE / FIX_FIRST; the follow-up commits remain unpushed. Marked draft pending coordinated state/marker handling. Existing green checks cover published head 0df1ba9eae, not these local follow-ups. macOS launchd remains unverified.
juliusmarminge linked this to fix #17490
Note
Generated by claude-opus-5-5 RESPONDING ON BEHALF OF SHARAD
This can be closed: it's already fixed on
main. #19652 (d0d0608b6b) closed #17490: after each remote update, the service unit points at the runtime the update committed. Runtime pruning also keeps whatever runtime the installed unit or launch agent starts, because both prune call sites pass its program as a prune reference (#22253, #25870). That covers what thelauncherVersionstate field does here, without the install/recovery race noted earlier on this PR.The attached script runs this PR's A→B→C scenario against current
main. Runtime A, named only by the service definition, survives the prune, and the control without the definition prunes it. Removingmain's unit reference makes the retention case fail, so that reference is what fixes #17490.main's repoint tests for systemd, launchd and Task Scheduler also pass.To reproduce, run
bash prove-pr-23250.shfrom a clean t3code checkout aftervp i, withghauthenticated.- Proof script: prove-pr-23250.sh
- Output from a run against
main2904fea7d5: prove-pr-23250.out.txt
Result
PASS issue #17490 is closed as completed by merged PR #19652 PASS #19652 is on main as d0d0608b6b PASS at the PR's merge-base the server-start prune passed no unit reference (the bug the PR targets) PASS main passes the service definition's program as a prune reference in both prune call sites Tests 2 passed (2) PASS on main, pruning after A->B->C keeps launcher runtime A (named only by the service definition) and removes the unreferenced runtime; the control without the definition prunes A Tests 1 failed | 1 passed (2) PASS with main's unit reference removed, the retention case fails (runtime A is pruned): main's reference is what fixes #17490 Tests 3 passed | 27 skipped (30) PASS main repoints systemd, launchd and Task Scheduler definitions at the committed runtime after an update VERDICT: CLOSE (already-fixed)Closing this draft: it has sat unfinished and #17490, which it was for, is closed.
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed