Skip to content

fix(worktrees): keep setup and cleanup failures readable - #131420

Merged
steipete merged 1 commit into
mainfrom
steipete/stoic-lalande-352bfc
Aug 28, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/stoic-lalande-352bfc

Conversation

@steipete

@steipete steipete commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Related: #131363 — readable shared Git diagnostics; follows its named setup/cleanup diagnostic follow-up. The original Git banner context is #131323 (already closed by that repair).

What Problem This Solves

Fixes an issue where users creating a managed worktree would receive an oversized setup error when a repository setup script emitted carriage-return progress or a long line. Setup failures also omitted the recorded exit or termination reason. If creation or restore cleanup failed, successful output from another cleanup command could hide the operation that actually failed.

Why This Change Was Made

The process diagnostic owner now serves both Git and repository setup: normalize each stream before choosing stderr or stdout, collapse redraws, strip ANSI, retain the last 12 logical lines within a surrogate-safe 2,000-character detail cap, bound the command label, and report actual process termination facts. The Git wrapper retains its 120-second timeout policy and Git-specific advice; setup uses its unchanged 120-second timeout for execution and reporting. Cleanup renders the failed operation, preferring removal if both operations fail.

This removes the service's duplicate renderer and moves the formatter landed in #131363 into one shared process module. Service-only truncation would duplicate policy and leave termination reporting inconsistent. Using formatted text as retry evidence would change cleanup authority, so the exact previous raw stderr/stdout, trim, last-12-newline expression stays in the retry owner. Commands, sequencing, conditions, hooks, success classification, retry authority, leases, registry lifecycle, schema, protocol, and configuration are unchanged.

User Impact

Failed setup and cleanup operations now show compact, useful diagnostics with the actual failure reason. No new options or operator migration are required. Repository setup guidance explains the output and timeout troubleshooting. The existing Git troubleshooting added by #131363 is preserved.

Release-note context: managed worktree setup/cleanup errors stay readable and identify the failed process or Git operation. AI-assisted, maintainer-authored work by @steipete; the implementation and its authority boundaries have been reviewed and understood.

Evidence

node --import tsx /tmp/worktree-diagnostics-repro.mts (local scratch reproduction, not a committed artifact) used a real executable setup script, real subprocesses, and a disposable Git repository with isolated state and a local bare remote. Its 122,473-character output produced a 122,495-character error containing 2,000 carriage returns and no exit code. The fixed error is 2,040 characters, contains no carriage returns, and retains the fatal detail and exit code 23. Worktree, branch, registry allocation, setup process, and fixture cleanup were checked.

The original six-file regression command failed with 10 intended failures, 65 passes, and one macOS skip before the production repair, then passed 75 tests with one skip. Existing retry-window tests already passed before the fix. The retained red/green logs are prior proof, not a claim of a newly rerun baseline.

Fresh reconciled-head validation:

node scripts/run-vitest.mjs src/agents/worktrees/service.diagnostics.test.ts src/agents/worktrees/service.test.ts src/agents/worktrees/service.hooks.test.ts src/agents/worktrees/service.provisioned.test.ts src/agents/worktrees/service.run-end-cleanup.test.ts src/agents/worktrees/service.remove-lease.test.ts src/infra/git-exec.test.ts src/agents/worktrees/git.test.ts src/process/command-error.test.ts src/process/exec.test.ts src/process/exec.no-output-timer.test.ts src/snapshot/git-backup.test.ts src/gateway/control-ui-session-prs.test.ts
node scripts/check-changed.mjs -- docs/concepts/managed-worktrees.md src/agents/worktrees/service.diagnostics.test.ts src/agents/worktrees/service.test.ts src/agents/worktrees/service.ts src/infra/git-exec.test.ts src/infra/git-exec.ts src/process/command-error.test.ts src/process/command-error.ts
pnpm docs:list
git diff --check

