Skip to content

feat(update): run Git checkout installs from releases behind the release link - #199706

Merged
obviyus merged 40 commits into
mainfrom
feat/update-git-releases
Nov 17, 2026
Merged

obviyus merged 40 commits into
mainfrom
feat/update-git-releases

Conversation

@obviyus

@obviyus obviyus commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A Git checkout install runs its Gateway from <checkout>/dist/index.js, and openclaw update rewrites that same tree. Everything around the rewrite exists to survive it: the updater copies its own runtime first (133–892 s on a 183k-file checkout), builds the candidate in a private repository and imports it through a pack (256 MB cap), stops and parks the serving Gateway, and rewrites the service definition every update.

Change

Extends #198835's linked package root (merged as b868ed4c) to Git checkouts, per the #197949 design. Based on main. It reuses #198835's release resolver, switchPackageReleaseLink, leases and 24 h collection unchanged. Its fallback follows installStagedPackage: when the layout can't be used, the update runs in place with a recoverable-maintenance warning, and the next update tries the layout again. The Gateway process never writes the release link. The only other writer is the boot launcher, and it only points the link back to the release recorded in a failed trial.

  • Layout. <stateDir>/git-install/lib/node_modules/openclaw -> releases/<id>/lib/node_modules/openclaw. Each release is git worktree add --detach off the developer's checkout (shared object store, no clone or copy).
  • Stage. The existing candidate preflight (candidate walk, local-commit replay, pnpm install --frozen-lockfile, build, candidate checks) runs in the new release's worktree, then --version with the service's Node. A same-source no-op requires the serving release to be at the checkout's commit and its artifacts to verify (fix: rebuild incomplete Git runtimes when source is current #158931).
    • Deviation from the design: the worktree is built at releases/<id>/build, then moved into place with git worktree move. Node refuses to strip types under node_modules (ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING), and the build runs .mts scripts. The built tree has no absolute symlinks, so the move is safe.
  • Switch. switchPackageReleaseLink from feat(update): keep each release in its own directory on OpenClaw-owned installs #198835. The serving Gateway keeps its release (Node resolves the entry's real path), so nothing is stopped, parked or verified before the flip.
  • Restart. The serving Gateway's maintenance tick sees the link move (installation replacement) and restarts itself into the new release. The updater waits for that successor (up to 90 s), then verifies. It falls back to a native restart only if no successor appears. A native restart from inside the service job (update.run) would end the updater itself.
  • Service. Written once, at conversion, to a frozen launcher <stateDir>/git-install/openclaw-launcher.mjs. A unit that names the launcher is never regenerated. The launcher is needed because a release that fails while loading never reaches Gateway code.
  • Trial. The switch writes releases/.trial. The launcher counts starts.
    • After two failed starts it switches the link back and restores the trial build's *.pre-<buildId> state files (falling back to feat(state): upgrade state by copy and swap at Gateway startup #198389's *.pre-<version>). Each SQLite family is restored together, and trial-created WAL/journal/SHM/seal files without a preserved predecessor are removed. The launcher mirrors feat(state): upgrade state by copy and swap at Gateway startup #198389's companionRemovals list because it must not load release code.
    • The trial ends when the Gateway's first maintenance tick runs, or when the updater verifies the restarted Gateway. The second path also covers targets that predate this PR.
    • Writes made during a failed trial are lost (approved).
  • The layout never fails an update (docs: propose a linked package root and staged candidate handoff for updates #197949 decision 8). If releases/ cannot be created, or something other than a release link sits at the package path, the update records a warning and takes the in-place runner. The next update tries the layout again.
  • Post-core work (requested-channel persistence, plugin convergence) runs in the updater, but only after the restarted release verified and its trial ended. A failed trial therefore never leaves plugins that require the release it switched away from. It runs without Doctor maintenance, which the Gateway holds, and without a plugin cohort, because no core rollback exists to pair it with. If plugins changed, the Gateway is asked to restart again (SIGUSR2). Under --no-restart the release is unverified, so only the requested channel is persisted and plugins converge on a later update.
  • The developer's checkout is never written. The first update builds the commit that serves now as the first release, rewrites the unit once, then stages the target.
  • Retention. feat(update): keep each release in its own directory on OpenClaw-owned installs #198835's collection, followed by git worktree prune. git-install is excluded from backups and from the startup state-upgrade copy. The latter is the same change as fix(state): leave Git release installations out of the startup upgrade copy #199770, included here so the stack stands alone.
  • One owner. usesGitReleases selects releases. Windows checkouts and package-to-Git switches keep the in-place runner, and the in-place CLI tests are pinned to that runner.

For Git releases this skips:

  • runtime retention
  • the pack transfer/import
  • the managed-service stop/park
  • the database rollback capture
  • the checkout's source-artifact lock
  • the native restart from inside the service job
  • per-update service regeneration

In-place fallback (decided)

Windows Git checkouts, package-to-Git switches, and checkouts with no installed Gateway service still use the in-place runner, so this PR bypasses that runner on POSIX instead of deleting it. A checkout with no service is run by hand, so nothing would start through the release link and its next start would run the old commit. gatewayServiceOwnsGitInstall reads the installed service once and accepts it only when the service owns the checkout or its release link. The command decides once and hands that decision to the runner. Prod LOC is net +980. Decided 2026-11-16: Windows Git updates are not refused. A follow-up, slice 4b (stacked on this PR), moves Windows to releases using junctions and then deletes the in-place Git runner.

E2E (mbp-m5, launchd, isolated profiles, shared-clone checkout; ≤15 min per run, ≤3 in parallel)

Final head 0b96d640 (rebased on main at 8a82b5e0): local ClawSweeper review clean (gpt-6.1-sol, normal speed). After the rebase: sweepPackageReleaseTemporaryLinks is exported again, because the first Git publish uses it. The CI ratchets are satisfied: a lazy generation name, Node-only release tests, and an allocation record for the regression tests. A conversion's first release is now the commit the checkout's dist serves, not a pulled HEAD that was never rebuilt. A failed trial also restores a symlinked config: a preserved symlink is judged by its own time, not its target's.

Rollback across same-version upgrades (decision d): the state upgrade now keeps a replaced file as <file>.pre-<buildId>, named after the build that replaced it, so two builds of one version each keep their own predecessor. Builds without a build ID, and earlier releases, still write .pre-<version>. Retention handles both forms. A failed trial restores the .pre-<buildId> of its own build, falling back to .pre-<version>. Fixes to the trial and launcher from the review rounds:

  • the inventory is recorded before anything is restored, so an interrupted rollback can resume without losing a restored WAL;
  • the trial's applied or interrupted upgrade plan is retired and the files it added are removed; a removal that fails is retried at the next start;
  • the config path is the one the update resolved (~ and external paths included);
  • state is restored before the link moves back.

The release layout is used only when the release switch actually reaches the next start: either the service already starts the launcher, or it owns the checkout and this update rewrites its definition and restarts it. --no-restart on a converted install leaves the serving release selected. The next start, which the operator triggers, selects the new release, without the two-start fallback. A first conversion requested with --no-restart stays in place.

Run (mbp-m5, isolated launchd profiles) Head Result
Release that crashes on boot d6d30a5e (the final head changes only how a symlinked backup is dated) update reports build-id-mismatch after 179 s; two "e2e boot crash" starts, then "failed to start twice; switched back"; link back on the previous release, trial cleared, ready
Conversion before the crash run d6d30a5e ok, 267 s

Current head 6d9acd6e (on main), mbp-m5, isolated launchd profiles:

Run Result
Conversion (first update from a checkout service) ok, root on the release link; 610 s with three runs in parallel; longest outage 9.7 s
Release → release ok, 239 s, longest outage 9.9 s
update.run through the Gateway finished|succeeded, 135 s; link moved, Gateway restarted, plist unchanged; outage 7.8 s
Checkout with no Gateway service updated in place: checkout HEAD moved to the target, no git-install/releases, result ok, mode git
Release that crashes on boot (at 0e3fefae) update reports build-id-mismatch after 188 s; after two "e2e boot crash" starts the launcher logs "failed to start twice; switched back", and the previous release serves ready
v2026.11.4 state → this head see Data-model compatibility

Older rows below ran at earlier heads.
Rows marked ‡ ran at head 8a720e49, rows marked † at 6032dedf; the rest ran at 1140b601, before plugin convergence moved after verification. At the final head 99b7f080 (rebased onto 823fa6d2), three runs ran in parallel on mbp-m5. (1) Conversion and release→release passed again, with the root on the release link and a longest outage of 7.6 s. (2) update.run finished succeeded (link moved, Gateway restarted, plist unchanged, outage 8.0 s). (3) A checkout with no Gateway service updated in place: checkout HEAD moved to the bumped commit, no git-install/releases was created, and the result was ok, mode git, root the checkout. An intermediate head 2d2387b6 keyed this choice on a preflight fact that Git installs never fill in, so conversion fell back to in-place (about 120 s outage). That head was never pushed.

Case Result
† First update of a checkout install (conversion, head→head+1) ok, 402 s wall (two builds, three runs in parallel), longest outage 7.6 s, total 13.1 s (unit rewrite, then a restart after plugin convergence); unit rewritten once to the launcher; checkout tree clean; no retention, pack or handoff steps
‡ Release→release (head+1→head+2) ok, 180 s wall, one outage of 7.2 s; unit untouched (mtime unchanged since conversion); service runs from releases/
‡ --no-restart on a switched release the updater leaves the Gateway running and converges no plugins; within the next maintenance tick the Gateway restarts itself into the release, and the trial is cleared; outage 7.5 s
† update.run via the Gateway (openclaw gateway call update.run) run `finished
Already-current rerun from the preserved checkout after conversion (head 60503ab3) skipped: already-current, link unchanged, 113 s
† Release that crashes on boot two crashes, the launcher switched back to the previous release, Gateway ready again; the update reports build-id-mismatch; longest outage 28.9 s
kill -9 mid-stage link and serving Gateway unchanged; the rerun succeeds; a partial release directory left by the killed run is collected after 24 h
kill -9 right after the link moves, before restart the old Gateway keeps serving; the rerun reports skipped: already-current; the Gateway restarts itself into the new release and the trial is cleared
env -i + umask 077 (conversion, then release→release) ok, 376 s and 198 s, outages 5.5 s and 7.5 s; launcher 0700 under umask 077
Install whose unit and state were written by 2026.11.3, moved to head, then converted ok, 229 s, outage 5.9 s; state DB integrity_check ok. 2026.11.3's own updater could not reach head on mbp-m5: it walked back to already-current (Node 24.21 below head's engines), so that hop was done with git reset + ocx build
Production-shaped install (207,229-file checkout, +3 GB SQLite in state), release→release ok, 145 s, outage 6.9 s, no retention step. Main was not timed on this host. Peanutto's production main run 90c601fc took 4,150 s, with 892 s retention and a 300 s outage

Not exercised: a plugin-only restart (SIGUSR2) after npm plugins actually change; the fixtures have no npm plugins.

Data-model compatibility

  • No new state schema. This diff adds or changes no SQLite schema, migration, or config schema file. The update ledger (update_runs), Gateway owner lease and config are read and written exactly as on the base.
  • origin stays compatible. UpdateRunRecordSchema.origin (including feat(update): keep each release in its own directory on OpenClaw-owned installs #198835's packageStage and packageRelease) is unchanged, and Git-release updates write no new origin key. A Git release records its switch in the result step and the release directories, not the ledger. So rows written by older builds parse as before, and rows written by this build parse in an older build. A Git checkout that can't use the layout falls back to the in-place runner with a recoverable-maintenance advisory (git-release-layout step), the same contract as installStagedPackage's swap fallback.
  • New on-disk state is additive and lives under <stateDir>/git-install/: releases/<id>/ (detached worktrees), the lib/node_modules/openclaw link, releases/.trial, and the launcher. An install without them is treated as unconverted and gets the conversion path. If the layout is unusable, the update falls back to in-place (decision 8).
  • Existing data proof: v2026.11.4 state upgraded and converted (E2E, 6d9acd6e).
    • The v2026.11.4 Gateway, started with --profile, created state/openclaw.sqlite (schema 22) and an agent DB.
    • This head's gateway install then stopped with "Client credentials require backed-up migration custody; … run openclaw doctor --fix". Plain main (964ab522) stops with the same message on a copy of that state, so it comes from main, not this diff.
    • Following the message, openclaw doctor --fix --non-interactive migrated the state to schema 40. After that, install succeeded and the update converted the checkout onto the release link. The update_runs row in the stable-created database reads finished|succeeded, and the stable config (Gateway port) still reads back.
  • Rollback keeps data readable: the crash-release trial switches the link back to the previous release, and the launcher restores the SQLite family (openclaw.sqlite, -wal, -shm) captured before the trial. The previous build reopens its own database (crash row, 28.9 s).

Tests

  • src/infra/git-release.test.ts:
    • trial fallback restores the SQLite family and drops trial-only companions
    • trial settlement
    • launcher mapping
    • a launcher unit is owned without regeneration
    • a non-link package path falls back to the in-place runner with a reason
  • src/infra/update-runner-git-release.test.ts:
    • a same-commit release with unverified artifacts is rebuilt
    • a current release is reported prepared, so finalization never regenerates it
    • the first release comes from the serving worktree's commit, and the checkout's different target is still built
  • update-command-post-update.test.ts: a switched release converges plugins only after its restart.
  • git-release.test.ts: a checkout with no owning Gateway service keeps the in-place runner. The test fails without the gate.
  • update-command-execution-validation.test.ts: when a developer build holds the checkout's artifact lock, a Git release update still runs. It never takes that lock, because releases build in their own worktrees. The test fails without the fix.
  • update-command-convergence-authority.test.ts: under --no-restart, a switched release persists the channel and leaves plugins alone; an already-current rerun from the checkout of a converted install completes.
  • update-runner-git-release.test.ts: a successful rebuild of an incomplete runtime reports the new release's verdict.
  • update-command-convergence-authority.test.ts: release convergence runs in the updater, with no fresh process and no Doctor.
  • update-command-verification.test.ts:
    • a verified release ends its trial
    • a switched release's Gateway restarts itself without a native restart
  • src/state/state-upgrade.test.ts: git-install stays out of the startup upgrade copy.
  • Gates: pnpm tsgo:core, pnpm check:test-types, oxlint/oxfmt on changed files. On mbp-m5 at 99b7f080, the broad update suite plus the package-release and package-update tests pass 1,944 / 1,948, with 1 skipped. The 3 failures are environmental:
    • update-runner-git-node-preflight ×3: mbp-m5's Node 24.21 is below engines.

LOC

prod +1018 / −38 (net +980); test +951 / −3.

Draft: lands after #198835. #198389 has merged; #199770 carries the same startup-copy exclusion for main.

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime cli CLI command changes size: L labels Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR builds managed Git updates in separate worktrees and switches a stable release link, with launcher-based startup recovery.

Example: A managed Git installation updates from release A to release B.

  • Before: The updater replaces the checkout runtime and regenerates the service definition.
  • After: It builds B separately, switches the release link, and restarts through the existing launcher while preserving the checkout.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful implementation with the prior blocker resolved and substantial real-run evidence, but incomplete plugin and stable-upgrade qualification.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Managed Git updates spend substantial work retaining and replacing the runtime that the Gateway and updater are using.
Reason: The maintainer-authored direction removes that replacement work from eligible installations while keeping existing installation types supported.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: the previous unmanaged-checkout defect is fixed, and the release-layout change remains useful, distinct work; no additional correctness defect was identified.

Priority: P2
Reviewed head: 99b7f0809cac1ce887424d48b2c44486e7c2b65f

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted terminal output or logs for an actual npm-plugin replacement and subsequent restart, plus a latest-stable-to-candidate conversion preserving configuration and databases once the stack supports that upgrade; redact credentials, IPs, phone numbers, and non-public endpoints.
Agent review details

How this fits together

The update CLI selects and validates Git candidates, publishes their runtime, and coordinates Gateway restart, recovery, and plugin convergence.

flowchart TD
A[Update CLI] --> B[Service ownership selection]
B --> C[Git candidate preflight]
C --> D[Release worktree]
D --> E[Stable release link]
E --> F[Gateway launcher]
F --> G[Verification and plugin convergence]
Loading

Technical review

Best possible solution:

Complete the Git-release slice using the existing candidate, link-switch, retention, and convergence owners while preserving supported in-place fallbacks.

Do we have a high-confidence way to reproduce the issue?

This is an architectural improvement rather than a newly reproduced bug; current-main source confirms the in-place runtime replacement that motivates it, and no target code was executed during review.

Is this the best way to solve the issue?

The implementation reuses the existing preflight, publication, retention, and plugin owners, and its independent launcher has a concrete purpose when candidate code cannot load; retaining the in-place path preserves supported installations.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3dc7eb96a528.

Provenance checked

  • Candidate validation and runtime replacement changes intended behavior with a stated reason (d1a69c0: Validate candidates while serving and retain recoverable activation; later artifact admission protected the checkout being rewritten.)
  • Fresh-process finalization and plugin rollback pairing changes intended behavior with a stated reason (refactor(update): simplify update execution and finalization #154160: Consolidate finalization and preserve target-runtime and rollback ownership; this PR instead converges after verified startup, when its trial can no longer roll core back.)
  • Service entry-point and installation identity changes intended behavior with a stated reason (refactor(cli): make update help and planning faster #133698: Keep service ownership and runtime selection consistent across replacement; this PR preserves those checks and introduces a stable launcher for Git releases.)
  • Startup copy-and-swap recovery keeps the original intent (ef930eb: Upgrade state through validated private copies while preserving prior file generations; excluding Git release code prevents copying installations as state.)
  • Backup exclusions keeps the original intent (fix(backup): preserve configured agent state roots #129773: Inventory user state separately from managed installation resources; git-install extends the existing managed-root exclusion.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Previous finding addressed: The command now selects releases only after inspecting the installed service; installations without an owning service retain the in-place runner. The complete PR body reports a current-head unmanaged-checkout run that moved checkout HEAD and created no release layout. (src/cli/update-cli/update-command-git.ts:659, 99b7f0809cac)
  • Pinned introduction and current-main distinction: The introduced diff adds the Git-release runner and wires it into the existing Git update entry point; fetched main still uses the in-place runtime promotion path. (src/infra/update-runner-git.ts:61, 99b7f0809cac)
  • Full proof context recovered: Read the complete body beyond the supplied excerpt, whose captured identity was d04c2124962ad8053de5eb81d43ff79aba36e13b6179d00921e32b113fc4f077. It records isolated macOS launchd conversion, consecutive updates, Gateway-initiated updates, crash recovery, and explicit plugin and stable-upgrade limitations. (99b7f0809cac)
  • Stack dependency and accepted direction: feat(update): keep each release in its own directory on OpenClaw-owned installs #198835 supplies the shared link-switch, lease, and retention owners and remains open; docs: propose a linked package root and staged candidate handoff for updates #197949 records the accepted linked-root direction and best-effort layout fallback. This maintainer-authored PR records acceptance of losing writes during a failed startup trial. (src/infra/git-release.ts:65, 99b7f0809cac)
  • Recovery and retention boundaries: The launcher restores preserved SQLite families before loading the previous release; the shared switch owner refreshes the deselected release's retention age, protecting immediate trial fallback from collection. (src/infra/git-release-launcher.ts:74, 99b7f0809cac)
  • Policy and history: Read the complete root and Gateway AGENTS.md files and applied the update, database, boundary-proof, test-audit, performance, and simplification guidance; no maintainer-notes directory exists. Targeted history and blame were available, although a broader historical git show --stat encountered an unavailable promisor object. (AGENTS.md:1, 99b7f0809cac)

Likely related people:

  • Ayaan Zaidi: Raw commit ef930eb adds src/state/state-upgrade.ts:1 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ef930ebbad77; files: src/state/state-upgrade.ts)

PR surface

Source +812, Tests +647. Total +1459 across 37 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 22 833 21 +812
Tests 15 648 1 +647
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 37 1481 22 +1459

Preflight source

Source 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

Metric Value Why it matters
Production versus test changes Production +833/-21; tests +648/-1 The growth implements worktree publication, a release-independent recovery launcher, and integration with existing lifecycle owners; the retained runner serves Windows, conversion, and unmanaged-checkout contracts.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status no longer selects a status label.

Label justifications:

  • P2: This is a useful update-reliability improvement for managed Git installations without an established urgent regression.
  • merge-risk: 🚨 compatibility: Conversion changes the service entry point and introduces persisted release/trial state; latest-stable upgrade compatibility remains unproven.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-11-15T20:27:00.460Z sha 665e0d6 :: blocked before merge. :: [P1] Build the conversion fallback from the installed worktree's commit | [P2] Exclude retained release trees from startup state upgrades | [P2] Settle healthy trials when the target predates this PR
  • reviewed 2026-11-15T21:49:06.956Z sha e69c286 :: blocked before merge. :: [P2] Require matching serving and checkout revisions before skipping conversion | [P2] Preserve finalization for targets without the Git-release handoff | [P2] Land the startup-copy exclusion before enabling Git release roots
  • reviewed 2026-11-16T01:28:55.120Z sha 1140b60 :: blocked before merge. :: [P1] Keep plugin replacement paired with Git trial recovery
  • reviewed 2026-11-16T02:02:27.048Z sha 6032ded :: blocked before merge. :: [P1] Defer plugin replacement while a no-restart release is unverified | [P2] Remove the previous runtime's failed verdict from successful results
  • reviewed 2026-11-16T02:29:50.122Z sha 8a720e4 :: blocked before merge. :: [P2] Carry the Git-release exemption through the already-current guard
  • reviewed 2026-11-16T05:46:16.450Z sha 4b3fb64 :: blocked before merge. :: [P2] Skip checkout artifact admission for every Git-release update
  • reviewed 2026-11-16T06:00:06.387Z sha df0476e :: blocked before merge. :: none
  • reviewed 2026-11-16T07:13:10.102Z sha 43ad68e :: blocked before merge. :: [P1] Preserve updates for checkouts without a managed launch owner

Reviewed November 16, 2026, 5:05 AM ET / 10:05 UTC (Revision 10).

@openclaw-barnacle openclaw-barnacle Bot added the commands Command implementations label Nov 15, 2026
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 15, 2026
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. and removed merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 15, 2026
@obviyus
obviyus force-pushed the feat/update-git-releases branch from e69c286 to 9bc4b73 Compare November 15, 2026 22:11
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

obviyus added a commit that referenced this pull request Nov 19, 2026
- No published release contains #199706: v2026.11.5 updates Git checkouts in place. The old layout comes from main builds since 2026-11-17, which still report 2026.11.5.
obviyus added a commit that referenced this pull request Nov 19, 2026
## Problem

#201874: on a managed Git install, a Gateway MCP turn fails before replying:

```text
warn mcp-loopback request handling failed: Stripping types is currently unsupported for files under node_modules, for "<state-dir>/git-install/releases/<release>/lib/node_modules/openclaw/extensions/deepseek/web-search-contract-api.ts"
error Embedded agent failed before reply: Claude Code started without the OpenClaw MCP server (status failed).
```

#199706 put each Git release, a full worktree with plugin TypeScript sources, at `releases/<id>/lib/node_modules/openclaw`. Two path rules then meet:

1. `resolvePublicSurfacePath` (`src/plugins/public-surface-runtime.ts`) picks `extensions/<plugin>/<file>.ts` before `dist` when the source exists. Only a Git release has sources; the npm package ships `dist/` only.
2. The plugin loader's Jiti options add `"openclaw"` to `nativeModules` (`src/plugins/sdk-alias.ts`). Jiti 2.7.0 turns that into `node_modules/(openclaw)/` and loads any match natively, even with `tryNative: false` (`src/require.ts:131`). Node then refuses (`lib/internal/modules/typescript.js:188`, `isUnderNodeModules(filename)`).

The updater missed it because it validated a different path than it serves: `buildRelease` built and checked the release at `releases/<id>/build`, then `git worktree move` put it under `node_modules`. The only check at the final path was `openclaw.mjs --version` (`update-runner-git-release.ts`, `git-release-smoke`), which loads no plugin.

Reproduced on a real release tree built by `main` at 18b04f2 (2026-11-19) on this machine, through Jiti with `nativeModules: ["openclaw"]` and `tryNative: false`: `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING` for `extensions/brave/web-search-contract-api.ts`, through both the real path and the link path.

The same class, TypeScript at runtime under `node_modules`, appeared before as #19815 (2026-02-18) and #53953 (2026-03-24).

## Change

Remove the cause in the owner: Git releases no longer live under `node_modules`.

- Layout: `<state>/git-install/openclaw -> releases/<id>/openclaw`. Moving only the tree is not enough: the Gateway names its root by the link (`openclaw-root.ts`), and Jiti matches the link path string too.
- Each release is built and validated where it serves. The build-beside-and-move step (`buildDir`, `git-release-place`) is deleted. A release path that a loader rule breaks now breaks the build before activation.
- `package-release-slot-path.ts` keeps one rule for both layouts: a release keeps the package at the link's path below the prefix (npm `lib/node_modules/<name>`, Git `<name>`). Lease, retention and the switch's deselect stamp use it, not npm-only `dirname` math.
- Retention resolves each retained release at the link's layout or at npm's `lib/node_modules/<name>`, where releases built before the move still live. `update status` keeps listing them, and an open update run that names one still protects it.
- Migration: `servingGitReleaseSlot` reads the old link while it still serves. The first update run by this release rebuilds the serving commit at the new path, publishes the new link, and removes the old link. The old Gateway then sees its installation replaced and restarts through the launcher, which now starts the new link.

No loader exception, no second source/dist rule, no flag.

## Impact

- Managed Git installs load bundled plugin sources again.
- Dev-channel installs on `main` builds since #199706 (they report version 2026.11.5; no published release has the layout) need one more `openclaw update` after the update to this change, because the older updater drives that first hop and still builds under the old path.
- npm, plain checkouts, Docker and package-to-Git switches are unchanged.

## Evidence

- **Regression test** (`src/infra/git-release.test.ts`, "loads a bundled plugin's source contract from the selected release (#201874)"). It copies `extensions/deepseek` into a release made by `createGitReleaseDirs`, publishes it, and loads `web-search-contract-api` through `loadPluginPublicArtifactModuleSync` from the release link path.
  - On `main` (307d9c4): fails. Under Vitest the `tsx` hooks strip the types, so the symptom is `ERR_MODULE_NOT_FOUND` for `openclaw/plugin-sdk/lazy-runtime`: the forced native import resolves the bare `openclaw/...` specifier to the release tree itself. Same cause.
  - On this branch: passes (`git-release.test.ts` 12/12).
- **Migration test** (`update-runner-git-release.test.ts`). A release under `lib/node_modules` is rebuilt at the new path, the new link's real path has no `node_modules` segment, and the old link is gone.
- **Mixed-layout inventory test** (`git-release.test.ts`). After the link moves out, a release still under `lib/node_modules/openclaw` stays listed by `listPackageReleases`, the source of `openclaw update status`.
- **Exact error on a real tree.** A release built by `main` (18b04f2) on a Mac profile, loaded through Jiti 2.7.0 with `nativeModules: ["openclaw"]` and `tryNative: false`: `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING … extensions/brave/web-search-contract-api.ts`, through both the real path and the link path.
- **Mutation proof (build at the final path).** The release build (`node --import ./scripts/tsx.mjs scripts/build-all.mts`):
  - In a worktree at `releases/r1/lib/node_modules/openclaw`: fails at once with `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING … scripts/lib/local-check-runtime.mts`.
  - The same commit at `out/r2/openclaw`: passes that stage (`runtime:scripts:check` 4.61 s).
  - So a release path that a loader rule breaks now fails the update before activation.
- **Stable tag unaffected.** A Docker lane run with a real service install of tag `v2026.11.5` (e13cf15): its updater returned `status: ok`, `root: …/git-checkout`, steps `clean-check, git-resolve-target, recovery-artifact-cleanup`. No release link was created. No published release has the release layout.
- **Gates:** `pnpm tsgo:core` exit 0; line-cap check OK (13 files); oxlint and oxfmt clean on changed files.
- **Every test file that reads the release layout:** 21 files. `rg -l 'git-release|gitReleaseSlot|GIT_RELEASE|usesGitReleases|package-release-slot-path|package-release-lease' src --glob '*.test.ts'`, plus `openclaw-root`, `program-args*`, `service-layout` and `stale-install`. All pass.
  - The first batch run (4 workers, load 22–49) timed out 6 update-cli cases. Rerun with 2 workers: 141/141.
  - Four suites did not load in that batch because a parallel scenario edit changed `scripts/` during the run. Rerun alone: 40/40 and 35/35.

## Not proven here

- **Real upgrade from `7db69bedeab6` (the reporter's build) to this change, with a Gateway request that loads the web-search contracts.** A Linux upgrade-survivor `git-release` scenario reached the stable-tag baseline above; the run from `7db69bedeab6` did not finish before landing. The scenario is not in this PR. The reporter is asked to confirm on #201874.
- **Windows.** No Windows host completed a run. On `main`, Windows Git checkouts never use releases (`usesGitReleases` returns false on win32), so they are unaffected by the bug and by this change. That comes from the code, not a run.
- **The old Gateway restarting after the old link is removed.** Before this change the Gateway saw the link move; here the link disappears. INFERENCE: it reads as installation replacement too.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 19, 2026
## Problem

#201874 shipped because no upgrade lane ran a Git install. All 35 upgrade-survivor scenarios start from an npm package, so the Git release layout from #199706 never booted in CI before users hit it.

## Change

- Adds an opt-in `git-release` upgrade-survivor scenario. Starting from `7db69bedeab6` (the #201874 reporter's build), it:
  1. builds the checkout and installs the Gateway service (systemctl shim);
  2. lets that build convert the install onto the old release layout;
  3. reproduces the type-stripping failure through the Gateway;
  4. updates to the candidate twice, the first run by the old build and the second by the candidate;
  5. asserts the release left `node_modules`, the old link is gone, and `tools.invoke web_search` succeeds with no stripping error in the Gateway log.
- The scenario stays out of the aggregate lanes and the published-baseline matrix; run it with `OPENCLAW_UPGRADE_SURVIVOR_SCENARIO=git-release`. Three full builds take about 24 minutes, so it gets a 3600 s container timeout.
- Corrects the update guidance in `docs/install/updating.md`. The run showed two things:
  - The old release cannot run its own updater, so users must update from a terminal with the checkout's `openclaw`.
  - With a web search provider configured, the Gateway on the old layout fails at startup.

## Evidence

- `OPENCLAW_UPGRADE_SURVIVOR_SCENARIO=git-release bash scripts/e2e/upgrade-survivor-docker.sh` against #201917's head `6b5d14b1`: exit 0, `summary.json` `passed`, 23m35s. Step results are in #201917 (comment)
- The same scenario against tag `v2026.11.5` shows the published release never takes the release layout: its updater returns `root: …/git-checkout` with no release link.
- `ocx test` on the survivor catalog, baseline, plan and qualification tests; `bash -n`; `git diff --check`.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 20, 2026
…law#201917)

## Problem

openclaw#201874: on a managed Git install, a Gateway MCP turn fails before replying:

```text
warn mcp-loopback request handling failed: Stripping types is currently unsupported for files under node_modules, for "<state-dir>/git-install/releases/<release>/lib/node_modules/openclaw/extensions/deepseek/web-search-contract-api.ts"
error Embedded agent failed before reply: Claude Code started without the OpenClaw MCP server (status failed).
```

openclaw#199706 put each Git release, a full worktree with plugin TypeScript sources, at `releases/<id>/lib/node_modules/openclaw`. Two path rules then meet:

1. `resolvePublicSurfacePath` (`src/plugins/public-surface-runtime.ts`) picks `extensions/<plugin>/<file>.ts` before `dist` when the source exists. Only a Git release has sources; the npm package ships `dist/` only.
2. The plugin loader's Jiti options add `"openclaw"` to `nativeModules` (`src/plugins/sdk-alias.ts`). Jiti 2.7.0 turns that into `node_modules/(openclaw)/` and loads any match natively, even with `tryNative: false` (`src/require.ts:131`). Node then refuses (`lib/internal/modules/typescript.js:188`, `isUnderNodeModules(filename)`).

The updater missed it because it validated a different path than it serves: `buildRelease` built and checked the release at `releases/<id>/build`, then `git worktree move` put it under `node_modules`. The only check at the final path was `openclaw.mjs --version` (`update-runner-git-release.ts`, `git-release-smoke`), which loads no plugin.

Reproduced on a real release tree built by `main` at 777a156 (2026-11-19) on this machine, through Jiti with `nativeModules: ["openclaw"]` and `tryNative: false`: `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING` for `extensions/brave/web-search-contract-api.ts`, through both the real path and the link path.

The same class, TypeScript at runtime under `node_modules`, appeared before as openclaw#19815 (2026-02-18) and openclaw#53953 (2026-03-24).

## Change

Remove the cause in the owner: Git releases no longer live under `node_modules`.

- Layout: `<state>/git-install/openclaw -> releases/<id>/openclaw`. Moving only the tree is not enough: the Gateway names its root by the link (`openclaw-root.ts`), and Jiti matches the link path string too.
- Each release is built and validated where it serves. The build-beside-and-move step (`buildDir`, `git-release-place`) is deleted. A release path that a loader rule breaks now breaks the build before activation.
- `package-release-slot-path.ts` keeps one rule for both layouts: a release keeps the package at the link's path below the prefix (npm `lib/node_modules/<name>`, Git `<name>`). Lease, retention and the switch's deselect stamp use it, not npm-only `dirname` math.
- Retention resolves each retained release at the link's layout or at npm's `lib/node_modules/<name>`, where releases built before the move still live. `update status` keeps listing them, and an open update run that names one still protects it.
- Migration: `servingGitReleaseSlot` reads the old link while it still serves. The first update run by this release rebuilds the serving commit at the new path, publishes the new link, and removes the old link. The old Gateway then sees its installation replaced and restarts through the launcher, which now starts the new link.

No loader exception, no second source/dist rule, no flag.

## Impact

- Managed Git installs load bundled plugin sources again.
- Dev-channel installs on `main` builds since openclaw#199706 (they report version 2026.11.5; no published release has the layout) need one more `openclaw update` after the update to this change, because the older updater drives that first hop and still builds under the old path.
- npm, plain checkouts, Docker and package-to-Git switches are unchanged.

## Evidence

- **Regression test** (`src/infra/git-release.test.ts`, "loads a bundled plugin's source contract from the selected release (openclaw#201874)"). It copies `extensions/deepseek` into a release made by `createGitReleaseDirs`, publishes it, and loads `web-search-contract-api` through `loadPluginPublicArtifactModuleSync` from the release link path.
  - On `main` (7fedfbe): fails. Under Vitest the `tsx` hooks strip the types, so the symptom is `ERR_MODULE_NOT_FOUND` for `openclaw/plugin-sdk/lazy-runtime`: the forced native import resolves the bare `openclaw/...` specifier to the release tree itself. Same cause.
  - On this branch: passes (`git-release.test.ts` 12/12).
- **Migration test** (`update-runner-git-release.test.ts`). A release under `lib/node_modules` is rebuilt at the new path, the new link's real path has no `node_modules` segment, and the old link is gone.
- **Mixed-layout inventory test** (`git-release.test.ts`). After the link moves out, a release still under `lib/node_modules/openclaw` stays listed by `listPackageReleases`, the source of `openclaw update status`.
- **Exact error on a real tree.** A release built by `main` (777a156) on a Mac profile, loaded through Jiti 2.7.0 with `nativeModules: ["openclaw"]` and `tryNative: false`: `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING … extensions/brave/web-search-contract-api.ts`, through both the real path and the link path.
- **Mutation proof (build at the final path).** The release build (`node --import ./scripts/tsx.mjs scripts/build-all.mts`):
  - In a worktree at `releases/r1/lib/node_modules/openclaw`: fails at once with `ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING … scripts/lib/local-check-runtime.mts`.
  - The same commit at `out/r2/openclaw`: passes that stage (`runtime:scripts:check` 4.61 s).
  - So a release path that a loader rule breaks now fails the update before activation.
- **Stable tag unaffected.** A Docker lane run with a real service install of tag `v2026.11.5` (e13cf15): its updater returned `status: ok`, `root: …/git-checkout`, steps `clean-check, git-resolve-target, recovery-artifact-cleanup`. No release link was created. No published release has the release layout.
- **Gates:** `pnpm tsgo:core` exit 0; line-cap check OK (13 files); oxlint and oxfmt clean on changed files.
- **Every test file that reads the release layout:** 21 files. `rg -l 'git-release|gitReleaseSlot|GIT_RELEASE|usesGitReleases|package-release-slot-path|package-release-lease' src --glob '*.test.ts'`, plus `openclaw-root`, `program-args*`, `service-layout` and `stale-install`. All pass.
  - The first batch run (4 workers, load 22–49) timed out 6 update-cli cases. Rerun with 2 workers: 141/141.
  - Four suites did not load in that batch because a parallel scenario edit changed `scripts/` during the run. Rerun alone: 40/40 and 35/35.

## Not proven here

- **Real upgrade from `47b219778879` (the reporter's build) to this change, with a Gateway request that loads the web-search contracts.** A Linux upgrade-survivor `git-release` scenario reached the stable-tag baseline above; the run from `47b219778879` did not finish before landing. The scenario is not in this PR. The reporter is asked to confirm on openclaw#201874.
- **Windows.** No Windows host completed a run. On `main`, Windows Git checkouts never use releases (`usesGitReleases` returns false on win32), so they are unaffected by the bug and by this change. That comes from the code, not a run.
- **The old Gateway restarting after the old link is removed.** Before this change the Gateway saw the link move; here the link disappears. INFERENCE: it reads as installation replacement too.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 20, 2026
…01956)

## Problem

openclaw#201874 shipped because no upgrade lane ran a Git install. All 35 upgrade-survivor scenarios start from an npm package, so the Git release layout from openclaw#199706 never booted in CI before users hit it.

## Change

- Adds an opt-in `git-release` upgrade-survivor scenario. Starting from `47b219778879` (the openclaw#201874 reporter's build), it:
  1. builds the checkout and installs the Gateway service (systemctl shim);
  2. lets that build convert the install onto the old release layout;
  3. reproduces the type-stripping failure through the Gateway;
  4. updates to the candidate twice, the first run by the old build and the second by the candidate;
  5. asserts the release left `node_modules`, the old link is gone, and `tools.invoke web_search` succeeds with no stripping error in the Gateway log.
- The scenario stays out of the aggregate lanes and the published-baseline matrix; run it with `OPENCLAW_UPGRADE_SURVIVOR_SCENARIO=git-release`. Three full builds take about 24 minutes, so it gets a 3600 s container timeout.
- Corrects the update guidance in `docs/install/updating.md`. The run showed two things:
  - The old release cannot run its own updater, so users must update from a terminal with the checkout's `openclaw`.
  - With a web search provider configured, the Gateway on the old layout fails at startup.

## Evidence

- `OPENCLAW_UPGRADE_SURVIVOR_SCENARIO=git-release bash scripts/e2e/upgrade-survivor-docker.sh` against openclaw#201917's head `6b5d14b1`: exit 0, `summary.json` `passed`, 23m35s. Step results are in openclaw#201917 (comment)
- The same scenario against tag `v2026.11.5` shows the published release never takes the release layout: its updater returns `root: …/git-checkout` with no release link.
- `ocx test` on the survivor catalog, baseline, plan and qualification tests; `bash -n`; `git diff --check`.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Nov 21, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 22, 2026
…lace Git runner (openclaw#200578)

Slice 4b of the update foundation. Follows openclaw#199706 (slice 4), openclaw#201917 (releases outside `node_modules`) and openclaw#201538 (half-switched Git updates).

## Problem

Since openclaw#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 openclaw#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 (e4b7909), 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 `47b219778879`-era updaters (openclaw#201874): bundled plugin public surfaces there load the built `dist/extensions/<plugin>/` JavaScript, so those installs update by themselves; the manual bridge in the openclaw#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`, `47b219778879`, `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`); `47b219778879` (`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 `47b219778879` → 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]>
obviyus added a commit that referenced this pull request Nov 22, 2026
…ident launcher (#203194)

## Problem

A Git install updates in place under the running Gateway, through a managed-service handoff helper. When the new build does not start, recovery depends on that helper and on the old updater that is already installed, so a failed update can leave the Gateway down or stuck in `update-recovery-pending`.

## Change

Git installs now update through prepared releases and a resident launcher:

1. `update.run`, `openclaw update` and automatic updates admit the run, resolve the target and run preflight (Node engine, required tools, disk space, container installs refused before any change).
2. The next release is built beside the running one (`git worktree add --detach`, then the target's install and build). The running checkout is not changed.
3. `openclaw update check-release` runs the new code offline against the current config and state and reports broken plugin or config surfaces. It does not migrate state.
4. `openclaw update plugins` runs from the published release: the existing plugin maintenance owner (`updatePluginsAfterCoreUpdate`), with the new core's code and version. A plugin problem, or a target too old to have the command, is recorded as a `plugins` step with a next action and never fails the update. An already-current install still runs it from the serving code and restarts a running Gateway when plugins changed (`docs/install/updating.md`).
5. The release is published as a pending trial, and the Gateway restarts with a process-replacing reason.
6. The launcher switches the release link at the next child start, counts attempts, commits the trial when the new Gateway is ready, and otherwise rolls back and starts the previous release.
7. The Gateway that starts after the switch (new on success, old after a rollback) finishes the run and sends the outcome to a requester that received the start notice.

Routing:
- `update.run` reads the install kind from the existing install-status owner (`resolveStartupInstallStatus`). `update-run.ts` wraps `update.run`; `update.ts` is unchanged and still serves package installs.
- `openclaw update` branches after `prepareUpdateCommand`, so every existing refusal (external supervisor, host-owned, immutable, system package owner, interrupted update) applies first. A requested non-dev channel on a Git checkout still switches it to a package through the existing flow, and `--dry-run` keeps the existing preview.
- Package installs move to this path in the next change, which also deletes the old Git machinery that this PR leaves unused.

Converting an existing install:
- The old entry points of a converted install (`openclaw.mjs`, `dist/index.js`) forward to the release launcher through a marker beside the tree. Existing service definitions and PATH shims keep working without a rewrite.
- A first update driven by an older installed updater still migrates state as it does today. Released updaters require migrated state: 23 stable and 6 extended-stable tags contain that check.

Fixes found by the real-install runs below, each a separate commit:
- `openclaw update --sha` now sends the tracked upstream that the protocol requires.
- The new path restarts with `update.run` / `update.auto`, so the process is replaced instead of restarted in place.
- A Gateway started by the launcher leaves its update successor to the launcher instead of spawning one outside it.
- Preflight skips dangling symlinks in agent homes, such as Codex `arg0` shims, when it sizes state databases.
- `check-release` writes its JSON result to stdout.
- Plain `openclaw update` keeps following the run while the restarting Gateway refuses connections with a retryable HTTP 503. Before, it exited 1 although the update succeeded.

Accepted edge cases:
- After `openclaw update` runs in a Git checkout, `openclaw.mjs` and `dist/index.js` in that checkout run the current release. A developer who edits the source of a checkout they also update from runs the release, not their edits.
- A stop request handled inside a launcher child exits with code 0, and the launcher starts the child again. A stop through the service manager stops the launcher and its child.
- On a Gateway with no service manager, the first update from a released version does not restart it. The released updater does this, and says so.
- Package updates now read the install status twice per request: once to route, once in the old handler.
- After a rollback, the previous release runs with plugins maintained for the new core. A plugin that cannot load stays off for that boot, as the plugin docs describe.
- `openclaw update --accept-capabilities` reaches plugin maintenance when the CLI prepares the release itself (`--no-restart`, or no Gateway answering). Through a running Gateway, `update.run` has no field for it, so a plugin that needs consent is reported with its `openclaw plugins update` next action. Carrying the flag through `update.run` is a protocol change and follows separately.
- `openclaw update` run from a different checkout than the one the configured local Gateway serves updates the Gateway's installation, not the invoking checkout. Binding the request to the checkout needs a protocol field and follows with `--accept-capabilities`.

## Evidence

Real install on macOS (Apple silicon). Isolated HOME, state, config and port, a foreground Gateway, no launchd service. Every candidate was built from `git archive` of its commit; the final candidate is this branch's head before review.

| Step | Run status | Trial | Served after | Health |
|---|---|---|---|---|
| 2026.11.6 → A (released updater) | succeeded | (old path) | A, after a recorded manual start | 200 / 200 |
| A → B′ (B′ fails at startup) | failed, `new build failed to start` | rolled-back, 2 attempts | A, as the launcher's child | 200 / 200 |
| A → B | succeeded | committed, 1 attempt | B, as the launcher's child | 200 / 200 |
| B → C | succeeded | committed, 1 attempt | C, as the launcher's child | 200 / 200 |

- The same launcher process stayed the parent through every replacement. The previous release was kept after each commit.
- Phase times (seconds), from the persisted run steps:

| Step | Staging (build) | Validating | Restarting | Total |
|---|---:|---:|---:|---:|
| A → B′ (rollback) | 192.5 | 0.8 | 29.2 | 222.7 |
| A → B | 195.7 | 1.1 | 32.9 | 229.8 |
| B → C | 201.6 | 0.9 | 36.9 | 239.5 |

- `check-release` on a copy of a real state directory (Linux, no network): exit 0 in 3.0 s, 187 surfaces checked, shared state schema 40 → 40, agent databases 43 → 43.

Plugin maintenance, real install on macOS (isolated, foreground Gateway, a real third-party npm plugin `@martian-engineering/lossless-claw` served through a scratch registry proxy that advertises 1.1.1, then the real latest 1.2.0):

| Case | Run | `plugins` step | Plugin | Gateway |
|---|---|---|---|---|
| Core update through the new path | succeeded, trial committed (1 attempt) | completed | 1.1.1 → 1.2.0 | one restart into the new release |
| Already current, plugin outdated | skipped / already-current | completed | 1.1.1 → 1.2.0 | restarted |
| Already current, nothing to change | skipped / already-current | completed | unchanged | no restart |
| Already current, registry returns HTTP 503 | skipped / already-current | completed, detail names the plugin and its `openclaw plugins update` retry | kept 1.1.1 | no restart; CLI prints "Plugin notes: …" |
| Already current, `--no-restart` | skipped / already-current | completed | 1.1.1 → 1.2.0 | same process, no restart |

- An earlier head counted a `warning` result as a failed step with no message; the run above found it and the fix is in this PR.
- A run with `--timeout 1` showed the CLI calling a still-running update "Update failed: unknown reason". The fix ("The update did not finish in time. Run `openclaw update status` to see it.") is covered by `src/update/cli.test.ts`; it was not rerun on the real install.

Tests:
- New: `src/update/*.test.ts` (target, preflight, Git and package preparation, check-release, store, launcher, trial settlement and outcome notice, CLI request shape), plus a launcher-child case in `process-respawn.test.ts`.
- The gateway `update*` suites run against package installs. Tests that pinned the old Git handoff, Git preflight delegation, explicit Git targets and foreground parking are deleted. Tests of behavior that package installs still use (notice policy, owner checks, campaign adoption, platform admission) now run on a managed package install.

## Review

- `--no-restart` on a Git install now prepares the release in the CLI process instead of asking the Gateway, so the Gateway does not restart. The release starts at the Gateway's next start, and the CLI says so and exits 0, instead of reporting "Updated".
- The first conversion creates the `prefix/openclaw` link to the running tree before it writes the forwarding marker. Forwarded commands work between publish and the switch.
- The run row is written through the existing asynchronous update-run owner (`update-run-write.async.ts`). The synchronous second writer is deleted, so there is no SQLite work on the Gateway thread.
- Rejected: settling trials of the format-1 Git-release launcher (#199706). No released build contains it (not 2026.11.6 `latest`, 2026.10.33 `extended-stable` or 2026.11.10-beta.1 `beta`), and main-only code is not a shipped contract. Only a Git checkout that tracked `main` between 2026-11-17 and this change can have such a trial.
- The in-process path (`--no-restart`, or no Gateway answering) uses the requested channel, else the saved `update.channel` (`readUpdateChannelConfig`), else `dev`, as the existing CLI does. The Gateway path passes the checkout's tag and branch facts, as the existing handler does, so a configless checkout on a stable tag stays on stable.
- After publishing a Git release, `git worktree repair` records it at its final path, so `git worktree list` and a later `git worktree prune` see the serving release where it is.
- `prefix/openclaw` is repointed to the running tree when it does not already resolve there, so a link left from an earlier package install cannot become the rollback target.
- Rejected for this PR: carrying the package layout's `lib/node_modules/openclaw` link. That layout belongs to package-release installs, which this PR does not route; the next change moves package installs and owns it.
- A new build that exits 78 (it refuses the configuration) during a trial now rolls back like any other failed candidate. Outside a trial, 78 stays terminal.
- Rejected again, same reason as the format-1 trial: making `git-install/lib/node_modules/openclaw` follow `prefix/openclaw`. Only the main-only Git-release conversion (#199706) creates that link, and no release contains it.
- A Gateway with `OPENCLAW_NO_RESPAWN` set now refuses `update.run` with `restart-unavailable` before anything is recorded or prepared, as the existing handler does. The prepared release starts only in a new process, which that Gateway cannot start.
- `openclaw update --timeout <seconds>` on a Git install is the overall budget again: it bounds how long the CLI follows the run, reaches the Gateway as `update.run` `timeoutMs`, and target resolution, the release build and plugin maintenance get only what remains of it. Preflight and `check-release` keep their own short bounds.
- Rejected again, same reason as the format-1 trial: settling legacy `.trial` records in `stale-install.ts`. Only #199706 writes them; `settleGitReleaseTrial` is in no released build (2026.11.6 `latest`, 2026.10.33 `extended-stable`, 2026.11.10-beta.1 `beta`).
- Rejected: routing `--tag` on a Git install to the package flow. The existing Git flow ignores `--tag` ("--tag applies to npm installs only; git updates ignore it"), so the Git route keeps that behavior.
- After merging `main`: Control UI and desktop app requests on a Git install show the update in the app instead of the conversation (#203357), through the same `appUpdateNoticePublisher` owner as package installs.
- A manual `update.run` on a Git install during a scheduled campaign adopts the campaign through its existing owner: it applies the pinned commit, records `trigger: campaign` with the campaign ID, binds the run, and refuses a mismatched `--sha` or a campaign already applying, as package installs do.
- Rejected a third time: settling legacy `.trial` records (same reason as above).
- Rejected: restoring the plugin cohort across a trial rollback. Removing the cohort is the approved design (plugins are non-fatal). After a rollback the previous release runs with plugins maintained for the new core; a plugin that cannot load stays off for that boot. Listed under accepted edge cases.
- Updating without a Gateway (`--no-restart`, or none answering) reads the checkout's tag and branch facts, as the Gateway route does, so a stable-tag checkout with no saved `update.channel` stays on stable instead of preparing `dev`.
- `openclaw update --no-restart --json` no longer prints the human "is ready" line before the JSON result.
- Deferred: carrying `--accept-capabilities` through `update.run` (a protocol change); listed under accepted edge cases.
- `openclaw update` delegates to `update.run` only when the call targets the configured local Gateway (`isImplicitLocalGatewayTarget`). With `gateway.mode=remote` or a Gateway URL override it prepares this checkout in-process instead of updating the remote installation.
- `check-release` and `update plugins` run through the existing process owner (`runCommandWithTimeout` with process-tree termination), so a timeout ends npm and every descendant and waits for them before the step settles.
- A linked Git worktree gets the root-level `.openclaw-launcher` marker (its `.git` is a file); only a main working tree uses `.git/openclaw-launcher`. Before, the marker went to the main working tree, so the linked worktree never forwarded. Not covered by a new test: it needs a full release build through publish.
- Deferred with `--accept-capabilities`: binding `update.run` to the CLI's checkout. When the configured local Gateway runs another installation than the checkout the CLI runs from, the Gateway updates its own installation. Matching them needs the admitted root in `update.run` (a protocol change). The previous in-place Git updater had the same mismatch: it updated the invoking checkout and restarted the configured service.
- A Git install is already current only when the serving build's commit (`resolveLoadedCommitHash`) matches the target, not when the checkout's `HEAD` does. A checkout pulled to the target without a rebuild still runs the old build, so it now prepares the release. An unknown build commit prepares a release too.
- The Git route honors `update.run` `restartDelayMs` when it restarts into a prepared release or after changed plugins, as the package route does.

## Merge danger

- Two-way door for the code: a revert restores the old Git update path. The forwarder that reads the launcher marker ships in this change, so after a revert the checkout's `openclaw.mjs` runs the checkout again and the old updater updates it in place; the `git-install/` prefix is left unused. A revert was not exercised.
- One-way parts: a converted install has a `git-install/` prefix with releases, the launcher and a forwarding marker beside the checkout; a revert leaves them in place. No schema, stored-row or protocol version change.
- Blast radius: Git installs only (source checkouts updating with `openclaw update`, `update.run` and automatic updates). Package installs keep the existing path.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 23, 2026
…ident launcher (openclaw#203194)

## Problem

A Git install updates in place under the running Gateway, through a managed-service handoff helper. When the new build does not start, recovery depends on that helper and on the old updater that is already installed, so a failed update can leave the Gateway down or stuck in `update-recovery-pending`.

## Change

Git installs now update through prepared releases and a resident launcher:

1. `update.run`, `openclaw update` and automatic updates admit the run, resolve the target and run preflight (Node engine, required tools, disk space, container installs refused before any change).
2. The next release is built beside the running one (`git worktree add --detach`, then the target's install and build). The running checkout is not changed.
3. `openclaw update check-release` runs the new code offline against the current config and state and reports broken plugin or config surfaces. It does not migrate state.
4. `openclaw update plugins` runs from the published release: the existing plugin maintenance owner (`updatePluginsAfterCoreUpdate`), with the new core's code and version. A plugin problem, or a target too old to have the command, is recorded as a `plugins` step with a next action and never fails the update. An already-current install still runs it from the serving code and restarts a running Gateway when plugins changed (`docs/install/updating.md`).
5. The release is published as a pending trial, and the Gateway restarts with a process-replacing reason.
6. The launcher switches the release link at the next child start, counts attempts, commits the trial when the new Gateway is ready, and otherwise rolls back and starts the previous release.
7. The Gateway that starts after the switch (new on success, old after a rollback) finishes the run and sends the outcome to a requester that received the start notice.

Routing:
- `update.run` reads the install kind from the existing install-status owner (`resolveStartupInstallStatus`). `update-run.ts` wraps `update.run`; `update.ts` is unchanged and still serves package installs.
- `openclaw update` branches after `prepareUpdateCommand`, so every existing refusal (external supervisor, host-owned, immutable, system package owner, interrupted update) applies first. A requested non-dev channel on a Git checkout still switches it to a package through the existing flow, and `--dry-run` keeps the existing preview.
- Package installs move to this path in the next change, which also deletes the old Git machinery that this PR leaves unused.

Converting an existing install:
- The old entry points of a converted install (`openclaw.mjs`, `dist/index.js`) forward to the release launcher through a marker beside the tree. Existing service definitions and PATH shims keep working without a rewrite.
- A first update driven by an older installed updater still migrates state as it does today. Released updaters require migrated state: 23 stable and 6 extended-stable tags contain that check.

Fixes found by the real-install runs below, each a separate commit:
- `openclaw update --sha` now sends the tracked upstream that the protocol requires.
- The new path restarts with `update.run` / `update.auto`, so the process is replaced instead of restarted in place.
- A Gateway started by the launcher leaves its update successor to the launcher instead of spawning one outside it.
- Preflight skips dangling symlinks in agent homes, such as Codex `arg0` shims, when it sizes state databases.
- `check-release` writes its JSON result to stdout.
- Plain `openclaw update` keeps following the run while the restarting Gateway refuses connections with a retryable HTTP 503. Before, it exited 1 although the update succeeded.

Accepted edge cases:
- After `openclaw update` runs in a Git checkout, `openclaw.mjs` and `dist/index.js` in that checkout run the current release. A developer who edits the source of a checkout they also update from runs the release, not their edits.
- A stop request handled inside a launcher child exits with code 0, and the launcher starts the child again. A stop through the service manager stops the launcher and its child.
- On a Gateway with no service manager, the first update from a released version does not restart it. The released updater does this, and says so.
- Package updates now read the install status twice per request: once to route, once in the old handler.
- After a rollback, the previous release runs with plugins maintained for the new core. A plugin that cannot load stays off for that boot, as the plugin docs describe.
- `openclaw update --accept-capabilities` reaches plugin maintenance when the CLI prepares the release itself (`--no-restart`, or no Gateway answering). Through a running Gateway, `update.run` has no field for it, so a plugin that needs consent is reported with its `openclaw plugins update` next action. Carrying the flag through `update.run` is a protocol change and follows separately.
- `openclaw update` run from a different checkout than the one the configured local Gateway serves updates the Gateway's installation, not the invoking checkout. Binding the request to the checkout needs a protocol field and follows with `--accept-capabilities`.

## Evidence

Real install on macOS (Apple silicon). Isolated HOME, state, config and port, a foreground Gateway, no launchd service. Every candidate was built from `git archive` of its commit; the final candidate is this branch's head before review.

| Step | Run status | Trial | Served after | Health |
|---|---|---|---|---|
| 2026.11.6 → A (released updater) | succeeded | (old path) | A, after a recorded manual start | 200 / 200 |
| A → B′ (B′ fails at startup) | failed, `new build failed to start` | rolled-back, 2 attempts | A, as the launcher's child | 200 / 200 |
| A → B | succeeded | committed, 1 attempt | B, as the launcher's child | 200 / 200 |
| B → C | succeeded | committed, 1 attempt | C, as the launcher's child | 200 / 200 |

- The same launcher process stayed the parent through every replacement. The previous release was kept after each commit.
- Phase times (seconds), from the persisted run steps:

| Step | Staging (build) | Validating | Restarting | Total |
|---|---:|---:|---:|---:|
| A → B′ (rollback) | 192.5 | 0.8 | 29.2 | 222.7 |
| A → B | 195.7 | 1.1 | 32.9 | 229.8 |
| B → C | 201.6 | 0.9 | 36.9 | 239.5 |

- `check-release` on a copy of a real state directory (Linux, no network): exit 0 in 3.0 s, 187 surfaces checked, shared state schema 40 → 40, agent databases 43 → 43.

Plugin maintenance, real install on macOS (isolated, foreground Gateway, a real third-party npm plugin `@martian-engineering/lossless-claw` served through a scratch registry proxy that advertises 1.1.1, then the real latest 1.2.0):

| Case | Run | `plugins` step | Plugin | Gateway |
|---|---|---|---|---|
| Core update through the new path | succeeded, trial committed (1 attempt) | completed | 1.1.1 → 1.2.0 | one restart into the new release |
| Already current, plugin outdated | skipped / already-current | completed | 1.1.1 → 1.2.0 | restarted |
| Already current, nothing to change | skipped / already-current | completed | unchanged | no restart |
| Already current, registry returns HTTP 503 | skipped / already-current | completed, detail names the plugin and its `openclaw plugins update` retry | kept 1.1.1 | no restart; CLI prints "Plugin notes: …" |
| Already current, `--no-restart` | skipped / already-current | completed | 1.1.1 → 1.2.0 | same process, no restart |

- An earlier head counted a `warning` result as a failed step with no message; the run above found it and the fix is in this PR.
- A run with `--timeout 1` showed the CLI calling a still-running update "Update failed: unknown reason". The fix ("The update did not finish in time. Run `openclaw update status` to see it.") is covered by `src/update/cli.test.ts`; it was not rerun on the real install.

Tests:
- New: `src/update/*.test.ts` (target, preflight, Git and package preparation, check-release, store, launcher, trial settlement and outcome notice, CLI request shape), plus a launcher-child case in `process-respawn.test.ts`.
- The gateway `update*` suites run against package installs. Tests that pinned the old Git handoff, Git preflight delegation, explicit Git targets and foreground parking are deleted. Tests of behavior that package installs still use (notice policy, owner checks, campaign adoption, platform admission) now run on a managed package install.

## Review

- `--no-restart` on a Git install now prepares the release in the CLI process instead of asking the Gateway, so the Gateway does not restart. The release starts at the Gateway's next start, and the CLI says so and exits 0, instead of reporting "Updated".
- The first conversion creates the `prefix/openclaw` link to the running tree before it writes the forwarding marker. Forwarded commands work between publish and the switch.
- The run row is written through the existing asynchronous update-run owner (`update-run-write.async.ts`). The synchronous second writer is deleted, so there is no SQLite work on the Gateway thread.
- Rejected: settling trials of the format-1 Git-release launcher (openclaw#199706). No released build contains it (not 2026.11.6 `latest`, 2026.10.33 `extended-stable` or 2026.11.10-beta.1 `beta`), and main-only code is not a shipped contract. Only a Git checkout that tracked `main` between 2026-11-17 and this change can have such a trial.
- The in-process path (`--no-restart`, or no Gateway answering) uses the requested channel, else the saved `update.channel` (`readUpdateChannelConfig`), else `dev`, as the existing CLI does. The Gateway path passes the checkout's tag and branch facts, as the existing handler does, so a configless checkout on a stable tag stays on stable.
- After publishing a Git release, `git worktree repair` records it at its final path, so `git worktree list` and a later `git worktree prune` see the serving release where it is.
- `prefix/openclaw` is repointed to the running tree when it does not already resolve there, so a link left from an earlier package install cannot become the rollback target.
- Rejected for this PR: carrying the package layout's `lib/node_modules/openclaw` link. That layout belongs to package-release installs, which this PR does not route; the next change moves package installs and owns it.
- A new build that exits 78 (it refuses the configuration) during a trial now rolls back like any other failed candidate. Outside a trial, 78 stays terminal.
- Rejected again, same reason as the format-1 trial: making `git-install/lib/node_modules/openclaw` follow `prefix/openclaw`. Only the main-only Git-release conversion (openclaw#199706) creates that link, and no release contains it.
- A Gateway with `OPENCLAW_NO_RESPAWN` set now refuses `update.run` with `restart-unavailable` before anything is recorded or prepared, as the existing handler does. The prepared release starts only in a new process, which that Gateway cannot start.
- `openclaw update --timeout <seconds>` on a Git install is the overall budget again: it bounds how long the CLI follows the run, reaches the Gateway as `update.run` `timeoutMs`, and target resolution, the release build and plugin maintenance get only what remains of it. Preflight and `check-release` keep their own short bounds.
- Rejected again, same reason as the format-1 trial: settling legacy `.trial` records in `stale-install.ts`. Only openclaw#199706 writes them; `settleGitReleaseTrial` is in no released build (2026.11.6 `latest`, 2026.10.33 `extended-stable`, 2026.11.10-beta.1 `beta`).
- Rejected: routing `--tag` on a Git install to the package flow. The existing Git flow ignores `--tag` ("--tag applies to npm installs only; git updates ignore it"), so the Git route keeps that behavior.
- After merging `main`: Control UI and desktop app requests on a Git install show the update in the app instead of the conversation (openclaw#203357), through the same `appUpdateNoticePublisher` owner as package installs.
- A manual `update.run` on a Git install during a scheduled campaign adopts the campaign through its existing owner: it applies the pinned commit, records `trigger: campaign` with the campaign ID, binds the run, and refuses a mismatched `--sha` or a campaign already applying, as package installs do.
- Rejected a third time: settling legacy `.trial` records (same reason as above).
- Rejected: restoring the plugin cohort across a trial rollback. Removing the cohort is the approved design (plugins are non-fatal). After a rollback the previous release runs with plugins maintained for the new core; a plugin that cannot load stays off for that boot. Listed under accepted edge cases.
- Updating without a Gateway (`--no-restart`, or none answering) reads the checkout's tag and branch facts, as the Gateway route does, so a stable-tag checkout with no saved `update.channel` stays on stable instead of preparing `dev`.
- `openclaw update --no-restart --json` no longer prints the human "is ready" line before the JSON result.
- Deferred: carrying `--accept-capabilities` through `update.run` (a protocol change); listed under accepted edge cases.
- `openclaw update` delegates to `update.run` only when the call targets the configured local Gateway (`isImplicitLocalGatewayTarget`). With `gateway.mode=remote` or a Gateway URL override it prepares this checkout in-process instead of updating the remote installation.
- `check-release` and `update plugins` run through the existing process owner (`runCommandWithTimeout` with process-tree termination), so a timeout ends npm and every descendant and waits for them before the step settles.
- A linked Git worktree gets the root-level `.openclaw-launcher` marker (its `.git` is a file); only a main working tree uses `.git/openclaw-launcher`. Before, the marker went to the main working tree, so the linked worktree never forwarded. Not covered by a new test: it needs a full release build through publish.
- Deferred with `--accept-capabilities`: binding `update.run` to the CLI's checkout. When the configured local Gateway runs another installation than the checkout the CLI runs from, the Gateway updates its own installation. Matching them needs the admitted root in `update.run` (a protocol change). The previous in-place Git updater had the same mismatch: it updated the invoking checkout and restarted the configured service.
- A Git install is already current only when the serving build's commit (`resolveLoadedCommitHash`) matches the target, not when the checkout's `HEAD` does. A checkout pulled to the target without a rebuild still runs the old build, so it now prepares the release. An unknown build commit prepares a release too.
- The Git route honors `update.run` `restartDelayMs` when it restarts into a prepared release or after changed plugins, as the package route does.

## Merge danger

- Two-way door for the code: a revert restores the old Git update path. The forwarder that reads the launcher marker ships in this change, so after a revert the checkout's `openclaw.mjs` runs the checkout again and the old updater updates it in place; the `git-install/` prefix is left unused. A revert was not exercised.
- One-way parts: a converted install has a `git-install/` prefix with releases, the launcher and a forwarding marker beside the checkout; a revert leaves them in place. No schema, stored-row or protocol version change.
- Blast radius: Git installs only (source checkouts updating with `openclaw update`, `update.run` and automatic updates). Package installs keep the existing path.

Co-authored-by: Ayaan Zaidi <[email protected]>
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…aw#194058)

Failed-update triage now captures the operator's environment before managed candidate admission, so a coding agent installed only on the operator's PATH is still offered when the Gateway service's PATH differs. Restores the operator-environment contract from openclaw#134490 and keeps the launch confirmation from openclaw#143139.

Proof: shipped CLI on isolated Linux (Crabbox) with a running systemd Gateway: accept launches the operator-only agent, decline starts nothing, base 18bee8e reports no agent found; published 2026.11.1 upgrades to the fix with settings intact.

Co-authored-by: TorstenW <[email protected]>
Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: steipete <[email protected]>

(cherry picked from commit 7c702c3)

Release adaptation: Capture invoking operator env before candidate admission, forward to interactive triage only; preserve latest target selectors, confirmation and lease cleanup ordering. Exact three authorized production paths plus real lifecycle regression.

Follow-up dispositions: ad4863d fix: preserve the running installation when an agent updates its Gateway (openclaw#201570); dc73ec0 fix: let updates finish when another tool briefly reads OpenClaw's databases (openclaw#202541); d07b530 fix: clarify PostgreSQL schema upgrades for Git installs (openclaw#202098); e60ea9f test(update): add a Git release upgrade-survivor scenario (openclaw#201956); 2ef6f7b fix(update): build and serve Git releases outside node_modules (openclaw#201917); dbc1aa0 fix: keep the openclaw command and Gateway working after updating a pnpm install (openclaw#201735); f5e7641 fix: Git checkout updates across a schema change no longer end as post-update-failed after the new release starts (openclaw#201600); 2183caf fix: Git checkout updates no longer fail before the new release starts on a schema change or a busy database (openclaw#201463); 47e8649 fix: explain why Doctor cannot restore a scheduled job’s account (openclaw#201550); 8f2cfd4 fix: remove updater-only restrictions from agent maintenance guidance; cb5cfb2 fix: keep a doubtful killed-update recovery on the repair path (openclaw#201361); 24cb734 fix: keep carried-over scheduled jobs running after updates (openclaw#200653); d1276e1 feat(doctor): check OpenClaw ID member roles and honor an optional roles default (openclaw#197785); 0a39956 fix: finish updates when another tool reads OpenClaw's databases during the update (openclaw#201330); ea1c9d5 fix(update): settle remounted package publications before admission (openclaw#201336); 66b5212 fix(update): isolate malformed retained-install markers (openclaw#201199); 7e79c83 fix: let the next update finish a killed source checkout update (openclaw#201009); d905d8a fix: let the next update finish a killed update after the machine restarted (openclaw#200994); fdf0c95 fix: let the next update finish a killed update that had already installed the new version (openclaw#200866); 0c19bcd chore(release): close out 2026.11.5 on main (openclaw#200577); a1940e0 fix(matrix): keep explicit recovery available during deferred migration (openclaw#200805); 18b4776 improve: explain package baseline drift during updates (openclaw#200802); 1ad4cad fix(doctor): reclaim macOS updater runtimes blocked by non-updater processes (openclaw#200732); 427c857 fix: keep one missing archived transcript from blocking every update (openclaw#200733); 802e3f7 fix(update): keep valid cold archives from blocking updates (openclaw#200659); 23fca1a fix: let the next update continue after a killed update when nothing is left to repair (openclaw#200680); 3afe212 fix: let Doctor publish unchanged plugin migrations in any order (openclaw#200658); f65e4db fix(doctor): reclaim runtimes blocked by unrelated Linux processes (openclaw#200657); dab086c fix(update): let candidate Doctor read plugin dependencies from the staged package (openclaw#200595); 3447bee fix(update): keep updates going when the predecessor writes during its stop (openclaw#200569); 0ce9c77 fix: let the next update settle a package publication that a killed update left behind (openclaw#200550); ae31ea3 fix(update): repair handoffs in the journal-pinned lease store (openclaw#200532); 74020ea fix: continue updates when initial SQLite capture is stale (openclaw#200328); 6747b1e feat(update): run Git checkout installs from releases behind the release link (openclaw#199706); e3f8a67 fix(state): keep completed retained agent stores out of startup upgrade (openclaw#200284); 3c512c5 fix(gateway): move managed update lease operations off the main thread (openclaw#200169); ea69fcb chore(release): close out 2026.11.4 on main (openclaw#199956); 618bf31 fix(state): bound startup upgrade copies and pruning to owned state (openclaw#199929); e4a3093 perf(update): replace the candidate canary with a runtime contract check (openclaw#198268); 5dbf569 fix(update): plugin failures never fail an update or Gateway health; 764761e fix(update): refuse missing host prerequisites in one line and record a cause per attempt; 4c4fef4 fix(ui): update dialog claims installation before progress is confirmed (openclaw#199254); 136e1f6 fix(update): retrying an update from a dev checkout is refused after a killed update (openclaw#198673); 3bd03da fix(update): avoid duplicate database copies while the Gateway is stopped (openclaw#198148); 68a839b fix: isolate held agent databases until explicit restoration (openclaw#198180); e333f7e chore(ci): drop retired test-lines allocation records (3/3) (openclaw#197657); fd6fa47 fix: converge Gateway updates with environment-only service overrides (openclaw#196371); 7cf5e75 fix: clarify split-install updates and blocked Doctor repairs (openclaw#196342); 6ff8c86 fix(update): retain lazy sqlite catalog generation (openclaw#197095); 930e1f7 fix: keep stable updates and recovery free of premature migrations (openclaw#196474); a15f737 fix: preserve external plugin data during update rehearsal (openclaw#196301); 92798ae fix: updates survive interrupted heartbeat runs (openclaw#195656); c1e55e2 fix(update): restore LaunchAgent registration after repair contention (openclaw#195406); 715c610 fix(doctor): repair retained ISO session end timestamps (openclaw#194685); 689cfc8 fix(update): reclaim dead closing triage repair leases (openclaw#194503); 86bc89e fix(doctor): keep standing Codex parameter advice out of retirement blockers (openclaw#193650); 691bc8d fix(backup): read the backup engine without copying the live database (openclaw#194234); 000542f fix(backup): backups and updates fail on slow storage when a header probe batch misses its deadline (openclaw#194239); 31a65d5 fix(update): skip --no-lazy-fetch on Git versions without it (openclaw#194198); e45e99d fix(update): preserve dev update sources in tag-only Git clones (openclaw#193109)

Validation: Baseline2 intended operator-agent failures/32 controls passed; candidate34/34passed (194058-green.log). Accept launches synthetic operator-only CLI with expected env, decline starts nothing. Isolated updater flow, not live systemd/upgrade qualification.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 6689fd575ada8fe40a9593784deac18ec73041cd)
(cherry picked from commit 92e7a9fa223b0dc35801f25f70be90b472d9a6b7)
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant