Repository navigation
fix(server): launcher confirms an update before discarding the database backup - #42665
juliusmarminge wants to merge 3 commits into
Conversation
… 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>
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenariosAll 64 scenario measurements match All 64 scenario measurements
Baseline: Scenario and decoded snapshot size10 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
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. |
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.#handlePreparedsendscommittedright after the update is saved, and only then deletes the backup and updates the service unit.prepareTrialtimes out waiting forcommitted, it readsservice-state.jsonand 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.mddescribes the new rule.Fixes #42653
Reproduction on main
On origin/main 4a8f2be, in apps/server/src/serviceLauncher.test.ts, I extended the existing
commitUpdateharness. 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 withvp test run src/serviceLauncher.test.ts -t commit. On main it fails withexpected '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.tswith the fix: 16 passedvp test run src/cloud/serviceLauncherClient.test.tswith only the client change reverted: 1 failed (the committed-state case), 15 passedvp run check:changed(format, lint, knip, graphql, typecheck, tests in 3 files): all pass, 66 testsNot in this change
#repointServiceUnitstill runs before the launcher handles the next queued transition; it was already after the reply and is unchanged.Who did the work
Run by the t3code factory in T3 Code.