Skip to content

fix: rebuild incomplete Git runtimes when source is current - #158931

Merged
shakkernerd merged 2 commits into
mainfrom
fix/git-update-artifacts
Sep 26, 2026
Merged

shakkernerd merged 2 commits into
mainfrom
fix/git-update-artifacts

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A Git checkout can have the requested source commit and matching build provenance while still missing required runtime artifacts.
In that state, openclaw update currently takes the already-current shortcut instead of rebuilding.
The final safety check then rejects the incomplete runtime, leaving the operator with an update failure and no repair.
This completes the artifact checks for the source-current workflow covered by #156996.

User Impact

A source-current checkout with missing build stamps, runtime entry, or Control UI startup assets now reaches the existing candidate build and validation path.
A complete checkout still skips core activation, and package-to-Git conversion still performs its required exposure work.
The existing service admission, external-supervisor guard, migration boundaries, and post-update maintenance remain in place.

Git status JSON also includes an optional update.git.artifacts observation with readiness and, when ready, the build identity and version.
The version comes from current build metadata, with the existing CLI package-version fallback when that metadata has no version.
The observation does not establish remote freshness, running Gateway health, candidate validation, or permission to restore state.
Package-install status remains unchanged, and no configuration or migration is added.

Why This Change Was Made

The updater already computes complete native artifact verification, but its shortcut used only the recorded build commit.
Both the immediate target match and the fallback to the installed commit now use that existing verified result.
The artifact owner also produces the status observation so its version cannot drift to an edited source package.json while the installed build remains unchanged.

The patch preserves the separate sourceRuntimePrepared fact introduced by #158849 and its existing admission and finalization behavior.
Preferred-target reporting and external-manager client/UI changes are outside this PR.

Evidence

Final-head CI passed, including production/test types, artifact/status tests, the corrected snapshot cases, and preferred-target status coverage.
The conflict-only replay after #158926 retains both status observation paragraphs and unchanged production/test edits.
Independent source review found no actionable defects.

The real-Git candidate tests cover incomplete-artifact repair, failed-candidate fallback, complete dev/stable/beta no-ops, package-to-Git exposure, and the existing sourceRuntimePrepared result.
They assert candidate build and validation before service stop.
The status fixture covers source-version drift, missing metadata, repeated artifact reads, and failed upstream fetches.

Changed test file Cloud macOS file wall time CI test-case time
update-check-status.test.ts 51.49 s, 33 passed 3.261 s
update-runner-git-candidate.test.ts 271.16 s, 64 passed 17.258 s
update-command-git-snapshot.test.ts 18.55 s, 3 passed 5.915 s

File runs used pnpm test <file> --maxWorkers=1; CI times sum reported case durations and exclude shard setup.
The three new artifact cases total 0.783 seconds in CI.
A separate execution-validation run passed all 23 cases in 11.38 seconds wall.
The ordered affected-suite run passed 164 tests and reproduced one workspace-runtime timeout, also reproduced on baseline b4bcfe29678a with current locked dependencies.
Standalone passes do not establish a fix for that ordered timeout.

Published updater and real Gateway trace

The Linux proof used the actual npm [email protected] artifact, build commit eb377ac59e6c, with real Gateway processes behind the maintained systemd fixture.
Its prepared Git destination used normal locked dependencies and a task-owned Git remote pinned to tested source aa515e53eb03.
The final 1ac1f31ea954 replay preserves the artifact contribution; the related status composition was inspected and passed final-head CI.

Driver and request Observed result
Published driver, dirty Git destination Refused; original Gateway PID 584 remained ready.
Published driver, clean destination status: ok; native candidate build/activation replaced PID 584 with PID 9304 and verified build 2026.9.6-aa515e53eb03-2026-09-26T14-44-30.783Z.
Candidate, missing runtime stamp, running fixture Gateway Refused at existing managed-service-preflight; PID and readiness remained unchanged.
Candidate, missing runtime stamp, owner-stopped Gateway, update --no-restart --json status: ok; real preflight build, unchanged source SHA, restored stamp, and new build 2026.9.6-aa515e53eb03-2026-09-26T14-52-44.871Z; service remained inactive.
Repaired checkout, fresh task-owned service installation Booted successfully and became ready; status reported artifacts.ready: true with the repaired build identity.

