Skip to content

fix(worktrees): preserve detached checkout state during retirement - #155169

Merged
fuller-stack-dev merged 3 commits into
mainfrom
openclaw/exact-state-retirement-20260921
Sep 21, 2026
Merged

fuller-stack-dev merged 3 commits into
mainfrom
openclaw/exact-state-retirement-20260921

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Closes #155048
Related: #137831

What Problem This Solves

Managed worktrees deliberately detached from their recorded branch cannot be retired without first changing source state, and ordinary snapshot recovery reconstructs the index instead of preserving partial staging and staged-only data.

User Impact

Operators get an explicit owner-fenced exact-state retirement and restore route. Ordinary removal, snapshot-loss permission, and clean/published-only removal keep their existing guards.

Exact retirement is archival, not immediate disk reclamation. The original checkout and its native Git registration remain at a reported recovery path for the existing 30-day snapshot retention period. This preserves late writes through already-open descriptors or working directories. Retention expiry removes that recovery checkout; it is not an active workspace. The runtime executing these commands must include this change.

Why This Change Was Made

A versioned snapshot retains the detached commit, separate recorded branch tip, exact index and split-index dependency, and staging/cache-tree/resolve-undo objects. Native archival and owner/lifecycle checks preserve the original source without weakening the ordinary HEAD guard. Restore prefers that retained source, including later workfile writes; if both the source and its registration are unavailable, it reconstructs the captured raw bytes and index without checkout transformations. Interrupted archival has an explicit original-request recovery route.

The object-only fallback preserves eligible tracked/untracked/provisioned bytes, symlinks, permission modes, modification times, and staging—not a complete filesystem image. Unrelated ignored caches are available only when the original retained checkout survives. Unsupported index representations, sparse checkouts, and non-file-ref backends fail closed.

Evidence

  • Baseline service-level fixtures fail at the existing detached-HEAD removal guard for normal and split indexes.
  • Real Git/service qualification: 128 passed, one existing platform skip, across nine scoped files and three canonical shards; 269.94 seconds wall time. Covers retained-source and object-only normal/split-index round trips, prune-resistant staged-only/resolve-undo/cache-tree objects, raw bytes, modes/symlinks, owner/lease/ref/index races, interrupted retirement/restore/expiry, late descriptor writes, and ordinary removal/CLI siblings.
  • Deterministic regressions reproduce the original HEAD guard and reviewed recovery defects before their corrections. Native Git/process fixtures are needed here to exercise actual index/ref exclusion, filesystem identity and durable recovery; timer-only simulations do not establish these properties.
  • Independent code review completed; actionable findings were reproduced and corrected. Post-index-publication writes are intentionally retained: publishing the original index is the object-only restoration commit point.
  • Full pnpm build: passed in 7m 18.5s, including CLI bootstrap/runtime closure checks.
  • Final built CLI in isolated disposable state: create → exact retirement → retained-source restore → second retirement → native disposable-source removal and object pruning → object-only restore; exact split index/status/provisioned bytes and receipt cleanup passed. Fixture cleanup completed.
  • Complete changed-source verification passed: format/line-cap/dependency and ownership guards, production and canonical test types, dead-export scans, full-core and script lint, storage/schema and import-cycle guards.
  • CI exposed and the follow-up corrects a type-import architecture cycle, two missing eager wrapper archive dependencies, a lost ordinary-restore branch cleanup diagnostic, and a stale integration expectation for the new compare-and-delete argument. The focused restore diagnostics suite passes 24/24; the ref-serialization integration passes 3/3 in 20.60s. Independent follow-up review found no actionable P0–P2 findings.
  • Local native wrapper qualification: 225 passed, 2 timed out, 1 platform skip in 854.27s. The two failures occurred in fresh-main fixture setup (native bare-clone timeout and 30-second test deadline) while the full build/check ran concurrently. A bounded unchanged replay of that seven-case family passed in 87.43s; this is not claimed as a code fix. All eager-archive and main-refresh cases passed. Hosted exact-head CI remains the landing gate.
  • Cold native PR provisioning qualification: 18 passed, 1 platform skip in 403.15s, including actual cold/warm APFS siblings and native sparse transitions.
  • ClawSweeper found a deleted-parent object-only recovery defect. The existing normal/split matrix now captures a missing multi-level indexed directory: baseline 2 fallback failures / 2 retained-source passes; corrected affected service/race proof 54 passed in 157.03s. Final service regression layout passes 10 tests in 89.51s, including replacement of a missing parent with a regular file or symlink. The final built CLI also preserves the absent directory and exact split index through both restore routes.
  • Compatibility: no database schema/version migration (native schema v17 remains unchanged); existing ordinary snapshots retain their contract. The new opt-in exact-v1 snapshots require a supporting runtime, as documented; older runtimes do not preserve the extra index state.
  • Installed previous-runtime → candidate compatibility proof: prior CLI created and archived an ordinary snapshot in isolated state; final built candidate restored the same legacy database/ref with tracked/untracked/provisioned bytes and unchanged worktree table schema/user version. Disposable fixture cleanup completed.
  • No production worktree retirement or runtime deployment was performed.

