Repository navigation
fix(worktrees): preserve detached checkout state during retirement - #155169
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Codex review: blocked before merge. Reviewed September 21, 2026, 5:49 PM ET / 21:49 UTC (Revision 4). ClawSweeper reviewWhat this changesAdds 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 Review scores
Verification
How this fits togetherManaged 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +2417, Tests +1522, Docs +104, Other +2. Total +4045 across 26 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
|
@clawsweeper re-review Addressed the absent-parent finding in 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. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Completed the remaining compatibility proof on the final head
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. |
|
Merged via squash.
|
…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
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
pnpm build: passed in 7m 18.5s, including CLI bootstrap/runtime closure checks.exact-v1snapshots require a supporting runtime, as documented; older runtimes do not preserve the extra index state.