Skip to content

fix(workers): retain repository commits across reclaim - #182387

Merged
steipete merged 2 commits into
mainfrom
steipete/cs-adoptlive-1024
Oct 24, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/cs-adoptlive-1024

Conversation

@steipete

@steipete steipete commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #110498
Follow-up to #182140.

What Problem This Solves

Repository-session reclaim kept file contents but silently discarded unpushed worker commits, even after the Gateway-source fix in #182140.

User Impact

Repository checkpoints now retain bounded worker Git deltas. Replacement workers, forks, and Gateway materialization restore those commits onto the fetched pinned base while preserving dirty files. Missing, oversized, non-descending, or unavailable history preserves file recovery and records why commits were not adopted. A moved branch is never force-updated.

The compact-store contract stays intact: upstream history and unchanged base files are not stored in the Gateway's bare artifact repository. Restoration still requires access to the pinned upstream base. No configuration or database migration is needed.

Why This Change Was Made

Repository uploads skipped Git-history negotiation and the checkpoint handoff dropped the history payload. Reclaim also skipped repository workspaces entirely. The existing bounded exporter and strict importer now serve this path: checkpoints retain the delta as an opaque Git blob in a synthetic parent, so Git garbage collection and checkpoint lifetime already own it. Restore fetches the base first, verifies ancestry, and uses the existing compare-and-swap branch/index adoption policy. Publication retains its separate commit ownership.

The change also extracts existing HTTP download and repository restore code into their owning modules to keep the modified files within their size limits. Production: +665/-248 lines (net +417); tests: +209/-3. The added production code owns opaque retention, restoration transport, and visible failure outcomes; it adds no new state store or exporter.

Evidence

  • Red on base 73c77aa3f99: repository reclaim/restore regression returned the base instead of the worker commit; 85.45 s command wall.
  • Initial full affected verification: 100 passed, 2 existing Windows-only skips, 413.29 s wall across nine files. Covers reclaim/restart/fork, Gateway materialization, existing repository lifecycle/recovery, history adoption, upload bounds, negotiation, and real HTTP/Git transfers.
  • Post-review focused verification: 24/24 passed, 151.13 s wall across the new lifecycle, negotiation, and upload-reader files. This includes unavailable capture metadata with a placeholder HEAD while the worker has a real commit. Final pnpm test src/gateway/worker-environments/workspace-result-repository-history.test.ts --maxWorkers=1: 6/6 passed, 65.59 s command wall. Its 41 s of test work exercises real Git, native HTTP transfer, SQLite custody, reclaim, and restart/fork.
  • pnpm run tsgo:core: passed, 4.55 s wall. Changed-file oxfmt --check passed. Type-aware node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json <changed TypeScript files> and git diff --check passed.
  • Independent review found an unavailable-history placeholder HEAD check that could block file recovery; fixed it and added the upload-handoff regression. Final review: no accepted/actionable P0–P2 findings. The subsequent test-only method binding fix satisfies type-aware lint.
  • CI follow-up: the new repository-history test was in the correct gateway-database-workers project but out of lexical order in gatewayDatabaseWorkerTestFiles. This caused all eight CLI ownership failures in checks-node-compact-small-2; local reproduction: 8 failed, 2 passed, 28.72 s wall. Moved the single entry into order without changing membership or assertions.
  • OPENCLAW_VITEST_RUNTIME=node pnpm test test/vitest-cli-ownership.test.ts test/vitest-projects-config.test.ts --maxWorkers=1: 42/42 passed, 141.67 s command wall. Changed-file formatting, type-aware lint, whitespace checks, and independent review passed. The initial CI run settled with no other failing test jobs; both red CI gates reflected this ownership failure. CI for the follow-up head is pending.
  • Live cloud/model proof is left to the maintainer as requested. No live Gateway or Team deployment was changed. PR CI supplies broad proof.

Retain bounded worker Git delta packs with repository checkpoints and restore them against the fetched pinned base. Keep file recovery and a visible note when history cannot be adopted. Follow-up to #182140; fixes #110498.
@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.