@clawsweeper

clawsweeper Bot commented Sep 21, 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 cli CLI command changes agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 21, 2026
@fuller-stack-dev
fuller-stack-dev marked this pull request as ready for review September 21, 2026 20:23
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime scripts Repository scripts labels Sep 21, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 21, 2026
@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 21, 2026, 5:49 PM ET / 21:49 UTC (Revision 4).

ClawSweeper review

What this changes

Adds explicit commands to archive detached managed Git checkouts and restore their exact staging state, with retained-source recovery, snapshot fallback, documentation, and regression coverage.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open as useful, maintainer-owned work. The previous absent-parent finding is fixed, and the added previous-runtime recovery evidence resolves the outstanding upgrade-proof request. No remaining actionable patch defect was found.

Priority: P2
Reviewed head: d1a5d299a43707f0413189e93bbf65617cdb93ca

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent implementation with meaningful native regression coverage and the prior compatibility follow-up addressed.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor-proof gate does not apply to this MEMBER-authored PR. Its recorded built-CLI runs exercise both exact restore routes and legacy-snapshot upgrade recovery; source and native regression inspection found no unresolved authority case requiring additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor-proof gate does not apply to this MEMBER-authored PR. Its recorded built-CLI runs exercise both exact restore routes and legacy-snapshot upgrade recovery; source and native regression inspection found no unresolved authority case requiring additional final-effect proof.
Evidence reviewed 9 items Pinned review scope: Reviewed the introduced merge-base-to-head changes and corresponding checkout sources. The supplied test merge is stale and was not used to infer removal of current-main behavior. Repository origin identifies openclaw/openclaw.
Still necessary on current main: Fetched main retains the detached-HEAD refusal and reconstructs staging during ordinary restoration. Searching its worktree owner and CLI found no exactState or recoverExactState route.
Release boundary: The supplied latest release also contains the detached-HEAD refusal; no released exact-state implementation was established.
Findings None None.
Security None None.

How this fits together

Managed worktrees provide isolated Git checkouts for OpenClaw sessions and tasks. Their lifecycle service combines registry ownership, run leases, Git snapshots, and filesystem state to retire and recover work.

flowchart TD
  A[Operator retirement request] --> B[Validate owner and live leases]
  B --> C[Capture exact Git and file state]
  C --> D[Archive original checkout]
  D --> E[Restore request]
  E --> F{Original checkout available?}
  F -->|Yes| G[Restore retained source]
  F -->|No| H[Restore snapshot bytes and index]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +2417, Tests +1522, Docs +104, Other +2. Total +4045 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 19 2782 365 +2417
Tests 5 1523 1 +1522
Docs 1 106 2 +104
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 0 +2
Total 26 4413 368 +4045

Review metrics

Metric Value Why it matters
Opt-in CLI surface 2 new flags; ordinary removal defaults unchanged Exact retirement and interrupted-retirement recovery require explicit operator selection.
Production versus test growth Production net +2,417 lines; tests/test routing net +1,522 lines Production growth implements the versioned archive and guarded recovery lifecycle; native tests exercise staging, filesystem identity, and interruption contracts.

Stored data model

Persistent data-model change detected: serialized state: src/cli/worktrees-cli.ts, unknown-data-model-change: src/cli/worktrees-cli.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Keep exact archival within the existing worktree lifecycle owner, preserving ordinary removal guards and the documented runtime compatibility boundary.

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

Not applicable as a new explicit archival mode: source confirms that existing removal intentionally rejects detached HEAD and ordinary restore reconstructs staging. This review did not execute a runtime reproduction.

Is this the best way to solve the issue?

Yes: extending the existing lifecycle owner with an opt-in exact snapshot format preserves the established safety guard and avoids a competing recovery system.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This adds bounded recovery capability for an advanced workflow whose current refusal preserves the original checkout.
  • merge-risk: 🚨 compatibility: New exact-v1 snapshots require a supporting runtime, an explicitly documented MEMBER-owned tradeoff; previous-runtime ordinary snapshot recovery is now reported verified.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The ordinary contributor-proof gate does not apply to this MEMBER-authored PR. Its recorded built-CLI runs exercise both exact restore routes and legacy-snapshot upgrade recovery; source and native regression inspection found no unresolved authority case requiring additional final-effect proof.

Evidence

