Repository navigation
Conversation
Keep the global allocation lease around authoritative reservation decisions. Run snapshots, restoration, rollback, and retirement under their existing mutation owners; count restores through pending slots and preserve checkouts when snapshots fail.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
@clawsweeper review Please check the final code at 3d557ff, particularly count-neutral restore publication, eviction/run exclusion, exact victim revalidation, closure-bound delegated authority, and failed-snapshot preservation. The remaining synthetic timing pairs are being added to the evidence; the code is frozen. |
|
🦞👀 Re-review progress:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3d557fffac
ℹ️ 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".
| throw new Error( | ||
| "Worktree inventory changed during orphan planning; directory preserved", | ||
| ); |
There was a problem hiding this comment.
Retry orphan planning conflicts without caching a permanent failure
When a foreground creation, removal, or activity update changes the inventory between orphan planning and this check, the resulting error reaches the catch block that stores it in orphanFailures. Subsequent GC passes skip the unchanged directory by device/inode before checking the now-current inventory, so a transient concurrency conflict prevents automatic cleanup for the remaining service lifetime unless an operator runs gc --retry-deferred. With allocations now intentionally allowed during maintenance, this can strand orphaned checkouts and their disk usage after ordinary concurrent activity. Treat inventory conflicts as retryable planning outcomes rather than persistent directory failures.
Useful? React with 👍 / 👎.
|
Codex review: needs maintainer review before merge. What this changesMoves slow worktree snapshots, restore preparation, and cleanup outside the global allocation lease while preserving capacity accounting and recovery data. Example: A new session requests an available slot while another checkout is being snapshotted.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a current allocation bottleneck, resolves all four prior findings, and has no new actionable defect identified; exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe managed-worktree service turns session and maintenance requests into Git checkout operations and SQLite registry updates, using allocation custody for capacity reservations and checkout custody for filesystem changes. flowchart TD
A[Session request] --> B[Worktree service]
B --> C[Short allocation lease]
C --> D[Pending slot]
D --> E[Checkout mutation lease]
E --> F[Git preparation and restore]
F --> G[Atomic registry publication]
H[Background cleanup] --> E
Technical reviewBest possible solution: Retain short authoritative reservation decisions and use the existing checkout, removal-claim, and registry owners for slow work and settlement. Do we have a high-confidence way to reproduce the issue? Current main retains allocation custody across slow work; supplied parent-red/head-green regression evidence isolates the blocking path, and no target code was executed during this read-only review. Is this the best way to solve the issue? The change fixes the scheduling boundary with existing owners, preserves atomic capacity accounting, and avoids introducing a parallel manager or configuration surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 307e88c5e91a. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +159, Tests +223, Docs 0, Other +118. Total +500 across 33 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (2 earlier review cycles)
Reviewed November 16, 2026, 9:22 PM ET / November 17, 2026, 02:22 UTC (Revision 3). |
Allow explicit historical restores beside a live same-owner successor while retaining capacity and identity checks. Keep orphan planning conflicts retryable, and update checkout-custody and archive-failure consumers to prove preservation and retry.
|
Addressed all three items from the review of
CI also identified consumers of the intentionally replaced purge-after-snapshot-failure policy. They now prove checkout preservation, retry, and lossless restoration, including accepted empty directories and ignored authored bytes. Focused repair runs passed: 106 worktree tests, 29 GC tests, and 89 workspace-projection tests (overlap with the original focused proof). The requested real product proof also passes. An isolated built Gateway ran @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1a476cb55b
ℹ️ 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".
| const currentCollision = | ||
| owner ?? | ||
| currentSlots.find( | ||
| ({ record, state }) => | ||
| (state === "pending" && params.ownerId && worktreeOwnerMatches(record, params)) || |
There was a problem hiding this comment.
Retry inferred-name collisions with newly published checkouts
When concurrent creates for different owners use the same suggestedName, both can select the same available destination before entering this allocation callback. If the first publishes before the second reads currentSlots, its pending slot has disappeared, and the live-owner lookup does not find it because the owners differ. This check therefore misses the collision, and reservePendingWorktreeInDatabase throws its generic live-name conflict instead of the retryable WorktreePendingContentionError. The second creation fails rather than replanning with an ordinal suffix, whereas previously destination selection and reservation shared allocation custody. Recheck live records by repository/name here and route collisions back through name planning.
Useful? React with 👍 / 👎.
Revalidate live name collisions alongside owner collisions inside the short allocation decision. Retry full destination planning when another owner publishes between planning and reservation. A deterministic two-owner regression fails before the repair and proves ordinal naming plus pending-slot cleanup.
|
Addressed the remaining item from the review of
The PR body distinguishes completed proof from the ongoing check:changed and final-byte timing refresh. Fresh CI is attached to the repaired head; no previous-head timeout was waived or rerun. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
Capacity admission selected a peer reservation even when that peer had no pending writes and no stronger safety reserve. A low-space creator then waited for unrelated planning work instead of rejecting insufficient space. Ignore those peers when choosing capacity blockers; required byte accounting is unchanged, and positive debts and stronger reserves still serialize. Add a real-service regression that detects the false wait before releasing the planning peer, plus worker coverage for selecting the actual blocker. Correct the competing-repositories fixture to offer room for exactly one reservation before applying pressure, preserving its one-success contract. This repairs the capacity regression exposed after #200335 without restoring slow I/O under the global allocation lease or increasing test timeouts. Validation: capacity/invariants 182 tests; additional invariant consumers 49; PostgreSQL capacity 2; full build; clean Codex review. check:changed passes except unused exports also reproduced on exact base f52f728. The original 120-second timeout was not reproduced locally; the new false-wait regression fails on unchanged production and passes with this fix.
* fix(worktrees): unblock allocations during snapshot cleanup Keep the global allocation lease around authoritative reservation decisions. Run snapshots, restoration, rollback, and retirement under their existing mutation owners; count restores through pending slots and preserve checkouts when snapshots fail. * fix(worktrees): preserve restore and cleanup retry contracts Allow explicit historical restores beside a live same-owner successor while retaining capacity and identity checks. Keep orphan planning conflicts retryable, and update checkout-custody and archive-failure consumers to prove preservation and retry. * fix(worktrees): retry newly published inferred names Revalidate live name collisions alongside owner collisions inside the short allocation decision. Retry full destination planning when another owner publishes between planning and reservation. A deterministic two-owner regression fails before the repair and proves ordinal naming plus pending-slot cleanup.
Capacity admission selected a peer reservation even when that peer had no pending writes and no stronger safety reserve. A low-space creator then waited for unrelated planning work instead of rejecting insufficient space. Ignore those peers when choosing capacity blockers; required byte accounting is unchanged, and positive debts and stronger reserves still serialize. Add a real-service regression that detects the false wait before releasing the planning peer, plus worker coverage for selecting the actual blocker. Correct the competing-repositories fixture to offer room for exactly one reservation before applying pressure, preserving its one-success contract. This repairs the capacity regression exposed after openclaw#200335 without restoring slow I/O under the global allocation lease or increasing test timeouts. Validation: capacity/invariants 182 tests; additional invariant consumers 49; PostgreSQL capacity 2; full build; clean Codex review. check:changed passes except unused exports also reproduced on exact base e284160. The original 120-second timeout was not reproduced locally; the new false-wait regression fails on unchanged production and passes with this fix.
Capacity admission selected a peer reservation even when that peer had no pending writes and no stronger safety reserve. A low-space creator then waited for unrelated planning work instead of rejecting insufficient space. Ignore those peers when choosing capacity blockers; required byte accounting is unchanged, and positive debts and stronger reserves still serialize. Add a real-service regression that detects the false wait before releasing the planning peer, plus worker coverage for selecting the actual blocker. Correct the competing-repositories fixture to offer room for exactly one reservation before applying pressure, preserving its one-success contract. This repairs the capacity regression exposed after #200335 without restoring slow I/O under the global allocation lease or increasing test timeouts. Validation: capacity/invariants 182 tests; additional invariant consumers 49; PostgreSQL capacity 2; full build; clean Codex review. check:changed passes except unused exports also reproduced on exact base f52f728. The original 120-second timeout was not reproduced locally; the new false-wait regression fails on unchanged production and passes with this fix. (cherry picked from commit fa11cdd) Companion review: preserves positive debt and stronger reserve constraints; restores no global allocation I/O lock. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 8441ab5a9d51bba10e6c6f666b42a6c9ca6789d6)
* fix(worktrees): unblock allocations during snapshot cleanup Keep the global allocation lease around authoritative reservation decisions. Run snapshots, restoration, rollback, and retirement under their existing mutation owners; count restores through pending slots and preserve checkouts when snapshots fail. * fix(worktrees): preserve restore and cleanup retry contracts Allow explicit historical restores beside a live same-owner successor while retaining capacity and identity checks. Keep orphan planning conflicts retryable, and update checkout-custody and archive-failure consumers to prove preservation and retry. * fix(worktrees): retry newly published inferred names Revalidate live name collisions alongside owner collisions inside the short allocation decision. Retry full destination planning when another owner publishes between planning and reservation. A deterministic two-owner regression fails before the repair and proves ordinal naming plus pending-slot cleanup. (cherry picked from commit 9f441ad) Companion review: include debt-free capacity follow-up fa11cdd with this change; retain checkout-first allocation order, pending slot publication, and lossless snapshot custody. No global lease spans snapshot IO. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 26cb1ccff679172ec086eee5928047f726dd1d82)
What Problem This Solves
Fixes: new sessions wait behind unrelated managed-worktree snapshots, hydration, and cleanup when capacity maintenance or restore holds the global allocation lease.
User Impact
User impact: a slow snapshot no longer prevents another session from reserving an available worktree slot. Failed capacity snapshots now preserve the checkout instead of purging it. No configuration or schema migration is required.
Why This Change Was Made
Keep the allocation lease around authoritative capacity decisions and pending-slot reservation. Existing checkout mutation leases own snapshot, restore, rollback, and retirement work. Restore consumes its existing pending slot atomically when publishing the live row; removal claims and exact registry predicates arbitrate eviction versus reuse. Orphan cleanup briefly revalidates and detaches a directory, then deletes it outside allocation custody.
This adds 159 production lines: capacity reservation for restores and custody for cleanup replace protection previously supplied by the long global lease. It introduces no cache, schema, or configuration surface.
Evidence
6a03a947c275dwith the allocation lease held, then passes with this change. It calls the real service while snapshot completion is gated.2a79ccf02d8dwith zero findings/open items, resolving all four prior items.pnpm buildpasses on1a476cb55b0f. The final two-file name-collision delta passes 63 focused tests and Codex review;check:changed --base 1a476cb55b0f --timedpasses every gate except those same 116 unused exports (zero added/removed).pnpm check:changed --base 3d557fffac078 --timedalso passes every gate except the same 116 parent unused exports described below (zero added/removed).pnpm check:changed --base 6a03a947c275d --timed: all changed-scope type, lint, format, size, schema, and ownership guards passed. The command exits 1 only for 116 unused-export findings, exactly matching the unchanged parent (zero added/removed). Recent baseline introducers include472cd0a2f542(compaction exports),94e34f956969(Talk thinking),b868ed4c21ba/ feat(update): keep each release in its own directory on OpenClaw-owned installs #198835 (package release exports), and1ce9df608b43/ feat(openclaw-id): owners can approve a member's new browser #200088 (browser approval export). These remain main regressions, not passing checks.1a476cb55b0fwith the worker uniqueness error and passes by creatingrelease-planning-2after repair. The short decision now considers both live owner and live name collisions before retrying; no additional worker query round trip.a958f1d25c1dpassed focused reproduction on macOS and 2-CPU Linux ARM64 with pinned Bun; CI was Linux x64. Its cause remains unproven. No timeout increase, CI rerun, or inherited-failure waiver was used.2a79ccf02d8d(all recorded source hashes verified). Acceptance: available-slot admission must escape the snapshot delay, with no unexplained >20% whole-operation CPU/allocation regression.All five paired samples are retained and every paired snapshot completed. Candidate allocation wait is 6–48 ms; baseline is 5,784–8,110 ms. Whole-operation median CPU is +16.9%, wall time +17.7%, and main V8 allocation -2.0%. No >20% median CPU/allocation regression appeared. These CPU differences are not asserted causal on the shared host: A/A controls report 7,422 / 15,528 ms allocation wait, 18,893 / 29,223 ms whole CPU, and 2.670 / 2.673 GB main allocation. The second baseline control hit the old snapshot timeout/purge path; it remains recorded and flagged. Source preparation overlapped the other checks. With five samples, p95 is the maximum, not a production-tail estimate. The principal result is removal of snapshot-length allocation blocking. Earlier-candidate measurements remain in the local evidence, separately pinned.
These owner-boundary counters include the measured Node process and thread workers but exclude child-process CPU; V8 allocation is main-isolate only. The synthetic database matches file size, not production transcript distribution. The existing memory checkpoint occurs at create return, when cleanup is at different stages, so no peak-RSS or retained-memory improvement is claimed. Separate CPU profiles from the earlier candidate are diagnostic only, not final-head performance evidence. No production data is used.
Real product proof on
1a476cb55b0fbefore the subsequent name-collision-only repair: an isolated built Gateway ransessions.create → chat.send → agent.wait → chat.historywhile a victim's actual Git object census remained paused. Allocation wait was 4 ms, session creation 482 ms, and a real OpenAIgpt-4.1assistant reply 5,131 ms, before releasing the snapshot. The assistant returnedALLOCATION_REPLY_OK. Raising capacity while paused intentionally changed cleanup's runtime configuration; after release, cleanup rejected the stale commit and preserved the exact victim bytes. The Gateway shut down cleanly.Reproduction command
Baseline uses
OPENCLAW_BENCH_BASELINE_DIRwith the changed owner files frozen at6a03a947c275d. Both arms use the same fixture and driver. Required guards, Git operations, and state workers remain active. CPU profiling runs separately from the reported timing samples.Exact-head CI: run 44001707093 passed on
2a79ccf02d8d. ClawSweeper final-head review reports zero findings/open items. Native review and preparation completed for that head; no admin waiver or CI rerun was used.