@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-24T07:54:45.801224Z a452d7d PR opened
ℹ️ 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 gateway Gateway runtime size: XL labels Oct 24, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a452d7dae9

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +457 to +461
gitHistoryNote = await restoreWorkerWorkspaceHistory({
root: params.workspaceDir,
gitHistory: params.transfer.checkpointGitHistory,
gitPackPath,
assertCurrent: () => params.signal?.throwIfAborted(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Bind the replacement repository branch before adopting history

For replacement workers and forks without source.prepared, checkoutAndCapture() explicitly runs git checkout --detach --force, and syncRepository() never binds source.branch before this restoration call. Consequently, restoreWorkerWorkspaceHistory() reaches adoptWorkerWorkspaceHistory() with detached HEAD and returns “the Gateway checkout has no managed branch” instead of adopting the retained commits (git symbolic-ref -h identifies detached refs as “non-symbolic”). Files are restored, but HEAD remains at the pinned base; a subsequent checkpoint can then replace the retained history with that base-only state. Bind the session's managed branch before restoring its Git history.

Useful? React with 👍 / 👎.

@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 added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 retains bounded worker Git history in repository checkpoints and restores it on replacement workers, forks, and Gateway moves.

Example: A worker commits hello.txt containing "committed\n", then appends "dirty\n" before Stop.

  • Before: Restoration recovers the file contents but leaves HEAD at the pinned upstream commit.
  • After: Restoration adopts the worker commit and preserves the later edit as an uncommitted change.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful, owner-approved retention work with meaningful integration coverage, one concrete restore defect, and an unresolved persisted-state compatibility gate.
Proof confidence 🦐 gold shrimp (3/6) Maintainer authorship exempts ordinary real-behavior proof; supplied evidence exercises production Git/HTTP/checkpoint owners in integration tests, but does not establish latest-stable persisted-checkpoint upgrade compatibility.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Repository-session users recover file contents after reclaim but lose unpushed worker commit history.
Reason: Earlier discussion established file-only recovery as intentional; this maintainer-authored PR approves extending retention while preserving compact storage and separate publication ownership.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: this owner-approved change addresses repository-session history loss, but the restore pack can collide with valid workspace paths.

Priority: P2
Reviewed head: 59a77e1b3cdd291c38243dfbde6aa1d463a1029e

Before merge

  • Store the restore pack outside manifest-controlled staging paths (P2) - A valid worker commit adding history.pack/readme.txt causes the earlier materialization loop to create a nonempty history.pack directory in staging. This download then tries to create a regular file at that same path, fails, and falls into the non-adoption catch. Replacement workers and forks consequently remain at the upstream base despite having valid retained history. Use a separately owned temporary pack location, as the upload reader already does, and cover this filename collision through the native restore path.
  • 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] Store the restore pack outside manifest-controlled staging paths — src/node-host/node-worker-transfer-client.ts:453-454

Tests

  • Missing end-to-end proof: Supply a latest-stable-to-head upgrade and restart run showing existing parentless checkpoints, retained files, settings, and subsequent history-bearing checkpoints remain usable.
Agent review details

How this fits together

Worker uploads enter the Gateway checkpoint owner as file manifests and bounded Git packs; checkpoint restoration fetches the upstream base, restores files, and safely advances the managed branch.

flowchart LR
A[Worker repository] --> B[Native workspace transfer]
B --> C[Repository checkpoint]
C --> D[Replacement worker or Gateway move]
D --> E[Pinned upstream base]
E --> F[Git import and branch adoption]
F --> G[Commits and dirty files]
Loading

Technical review

Best possible solution:

Keep bounded history in the existing checkpoint owner and download restore packs into a separately owned temporary location outside workspace paths.

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

Current main's repository upload and checkpoint handoff omit worker history, establishing the loss path from source; this read-only review ran no target code.

Is this the best way to solve the issue?

Reusing bounded export, immutable checkpoints, strict import, and compare-and-swap adoption is appropriate; transport artifacts must remain outside manifest-controlled paths.

Full review comments:

  • [P2] Store the restore pack outside manifest-controlled staging paths — src/node-host/node-worker-transfer-client.ts:453-454
    A valid worker commit adding history.pack/readme.txt causes the earlier materialization loop to create a nonempty history.pack directory in staging. This download then tries to create a regular file at that same path, fails, and falls into the non-adoption catch. Replacement workers and forks consequently remain at the upstream base despite having valid retained history. Use a separately owned temporary pack location, as the upload reader already does, and cover this filename collision through the native restore path.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.95

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/worker-environments/workspace-result-repository-history.test.ts --maxWorkers=1
  • pnpm test src/node-host/node-worker-transfer-client.git.test.ts --maxWorkers=1
  • pnpm test src/gateway/session-repository-materialization.test.ts --maxWorkers=1
  • pnpm run tsgo:core
  • Upgrade isolated v2026.10.6 state with retained repository checkpoints, restart, and verify old recovery plus new history retention.

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 140d9e7 adds src/gateway/worker-environments/session-repository-checkpoints.ts:46 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 140d9e705ea3; files: src/gateway/worker-environments/session-repository-checkpoints.ts)
  • RoboClaw: Raw commit b077d4e adds src/gateway/worker-environments/node-worker-workspace-actions.ts:155 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: b077d4e4a5e8; files: src/gateway/worker-environments/node-worker-workspace-actions.ts)

PR surface

Source +417, Tests +207, Docs 0. Total +624 across 27 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 22 665 248 +417
Tests 4 210 3 +207
Docs 1 3 3 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 27 878 254 +624

Review metrics

Metric Value Why it matters
Production versus test growth Production +665/-248; tests/support +209/-3 Growth implements opaque history retention and restoration through existing owners; the new tests cover distinct lifecycle and unavailable-history outcomes.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #110498
Summary: This PR extends worker-history retention to repository sessions, which the earlier merged fix explicitly excluded.

Members:

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

Labels

Label changes:

  • add P2: Repository-session commit retention has clear value, and the identified restore failure has a focused repair.
  • 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: Repository-session commit retention has clear value, and the identified restore failure has a focused repair.
  • 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 24, 2026, 4:24 AM ET / 08:24 UTC.

@steipete
steipete merged commit b27c88e into main Oct 24, 2026
170 of 172 checks passed
@steipete
steipete deleted the steipete/cs-adoptlive-1024 branch October 24, 2026 08:59
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

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud-worker reclaim drops worker-authored Git commits

1 participant