What I checked:

  • Pinned review scope: Reviewed the introduced merge-base-to-head changes and corresponding checkout sources. The supplied test merge is stale and was not used to infer removal of current-main behavior. Repository origin identifies openclaw/openclaw. (d1a5d299a437)
  • Still necessary on current main: Fetched main retains the detached-HEAD refusal and reconstructs staging during ordinary restoration. Searching its worktree owner and CLI found no exactState or recoverExactState route. (src/agents/worktrees/removal-git.ts:11, fbac0f74739d)
  • Release boundary: The supplied latest release also contains the detached-HEAD refusal; no released exact-state implementation was established. (src/agents/worktrees/removal-git.ts:11, ec9c1a13db89)
  • Previous finding resolved: The final commit permits absent non-root ancestors only for captured-missing entries, then revalidates their absence or identity. The normal/split-index matrix now includes deleted multi-level parents and file/symlink replacement rejection. GitHub's commit API supplied the precise corrective patch when the local earlier-head comparison encountered an unavailable object. (src/agents/worktrees/snapshot-exact-state.ts:575, d1a5d299a437)
  • Upgrade evidence addresses prior review: The captured MEMBER comment at fix(worktrees): preserve detached checkout state during retirement #155169 (comment) reports that the installed previous-runtime CLI created an ordinary snapshot and the final built candidate restored the same database/ref, preserving tracked, untracked, and provisioned bytes with unchanged table definitions and SQLite user version. This directly addresses the prior review's compatibility request; it is reported execution evidence, not a reviewer-run test. (d1a5d299a437)
  • Documented compatibility tradeoff: The MEMBER author's captured body and follow-up explicitly retain ordinary snapshot behavior and require a supporting runtime for new opt-in exact-v1 snapshots. Documentation also states that archival retains the checkout for the existing 30-day period and does not immediately reclaim its disk space. These are disclosed design boundaries, not renewed acceptance requests. Public docs: docs/concepts/managed-worktrees.md. (docs/concepts/managed-worktrees.md:362, d1a5d299a437)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Peter Steinberger: 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 (3 earlier review cycles)
  • reviewed 2026-09-21T21:09:16.497Z sha 40e50cf :: blocked before merge. :: [P2] Allow absent parents when restoring captured missing paths
  • reviewed 2026-09-21T21:18:15.134Z sha 40e50cf :: blocked before merge. :: [P2] Allow absent parents when restoring captured missing paths
  • reviewed 2026-09-21T21:35:01.166Z sha d1a5d29 :: blocked before merge. :: none

@fuller-stack-dev

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

Addressed the absent-parent finding in d1a5d299a43707f0413189e93bbf65617cdb93ca.

The expanded native normal/split-index matrix reproduced two object-only ENOENT failures while both retained-source routes passed. The correction accepts absent non-root ancestors only for captured-missing entries, continues rejecting existing non-directory/symlink parents, and revalidates identities/absence before accepting the result. Affected native service/race proof passed54 cases; final service layout passed10, including file/symlink replacement guards. The final built CLI also passed the multi-level absent-parent case through retained-source and object-only recovery after prune, with byte-identical split index and fixture cleanup. Independent follow-up review found no P0–P2 findings.

Compatibility: this does not change the database schema (v17 remains unchanged), config, existing ordinary snapshots, or retention. Existing ordinary removal/restore siblings remain qualified. New opt-in exact-v1 snapshots require a supporting runtime; older runtimes cannot preserve the additional index state, as the documentation states. No downgrade support for the new format or production deployment is claimed.

@clawsweeper

clawsweeper Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 21, 2026
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Completed the remaining compatibility proof on the final head d1a5d299a43707f0413189e93bbf65617cdb93ca:

  • The installed previous-runtime CLI created and archived an ordinary managed worktree in a fresh disposable repository and isolated state/config.
  • The final built candidate opened that same database and restored the legacy row and snapshot ref, preserving tracked, untracked, and provisioned bytes.
  • The worktree table definitions and SQLite user version were unchanged. All fixture source/state was cleaned up.

This directly exercises previous-runtime → candidate recovery. It does not claim that an older runtime can restore the new opt-in exact-v1 format; that limitation remains documented. No production worktree or service was modified.

@fuller-stack-dev
fuller-stack-dev merged commit 1520154 into main Sep 21, 2026
221 checks passed
@fuller-stack-dev
fuller-stack-dev deleted the openclaw/exact-state-retirement-20260921 branch September 21, 2026 21:53
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 22, 2026
…penclaw#155169)

* fix(worktrees): preserve detached checkout state during retirement

* fix(worktrees): close exact-state retirement integration gaps

* fix(worktrees): restore captured deletions with absent parents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL 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.

Managed detached worktrees cannot retire without losing exact staging state

1 participant