Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): retain the runtime used by the service launcher #23250

Closedjuliusmarmingewants to merge 3 commits intomain fromrefs/pull/23250/headopened View on GitHub

juliusmarmingecommented

Problem

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/EXEC after A was removed. Runtime transcript.
  • Targeted lint on the seven changed files and the server tsc-rs --noEmit check 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.probe succeeded. 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.

FixtureBeforeExact-head afterResult
Sequential A→B→C, stopped/aged prune, restart through AExisting 203/EXEC transcriptRow 1 recordingControl removed; A/B/C retained; restart serves C; probe succeeds
Successful unit repoint to B while launcher A stays alive; update C→DExisting regression tests only; no earlier runtime pairRow 2 recordingSame launcher PID; B neither active nor rollback; prune removes A/control, retains B/C/D; restart through B serves D
Candidate-start failure, prune, restartExisting failure tests only; no earlier runtime pairRow 3 + restart continuationFailed 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. @@ -557,3 +557,7 @@
      557557 this.#timer = undefined;
      558558 }
      559559
      560+ async #writeState(next: ServiceState): Promise<void> {
      561+ // `t3 update` without a restart repoints the unit and records its launcher
      562+ // runtime while this launcher keeps running, so what the file says wins.
      563+ const current = await NodeFSP.readFile(this.#statePath, "utf8").then(
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High src/serviceLauncher.ts: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.

      🚀 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.
    2. 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
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.9 KiB20.9 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB+7 B (+0.1%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB+7 B (+0.6%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.2 KiB21.2 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 6318bfc · PR result: 0df1ba9 · Source CI: success

      Scenario 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.

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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.ts
      • apps/server/src/cloud/bootService.ts
      • apps/server/src/cloud/pinnedRuntime.test.ts
      • apps/server/src/cloud/pinnedRuntime.ts
      • apps/server/src/cloud/serviceProtocol.ts
      • apps/server/src/serviceLauncher.test.ts
      • apps/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.ts
      ServiceState accepts an optional exact-format launcherVersion. 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.ts
      Launcher state writes preserve the existing launcherVersion during 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.ts
      Runtime pruning protects the version recorded as launcherVersion, even when it differs from activeVersion. 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: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: retaining the runtime used by the service launcher.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Description checkPassedThe 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
      Comment `@coderabbitai help` to get the list of available commands.
    5. juliusmarminge added labelsbugfix

    6. juliusmarminge added labelspr:needs-julius

    7. juliusmarminge added labelspr:gate-failed

    8. juliusmarminge removed labelspr:needs-julius

    9. juliusmarminge removed labelspr:gate-failed

    10. juliusmarminge added labelspr:in-progress

    11. juliusmarminge removed labelspr:in-progress

    12. juliusmarminge added labelspr:needs-julius

    13. 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.

    14. juliusmarminge linked this to fix #17490

    15. 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 the launcherVersion state 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. Removing main'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.sh from a clean t3code checkout after vp i, with gh authenticated.

      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)
    16. Closing this draft: it has sat unfinished and #17490, which it was for, is closed.

    17. juliusmarminge closed this

Sign in to join this conversation.