The published driver cannot repair its own same-commit shortcut through candidate code; the corrected driver supplies that behavior after installation.
The fixture lacks native cgroup membership and complete enablement-policy observations, so the running candidate attempt and a later CLI start-wrapper attempt were safely blocked.
No guard was bypassed, and those attempts are not claimed as passing managed same-commit restart proof.
The successful same-commit repair used explicit owner quiescence; the subsequent boot used the same recorded repaired build and stamp in a fresh service fixture.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 docs Improvements or additions to documentation size: S labels Sep 26, 2026
@shakkernerd shakkernerd self-assigned this Sep 26, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 11:06 AM ET / 15:06 UTC (Revision 2).

ClawSweeper review

What this changes

Git updates rebuild incomplete source-current runtimes and report installed artifact readiness, version, and build identity in status JSON.

Merge readiness

✅ Ready for maintainer review

Current main still skips a source-current Git update when the recorded build commit matches, even if runtime artifacts are missing. This PR addresses that remaining failure. The updated runtime evidence and focused tests support the change, and I found no introduced correctness defect.

Priority: P1
Reviewed head: 1ac1f31ea954c2d1c81a9d09ea43e06cc3ab840d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused patch has strong boundary coverage and useful real updater observations, with a clearly stated limit on the managed same-commit fixture.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The reported Linux systemd runs exercise the Git updater's candidate path: a published driver preserved the old Gateway on refusal and activated a verified build on success; a candidate repaired a missing stamp at the same source SHA with the Gateway owner-stopped, and that repaired build subsequently booted. The fixture could not demonstrate a managed same-commit restart while running. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The reported Linux systemd runs exercise the Git updater's candidate path: a published driver preserved the old Gateway on refusal and activated a verified build on success; a candidate repaired a missing stamp at the same source SHA with the Gateway owner-stopped, and that repaired build subsequently booted. The fixture could not demonstrate a managed same-commit restart while running. No stored-data contract changes.
Evidence reviewed 9 items Current main still has the incomplete shortcut: The current main preflight skips when the recorded build commit matches the source SHA; it does not require the other runtime artifacts to be present.
Introduced no-op decision: The PR uses the existing full recovery-verification result for the source-current shortcut and its fallback candidate decision.
Canonical verifier: Recovery verification checks the source commit, both build stamps, runtime entry, Control UI assets, package version, and build identity before reporting a restart-safe runtime.
Findings None None.
Security None None.

How this fits together

The Git updater compares a checkout and selected target with the installed runtime before deciding whether to skip or build a candidate. Its result affects Gateway activation and the information shown by update status.

flowchart LR
A[Git checkout and target] --> B[Verify installed artifacts]
B --> C{Source current and runtime ready?}
C -->|Yes| D[Skip core activation]
C -->|No| E[Build and validate candidate]
E --> F[Gateway activation]
B --> G[Git status JSON]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +10, Tests +122, Docs +5. Total +137 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 4 19 9 +10
Tests 3 133 11 +122
Docs 2 15 10 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 167 30 +137

Review metrics

Metric Value Why it matters
Production and test lines production +19/−9; tests +133/−11 The small production increase reuses the existing artifact verifier; the larger test change covers repair, refusal, status, and no-op behavior.
Status contract 1 optional Git artifact observation added Consumers can distinguish verified installed artifacts from missing or unverified ones in status JSON.

Root-cause cluster

Relationship: canonical
Canonical: #158931
Summary: This PR owns the remaining incomplete-artifact case in the source-current shortcut; related merged updater work handles neighboring conditions and admission boundaries.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

A source-current Git installation should repair incomplete artifacts through normal update admission and expose a clear readiness observation without treating status as permission to recover state.

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

Yes. Current-main source shows the shortcut accepts a matching build commit without checking the remaining artifacts, and the real-Git fixture removes a required stamp to exercise that condition. I did not execute a new baseline reproduction in this read-only review.

Is this the best way to solve the issue?

