Skip to content

fix: reject pending worktree merges before recovery capture - #199098

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-worktree-removal-snapshot-commit-stalls-20260919
Nov 14, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-worktree-removal-snapshot-commit-stalls-20260919

Conversation

@steipete

@steipete steipete commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated recovery capture during idle cleanup when a managed worktree still has a pending workspace integration, and makes slow removal failures diagnosable.

User Impact

Cleanup preserves the pending merge and user files without first capturing a recovery commit it cannot use. Slow failed removals report a bounded error class/message without checkout paths, retaining recognized causes even when they follow a path or appear on a later line. Linux cleanup also yields when a slow filesystem commit would otherwise be hidden by subsequent fast commits.

Why This Change Was Made

The projection owner now admits an archive before ordinary removal captures its Git snapshot, then finalizes the admitted archive with that snapshot under the existing custody operation. Capacity eviction keeps its separate best-effort snapshot behavior. Successful archival removal still requires the per-worktree recovery commit; checkout deletion already uses a retirement directory. Pre-deletion retries replace the same recovery ref, while the existing pending-removal ref pins an interrupted deletion's capture.

The btrfs kernel counter exposes a lifetime maximum, not an interval maximum. The probe therefore uses the existing interval total as a conservative upper bound instead of an average. Several shorter commits totaling one second may also defer optional cleanup for five minutes. The timing event has an explicit maintainer requirement to omit all paths; this is an intentional exception to the general raw-local-log default for that compact event. The original exception and existing cleanup warning remain unchanged. The existing sanitizer receives the complete error and owns both relative-path suppression and cause preservation. There is no product config, schema, cache or retention change.

Evidence

Regressions were red on the parent for capture before pending-merge refusal and for a 9.25-second commit followed by nine 2-ms commits. Focused maintenance/service/recovery tests passed (122 tests), archive/publication consumer tests passed (90 passed, two environment-specific skips), and the final diagnostics/capacity rerun passed (32 tests). These suites overlap; counts are per run. The post-capture fault regression verifies preserved bytes, one recovery ref across retry, and restoration of the latest edit. The review follow-up also proves Permission denied survives a relative-path tail and No space left on device survives a later absolute-path line (red on the initial PR head, green with the fix). All 101 diagnostics/retention/sanitizer tests passed on the final candidate, including a spaced relative-path privacy regression. Error class is recorded separately; ambiguous path-bearing text is conservatively removed after recognized causes are extracted. The existing fixed-prefix guard was simplified to keep the sanitizer within its line cap. Independent Codex autoreview is scoped-clean on the complete final staged candidate (P0–P2).

All selected pnpm check:changed --base e6e62dfd30d0 checks passed except the full-tree unused-export gate, which reports compaction exports added by #196550 (c9ee2646f8c6). The exact main parent e6e62dfd30d0 reproduces the identical eight production/four full-tree findings with node --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mts (exit 1); git show c9ee2646f8c6 identifies their introduction. This is a main check regression, not a passing check or noise. All other selected checks, including core/script lint, types, formatting, import cycles and schema guards, passed. No UI-imported module changed. An additional isolated pnpm openclaw worktrees remove attempt stopped before removal at the runtime-artifact publication guard because offline Gateway state could not be verified. No live service was changed; this is a CLI proof gap, not a removal result. The production scheduler-to-removal synthetic fixture is the owner-path evidence.

Measurement contract and scope

Acceptance was recorded before measurement: two A/A controls followed by five serial interleaved A/B pairs, operation counts first, owner wall/CPU/allocation and physical SQLite/btrfs tails reported separately. Pending-merge owner runs must change two recovery-ref updates to zero while preserving checkout notes and MERGE_HEAD. Use fresh processes and reuse the preserved synthetic fixture for warm retries; keep the initial fresh-fixture result separate. A physical latency improvement is not claimed without reproduced tails.

The owner workload extends scripts/perf/worktree-cleanup-pacing-measure.ts --pending-integration --reuse-pending-integration, with two 62,000-file / 1.143 GB checkouts and 5,000 real session metadata rows. It exercises the Gateway scheduler and removal owner on APFS; scheduler waits are accelerated, so these are owner costs rather than filesystem/chat-latency measurements. Sparse overlays pin the archive contract to parent e6e62dfd30d0 for baseline arms. Separate CPU/allocation profiles cover both arms.

The physical workload is scripts/perf/worktree-btrfs-pressure-measure.py: a task-owned btrfs loop filesystem, a physical 35 GiB SQLite database, 5,000 synthetic sessions, WAL synchronous=FULL, and two 62,000-file trees with 20,667 individually rewritten small-file extents each. Removal spacing is 60 seconds with a 60-second tail; kernel counters are sampled every 50 ms. This exercises the production deletion worker and admission probe, not the full Gateway transport. Setup and flushes are excluded. No production data is used.

