Skip to content

feat: configure a global managed worktree storage root - #134872

Merged
steipete merged 5 commits into
mainfrom
codex/worktree-root
Sep 1, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/worktree-root

Conversation

@steipete

@steipete steipete commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #134848

What Problem This Solves

Operators could not place managed worktree checkouts on another disk without relocating the rest of their OpenClaw state. Large repositories can exhaust the disk holding the Gateway state directory.

Why This Change Was Made

Add the approved top-level worktreeRoot option, defaulting to <state-dir>/worktrees. Accept absolute host paths, bare ~, and ~/ expansion. The shared managed-worktree service owns this setting for manual, session, and Workboard allocations, with no per-agent override.

Changing the root affects new allocations. Existing records retain their absolute paths for reuse, removal, and snapshot restore, even when the new allocation root is unavailable. Repository-scoped names remain unique across roots. Custom-root cleanup acts only on registered worktrees and leaves unrelated folders alone. Default orphan scanning excludes overlapping custom roots, including nested roots and symlink aliases; recorded roots remain protected after changing the setting.

The shared SQLite registry, allocation lease, capacity limits, and snapshot storage stay unchanged; no schema migration or automatic checkout move is introduced. Types, validation, normalization, configuration help, generated baselines, and operator documentation are aligned. The retired worktrees namespace remains invalid.

User Impact

Set worktreeRoot to a writable directory on the Gateway host to store all new managed worktrees there. Existing installations keep their default behavior. Existing worktrees remain usable at their recorded locations, so their original storage must remain available until those records are no longer needed.

Release note: Managed worktrees can now use a global custom storage root while preserving existing checkout paths and restore behavior.

Evidence

  • Before implementation, the new configured-root regression suite failed five scenarios because allocations still used the state directory. The same scenarios now pass.
  • Focused real-Git tests cover all three owner kinds, canonical/symlink paths, names across roots, unavailable new storage, dirty snapshots, global capacity, orphan safety, and garbage collection. Configuration validation, normalization, help, and metadata checks pass.
  • pnpm build passes. Changed-file gates pass, including core/test type checks and the dead-export scan (the latter identified and verified removal of one obsolete helper).
  • Live proof against the built CLI and an isolated real Gateway passes: default allocation; custom-root manual and session creation; root change; original-path reuse; session archive/unarchive with draft preservation; snapshot restore with tracked and untracked edits; custom-root cleanup preserving unrelated files; one shared registry across all roots; and CLI cleanup/restore after changing roots. No production Gateway or external provider was used.
  • Linux CI exposed a stale session-fixture config snapshot after real worktree creation. Refreshing the fixture snapshot before runtime publication reproduced the exact missing-owner failure before the change and passed all 130 session-creation tests afterward on Blacksmith Testbox tbx_01m1dqwys3hvcn29zsq25y419r (exit 0; lease stopped). Production dispatch ownership is unchanged.
  • The nested-root GC regression failed for direct, deep, and symlinked roots before repair. All 36 configured-root, orphan, and GC tests pass afterward, including live checkout/file preservation across root changes.
  • The real CLI source entry also passes the repaired nested-root path: symlinked deep allocation, unsnapshotted edits, GC before and after changing the root, retained live registry record, unrelated-file preservation, and snapshot remove/restore.
  • Independent Codex autoreview returned no findings at its configured P0 blocking threshold. The source and lifecycle paths also received direct maintainer review.

Production LOC: +102/-59 (net +43), providing the new config capability and path-independent lifecycle behavior while deleting the old parent-pruning and obsolete path-lookup helpers. Tests/test support: +221/-6. Documentation/generated metadata: +42/-7. Generated channel/plugin baseline hashes also refresh to their existing metadata; their config counts are unchanged, while the core count increases by one.

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review September 1, 2026 05:28
@steipete steipete self-assigned this Sep 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 1, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed September 1, 2026, 3:16 AM ET / 07:16 UTC.

ClawSweeper review

What this changes

The PR adds a global worktreeRoot configuration option for placing new managed Git worktrees on a chosen Gateway-host directory while retaining existing checkout records and restore paths.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: the current head fixes the earlier live-record nested-root case, but a former nested custom root becomes unprotected after its 30-day snapshot record is pruned, allowing a later default-root orphan sweep to delete unrelated contents.