Fresh precommit and reconciled-branch Codex autoreviews both passed with no actionable P0 findings. The real subprocess reproduction was rerun on aa7f2904036b8e3bd18aebc45459d7dd223f459b with the fixed results above. The full focused command passed all 13 files: 202 passed, 2 existing platform skips, across six routed Vitest shards. It includes the generic formatter through normal tracked routing, all six worktree lifecycle files, the shared Git tests, real process-runner tests, backup caller tests, and the Gateway PR caller. No test rerun or repair was needed; the loaded local host took 19m38s. Exact-head CI run 33135477052 is successful at aa7f2904036b8e3bd18aebc45459d7dd223f459b. node scripts/watch-pr-ci.mjs 131420 aa7f2904036b8e3bd18aebc45459d7dd223f459b exited 0 with GREEN and zero pending checks. One changing-pagination read was retried; no CI job rerun or repair was needed. The actual local changed-file gate passed (exit 0), including production/test types, lint, format, zero-entry dead-code scans, schema/database guards and zero runtime value import cycles. The only warning was manual test fixture creation; teardown closes database handles and removes the fixture, and the real reproduction verifies cleanup.

Proof limits: service + real subprocess + isolated Git proof; no Gateway/UI screenshot or live Gateway flow. The operator expressly excluded Gateway launches and live operator-state changes for this task, so UI proof cannot be performed within the authorized scope. This changes error rendering, not UI layout. Timeout and signal metadata cases are injected at the process-result boundary; the process runner suite exercises real processes. No external API, package, or lazy-loader boundary changed, so no broad local build/full-suite run was added.

Production LOC against reconciled main: +74/-54 (net +20). Tests: +319/-6 (net +313). Docs: +2. The shared owner absorbs the old Git formatter; remaining production growth supplies setup termination reporting, per-stream normalization before selection, and failed-operation selection at both lifecycle cleanup sites. Further reduction would either mix Git policy into setup or conflate diagnostics with retry authority.

Provenance: stable v2026.7.1 contains the original newline-only service renderer. Local history is shallow and does not establish its original introducing commit; the later shared extraction and #131363 are not attributed as its introduction. The already-landed result types, caller fixtures, and Git wrapper regressions are retained without duplication.

Unchanged follow-ups remain out of scope: Gmail setup diagnostics, untracked-test discovery, and existing managed-worktree hook-policy prose. No redundant issue was opened.

Latest ClawSweeper review covers this exact head and reports no correctness or security findings. Both before-merge items request exact-head validation of the consolidated formatter and its justified net +20 production lines; the 202-pass focused command and successful hosted CI above address them. No separate Rank-up moves list was published. Its reported live-verification failure is an output-matching failure: the command exited successfully with 13 tests passed, but the default reporter did not print the suite title expected by the harness. No test or assertion was weakened to address that mismatch. Gateway proof remains outside the explicitly authorized scope.

@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Aug 28, 2026
@steipete
steipete marked this pull request as ready for review August 28, 2026 02:17
@steipete steipete self-assigned this Aug 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 28, 2026
@clawsweeper

clawsweeper Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 10:25 PM ET / August 28, 2026, 02:25 UTC.

ClawSweeper review

What this changes

The PR centralizes process-failure formatting so managed-worktree setup and cleanup errors preserve a bounded final diagnostic and the process termination reason.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. The PR head is not in current main and provides the remaining setup and cleanup diagnostic repair after the merged Git-only formatter fix.

Priority: P2
Reviewed head: aa7f2904036b8e3bd18aebc45459d7dd223f459b

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary repair with direct subprocess evidence, lifecycle-focused regression coverage, and no identified correctness or security defect.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless documents an after-fix disposable Git repository and real executable setup-script run.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless documents an after-fix disposable Git repository and real executable setup-script run.
Evidence reviewed 5 items Current-main ancestry: The PR head is not an ancestor of fetched main, while its pinned base is; current main has not absorbed this change.
Introduced owner-boundary repair: Setup now delegates failure rendering to the shared formatter, and cleanup selects the command that actually failed without changing raw retry evidence.
Shared formatter contract: Each output stream is normalized before selection, the final diagnostic is bounded safely, and recorded timeout, signal, output-limit, or exit facts are retained.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/worktrees/service.diagnostics.test.ts

Result: FAIL (failed) — step 1 expect_output ManagedWorktreeService failure diagnostics: terminal command exited successfully before expected output appeared: "ManagedWorktreeService failure diagnostics"

[failure]
terminal command exited successfully before expected output appeared: "ManagedWorktreeService failure diagnostics"

