Skip to content

fix(server): launcher confirms an update before discarding the database backup - #42665

Open
juliusmarminge wants to merge 3 commits into
mainfrom
factory/issue-42653
Open

juliusmarminge wants to merge 3 commits into
mainfrom
factory/issue-42653

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

A server update could restart the server twice. The launcher saved the update, then deleted the pre-update database backup before telling the new server it was confirmed. When the deletion took more than 30 seconds (a large database, a nearly full disk), the new server stopped waiting, exited and was started again, adding minutes of downtime. Both sides are fixed, because a remote update keeps the launcher that is already running.

  • Launcher.#handlePrepared sends committed right after the update is saved, and only then deletes the backup and updates the service unit.
  • When prepareTrial times out waiting for committed, it reads service-state.json and continues if that file shows this update as committed, so an older launcher that replies late no longer causes a second restart. Any other state still fails as before.
  • docs/internals/07_server-updates.md describes the new rule.

Fixes #42653

Reproduction on main

On origin/main 4a8f2be, in apps/server/src/serviceLauncher.test.ts, I extended the existing commitUpdate harness. It runs the real Launcher with real child processes for an old and a new fake runtime: the old child asks for an update, the launcher backs up the database and starts the new child as a trial, and the trial reports prepared. On receiving "committed", the fake trial now writes whether runtime/db-backup/ still exists. New test: "tells the trial it is committed before discarding the database backup". Run with vp test run src/serviceLauncher.test.ts -t commit. On main it fails with expected 'false' to equal 'true': the launcher deletes the backup (rm -rf plus a directory fsync) before it sends "committed", so the trial's 30-second wait in serviceLauncherClient covers the whole cleanup. Control: with the launcher changed to send "committed" first and discard the backup in the finally block, the new test passes. That rough change also broke "waits for disk recovery during pending update without losing the update lifecycle", which passes on main, so a fix must keep that test green. Not reproduced here: the reporter's minutes-long cleanup on a 99%-full APFS volume with a 40 GB database, and the full exit-and-restart sequence. That needs macOS with a large, nearly full disk. The order and the 30-second limit that turn slow cleanup into a second restart are on main as reported.

Evidence

Being captured: before and after in the real app. This section is filled in before the pull request can merge.

Tests

  • vp test run src/cloud/serviceLauncherClient.test.ts with the fix: 16 passed
  • vp test run src/cloud/serviceLauncherClient.test.ts with only the client change reverted: 1 failed (the committed-state case), 15 passed
  • vp run check:changed (format, lint, knip, graphql, typecheck, tests in 3 files): all pass, 66 tests

Not in this change

  • #repointServiceUnit still runs before the launcher handles the next queued transition; it was already after the reply and is unchanged.
  • The launcher still deletes the backup on its message queue, so a slow deletion still delays the launcher's next transitions (for example handling a later exit), though not the new server's start.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

juliusmarminge and others added 3 commits November 25, 2026 06:17
… discarded

Reproduces #42653: the launcher deletes and fsyncs the pre-update backup
before replying committed, while the trial waits only 30 seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…se backup

The trial waits 30 seconds for "committed". The launcher removed the
pre-update database backup (rm -rf plus a directory fsync) before
replying, so a slow cleanup made the trial give up and the committed
version start a second time. Reply first, then discard the backup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lies late

A remote update keeps the running launcher, so an older one can still
finish backup cleanup before it replies "committed". After the 30-second
wait, the trial now reads service-state.json and continues when it holds
this update as committed instead of exiting and restarting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 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 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: c6c8b20 · PR result: ca08db0 · 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.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The update handoff now sends the launcher’s commit reply before database-backup cleanup. If the trial times out waiting for that reply, it checks persisted service state and proceeds only when the same update is committed.

Changes: Service update handoff

Layer / File(s) Summary
Commit reply before backup cleanup
apps/server/src/serviceLauncher.ts, apps/server/src/serviceLauncher.test.ts
The launcher sends the committed message before attempting backup removal. Tests record whether the backup exists when the trial receives the message and verify cleanup after launcher shutdown.
Confirm timed-out commit from state
apps/server/src/cloud/serviceLauncherClient.ts, apps/server/src/cloud/serviceLauncherClient.test.ts, docs/internals/07_server-updates.md
After a timeout, the trial checks the runtime state file. It proceeds only when the file shows the same update as committed. Tests cover committed and pending states, and the documentation describes this behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: motaghi, maria-rcks

Merge Risk: Minimal · up to ca08d

