Skip to content

fix(workers): preserve cloud commits on reclaim - #182140

Merged
steipete merged 4 commits into
mainfrom
steipete/cs-110498-1023b
Oct 24, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/cs-110498-1023b

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #110498

What Problem This Solves

Reclaiming a cloud worker currently keeps its files but drops unpushed worker-authored commits.

User Impact

Stop and reclaim now preserve worker commits in Gateway-source managed worktrees when they can fast-forward safely. Dirty working files and unrelated staged changes survive. Divergent worker history, a moved Gateway branch, or conflicting staged changes keep file reconciliation and produce a visible transcript note. Older workers and Gateways retain v1 behavior; repository-only restoration and publication behavior are unchanged.

Why This Change Was Made

Capability-negotiated result upload v2 carries worker HEAD, ancestry metadata, and a Git pack capped at 256 MiB. The existing staged result retains the imported history until reclaim verifies ancestry and advances the branch with an expected-old-value ref update. A two-tree index merge preserves staged-only content. Ordinary turn reconciliation and recovery remain file-only.

The change stays within the existing transfer, staging, and reclaim owners. Both native and SSH transports use the same history capture and adoption policy. Production: +708/-59 lines; tests: +707/-5; docs: +6/-2. The necessary growth covers negotiated transport and reclaim together, without adding a state store.

Evidence

