Repository navigation
fix(worktrees): avoid redundant cleanup passes and manifest scans - #198362
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. |
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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR coalesces archive cleanup requests and skips unchanged manifest scans using durable sweep demand. Example: Six repeated archive requests over one simulated hour with unchanged workspace manifests.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains useful and has no actionable findings. The added stable-upgrade and restart evidence resolves the previous compatibility blocker, and exact-head CI is green. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherSession archive effects notify the Gateway maintenance owner, which removes retired checkouts and asks shared-state workers to collect unreachable manifest content. flowchart TD
A[Session archive] --> B[Archive effects]
B --> C[Maintenance owner]
D[Hourly scheduler] --> C
C --> E[Worktree cleanup]
C --> F[Manifest sweep worker]
G[Workspace writer] --> H[SQLite sweep demand]
H --> F
Technical reviewBest possible solution: Keep archive admission in the session-effects owner and durable sweep demand in the existing workspace writer, as this PR does. Do we have a high-confidence way to reproduce the issue? Parent source unconditionally requests maintenance for archives and scans manifests on every cleanup pass; the supplied evidence reports matching regressions failing on that exact parent. Is this the best way to solve the issue? The change removes unnecessary work at existing owners, preserves two-epoch preparation grace, and records demand atomically instead of inferring it from checkout-removal counts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2ca47150600a. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +103, Tests +117, Docs +8, Other +57. Total +285 across 13 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 (1 earlier review cycle)
Reviewed November 13, 2026, 11:59 AM ET / 16:59 UTC (Revision 2). |
|
Addressing the sole open item in review 6859104499 against unchanged head
The missing-marker upgrade admission is at local-workspace-cas.kernel.ts:223; grace and conditional completion are at line 185. The existing conversion preserves pending legacy receipt bytes at local-workspace-manifest-scan.ts:407 and line 458. The committed restart/failure/retirement regression remains at local-workspace-store.test.ts:74. Exact-head CI is green: run 43462498583. There are no source changes since review. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
What Problem This Solves
Worktree cleanup can repeat a full pass after an archive already covered by its census, and each archive-triggered pass can reread gigabytes of unchanged workspace manifests.
User Impact
Newly archived checkouts still receive prompt cleanup. Repeated archives and sessions without a checkout no longer wake GC. Hourly expiry checks remain, while unchanged manifest content avoids the reachability scan, including after restart. No configuration or schema change is required.
Why This Change Was Made
An archive arriving during scratch cleanup previously set
archivePending, although the worktree census had not started. That flag requested another pass after completion. Clear it immediately before GC starts; archives arriving after that point retain their follow-up. Only a newly archived bound checkout requests the wake.The existing hourly job now owns global manifest sweeping. Its existing writer records pending sweep epochs in
config_machine_state, atomically with content preparation or manifest-reference changes. Two epochs preserve preparation grace; successful completion settles demand only when no later write needs another epoch. Failed sweeps remain pending, old databases receive an initial cycle, and ordinary projection bookkeeping does not request a scan. This avoids incorrectly treating zero checkout removals as proof that no abandoned preparation or obsolete manifest exists.Production growth is +103 LOC against
af10e5594d380c6cae45d45085618334ec0c8b7a, for durable work admission/settlement and hourly ownership. There is no graph cache, new state file, table, index, or schema version. Cleanup custody and identity decisions are unchanged.Evidence
Acceptance was recorded in the draft body before measurement: reuse the prior synthetic manifest fixture; two parent A/A controls plus five alternating parent/candidate samples; compare warm owner timing, CPU, allocation, work counts, and logical pager reads separately. Preserve candidate digests, live content, preparation grace, failure/restart recovery, and immediate cleanup for a new bound archive.
The reused fixture from #198295 is 6,008,033,280 bytes, with 10,000 projections and 234 distinct 62,000-file manifests. It exercises the shared-state reader; it does not copy production agent data or benchmark unrelated transcript storage. Six unchanged requests represent one simulated hour. Parent already includes #198157 and #198295.
At n=5, p95 is the maximum. The two A/A timing controls were 11,709.759 and 11,541.070 ms. Host load was recorded per sample; submillisecond candidate timings are approximate. Pager reads use the same SQLite CACHE_MISS probe as #198295 with a 2 MiB pager cache and mmap disabled. Zero denotes warm metadata-cache hits, not a guarantee of no physical disk IO on cold admission. This is CAS-owner CPU/allocation, not Gateway main-thread CPU, chat latency, or btrfs delete throughput. A changed-content hour still permits its normal hourly scan; after settling, unchanged hours do not traverse the graph.
The candidate's first process, opening a parent-produced database without a demand marker, performed two settling scans; its subsequent pager/allocation processes performed zero warmup scans. Both fixture schema hashes stayed identical. Candidate digests matched every arm.
Rerunnable workload (use a task-owned synthetic fixture copy because demand mode updates sweep metadata):
Use
allocationfor the separate 32 KiB sampled allocation pass,--pager-extension=/path/to/pager-probefor logical bytes, andOPENCLAW_BENCH_BASELINE_DIRfor the exact-parent sparse overlay. Send one stdin line per sample when using--sweep-step.Three regressions fail on the exact parent: unbound/repeated archives request GC; an archive during scratch requests two passes; six unchanged sweeps still read the graph after reopen. 106 focused cases pass across the owner suites and scoped replays, covering archive/restore, post-census follow-ups, live and concurrently reused content, grace, retirement, interrupted sweep, and reopen. The clock-rate assertion needed a second explicit scheduler wake; nullable-epoch test callers and lint issues were corrected and replayed. No skipped or expected-failure baseline was added.
pnpm check:changedran. Core/script types, affected test types, format, and changed lint are green after scoped repairs. The remaining unrelated local failure isRELEASE_VALIDATION_WAIVERS, reproduced with pinned Knip 6.40.0 on the exact parent and introduced by2a1285197991490df98f847f425f2c7fdb41d433/ #173437. This existing main regression remains reported; it is not treated as noise.Independent Codex autoreview of the local diff against that parent: scoped-clean P0–P2, no actionable findings. The final mechanical changes wrap documentation and remove a redundant test sweep, strengthening its immediate recovery assertion. No production deployment or manual cleanup was performed.
Stable-state upgrade and restart proof
At unchanged head
e3ada3d457dc838f7d453385fc64257245233f3f, a separate checkout of stablev2026.11.3(847611dcaa3bf0e2783335f961dd1fd0580e4d9f) wrote the synthetic projection through its actual state transaction and workspace mutation owner. The fixture contains an accepted manifest forkeep.txt, workspace binding/source-path settings, pending target/ref, paused-runtime settings, and a 31-byte synthetic pending-recovery payload. No real user data or credentials were used.Candidate
pnpm openclaw doctor --fix --non-interactivesaved a pre-migration SQLite backup and completed the existing schema-22-to-40 migrations, exit 0. These migrations already exist on the parent; this PR changes no schema. Direct worker admission initially refused without backed-up migration custody, as intended. The first Doctor attempt on the external-volume fixture was refused by secure-temp ancestor admission; the isolated fixture copy was moved to a safe private temporary root, without changing shared filesystem permissions.The candidate's real workspace store then loaded and converted the stable accepted manifest, preserving its exact bytes/reference, source paths, binding, pending ref/target, paused-runtime settings, and recovery bytes. Two actual
sweepLocalWorkspaceManifestscalls settled epoch 2 with pending demand 0. A fresh Node process reloaded the same database, materialized the same manifest, and made six more sweep requests: epoch remained 2, demand remained 0, all stored fields/recovery bytes matched, and decoding the retained CAS tree still returned the expectedkeep.txtdigest. No mocks or patched owner methods were used. This is stored-state compatibility and sweep/restart proof; it does not claim to replay a real external recovery operation from the synthetic sentinel payload.Redacted receipts:
Exact-head CI: run 43462498583, native watcher GREEN (superseded jobs excluded by its existing rules). Hosted Codex review also completed with no findings.