Priority: P0
Reviewed head: d02b4ad28292cfe685426d7bb850afb4e19ad4e1
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The PR has focused lifecycle coverage and clear operator documentation, but the untested retention boundary leaves a material data-removal flaw.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies this as a MEMBER-authored, maintainer-labeled PR, so external-contributor proof is not a gate; the supplied live-run narrative does not cover the retention-expiry path identified here.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies this as a MEMBER-authored, maintainer-labeled PR, so external-contributor proof is not a gate; the supplied live-run narrative does not cover the retention-expiry path identified here.
Evidence reviewed 6 items Introduced cleanup protection: The current PR head derives protected custom roots solely from the current setting and currently retained registry records before default-root orphan reconciliation.
Retention removes the only historical root record: GC reconciles orphans before deleting records whose removed timestamp exceeds the 30-day snapshot-retention period; the next GC no longer has the old root available for protection.
Nested-root test stops while the record is live: The added regression keeps the nested-root worktree live while changing roots, so it does not exercise removal, retention pruning, and a subsequent orphan sweep.
Findings 1 actionable finding [P1] Keep expired nested roots out of orphan reconciliation
Security None None.

How this fits together

Managed worktrees create isolated Git checkouts for manual commands, sessions, and Workboard work. The shared service reads Gateway configuration, records each checkout in the state database, and later restores or garbage-collects registered worktrees.

flowchart LR
  A[Gateway configuration] --> B[Managed worktree service]
  C[Manual session and Workboard requests] --> B
  B --> D[Checkout path selection]
  D --> E[Git worktree]
  B --> F[Shared state registry]
  F --> G[Restore and cleanup]
  E --> G
Loading

Decision needed

Question Recommendation
Should absolute roots nested inside the default managed-worktree directory remain supported, despite requiring durable ownership outside the expiring worktree record? Reject nested default-root paths: Validate that worktreeRoot cannot be inside the default managed-worktree directory, keeping default orphan cleanup authoritative and safe.

Why: The PR explicitly tests nested-root support, but the advertised unregistered-content safety guarantee cannot survive record retention expiry with the present model.

Before merge

  • Keep expired nested roots out of orphan reconciliation (P1) - After a nested custom root's last removed record ages past SNAPSHOT_RETENTION_MS, the prune loop deletes that record. On the following GC this list no longer contains the former root, so default-root reconciliation descends into it and can remove its unregistered directories. The added test keeps its record live; cover removal, retention expiry, and a second GC, then either reject nested roots or retain durable protection.
  • Resolve merge risk (P1) - After a removed nested-root record passes snapshot retention, a later GC can treat the former root as a default-root fingerprint directory and recursively delete unrelated folders beneath it.
  • Complete next step (P2) - This maintainer-labeled PR needs the nested-root product boundary decided and corrected before merge; it is not a ClawSweeper repair-dispatch candidate.

Findings

  • [P1] Keep expired nested roots out of orphan reconciliation — src/agents/worktrees/service.ts:1749-1752
Agent review details

Security

None.

PR surface

Source +43, Tests +215, Docs +35, Generated 0. Total +293 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 10 102 59 +43
Tests 5 221 6 +215
Docs 2 37 2 +35
Config 0 0 0 0
Generated 2 5 5 0
Other 0 0 0 0
Total 19 365 72 +293

Review metrics

Metric Value Why it matters
Configuration surface 1 added global option; default unchanged Existing installations retain the state-directory default, while opted-in operators gain a new persistent allocation location.
Production versus test delta production +102/-59 (net +43); tests/support +221/-6 The feature’s production growth implements a new configuration capability and its path-independent lifecycle behavior; the test growth covers allocation and cleanup cases.

Merge-risk options

Maintainer options:

  1. Constrain nested roots before merge (recommended)
    Reject custom roots under the default worktree directory and add retention-followed-by-GC regression coverage.
  2. Implement durable nested-root ownership
    Keep nested roots supported only after adding a lifecycle design that prevents former custom locations from becoming orphan-cleanup candidates.

Technical review

Best possible solution:

Preserve the cleanup boundary by rejecting configured roots inside the default managed-worktree directory, or define and retain a durable ownership marker that keeps every former nested custom root out of default orphan reconciliation.

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

