Repository navigation
fix(worktrees): keep setup and cleanup failures readable - #131420
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 10:25 PM ET / August 28, 2026, 02:25 UTC. ClawSweeper reviewWhat this changesThe PR centralizes process-failure formatting so managed-worktree setup and cleanup errors preserve a bounded final diagnostic and the process termination reason. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep 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 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — step 1 Assertions:
How this fits togetherManaged 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
Before merge
Agent review detailsSecurityNone. PR surfaceSource +20, Tests +313, Docs +2. Total +335 across 8 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
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 aa7f2904036b8e3bd18aebc45459d7dd223f459bThe 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. 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. |
|
Merged via squash.
|
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:
Fresh precommit and reconciled-branch Codex autoreviews both passed with no actionable P0 findings. The real subprocess reproduction was rerun on
aa7f2904036b8e3bd18aebc45459d7dd223f459bwith 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 ataa7f2904036b8e3bd18aebc45459d7dd223f459b.node scripts/watch-pr-ci.mjs 131420 aa7f2904036b8e3bd18aebc45459d7dd223f459bexited 0 withGREENand 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.