Five paired owner runs (median / p95, with p95 the maximum of five):

Metric, two refused removals Parent Candidate
Recovery-ref updates, every run 2 0
Owner wall 32.01 / 65.40 s 11.21 / 14.96 s
Process CPU, workers included 35.56 / 46.64 s 25.25 / 27.65 s
Main-thread CPU 9.79 / 11.77 s 3.22 / 3.68 s
Main-thread allocation 1,506 / 1,537 MB 640 / 658 MB
Event-loop p99 15.74 / 56.56 ms 14.66 / 29.70 ms
Event-loop maximum 70.12 / 440.66 ms 72.22 / 78.77 ms

Warm A/A controls: wall 66.72/27.10 s, process CPU 57.96/33.78 s, allocation 1,507/1,438 MB. Host load was substantial and varied; timing estimates are less stable than the consistent operation-count and allocation reductions. CPU excludes spawned Git children. These sparse-overlay runs isolate archive ordering, not the independent pressure/diagnostic changes. Separate profile runs completed. The physical btrfs series completed with no errors and no missed commit-counter increments:

Physical metric, five arms each Parent Candidate
SQLite commit p99, median across arms 39.42 ms 53.42 ms
SQLite commit maximum, worst arm 343.84 ms 367.60 ms
Fresh observed btrfs commit p99 / maximum 224 / 224 ms 228 / 228 ms
Fresh commits sampled 22 20
Deletion wall, median / maximum 619 / 2,751 ms 555 / 1,280 ms
Child CPU per two deletions, median 1.130 s 1.095 s

A/A physical controls: SQLite p99 22.04/63.79 ms, maximum 190.31/1,036.97 ms; fresh btrfs maxima 17/1,055 ms. The paired arms all admitted both removals, so the pressure change was not exercised by a slow interval in those runs. SQLite p99 worsened in this series, and the physical latency acceptance was not established. This evidence does not demonstrate a production-storage improvement or reproduce a 5–10-second commit. The pressure correction is supported by the deterministic counter regression; the measured work reduction is the pending-integration capture avoidance. Future production qualification remains necessary.

Production LOC grows by 21, primarily for bounded failure diagnostics and the prepared archive closure. The old late admission decision moves rather than being duplicated; recovery ownership remains unchanged.

Admit ordinary archives under projection custody before snapshotting. Preserve capacity eviction's best-effort capture and deterministic recovery refs on retry. Include bounded path-redacted failure causes in slow removal diagnostics, and prevent recent btrfs stalls from averaging away between maintenance samples.
@clawsweeper

clawsweeper Bot commented Nov 14, 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 gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: M labels Nov 14, 2026
@steipete
steipete marked this pull request as ready for review November 14, 2026 18:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T19:39:20.703275Z a5ba88e New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bfb88e65df

ℹ️ 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".

Comment thread src/infra/git-operation-timing.ts Resolved
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR rejects pending workspace integrations before recovery capture, preserves useful removal diagnostics, and detects expensive Linux filesystem commit intervals.

Example: Idle cleanup attempts to remove two managed worktrees with pending MERGE_HEAD state.

  • Before: Cleanup updates two recovery refs before refusing removal.
  • After: Cleanup refuses both removals without updating recovery refs and preserves files and merge state.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is coherent and the prior finding is fixed; confidence rests on production-owner synthetic evidence rather than a completed shipped-entry-point run.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the external-contributor proof gate; supplied production-owner measurements support capture avoidance, while the CLI attempt stopped before removal and the physical btrfs runs did not exercise a slow-interval deferral.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Idle cleanup repeatedly performs expensive recovery capture for worktrees whose pending integration prevents removal, while failure diagnostics can lose useful causes.
Reason: The maintainer-authored direction removes demonstrated wasted work and preserves the existing integration and recovery contracts.

Merge readiness

✅ Ready for maintainer review

This useful maintainer-authored PR remains necessary on current main; the earlier cause-loss finding is resolved, and no blocking patch defect was found.

Priority: P2
Reviewed head: a5ba88eaecf5b2e9327e48fd3818095aa039ff78

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied CLI attempt stopped before removal at artifact-publication safety; successful shipped-CLI or live-Gateway removal was not demonstrated.
Agent review details

How this fits together

Gateway maintenance sends eligible managed worktrees through projection custody, Git recovery capture, and checkout removal; failures preserve recovery state and emit bounded diagnostics.

flowchart TD
  A[Gateway maintenance] --> B[Managed worktree service]
  B --> C[Projection archive admission]
  C --> D[Git recovery capture]
  D --> E[Archive receipt finalization]
  E --> F[Checkout removal]
  B --> G[Removal diagnostics]
Loading

Technical review