Yes. The patch gates the existing no-op with the updater's canonical artifact verifier and retains the established candidate build and service-admission path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 785fdcaa5457.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The reported Linux systemd runs exercise the Git updater's candidate path: a published driver preserved the old Gateway on refusal and activated a verified build on success; a candidate repaired a missing stamp at the same source SHA with the Gateway owner-stopped, and that repaired build subsequently booted. The fixture could not demonstrate a managed same-commit restart while running. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: The existing shortcut can leave an incomplete Git runtime unrepaired during an update.
  • merge-risk: 🚨 availability: A source-current update can now enter candidate build and Gateway activation where it previously skipped; the reported real runs and retained admission guards limit that exposure.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The reported Linux systemd runs exercise the Git updater's candidate path: a published driver preserved the old Gateway on refusal and activated a verified build on success; a candidate repaired a missing stamp at the same source SHA with the Gateway owner-stopped, and that repaired build subsequently booted. The fixture could not demonstrate a managed same-commit restart while running. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The reported Linux systemd runs exercise the Git updater's candidate path: a published driver preserved the old Gateway on refusal and activated a verified build on success; a candidate repaired a missing stamp at the same source SHA with the Gateway owner-stopped, and that repaired build subsequently booted. The fixture could not demonstrate a managed same-commit restart while running. No stored-data contract changes.

Evidence

What I checked:

  • Current main still has the incomplete shortcut: The current main preflight skips when the recorded build commit matches the source SHA; it does not require the other runtime artifacts to be present. (src/infra/update-runner-git-preflight.ts:597, 785fdcaa5457)
  • Introduced no-op decision: The PR uses the existing full recovery-verification result for the source-current shortcut and its fallback candidate decision. (src/infra/update-runner-git-preflight.ts:595, 1ac1f31ea954)
  • Canonical verifier: Recovery verification checks the source commit, both build stamps, runtime entry, Control UI assets, package version, and build identity before reporting a restart-safe runtime. (src/infra/update-git-runtime.ts:81, 1ac1f31ea954)
  • Status observation: The new status field derives readiness from the same verifier and prefers recorded build metadata for the reported version. (src/infra/update-git-runtime.ts:92, 1ac1f31ea954)
  • Regression coverage: The real-Git candidate fixture removes a runtime stamp and checks successful rebuild ordering and failed-build refusal before service stop. The snapshot fixture now supplies a complete runtime for its legitimate no-op case. (src/infra/update-runner-git-candidate.test.ts:275, 1ac1f31ea954)
  • Reported real updater behavior: The PR body reports a published v2026.9.6 updater preserving the old Gateway on refusal and replacing it with a verified build on a clean destination. It separately reports a candidate same-commit repair with the owner-stopped Gateway, followed by a successful boot of that repaired build. The running same-commit fixture was refused by existing service admission, so it is not claimed as a successful managed restart.

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Patrick Erichsen: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-26T14:15:20.703Z sha ae64cd0519274f44152b443599d2f2fd066d1249 :: blocked before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Sep 26, 2026
@shakkernerd
shakkernerd force-pushed the fix/git-update-artifacts branch from aa515e5 to 1ac1f31 Compare September 26, 2026 14:33
@shakkernerd
shakkernerd merged commit c1245de into main Sep 26, 2026
206 checks passed
@shakkernerd
shakkernerd deleted the fix/git-update-artifacts branch September 26, 2026 15:06
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: source-current Git updates rebuild incomplete runtime artifacts and report verified artifact readiness with the built version.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Sep 26, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
…#158931)

Rebuild source-current Git installs when required runtime artifacts are incomplete and report verified artifact readiness with the built version.
obviyus added a commit that referenced this pull request Nov 17, 2026
…ase link (#199706)

## 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 (#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 #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 #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 #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** (#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.** #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 #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|succeeded`, 140 s; link moved; the Gateway restarted itself; unit untouched; outage 7.4 s |
| 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 #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.

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

## 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 openclaw#198835's linked package root (merged as `540d13a5`) to Git checkouts, per the openclaw#197949 design. Based on `main`. It reuses openclaw#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 (openclaw#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 openclaw#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 openclaw#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 openclaw#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** (openclaw#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.** openclaw#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 openclaw#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 `78d37094`): 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|succeeded`, 140 s; link moved; the Gateway restarted itself; unit untouched; outage 7.4 s |
| 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 openclaw#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` (`14466930`) 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 openclaw#198835. openclaw#198389 has merged; openclaw#199770 carries the same startup-copy exclusion for main.

Co-authored-by: Ayaan Zaidi <[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 docs Improvements or additions to documentation merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant