Repository navigation
fix: let a half-switched Git checkout finish updating from its new release - #203608
fuller-stack-dev wants to merge 7 commits into
Conversation
A checkout left half-switched by the openclaw#199706-era updater keeps a Gateway whose update.run repeats the failure, and while it serves, new code cannot write the state it has not migrated. The release CLI now prepares the update without the state database, points the service at the launcher, restarts it, and records the run once the new release serves.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
RED raw logs (1/4): base release CLI `update --yes --json` (handled by the old Gateway): exit 1, 154.1 s, stdoutrelease CLI `doctor --fix --non-interactive`: exit 1, 1.1 s, stderrrelease CLI `update repair --json`: exit 1, 12.5 s, stdoutrelease CLI `update --yes --json --no-restart`: exit 1, 2.1 s, stdoutrelease CLI `gateway install --force --json`: exit 0, 3.5 s, stdout |
|
RED raw logs (2/4): plain plain `openclaw update`: exit 0, 117.6 s, stdout |
|
RED raw logs (3/4): the 8f80 updater's own 8f80 `openclaw update` stdout, part 1 |
|
RED raw logs (4/4): continuation of the 8f80 updater's stdout, lines 426- 851. 8f80 `openclaw update` stdout, part 2 |
…he service Restore the earlier updater's trial only when nothing restarted, read back the effective service command, give the boot wait its own budget from the restart, and convert only for the configured local Gateway.
…sume an interrupted restart Require the effective service to start the checkout and to use the same state and config before converting; let the next update restart into a trial whose restart never happened; follow the run within the one --timeout budget.
… resuming Refuse before publishing when the service starts another checkout; compare the service's own state and config selection; read the service only for trials that can need conversion; prepare afresh for --sha; stop before the restart when --timeout is spent; resume only the trial prepared for this checkout and config.
|
RED recording: base red-half-switched-base-a1aa127.mp4 |
|
Codex review: blocked before merge. What this changesThis PR lets a new release CLI recover a Git installation whose old updater prepared a release without switching the serving Gateway. Example: A checkout serves OpenClaw 2026.11.4 while its updater has prepared 2026.11.6.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 6 items remain Keep this PR open: it addresses an observed recovery failure, but timeout handling, retry routing, and resume validation still contain blocking defects. Priority: P1 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe Git updater connects CLI requests to release preparation, native service definitions, launcher trials, boot-time state migration, and persisted update outcomes. flowchart TD
A[Release CLI] --> B[Detect interrupted conversion]
B --> C[Existing release preparation]
C --> D[Service definition owner]
D --> E[Resident launcher trial]
E --> F[Gateway boot and migration]
F --> G[Update run settlement]
Technical reviewBest possible solution: Keep recovery in the release CLI while making every abort and retry preserve a consistent service definition, pending trial, selected state, and deadline through the existing owners. Do we have a high-confidence way to reproduce the issue? The supplied real-service failure logs and current-main delegation path establish the central failure; the additional retry defects are traceable directly through the introduced code without executing it. Is this the best way to solve the issue? CLI-owned conversion is justified because the running old Gateway cannot execute the fix, and reusing release preparation with deferred ledger writes avoids a competing update engine. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a63a4297f32b. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +559, Tests +365. Total +924 across 7 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 22, 2026, 3:29 PM ET / 20:29 UTC. |
|
GREEN at the PR head
green-half-switched-head-beaa7d2.mp4convert: exit 0, 406.1 s (raw stdout)status: exit 0, 2.3 s (raw stdout)path-cli: exit 1, 1.5 s (raw stdout)next-update: exit 0, 372.8 s (raw stdout)Per-step outages, per-directory disk and marker checks |
|
Closing this in favor of a by-hand procedure that I verified end to end. It covers the half-switched state this PR targeted and also a clean checkout still on the old updater, with no product change. Why not this PR. The conversion here only runs when someone starts the release CLI by its full path, so it is a manual step either way. The updater installed in an affected checkout (8f80fe0) cannot be changed from the target side: it stops at its own in-process schema check before any target code can migrate state or restart the Gateway. Verified procedure (run from the checkout, as the service's user; same for a clean and a half-switched checkout):
Measured in Linux containers with systemd as PID 1, a user Gateway service, a 512 MiB agent database under 1 MiB/s of writes and a node runner started from the checkout. Target was main at e6b42e3; synthetic state only.
Marker rows and their hash were intact in every run. The build is about 250 s of the outage. Afterwards three ordinary What does not work. Pull, install, build, restart without stopping the Gateway first: Leftovers on a half-switched checkout. A later successful update collected both old-layout releases once they aged out (aging simulated by changing mtimes). It left their Git worktree records and the old link behind. This removed them, and the Gateway restarted and served normally afterwards: Not proven. macOS/launchd (the stop, start and install steps and the build's live-service check are service-manager specific); a service whose start command names |
What Problem This Solves
A Git checkout that tracked
mainbetween #199706 (2026-11-17) and #200578 can be left half-switched by its own updater, and nothing after #203194 gets it out. That updater builds a release, links it atgit-install/lib/node_modules/openclawand arms a trial without thevfield. It never starts the release, leaves the service on the checkout's build and exits 1 withopenclaw doctor. From then on:openclaw update,openclaw doctor --fixand the Gateway's automatic updates all run that old build (unpatchable). Repeats reportalready-currentwhile the Gateway serves 2026.11.4 on schema 40/42. Whenmainmoves, each one builds another 4.6 GiB release and fails the same way.node ~/.openclaw/git-install/lib/node_modules/openclaw/openclaw.mjs update. Onmainthat CLI sendsupdate.runto the running old Gateway. The old Gateway answers with its own handler (managed-service update handoff,driver:adopted), builds another release and fails the same way.--no-restart,update repairordoctor --fix, the new CLI cannot write the state database. The old Gateway owns it, and the database needs a forward migration that the new code may only do at the release's boot.gateway install --forcepins the service to that release'sdist/index.js, outside the launcher, with no trial and no rollback.This is a real install shape: any checkout that tracked
mainin that window, including a live instance we run.User Impact
From that state, one command converges:
node ~/.openclaw/git-install/lib/node_modules/openclaw/openclaw.mjs update.check-release. Neither step touches the state database..pre-*originals that a rollback restores.openclaw updatefollows it tosucceeded.Every later update takes the normal release path. Plugin maintenance waits for the next update (an already-current update maintains plugins too), because it needs the state database that the old build owned during the conversion.
Every other install is unaffected. The new route runs only in three states:
releases/.triallacks the format field (only feat(update): run Git checkout installs from releases behind the release link #199706's updater writes that), and the effective service still starts the checkout rather than the launcher. An install that feat(update): run every Git install from releases and delete the in-place Git runner #200578's machinery finished, with a deferred format-1 trial, already starts the launcher and keeps the normal route.openclaw updateonly restarts into the prepared release and records the run.The conversion refuses before changing anything in these cases, and each message says so:
--timeoutis already spent before the restart.A resume starts only the trial that was prepared for this checkout and config.
--shaprepares afresh instead of resuming. Installs whose trial cannot need conversion keep the normal route without a native service read.Why This Change Was Made
Which entry points can run the fix. Everything on the user's path runs the old build:
openclawon PATH (a link to the checkout), the service (<checkout>/dist/index.js, which has no forwarder), the Gateway'supdate.runand automatic updates. The release that build's updater left behind is the only one that runs code from this change, and only by its full path. So that CLI owns the conversion.Owner and invariant. The release path's preparation (
prepareUpdate) records every step in the state database. Here the database belongs to a build that cannot be migrated while it runs.prepareUpdatenow takes the run ledger as a parameter; the default is the state database, so no other caller changes. The conversion collects the run's progress in memory and records it once the release owns state. It also passes the checkout's serving commit, because the CLI's own build is not what serves.Service definition.
src/update/convert-service.tsis the same module, with the same interface, as #203497'sstageReleaseService. It stages the launcher through the existing definition-backup owner, without stopping the Gateway. Whichever PR lands second drops its copy. After staging, the conversion reads back the effective command, drop-in overrides included. If that command does not start the launcher (for example a system-owned unit or an override), the conversion stops before any restart, puts back the earlier updater's trial, and says that the current version is still running. The nextopenclaw updatethen tries the conversion again. Once the restart has been attempted, the trial stays with the launcher, which may already be booting the release and needs the trial to roll back. Waiting for the trial gets its own budget, which starts at the restart: the launcher's 20-minute trial plus one minute, within what remains of--timeout. When that budget runs out, the message namesnode ~/.openclaw/git-install/openclaw/openclaw.mjs update status. The conversion runs only when the CLI targets the configured local Gateway.Rollback. The trial's fallback is the checkout's own build, which is what serves. If the release does not become ready, the launcher restores the boot-migration originals and starts the checkout's build. The next
openclaw updateconverts again: the route also matches a rolled-back trial whose serving tree has no forwarder.What stays manual.
openclawon PATH still starts the checkout's 2026.11.4 build. That build now refuses with its own true message ("uses newer schema version 41; this build supports 40") and changes nothing. The run records awarning:checkout-clistep, whichopenclaw updateprints. It namesnode ~/.openclaw/git-install/openclaw/openclaw.mjs, which follows every release. Fixing PATH automatically would mean rewriting the user's pnpm global link or rebuilding their checkout. This change does neither.Prior decision. #203194 rejected settling #199706's format-1 trials and the
lib/node_moduleslink, because "main-only code is not a shipped contract". This PR asks maintainers to revisit that for one reason: the state is observed on a production instance, and no entry point recovers it without hand edits. It does not settle format-1 trials or follow the legacy link. It replaces the trial with the current format through the normal preparation, and leaves the legacy link and releases to the normal 24-hour release collection.Update behavior. This runs from new code only. The old updater and Gateway are unchanged and cannot be patched. The user runs the release CLI once, by full path. That release must contain this change, which holds after the old Gateway's own automatic update builds a newer
main. No schema, config key, protocol, dependency or retention change.Evidence
Real Linux container with systemd as PID 1, a lingering user manager and a real user bus. A user systemd Gateway service, a Gateway-gated writer on a 512 MiB agent database, and 1,000 marker rows checked by count, SHA-256 and
PRAGMA quick_checkafter every step. Synthetic state only. Setup: a checkout at8f80fe08cad(#199706 era) with the service installed, andorigin/mainpointed at the code under test. The checkout's ownopenclaw update(the 8f80 updater) then leaves it half-switched: exit 1openclaw doctor, the release linked atlib/node_modules, a format-1 trial, the service on the checkout, schema 40/42.origin/mainthen moves one commit.RED: base
a1aa1276017, whose release the 8f80 updater built.node …/lib/node_modules/openclaw/openclaw.mjs update --yes --json(release CLI →update.run→ the old Gateway's own handler)trigger: api,openclaw doctor; a third release built; a new format-1 trialopenclaw update(8f80 on PATH)skipped/already-current(false)doctor --fixupdate repairupdate --no-restartgateway install --forcedist/index.js(no launcher, no trial, no rollback)GREEN: PR head
beaa7d2c706, with the 8f80 updater building that head as the half-switched release.node …/lib/node_modules/openclaw/openclaw.mjs update --yes --jsonsucceeded(trigger: cli, before 2026.11.4, after 2026.11.6 at the target build). The unit now namesgit-install/openclaw-launcher.mjs. Trial v2committedafter 1 attempt, with the checkout as fallback. The run records the deferred plugin note and thewarning:checkout-clinote.quick_checkok;/readyz200openclawon PATH (8f80)node ~/.openclaw/git-install/openclaw/openclaw.mjs update --yes --jsonsucceededthrough the new Gateway'supdate.run. Trial committed, fallback the previous release.The same green rows passed at two earlier heads:
5ba368f4ebc(428 s, 31.5 s outage) and3f1e3eb7dbc(408 s, 33.7 s outage).Raw red output, unedited: release CLI attempts, plain update on PATH, and the 8f80 updater's half-switch (part 1, part 2). Red recording: base. Green recording and raw output at the head: head. Full logs are not attached because the artifact store rejects uploads from this machine.
Tests:
src/update/half-switched.test.ts(new):current.src/update/cli.test.ts:update.run. Red on the base: it sentupdate.run.releases/.trial.try/finallyenv restore, which the sharedafterEachnow covers.test/vitest/vitest.database-worker-core-paths.mjs: the new file runs with the state database broker, asprepare.test.tsdoes.Checks:
node scripts/run-vitest.mjs src/update/ src/gateway/server-methods/update-run.test.ts,update-restart-module-outcomeandeager-import-closure,pnpm tsgo:core,pnpm tsgo:core:test, oxlint and oxfmt on the touched files,pnpm check:baseline-ratchets(all ok, session-identity included),git diff --check.Review:
ClawSweeper's local review, round 3 (the last round): overall F, proof D, patch F. Fixed after it, with tests where noted:
--sha.--timeoutis spent.Not fixed: it asks to identify a rolled-back checkout's running build by its capabilities rather than by the forwarder file at its root. A checkout pulled to current
mainwithout a rebuild would have the file but still run the old build. Listed under "Not proven".ClawSweeper's local review, round 2: overall F, proof D, patch F. Its findings, all handled:
resumeroute, tested.--timeoutbudget: done.ClawSweeper's local review, round 1: overall F, proof D, patch F. Its findings, and what I did:
A fresh independent reviewer found three P1 issues, all fixed:
Its P2 findings, handled:
autoreviewcannot run here. The worktree sits under a shared temp directory, and its Codex preflight refuses that.Not proven:
mainbut not rebuilt. Detection reads the forwarder file at the checkout root, so this case is not converted again./.dockerenv, because fix: let Git checkouts inside containers update again #203586 (the container refusal) is not merged.