Yes, source-reproducible: configure a root beneath the default root, remove its registered worktree, advance beyond the 30-day retention window, then run GC twice after changing the setting.

Is this the best way to solve the issue?

No: root selection belongs in the shared service, but protection based only on retained records cannot uphold the custom-root cleanup contract after retention expiry.

Full review comments:

  • [P1] Keep expired nested roots out of orphan reconciliation — src/agents/worktrees/service.ts:1749-1752
    After a nested custom root's last removed record ages past SNAPSHOT_RETENTION_MS, the prune loop deletes that record. On the following GC this list no longer contains the former root, so default-root reconciliation descends into it and can remove its unregistered directories. The added test keeps its record live; cover removal, retention expiry, and a second GC, then either reject nested roots or retain durable protection.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P0: Merging the current cleanup path can delete unrelated operator files after the configured-root record expires.
  • merge-risk: 🚨 compatibility: The new global setting changes allocation and cleanup behavior for operator-selected filesystem locations.
  • merge-risk: 🚨 session-state: Snapshot retention removes historical worktree records that the new cleanup protection relies on.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The repository state identifies this as a MEMBER-authored, maintainer-labeled PR, so external-contributor proof is not a gate; the supplied live-run narrative does not cover the retention-expiry path identified here.

Evidence

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Decide whether nested roots are supported, then add a regression that advances past snapshot retention and verifies a later GC preserves unrelated files.

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 (2 earlier review cycles)
  • reviewed 2026-09-01T05:55:11.365Z sha acb9ef0a8dd1ac49ecf3ce9dffa9a964a458d317 :: found issues before merge. :: [P3] Document the supported bare home-directory root
  • reviewed 2026-09-01T06:06:32.934Z sha 13e3b046d9d4342fcd1b7dee860be3ae16f3b05c :: found issues before merge. :: [P1] Keep configured roots out of orphan reconciliation

@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Maintainer decision confirmed: the approved contract is one top-level global worktreeRoot, inherited by all managed-worktree owners, with the current default and existing recorded paths preserved. Peter explicitly authorized adding this configuration option and then implementing, documenting, live-testing, and landing it. No per-agent override or SQLite change is intended.

Both ClawSweeper rank-up moves are addressed. Commit 13e3b046d9d clarifies bare ~ as well as ~/… in both operator documents; the schema and regression tests already support those values. The approval record is above. Formatting and git diff --check pass. This follow-up changes only two documentation lines; production code and tests are identical to green CI run 33474909274. The new head is going through required checks before native landing.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. 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. and removed P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 1, 2026
@steipete

steipete commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor Author

The release-inventory overflow is now fixed on main by #134824 (merge eaaa6da). This PR was rebased over that landed fix; git range-diff confirms all four feature/test/documentation patches are unchanged. Required checks are running on head 8f40daa before native landing. No changes were made to #134824's branch.

@steipete
steipete force-pushed the codex/worktree-root branch from 13e3b04 to 8f40daa Compare September 1, 2026 06:33
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the P1 nested-root orphan-cleanup finding in d02b4ad. The scanner now protects canonical overlaps with both the configured root and roots retained by registry records, so changing the setting does not expose existing checkouts. Default-root debris cleanup remains covered.

Before the repair, all three new cases failed: nested, deeper nested, and symlinked roots. Afterward, all 36 configured-root, orphan, and GC tests pass. The real CLI source entry also passed creation in a symlinked deep root, GC before/after a root change, preserved unsnapshotted edits and unrelated files, live registry retention, and remove/restore. The prior built CLI plus real Gateway lifecycle proof still covers the complete feature. Independent Codex autoreview is scoped-clean at the configured P0 threshold.

The global option approval remains recorded above. Both the earlier bare-home documentation move and the new nested-root safety move are resolved. Required CI is running on the new head: 33479926104. The preceding run's sole test failure was an unrelated Doctor source-startup readiness timeout; it is being independently investigated, without weakening its deadline or modifying another writer's branch.

@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Verified the feature and lifecycle behavior for head d02b4ad28292cfe685426d7bb850afb4e19ad4e1. The rebase over the landed release-inventory repair preserved all four feature/test/documentation patches, verified with git range-diff.