Final validation used Node 24.22.1 with OPENCLAW_VITEST_RUNTIME=node and --maxWorkers=1.

  • Second CI follow-up: the ownership failure names scripts/control-ui-retention/dependency-retention.test.ts, introduced on main by 0076083eba1 (fix(ui): release disposed settings and Workboard views #182101). It belongs to the documented opt-in retention census, so the normal full-suite audit now excludes that directory. The three worker tests added by this PR already have exactly one owner; their registrations are unchanged.

  • Ownership reproduction on main 6f323c428768: failed with that exact missing file in 21.27 s. Applying only the two-line census exclusion made the same audit pass in 21.43 s. Full pnpm test test/vitest-projects-config.test.ts --maxWorkers=1 on the fixed PR branch: 32/32 passed, 97.32 s wall.

  • Lifecycle CI diagnosis: the failed assertion is workerNode.publishInventory() at line 834; the preceding recoveryError assertion passed. The requested unchanged lifecycle case passes under Node 24.22.1 on both main 6f323c428768 (587.41 s command wall, 217.49 s test) and PR 85e012d0d744 (633.50 s command wall, 249.81 s test). Command times include fresh isolated runtime builds; one unrelated case was filtered out in each run. The CI log used Bun. Its inventory-publication rejection failure was not reproduced in these Node runs, so no worker production code or lifecycle expectations were changed; that CI failure remains unverified rather than claimed fixed.

  • Second follow-up checks: oxfmt --check, type-aware node scripts/run-oxlint.mjs --tsconfig test/tsconfig/tsconfig.test.root.json test/vitest-projects-config.test-support.ts, pnpm run tsgo:core (10.00 s wall), git diff --check, and independent review all passed. Follow-up scope: two added test-helper lines, no production changes.

  • CI follow-up: reproduced the missing transfer-protocol dependency in the trusted PR-wrapper closure, then moved the v2 constant and shared history schema into existing inventory owners. scripts/pr-lib/wrapper-components.txt is unchanged.

  • Follow-up pnpm test test/scripts/eager-import-closure.test.ts --maxWorkers=1: 19/19 passed, 144.33 s wall, including both previously failing wrapper extraction checks. The pre-fix inventory regression failed as expected in 27.65 s.

  • Follow-up inventory, connection, real native v1/v2 HTTP transfer, negotiation, upload-reader, tunnel, Git-history and SSH tests: 117 passed, 1 existing platform skip, 291.27 s wall across 8 files. Format, type-aware lint, tsgo:core (6.00 s) and independent review passed.

  • pnpm test workspace-result-history.test.ts placement-reclaim-history.test.ts: 8 passed, 323.08 s wall. Covers retained ancestry through Git GC, adoption, dirty edits, staged-only content, moved/divergent fallback, and empty commits.

  • Focused transport/reconciliation/recovery run: 197 passed, 1 existing platform skip, 508.90 s wall. Its sole failure was the new SSH status assertion encountering deliberately invalid submodule metadata in the fixture. Scoped that assertion to ignore submodule status; pnpm test src/gateway/worker-environments/workspace-sync-tunnel.test.ts --maxWorkers=1 then passed 11/11, 48.64 s wall, including the 1,800-file round trip.

  • That focused run included node-worker-transfer-client.git, connection, node-worker-result-negotiation, node-workspace-upload-reader, placement-dispatch-reclaim, placement-reclaim-history, worker-workspace-recovery-transcript, workspace-reconcile, workspace-result-staging.reads, workspace-local-reconciliation, node-worker-tunnel, and node-worker-tunnel.device-folder. It proves real v1/v2 HTTP uploads, pack bounds, visible notes, and all three lifecycle cases: direct reclaim and reclaim recovery adopt before destruction; ordinary recovery leaves HEAD unchanged.

  • Red-on-base proof at 094bbd6b153: the new reclaim lifecycle regression fails at the pre-destroy HEAD assertion, 308.33 s wall. The fixed lifecycle cases pass.

  • Changed-file oxfmt --check, type-aware node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json, pnpm run tsgo:core (5.91 s final wall), and git diff --check passed.

  • An earlier default-runtime Bun attempt hit the 60-second large-workspace timeout and a large-upload worker heap limit before being interrupted. Both cases passed under the required Node runtime; that preliminary attempt is not counted as final validation.

  • Independent Codex review: no actionable P0–P2 findings after repairs. No live cloud/model E2E was run; PR CI supplies broad proof.

@clawsweeper

clawsweeper Bot commented Oct 24, 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.

@steipete
steipete marked this pull request as ready for review October 24, 2026 03:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T04:24:17.424414Z 8bf295d New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: XL labels Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 8bf295df404804c99df7061041c04dc03f059863
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server/ws-connection/connect-hello.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR transfers worker Git history and adopts safe fast-forward commits when reclaiming Gateway-source worktrees.

Example: A worker commits tracked.txt with content "worker change", then leaves an additional uncommitted edit.

  • Before: Reclaim restores file contents while the Gateway branch remains at its dispatch commit.
  • After: Reclaim advances the unchanged Gateway branch to the worker commit and retains the later edit as an unstaged change.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful, owner-approved capability with meaningful integration coverage, two blocking implementation defects, and incomplete persisted-state compatibility evidence.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Unpushed worker-authored commits disappear from the managed branch after reclaim even though their file contents return.
Reason: The maintainer-authored PR approves changing the previously deliberate file-only contract while preserving repository-only restoration and publication ownership.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: this maintainer-approved capability addresses lost worker history, but the patch introduces a reconciliation failure for oversized history and breaks the extracted PR wrapper.

Priority: P2
Reviewed head: 9148e0411f71f264f6913c428a9f7007430555c8

Before merge

  • Include the protocol module in the extracted PR wrapper (P2) - The new runtime import reaches src/worker/node-workspace-transfer-protocol.ts from the PR wrapper’s existing dependency graph, but scripts/pr-lib/wrapper-components.txt does not extract that file. The trusted-anchor wrapper therefore has an unresolved module in its extracted environment. Exact-head checks-node-compact-small-2 reports both the missing inventory entry and the unresolved extracted import. Include the dependency in the wrapper inventory or keep the version constant in an already extracted contract owner.
  • Preserve file reconciliation when history exceeds its cap (P2) - A worker can commit five 60 MiB incompressible files: each file and their 300 MiB total fit the existing reconciliation limits, but the resulting history pack exceeds 256 MiB. This script throws, prepareNodeWorkerGitResult propagates the error before the native file upload begins, and SSH capture propagates the same failure. Because both ordinary turns and reclaim require this capture, enabling history retention now prevents these previously valid results from reconciling or stopping successfully. Keep the history bound, but preserve file reconciliation with a visible non-adoption outcome when history cannot fit.
  • 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

  • [P2] Include the protocol module in the extracted PR wrapper — src/infra/node-runner-inventory.ts:4
  • [P2] Preserve file reconciliation when history exceeds its cap — src/worker/node-workspace-transfer-protocol.ts:54-58

Tests

  • Low-value test src/gateway/worker-environments/node-worker-result-negotiation.test.ts: Remove the first parameterized group: it supplies a mocked capability boolean, asserts copied request fields and call counts, then deliberately aborts before transfer; retain the separate changed-HEAD rejection case.
  • Missing end-to-end proof: No latest-stable-to-head upgrade and restart run demonstrates retained pending results, legacy staged refs, settings, and file/index state surviving the new persisted format.
Agent review details

How this fits together

Cloud-worker transfers deliver workspace snapshots to Gateway staging; reconciliation preserves files, and reclaim optionally imports retained commits into the managed branch before worker teardown.

flowchart LR
A[Worker Git workspace] --> B[Native HTTP or SSH transfer]
B --> C[Gateway staged result and Git objects]
C --> D[File reconciliation]
D --> E[Reclaim ancestry and index checks]
E --> F[Managed branch and transcript]
Loading

Technical review

Best possible solution:

Retain history through the existing staging and reclaim owners, preserve file recovery when history exceeds its bound, and include the wrapper’s new runtime dependency.

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

Current main’s staging and lifecycle documentation establish file-only reclaim, and the linked issue records a live worker commit returning as file changes; this review ran no target code.

Is this the best way to solve the issue?

Bounded ancestry-verified transfer and compare-and-swap adoption fit the existing owners, but optional history retention must not prevent otherwise valid file recovery.

Full review comments:

  • [P2] Include the protocol module in the extracted PR wrapper — src/infra/node-runner-inventory.ts:4
    The new runtime import reaches src/worker/node-workspace-transfer-protocol.ts from the PR wrapper’s existing dependency graph, but scripts/pr-lib/wrapper-components.txt does not extract that file. The trusted-anchor wrapper therefore has an unresolved module in its extracted environment. Exact-head checks-node-compact-small-2 reports both the missing inventory entry and the unresolved extracted import. Include the dependency in the wrapper inventory or keep the version constant in an already extracted contract owner.
    Confidence: 1
  • [P2] Preserve file reconciliation when history exceeds its cap — src/worker/node-workspace-transfer-protocol.ts:54-58
    A worker can commit five 60 MiB incompressible files: each file and their 300 MiB total fit the existing reconciliation limits, but the resulting history pack exceeds 256 MiB. This script throws, prepareNodeWorkerGitResult propagates the error before the native file upload begins, and SSH capture propagates the same failure. Because both ordinary turns and reclaim require this capture, enabling history retention now prevents these previously valid results from reconciling or stopping successfully. Keep the history bound, but preserve file reconciliation with a visible non-adoption outcome when history cannot fit.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9cf739b6c0da.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test test/scripts/eager-import-closure.test.ts --maxWorkers=1
  • pnpm test src/node-host/node-worker-transfer-client.git.test.ts src/gateway/worker-environments/node-workspace-upload-reader.test.ts --maxWorkers=1
  • pnpm test src/gateway/worker-environments/workspace-sync-tunnel.test.ts src/gateway/worker-environments/workspace-result-history.test.ts src/gateway/worker-environments/placement-reclaim-history.test.ts --maxWorkers=1
  • Exercise oversized history through both production transfer owners and verify file acceptance plus a visible non-adoption outcome.
  • Upgrade isolated v2026.10.6 state with retained pending results to the repaired head, restart, and verify legacy refs, settings, files, and staged content remain usable.

What I checked:

Likely related people:

  • RoboClaw: Raw commit 002288f adds src/gateway/worker-environments/workspace-result-staging.ts:168 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 002288fc669c; files: src/gateway/worker-environments/workspace-result-staging.ts)