[command 1 combined output]
[test] starting test/vitest/vitest.agents-support.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-131420-a7QXXf/target

 ✓  agents-support  src/agents/worktrees/service.diagnostics.test.ts (13 tests) 4727ms
     ✓ reports setup 'exit without output' and removes its allocation  473ms
     ✓ reports the failed 'remove' operation during 'restore' cleanup  612ms
     ✓ reports the failed 'branch' operation during 'restore' cleanup  610ms
     ✓ reports the failed 'both' operation during 'restore' cleanup  567ms
     ✓ preserves retry authority for 'long evidence inside the existing win…'  430ms

 Test Files  1 passed (1)
      Tests  13 passed (13)
   Start at  02:26:20
   Duration  7.07s (transform 1.76s, setup 976ms, import 1.01s, tests 4.73s, environment 0ms)

[test] passed 1 Vitest shard in 14.10s

Assertions:

  • FAIL expect_output: ManagedWorktreeService failure diagnostics

How this fits together

Managed worktrees create isolated Git folders for agent sessions, optionally run a repository setup script, then clean up failed allocations. Process and Git command results flow through error rendering to CLI and session-facing failure messages.

flowchart LR
  A[Session worktree request] --> B[Managed worktree service]
  B --> C[Git create and setup script]
  C --> D[Process result]
  D --> E[Shared error formatter]
  E --> F[CLI and session error message]
  B --> G[Failure cleanup]
  G --> E
Loading

Before merge

  • Resolve merge risk (P1) - Production code grows by 20 net lines for a bug fix; the shared formatter and deletion of the Git-local implementation justify it, but exact-head focused validation should confirm the consolidation.
  • Complete next step (P2) - This maintainer-authored, assigned PR has a coherent patch and needs normal exact-head validation rather than an automated repair lane.
Agent review details

Security

None.

PR surface

Source +20, Tests +313, Docs +2. Total +335 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 3 74 54 +20
Tests 4 319 6 +313
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 395 60 +335

Review metrics

Metric Value Why it matters
Production versus test delta production +74/-54 (net +20); tests +319/-6 (net +313); docs +2 The production growth supplies one shared diagnostic owner and explicit cleanup-operation reporting while removing the previous Git-local renderer.

Root-cause cluster

Relationship: canonical
Canonical: #131420
Summary: This is the distinct follow-up that completes readable failure diagnostics for setup and cleanup after the Git-only repair merged.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep one shared process-error formatter for Git and setup failures while retaining the raw retry-evidence calculation as its separate authority boundary.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one shared process-error formatter for Git and setup failures while retaining the raw retry-evidence calculation as its separate authority boundary.

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

No independent current-main execution was performed in this read-only review, but the pre-fix source path and focused disposable-Git/setup-script regression coverage make the defect source-reproducible with high confidence.

Is this the best way to solve the issue?

Yes. Moving rendering into the shared process-error boundary avoids retaining two formatters, while preserving the raw setup-add failure evidence needed for retry decisions.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded repair to managed-worktree recovery diagnostics without evidence of data loss, security-boundary changes, or runtime unavailability.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless documents an after-fix disposable Git repository and real executable setup-script run.

Label justifications:

  • P2: This is a bounded repair to managed-worktree recovery diagnostics without evidence of data loss, security-boundary changes, or runtime unavailability.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is exempt from the external-contributor proof gate; its body nevertheless documents an after-fix disposable Git repository and real executable setup-script run.

Evidence

What I checked:

  • Current-main ancestry: The PR head is not an ancestor of fetched main, while its pinned base is; current main has not absorbed this change. (79a119ef3249)
  • Introduced owner-boundary repair: Setup now delegates failure rendering to the shared formatter, and cleanup selects the command that actually failed without changing raw retry evidence. (src/agents/worktrees/service.ts:275, aa7f2904036b)
  • Shared formatter contract: Each output stream is normalized before selection, the final diagnostic is bounded safely, and recorded timeout, signal, output-limit, or exit facts are retained. (src/process/command-error.ts:6, aa7f2904036b)
  • Caller and test coverage: The service creation path invokes setup before cleanup, while tests exercise real disposable Git worktrees and setup scripts plus injected termination facts and cleanup-operation selection. (src/agents/worktrees/service.diagnostics.test.ts:112, aa7f2904036b)
  • Adjacent merged provenance: The prior merged repair centralized Git diagnostic behavior; this PR extends that same invariant to the separate setup and cleanup paths. (src/infra/git-exec.ts:19, d9069c731e1c)