This change sends the update's commit reply before slow backup cleanup. If the reply is late, it accepts a timed-out trial only when saved state shows the same update as committed. This should prevent the extra restart reported in the linked issue, and any other state still fails safely. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(server): launcher confirms an update before discarding the database backup" matches the main change. The launcher now sends the committed message before it deletes the database backup i…
Description check Passed The description follows the template well. It has a Problem section (a 30-second timeout and a second restart caused by backup deletion order), a Change section (launcher ordering, client fallback, do…
Linked Issues check Passed Issue #42653 asks for two fixes, and the PR applies both. (1) Launcher ordering: in apps/server/src/serviceLauncher.ts, #handlePrepared now sends committed inside a try block, and `discardDatabaseBa…
Out of Scope Changes check Passed All changed files relate to the issue. serviceLauncher.ts reorders the commit reply and backup cleanup. serviceLauncherClient.ts adds the committed-state fallback after a timeout, with the protocol im…
Full details: Title check

Explanation

The title "fix(server): launcher confirms an update before discarding the database backup" matches the main change. The launcher now sends the committed message before it deletes the database backup in serviceLauncher.ts. The title is a conventional commit, short, and specific. It does not cover the client-side timeout fallback in serviceLauncherClient.ts, but it does not need to cover every detail.

Full details: Description check

Explanation

The description follows the template well. It has a Problem section (a 30-second timeout and a second restart caused by backup deletion order), a Change section (launcher ordering, client fallback, docs), a Scope section that links issue #42653 with a bug-fix framing, and a Verification section with specific commands, results, and a reproduction on main. It also names the model and harness, as the template asks. Gaps: the Evidence section says it is still being captured and must be filled before merge, and the Scope section does not explain why a small fix needs an issue link beyond the linked issue. These gaps are non-critical, so the check passes.

Full details: Linked Issues check

Explanation

Issue #42653 asks for two fixes, and the PR applies both. (1) Launcher ordering: in apps/server/src/serviceLauncher.ts, #handlePrepared now sends committed inside a try block, and discardDatabaseBackup plus #repointServiceUnit run in the finally block after the send. The backup cleanup no longer delays the reply the trial waits for. (2) Trial tolerance: in apps/server/src/cloud/serviceLauncherClient.ts, prepareTrial catches a timeout from the commit exchange, reads runtime/service-state.json, parses it, and continues only when update.id matches the pending update and update.status is committed. Any other state, or a read or parse failure, fails with the original timeout error. This covers an older launcher that replies late, which the issue describes as the case for existing installs. The docs update in docs/internals/07_server-updates.md matches the new rule. The issue's reported macOS and APFS conditions were not reproduced, as the PR states. Evidence in the PR shows a test that fails on main and a client test that fails when the client change is reverted. I did not verify the error field name used in the timeout check or the content of the modified disk-recovery test, so those points rest on the PR summary.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the issue. serviceLauncher.ts reorders the commit reply and backup cleanup. serviceLauncherClient.ts adds the committed-state fallback after a timeout, with the protocol imports it needs (parseServiceState, SERVICE_STATE_FILE). The tests in serviceLauncher.test.ts and serviceLauncherClient.test.ts cover those two changes. The docs file describes the new commit rule. No unrelated behavior change appears in the diff. The PR description says #repointServiceUnit and the queued backup deletion are unchanged in timing, which matches the diff. The summary says the disk-recovery test was adjusted to wait for launcher shutdown; that is a test change supporting the reorder, not an unrelated change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c6c8b20 and ca08db0.

Files selected for processing: 5

  • apps/server/src/cloud/serviceLauncherClient.test.ts
  • apps/server/src/cloud/serviceLauncherClient.ts
  • apps/server/src/serviceLauncher.test.ts
  • apps/server/src/serviceLauncher.ts
  • docs/internals/07_server-updates.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@juliusmarminge

Copy link
Copy Markdown
Member Author

The automated pipeline stopped on this pull request and will not merge it:

the capture was not run as reported, so nothing is shown either way:

On both commits, seed the pending-trial state and an isolated backup directory; launch the real server through the real Launcher; let migrations finish and the trial send prepared; delay backup removal for 40 real seconds; record IPC, readiness, exits and launches for 65 seconds; restart the launcher after failure using the driver supervisor; intentionally stop afterward. Base timed out at 32.68s, exited at 33.47s, launched server #2 at 42.72s and became ready at 46.56s. Head sent committed at 7.82s before cleanup, became ready at 8.04s and retained one server. With the base launcher retained, head became ready at 34.88s before the delayed committed IPC at 44.71s and retained one server.

It stays open for a person to finish or close.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server self-update restarts twice: the launcher confirms the update after the new server's 30-second wait

1 participant