PR surface

Source +645, Tests +704, Docs +4. Total +1353 across 44 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 31 704 59 +645
Tests 12 709 5 +704
Docs 1 6 2 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 44 1419 66 +1353

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #110498
Summary: This PR is the proposed implementation of the linked worker-history retention request.

Members:

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

Labels

Label changes:

  • add P2: Commit retention has clear value for cloud-workspace users, with focused implementation defects requiring repair.
  • add merge-risk: 🚨 compatibility: Previously valid file results can fail reconciliation solely because their worker history exceeds the new pack limit.
  • add merge-risk: 🚨 automation: The new runtime import breaks the trusted-anchor PR wrapper’s extracted dependency closure, as confirmed by exact-head CI annotations.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Commit retention has clear value for cloud-workspace users, with focused implementation defects requiring repair.
  • merge-risk: 🚨 compatibility: Previously valid file results can fail reconciliation solely because their worker history exceeds the new pack limit.
  • merge-risk: 🚨 automation: The new runtime import breaks the trusted-anchor PR wrapper’s extracted dependency closure, as confirmed by exact-head CI annotations.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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.

Reviewed October 23, 2026, 11:21 PM ET / October 24, 2026, 03:21 UTC.

# Conflicts:
#	test/vitest/vitest.gateway-server-paths.mjs
@steipete
steipete merged commit d6c2905 into main Oct 24, 2026
160 checks passed
@steipete
steipete deleted the steipete/cs-110498-1023b branch October 24, 2026 04:43
steipete added a commit that referenced this pull request Oct 24, 2026
#182140 carried worker commits back on reclaim, but repository sessions never used it: their upload and checkpoint handoff did not request Git history, the Gateway's compact bare store deliberately holds no upstream history (so it lacks the base the worker's delta pack builds on), and adoption returned silently. Repository sessions now capture the worker's bounded, strictly verified delta pack and retain it as an opaque object with the existing checkpoint; restore, restart, fork and Gateway materialization fetch the pinned base as before, import the delta, verify ancestry, and put the managed branch at the worker head when the base is unchanged. Commits that cannot be retained (oversize, missing history, non-descending) now record the visible not-adopted note instead of disappearing. The store still keeps no upstream history. Live: on main a worker commit in an octocat/Hello-World session vanished after reclaim (parentless result commits only); with this change the checkpoint records base 7fd1a60 -> head 7cf381c and the next turn, restored onto a fresh AWS worker, showed git log '7cf381c cloudmatrix proof1024b-repo-aws' on top of '7fd1a60 Merge pull request #6'. Refs #110498 #182140.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
Commits a cloud worker made in its workspace were lost when the environment was reclaimed: only the working-tree result came back, so worker-authored history disappeared. Reclaim now carries the worker's commits back as a bounded, verified Git pack (index-pack --strict, 256 MiB cap enforced at each stage) and adopts them into the local result history with a compare-and-swap update-ref against the recorded base commit, only when the local branch has not moved and after a dry-run merge proves the result applies. Divergent or oversized results stay visible as the existing workspace-result outcome instead of overwriting local work. Also fixes the full-suite ownership audit, which counted the opt-in control-UI retention probe that landed on main as an unowned test file.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
openclaw#182140 carried worker commits back on reclaim, but repository sessions never used it: their upload and checkpoint handoff did not request Git history, the Gateway's compact bare store deliberately holds no upstream history (so it lacks the base the worker's delta pack builds on), and adoption returned silently. Repository sessions now capture the worker's bounded, strictly verified delta pack and retain it as an opaque object with the existing checkpoint; restore, restart, fork and Gateway materialization fetch the pinned base as before, import the delta, verify ancestry, and put the managed branch at the worker head when the base is unchanged. Commits that cannot be retained (oversize, missing history, non-descending) now record the visible not-adopted note instead of disappearing. The store still keeps no upstream history. Live: on main a worker commit in an octocat/Hello-World session vanished after reclaim (parentless result commits only); with this change the checkpoint records base 7fd1a60 -> head 7cf381c and the next turn, restored onto a fresh AWS worker, showed git log '7cf381c cloudmatrix proof1024b-repo-aws' on top of '7fd1a60 Merge pull request openclaw#6'. Refs openclaw#110498 openclaw#182140.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime security-sensitive-changed size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud-worker reclaim drops worker-authored Git commits

1 participant