Best possible solution:

Keep archive admission in the existing projection owner and finalize its receipt with the required recovery snapshot under the existing custody operation.

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

Current-main source captures the recovery snapshot before the projection owner's pending-integration refusal; committed regressions and reported parent failures directly cover that ordering, but no target code was executed during this review.

Is this the best way to solve the issue?

The change repairs ordering at the existing owner, migrates its callers together, and preserves snapshot and receipt contracts without introducing another state owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Pending-integration archive refusal keeps the original intent (23173ed: Preserve unresolved base-refresh integration and saved workspace files before archival.)
  • Worker-owned archive receipts keeps the original intent (e1c2517: Keep full-tree archive validation in the existing worker while retaining accepted ignored content and directory restore receipts.)
  • Linux pressure admission changes intended behavior with a stated reason (aedae9d: Pace optional cleanup and pause during recent filesystem distress without retaining historical maxima indefinitely.)
  • Compact removal diagnostic privacy changes intended behavior with a stated reason (fix: reject pending worktree merges before recovery capture #199098 (comment): The maintainer explicitly requires this timing event to omit paths while leaving the original exception and existing warning unchanged.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ee122ba adds src/gateway/worker-environments/local-workspace-state.ts:422 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ee122ba9471c; files: src/gateway/worker-environments/local-workspace-state.ts)
  • Shakker: Raw commit 23173ed adds src/gateway/worker-environments/local-workspace-state.ts:471 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 23173ed1f61b; files: src/gateway/worker-environments/local-workspace-state.ts)

PR surface

Source +21, Tests +74, Docs +10, Other +236. Total +341 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 72 51 +21
Tests 4 79 5 +74
Docs 1 11 1 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 3 249 13 +236
Total 16 411 70 +341

Preflight source

Source 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

Metric Value Why it matters
Production versus regression coverage Runtime +72/-51 lines; tests and test support +79/-5 lines The net runtime growth supports failure diagnostics and archive ordering; regression coverage checks distinct preservation, recovery, and pressure failures.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Avoids unnecessary background recovery capture and improves cleanup diagnostics without evidence of an urgent user-facing outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-14T19:02:23.025Z sha bfb88e6 :: needs changes before merge. :: [P2] Preserve failure details until the log export boundary

Reviewed November 14, 2026, 2:45 PM ET / 19:45 UTC (Revision 2).

Pass complete errors to the existing diagnostic sanitizer before removing path-bearing text. Keep the bounded error class separately and cover spaced relative paths, later-line causes, and recovery-ref reuse.
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: a5ba88eaecf5b2e9327e48fd3818095aa039ff78
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/logging/diagnostic-support-redaction.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the single open item from the latest review against a5ba88e:

  1. Preserve failure details until log export boundary (P2). The cause-loss example was real and is fixed. The complete original error now reaches the existing sanitizer at git-operation-timing.ts:143. Its existing closed-cause extraction preserves causes from path tails and later lines. The bounded error class is a separate field. A production-service regression injects a post-capture error with a spaced relative path, Permission denied, and a later absolute-path No space left on device; it asserts both causes, no private path, one recovery ref across retry, and restoration of the latest edit. The explicit maintainer task requires this compact timing event to contain no paths beyond the worktree ID, so raw path logging here would violate that requirement. The original exception and existing cleanup warning remain unchanged. This is a scoped exception to the general raw-local-log rule, now stated in the PR body.

All 101 focused diagnostics/retention/sanitizer tests pass; the cause-loss and spaced-path regressions were observed red before their fixes. Fresh independent Codex autoreview of the complete final staged candidate is scoped-clean at P0–P2. The PR body retains the physical measurement limitation and the separately attributed main dead-export regression. The additional supported CLI attempt was blocked before removal by runtime-artifact publication safety; no live service was changed. The real scheduler-to-removal synthetic fixture remains the owner-path proof.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Nov 14, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 14, 2026
@steipete
steipete merged commit f8456a9 into main Nov 14, 2026
171 checks passed
@steipete
steipete deleted the steipete/perf-micro-worktree-removal-snapshot-commit-stalls-20260919 branch November 14, 2026 20:00
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 15, 2026
…#199098)

* fix: reject pending worktree merges before recovery capture

Admit ordinary archives under projection custody before snapshotting. Preserve capacity eviction's best-effort capture and deterministic recovery refs on retry. Include bounded path-redacted failure causes in slow removal diagnostics, and prevent recent btrfs stalls from averaging away between maintenance samples.

* fix(worktrees): preserve causes in path-free removal diagnostics

Pass complete errors to the existing diagnostic sanitizer before removing path-bearing text. Keep the bounded error class separately and cover spaced relative paths, later-line causes, and recovery-ref reuse.
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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts security-sensitive-changed size: M 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.

1 participant