Likely related people:

  • steipete: Current history attributes this PR and the preceding merged Git-diagnostics repair to this contributor. (role: feature owner and recent area contributor; confidence: high; commits: aa7f2904036b, d9069c731e1c, 37b4fc8621d9; files: src/agents/worktrees/service.ts, src/infra/git-exec.ts, src/process/command-error.ts)

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready at aa7f2904036b8e3bd18aebc45459d7dd223f459b, following the merged shared Git repair #131363.

The service's newline-only renderer let redraws/long lines escape its bound and omitted process termination facts; cleanup could select successful output. One process formatter now owns display, while Git keeps Git-specific timeout advice and retry retains its exact raw evidence expression. No command order, cleanup/retry authority, setup gating, timeout value, persistence, or configuration changes. Production +74/-54 (net +20), tests +319/-6 (net +313), docs +2; deleting the old Git renderer absorbs the shared owner, with the remaining growth covering setup termination reporting, normalized stream selection, and failed-operation selection.

Fresh validation on this head:

node scripts/run-vitest.mjs src/agents/worktrees/service.diagnostics.test.ts src/agents/worktrees/service.test.ts src/agents/worktrees/service.hooks.test.ts src/agents/worktrees/service.provisioned.test.ts src/agents/worktrees/service.run-end-cleanup.test.ts src/agents/worktrees/service.remove-lease.test.ts src/infra/git-exec.test.ts src/agents/worktrees/git.test.ts src/process/command-error.test.ts src/process/exec.test.ts src/process/exec.no-output-timer.test.ts src/snapshot/git-backup.test.ts src/gateway/control-ui-session-prs.test.ts
node scripts/check-changed.mjs -- docs/concepts/managed-worktrees.md src/agents/worktrees/service.diagnostics.test.ts src/agents/worktrees/service.test.ts src/agents/worktrees/service.ts src/infra/git-exec.test.ts src/infra/git-exec.ts src/process/command-error.test.ts src/process/command-error.ts
node --import tsx /tmp/worktree-diagnostics-repro.mts
node scripts/watch-pr-ci.mjs 131420 aa7f2904036b8e3bd18aebc45459d7dd223f459b

The focused suite passed 202 tests in 13 files, with two existing platform skips and no rerun. The real executable setup/isolated Git reproduction retained fatal detail and exit 23 in a 2,040-character error with zero carriage returns; checkout, branch, registry, process, and fixture cleanup all passed. The original pre-fix proof was 10 intended failures; those retained logs are distinguished from these fresh runs in the PR body. The actual local changed-file gate passed (exit 0), including production/test types, lint, format, zero-entry dead-code scans, schema/database guards and zero runtime value import cycles. The only warning was manual test fixture creation; teardown closes database handles and removes the fixture, and the real reproduction verifies cleanup.

CI run 33135477052 and its ci-gate are successful on this exact head; the canonical watcher exited 0/GREEN. One pagination read retried, no CI repair or rerun. Fresh canonical precommit and reconciled-branch Codex autoreviews reported no actionable P0 findings; native artifacts record the owner/caller/sibling/dependency review and best-fix judgment. scripts/pr review-init 131420, artifact initialization, main/PR review checkouts, scripts/pr review-validate-artifacts 131420, and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 131420 all completed successfully. Native prepare verified hosted CI and the exact remote head; no new commit or push was needed.

The latest ClawSweeper review found no correctness/security defect. Both before-merge items ask for exact-head focused validation of the justified +20 production lines; the above proof addresses both. No separate Rank-up moves list was published. Its live-harness FAIL was an expected suite-title output mismatch: the actual command exited successfully with 13 tests passing. No assertion or safety gate was weakened.

Known proof limit: service + real subprocess + isolated Git, not a live Gateway/UI screenshot flow. The operator explicitly excluded launching a Gateway or touching operator state; no such actions were performed. Timeout/signal service metadata cases are injected at the process boundary and supplemented by real process-runner tests. This is error rendering, not a UI-layout change. Live main rules require CI, not an independent approval; no bypass is used. Proceeding only through the native prepare/merge workflow.

@steipete
steipete merged commit b29f975 into main Aug 28, 2026
316 checks passed
@steipete
steipete deleted the steipete/stoic-lalande-352bfc branch August 28, 2026 03:07
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. 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