Repository navigation
fix: keep the Windows openclaw command on the current release after Git updates - #203247
Conversation
…taller wrapper A Git release install leaves the npm package forwarding to its launcher, but the executor's occupied-slot check only accepted a package path that resolves to the installation, so switching back to npm failed with 'Occupied slot does not resolve to its original installation.' Reserve this install's exact forwarding package, the same ownership proof destination admission uses. install.ps1 wrote the Git wrapper as dist\\entry.js (a literal double backslash), which the updater's exact match never recognized, so Windows Git installs kept running the checkout's installer-time build from PATH. Match the wrapper's entry by normalized Windows path and write single backslashes. Refs #200578
…l's executor Refs #200578
|
🦞👀 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. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis PR restores Git-to-npm switching and makes Windows Git installer wrappers follow the selected release. Example: An npm installation switches to Git, then runs openclaw update --channel stable.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs two source-confirmed Git update failures that remain on current main, and no introduced correctness defect was found. Priority: P1 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe update CLI coordinates installation leases, package activation, and PATH wrappers so requested updates select the release that later CLI and Gateway launches run. flowchart TD
A[Update command] --> B[Installation executor]
B --> C[Package destination admission]
C --> D[Package activation]
A --> E[Git release update]
E --> F[Installer wrapper]
F --> G[Release launcher]
Technical reviewBest possible solution: Retain these focused repairs in the existing executor and wrapper owners while preserving unrelated installations and user-written wrappers. Do we have a high-confidence way to reproduce the issue? The producer, destination admission, executor reservation, and wrapper comparison expose both failing paths directly; no product code or tests were executed during this read-only review. Is this the best way to solve the issue? The patch restores the documented release-migration contract with existing ownership predicates and Windows path normalization, without adding a competing owner or unnecessary test machinery. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 89596c51481e. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +23, Tests +75, Other 0. Total +98 across 5 files. Added test files: 0. 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. 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 21, 2026, 2:30 PM ET / 19:30 UTC. |
…xits cleanly cmd.exe rereads a running batch file at its saved byte offset. openclaw update usually runs through the wrapper it rewrites, so after the update returned cmd resumed inside the new command line and the update exited 1 with 'The system cannot find the path specified.' Pad the new wrapper so the old length lands on an exit line that keeps the update's exit code. Drop the npm switch-back slot admission: package publication recovery also requires the executor's installation to be the npm directory, so the switch back needs a root decision in the package update owner, not a slot exception. Refs #200578
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ac2174e34e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const head = "@goto run\r\n@rem "; | ||
| const pad = "x".repeat(Math.max(0, Buffer.byteLength(contents) - head.length - 2)); | ||
| const next = | ||
| platform === "win32" | ||
| ? `@echo off\r\nnode "${entry}" %*\r\n` | ||
| ? `${head}${pad}\r\n${WINDOWS_WRAPPER_EXIT}\r\n:run\r\n@node "${entry}" %*\r\n` |
There was a problem hiding this comment.
Avoid growing the Windows wrapper on every Git update
On Windows, every subsequent Git update recognizes the padded wrapper but rewrites it with padding based on its entire current length, adding another exit/launcher suffix each time. With the paths in the new regression test, the wrapper exceeds 4096 bytes after 42 rewrites, at which point this function's size guard silently skips it—including when switching back to npm. The stale wrapper can therefore remain ahead of npm on PATH and continue launching the Git installation. Preserve an already-correct launcher wrapper unchanged; the new test's second-call equality assertion also fails with the current implementation.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
…it updates (openclaw#203247) * fix(update): admit Git-to-npm switch back and repoint the Windows installer wrapper A Git release install leaves the npm package forwarding to its launcher, but the executor's occupied-slot check only accepted a package path that resolves to the installation, so switching back to npm failed with 'Occupied slot does not resolve to its original installation.' Reserve this install's exact forwarding package, the same ownership proof destination admission uses. install.ps1 wrote the Git wrapper as dist\\entry.js (a literal double backslash), which the updater's exact match never recognized, so Windows Git installs kept running the checkout's installer-time build from PATH. Match the wrapper's entry by normalized Windows path and write single backslashes. Refs openclaw#200578 * fix(update): admit the forwarding package only for its own Git install's executor Refs openclaw#200578 * fix(update): rewrite the Windows Git wrapper so the running cmd.exe exits cleanly cmd.exe rereads a running batch file at its saved byte offset. openclaw update usually runs through the wrapper it rewrites, so after the update returned cmd resumed inside the new command line and the update exited 1 with 'The system cannot find the path specified.' Pad the new wrapper so the old length lands on an exit line that keeps the update's exit code. Drop the npm switch-back slot admission: package publication recovery also requires the executor's installation to be the npm directory, so the switch back needs a root decision in the package update owner, not a slot exception. Refs openclaw#200578 * fix(update): leave a wrapper that already runs the release launcher unchanged Refs openclaw#200578
…lace Git runner (#200578) Slice 4b of the update foundation. Follows #199706 (slice 4), #201917 (releases outside `node_modules`) and #201538 (half-switched Git updates). ## Problem Since #199706, POSIX Git checkouts with a Gateway service update through releases: a detached worktree at `<state>/git-install/releases/<id>/openclaw`, behind the link `<state>/git-install/openclaw`, started by a launcher that switches back after two failed starts. Three cases still used the in-place Git runner, which rewrites the checkout the Gateway runs from: - Windows checkouts; - package-to-Git switches; - checkouts with no Gateway service. That runner is RC1 of the update RCA: in-place replacement at a path running processes use. Keeping it meant keeping its rollback, retention, pack transfer, staging and handoff code. ## Change Every Git install now updates through releases. The in-place Git runner and its command-side rollback are deleted on every platform in one cutover. `openclaw update` no longer moves the checkout `HEAD` or rebuilds its `dist`. (`scripts/update-gateway.sh`, a separate maintainer script, still rebuilds a checkout in place; it is unchanged.) - **Windows:** - The release link is an NTFS junction, which needs no administrator rights. It is owned by the existing `package-release-slot*` code; the win32 exclusions there and in the release lease are removed. - Windows cannot rename onto a junction, so a switch removes the old junction and then renames. - The Windows task supervisor starts its Gateway child through the release launcher, so the child's starts count toward the trial. - **Package-to-Git:** - The checkout is cloned and the target is built as the release on trial. Its fallback is the npm package that was serving, kept intact: if the Git build fails to start twice, the launcher switches the link back to the package, and the Gateway and `openclaw` on PATH run the npm build again with no manual step. A deferred (`--no-restart`) switch keeps the same fallback. The package counts as this install's only while its `openclaw.mjs` is exactly this install's forwarding entry; retention never touches it. - The global npm package's `openclaw.mjs` is rewritten once to import the release launcher, so the existing npm bin shims run the release. Without that, `openclaw` on PATH would keep running the old npm build, whose updater treats the install as npm. - The rejected alternative, re-pointing the npm package path at the release, would name the release through `node_modules/openclaw` again, the cause of #201874. - Installs whose switch was done by an older updater have the npm package path linked to the checkout, which releases never rebuild. A Git release update replaces that link (only a link to the checkout) with a directory holding `openclaw.mjs` and `dist/index.js`, both starting the launcher; the second keeps a service definition that names the package path working after a `--no-restart` update. Without this, the CLI and its updater stayed on the version the switch built (found by the package-to-Git upgrade lane). - **No service:** a checkout run by hand updates through a release too. The next `openclaw gateway` runs it. - **CLI on PATH:** after a Git release update, the installer's `openclaw` wrapper (POSIX and Windows) is rewritten once to run the release launcher, and a global npm, pnpm (`pnpm add -g openclaw@link:`) or Bun (`bun link`) link to the checkout is replaced the same way as the npm link above. The launcher selects a `--no-restart` release on the next Gateway run and counts `openclaw gateway` / `openclaw gateway run` as trial starts; other commands (`gateway status`, `--version`) never count. - **Service definition:** `serviceUsesUpdatedRoot` reads the service definition, not the running process. A `--no-restart` Git release update whose service still starts the checkout writes a definition that starts the launcher without starting or restarting the Gateway (`stage`; systemd reloads unit metadata only). Every OpenClaw restart route on macOS (`openclaw gateway restart` and the Gateway's own restart) re-bootstraps the job when the loaded command is known to differ from the plist on disk; otherwise it kickstarts. Only a failed write leaves an owed `service-definition` step. - **Conversion stop:** a Git update stops a Gateway whose service does not yet name the launcher before the release activates, so the existing install rebinds it. A Dashboard update on macOS runs inside the Gateway's LaunchAgent, which cannot rewrite itself while loaded; without the stop, the update reported success, the Gateway kept the old checkout and the result asked for `openclaw gateway install --force`. This replaces `main`'s macOS in-place fallback (247b958), whose runner this PR deletes. An update the previous definition does not start is reported as pending, not succeeded. Services that already name the launcher still switch without a stop. - **Restart:** the converted service restarts once, not twice. Git release updates no longer warn to restart a live Gateway by hand: a release replaces no root the Gateway uses. - **No manual steps (Ayaan, 2026-11-20):** - Releases built under `lib/node_modules` by `7db69bedeab6`-era updaters (#201874): bundled plugin public surfaces there load the built `dist/extensions/<plugin>/` JavaScript, so those installs update by themselves; the manual bridge in the #201874 comment is no longer needed. - A killed npm link swap leaves the link under npm's backup name; the next Git update restores it and retries. - The launcher finishes a Windows link switch killed between removing the old junction and renaming the new one. - npm -> Git -> npm: destination ownership recognizes this install's exact forwarding `openclaw.mjs`, so switching back is admitted. ## Impact - One update path for Git installs on macOS, Linux and Windows. - `openclaw` on PATH runs the current release after an update. - **Accepted edge cases:** - Two checkouts that share one state directory share its single release install. - After a package-to-Git switch, the old npm package keeps its disk space until a switch back to npm replaces it. - A Gateway run for another profile through the default `openclaw` on PATH counts toward the default install's trial (accepted by Ayaan, 2026-11-20). - `--no-restart` selects the new release at the next start without the two-start switch-back. - A checkout installed at `<state>/git-install/openclaw` (the release link path; the installer default is `~/openclaw`) is left in place, and every update fails visibly with nothing changed, naming the fix: move the checkout or reinstall with another `--git-dir` (accepted by Ayaan, 2026-11-21). - The first update of an install whose service still names the checkout has a one-time outage while the Gateway stops and the LaunchAgent or unit is rebound (26 s on the macOS Dashboard run). - If a macOS release's `launchctl print` omits the job's arguments, a definition staged by `--no-restart` applies at the next login or update instead of the next restart. - Unchanged follow-up: when local commits conflict with every newer commit, the preflight reports `already-current` instead of naming the conflict. This predates the PR and gets its own PR. ## Size Against the merge base, 32 commits: - Production code: +821 / −2,166 (56 files). - Tests: +1,391 / −8,893 (74 files). Cut tests covered steps a Git release no longer takes (checkout rollback, in-place staging, service stop before checkout); each is listed in the contract. - Upgrade-survivor scenario: +836 / −104 (4 files): baselines `v2026.11.5`, `7db69bedeab6`, `main`; package-to-Git; no service; SIGKILL at stage, build, publish, link switch and launcher restore. - Docs: +132 / −104. ## Evidence Final head `99ecf23e04e8`. Each row names the head its end-to-end proof ran on; later commits change tests, the e2e helper's lint, the restart warning text, the macOS reload probe's unknown case, the npm/pnpm/Bun link lookup and the deferred-switch staging (unit-proven, red on base). | Invariant | Result | Proof | |---|---|---| | Release built where it serves; no `node_modules` in the link or realpath | Pass | Linux upgrade-survivor lanes; macOS launchd (isolated profile on a maintainer Mac); hosted Crabbox Windows Server 2025 | | Gateway serves the new release and `tools.invoke web_search` works after every update | Pass | every hop on all three OSes | | SIGKILL at stage, build, publish, link switch, launcher restore leaves a serving install | Pass | Linux kill-point lane (`8f63330`) | | Two failed starts switch back and restore `.pre-` state | Pass | Linux lanes; macOS `8f63330` (`failed to start twice; switched back`); Windows `9cbc4b5`, automatic through the Scheduled Task, 67.5 s outage. Older-supervisor and pending cases: unit tests red on base (`6003675`, `75e7bd5`) | | The release updates itself | Pass | Linux; macOS `8f63330`; Windows `9cbc4b5` | | The checkout is never written (HEAD, status) | Pass | every lane and OS run | | Every shipped layout reaches releases with no manual step | Pass | `v2026.11.5`, merge-base `main` (`8f63330`); `7db69bedeab6` (`6003675`) | | npm → Git switch; `openclaw` on PATH runs the release | Pass | Linux `75e7bd5` | | No service: the next `openclaw gateway` runs the release | Pass | Linux `8f63330` | | `--no-restart` keeps the Gateway up; the next restart runs the release | Pass | macOS `8f63330`: 0 s outage, `gateway restart` reloads launchd arguments | | macOS Dashboard update (`update.run`) on a LaunchAgent that names the checkout, twice, then a terminal update | Pass | `80d9587`, isolated profile on a maintainer Mac: each update served its new commit, launchd runs `openclaw-launcher.mjs`, `web_search` passed, checkout unchanged, no manual step needed. Red on `3c14869` (Gateway kept the checkout, manual install step) | | Linux `7db69bedeab6` → head and npm → Git | Pass | `80d9587` | | Windows junction; a release held open is retained, then collected | Pass | hosted Crabbox (Windows Server 2025) | | Windows without admin rights | Not run | S4U Limited stays admin on the Crabbox image | | Installer-made partial clones (`--filter=blob:none`) | Not run | all lanes clone fully | Reviews: local ClawSweeper on every head (last finding accepted above); Fable 5.2 contract reviews. Unit: release, update-runner, launcher, wrapper, service, launchd, systemd, restart, task-supervisor, plugin loader suites; `tsgo:core` and `tsgo:core:test` clean. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit b229b26) Release adaptation: Extract only the three public-surface resolver, caller and regression paths. Preserve globals, source checkouts and already-bound plugin instances; exclude the Git updater rewrite. Companion audit: PR #200578 is the source; #203247 and #204835 follow the excluded Windows launcher and install switch. No follow-up modifies the selected public-surface files. Co-authored-by: RomneyDa <[email protected]>
…it updates (#203247) * fix(update): admit Git-to-npm switch back and repoint the Windows installer wrapper A Git release install leaves the npm package forwarding to its launcher, but the executor's occupied-slot check only accepted a package path that resolves to the installation, so switching back to npm failed with 'Occupied slot does not resolve to its original installation.' Reserve this install's exact forwarding package, the same ownership proof destination admission uses. install.ps1 wrote the Git wrapper as dist\\entry.js (a literal double backslash), which the updater's exact match never recognized, so Windows Git installs kept running the checkout's installer-time build from PATH. Match the wrapper's entry by normalized Windows path and write single backslashes. Refs #200578 * fix(update): admit the forwarding package only for its own Git install's executor Refs #200578 * fix(update): rewrite the Windows Git wrapper so the running cmd.exe exits cleanly cmd.exe rereads a running batch file at its saved byte offset. openclaw update usually runs through the wrapper it rewrites, so after the update returned cmd resumed inside the new command line and the update exited 1 with 'The system cannot find the path specified.' Pad the new wrapper so the old length lands on an exit line that keeps the update's exit code. Drop the npm switch-back slot admission: package publication recovery also requires the executor's installation to be the npm directory, so the switch back needs a root decision in the package update owner, not a slot exception. Refs #200578 * fix(update): leave a wrapper that already runs the release launcher unchanged Refs #200578 (cherry picked from commit 9809b28) Release adaptation: Keep only normalized install paths and recognition of the owned stable wrapper when its legacy entry path contains repeated separators. Exclude resident launcher and its retirement rewrite. Companion audit: PR #203247 is the source. #203588 atomic replacement is already present via NullString.Value; later memory gating is out of scope. Co-authored-by: RomneyDa <[email protected]>
Related: #200578
What Problem This Solves
On Windows, a Git install's
openclawcommand keeps running the build made when the installer ran. After #200578, every Git update should repoint the installer'sopenclaw.cmdat the release launcher. On Windows it never did, soopenclawkeeps running the checkout's old build and its old updater. At the next state schema bump that build would refuse every command, includingopenclaw update. macOS and Linux are not affected.User Impact
openclawat the current release.Why This Change Was Made
install.ps1built the wrapper path with"dist\\entry.js". In a double-quoted PowerShell string that is a literal double backslash, so the wrapper readsnode "C:\repo\dist\\entry.js" %*. The updater compared that line exactly againstC:\repo\dist\entry.js, so it skipped the wrapper every time. The installer's ownTest-PreviousGitWrapperregex rejected the line for the same reason. The fix:Once the rewrite happened, a second problem showed up live.
openclaw updateusually runs through the very wrapper it rewrites. cmd.exe rereads a running batch file at its saved byte offset, so when the update returned, cmd resumed in the middle of the new line. The update then exited 1 withThe system cannot find the path specified.even though it had succeeded.The new wrapper is:
@goto run;@remline padded so the old file's length lands exactly on@exit /b %errorlevel%;:run;@node "<launcher>" %*.A fresh run jumps to the launcher. The cmd.exe that ran the update exits with the update's own exit code. The updater and the installer recognize both formats, and a later update rewrites the wrapper byte for byte.
POSIX wrappers are unchanged: they
exec, so bash never reads the rewritten file.Evidence
Regression test. The wrapper
install.ps1writes is repointed at the launcher. In the new file, the old file's byte length lands on the exit line, and a second update rewrites it unchanged. The test fails on base and passes with the fix.Live, Crabbox Windows Server 2025 (AWS). Base
install.ps1writes the wrapper, then oneopenclaw update --channel devfrom a checkout at the driver commit:openclaw --version9156690807fnode "C:\g\oc\dist\\entry.js"(checkout build)The system cannot find the path specified.ac2174e34e5)0810295Through the padded launcher wrapper,
openclaw --versionexits 0 and an unknown command exits 1.The final head (
b4828c4ce9f) adds only the unit-proven skip that leaves a wrapper already on the launcher unchanged.test/scripts/install-ps1.test.tspasses locally with pwsh.Reviews on
b4828c4ce9f: autoreview scoped-clean, and an independentcodex execreview found nothing. Earlier rounds found the repeated-rewrite padding growth and the vacuous second-call test; both are fixed.Not in this PR. The evidence is on #200578.
Occupied slot does not resolve to its original installation.) needs more than a slot exception. Package publication recovery also requires the executor's installation to be the npm directory, so the fix belongs with the package update owner. Verified workaround:npm i -g openclaw@<version>, thenopenclaw gateway install --force.node ~/.openclaw/git-install/openclaw-launcher.mjs update --channel dev.