The shared managed-worktree service owns the global root. Existing registry paths remain authoritative for reuse/removal/restore; names remain repository-scoped across roots. Custom-root cleanup leaves unrelated folders alone. Removed the old parent-walking cleanup helper and unused registry path lookup. Production +102/-59 (net +43), tests/test support +221/-6. The one added config option is explicitly approved, defaults unchanged, and requires no SQLite migration.

Local verification:

pnpm build
node scripts/check-changed.mjs
node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mts
node scripts/run-vitest.mjs src/agents/worktrees/service.configured-root.test.ts src/agents/worktrees/service.canonical-paths.test.ts src/agents/worktrees/service.naming.test.ts src/agents/worktrees/service.orphans.test.ts src/agents/worktrees/service.capacity.test.ts src/config/zod-schema.worktree-root.test.ts src/config/normalize-paths.test.ts src/config/schema.hints.test.ts src/config/schema.help.quality.test.ts
node scripts/run-vitest.mjs src/agents/worktrees/service.configured-root.test.ts src/agents/worktrees/service.gc.test.ts
node scripts/run-vitest.mjs src/agents/worktrees/registry.test.ts

All gate components passed. The dead-export gate initially found the obsolete lookup, which was removed and the gate rerun to green. A regression test initially used the pre-restore idle timestamp; it was corrected to the actual recorded timestamp and the configured-root plus GC suites passed. Independent Codex autoreview passed for the feature and subsequent deletion-only cleanup at the configured P0 threshold.

The built CLI and an isolated real Gateway passed this sequence using synthetic local Git repositories:

  1. Create a worktree with no setting and confirm the default path.
  2. Set worktreeRoot to root A, boot Gateway, create manual and session worktrees there.
  3. Write tracked edits, untracked content, and a session draft.
  4. Set root B and restart the isolated Gateway. Named reuse stays at A; new allocation uses B.
  5. Archive/unarchive the session and remove/restore the manual worktree. Original paths and all edited files survive.
  6. Run GC with an unrelated directory under B; its file remains untouched.
  7. Confirm one shared registry spans default/A/B, then use CLI removal/restore across roots.

All assertions passed. No external provider was invoked; no production Gateway was changed. Documentation includes the setting, default, global scope, retained old paths, and cleanup ownership boundary. Native review artifacts validate with no findings.

CI run 33473773081 exposed a stale session-fixture config snapshot: real IO could pin an incomplete roster before the fixture published reply runtimes. The fixture now clears that snapshot before forced publication, keeping production ownership enforcement intact. The full session test file (node scripts/run-vitest.mjs src/gateway/server.sessions.create.test.ts) was verified remotely because local host disk space was below the worktree safety reserve. Blacksmith Testbox tbx_01m1dqwys3hvcn29zsq25y419r reproduced the exact missing-owner failure without the repair, then passed all 130 session-creation tests with it in the same order. Wrapper exit 0; lease confirmed stopped. Testbox run.

Both ClawSweeper rank-up moves are addressed: bare ~ is documented alongside ~/…, and explicit approval for the global option is recorded in comment5489597250. The separate release-inventory overflow was repaired on main by #134824 (eaaa6da). A clean rebase over that repair preserved all four feature/test/documentation patches exactly.

The later P1 nested-root GC finding is fixed by canonical overlap protection for configured and recorded roots. Three nested/deep/symlink regressions fail before repair and all 36 owner/sibling tests pass afterward. Real CLI source execution preserves live dirty worktrees and unrelated files before/after changing roots, then removes/restores the original snapshot successfully. Proof response: #134872 (comment).

Final exact-head CI is green: 33479926104, completed successfully for d02b4ad28292cfe685426d7bb850afb4e19ad4e1. The Doctor readiness shard also passed on this run. The final full changed-file gates completed with exit 0, including core/test types, formatting, lint, all three dead-export scans, and ownership/storage guards. Native review artifacts validate with zero findings.

@steipete
steipete merged commit 4f81644 into main Sep 1, 2026
268 checks passed
@steipete
steipete deleted the codex/worktree-root branch September 1, 2026 07:18
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
* feat: configure a global managed worktree storage root

* refactor: remove obsolete managed worktree path lookup

* test: refresh session fixture config before runtime publication

* docs: clarify bare home directory worktree roots

* fix: protect nested worktree roots during orphan cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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.

[Feature]: Configure a global managed worktree storage root

1 participant