Skip to content

fix(worktrees): recover failed checkouts and report the cause - #982

Merged
nixuuu merged 3 commits into
devfrom
fix/sanitize-worktree-failures
Nov 18, 2026
Merged

nixuuu merged 3 commits into
devfrom
fix/sanitize-worktree-failures

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

What changed

  • Report Git timeouts, output-limit failures and nonzero checkout exits separately. Keep raw command output out of the new checkout errors and map worker and link failures to fixed messages in spawn_thread.
  • Mark the new branch and the temporary Git worktree lock with the same attempt ID. After a failed checkout, remove only a matching worktree and the unchanged, unused branch created by this attempt. Preserve the original failure and report when cleanup is incomplete.
  • Verify that rollback waits for the process to close and for the attempt to stop its descendants to finish. Keep the 60 s checkout and 90 s gateway budgets. A gateway deadline or disconnect can still leave the outcome unconfirmed, so the agent prompts the caller to check before retrying.

The report involved a Windows 11 checkout of about 58,000 tracked files with CRLF conversion and Git LFS. Both reported nightly.70 and the edited report's nightly.74 already include the 60 s checkout limit. The original error alone cannot distinguish elapsed time from excess output. The fixtures reproduce those failure paths with real Git on Linux. The original Windows checkout and its initiating cause remain unverified. A longer checkout budget would need corresponding worker, gateway and client deadline changes based on that evidence.

Verification

  • Verified PR head dc73d853 on nix-pc (Linux, Bun 1.4.4, Git 2.56.0). Ran check:tmp on the worker worktree tests and five integration files covering worktrees, creation progress, creation failures, automation and the process governor. Also ran the worker's device preview key tests. In all, 51 passed, zero failed, and no temporary test files were left.
  • The tests exercise a checkout filter that times out before completing, a hook that exceeds output capture, a hook that exits nonzero, a successful retry with the same branch name, a ref modified during checkout, preservation of pre-existing worktrees and refs, both gRPC callers, and an older worker that reports the two limits under one code.
  • A generated 58,000-file CRLF checkout completed and unlocked in 2.14 s on Linux. The fixture used small files and had no LFS filters.
  • The prior CI run failed in Tests (6/8) because device preview depended on the shared process error text. The runner now preserves that text and exposes the precise reason to Git. The existing device preview assertions passed locally.
  • Affected worker, gateway and process-governor typechecks, edited-file lint and formatting, and git diff --check passed. Full verification runs in CI.
  • Copy audit (§8). The ambiguous limit message now identifies time or output, checkout failure names Git settings and filters, and an incomplete rollback tells the user what to check. New messages use static sentence-case text without dynamic paths or names. The creation step and retry were tested through the UI's gRPC API. No browser or Windows runtime verification.

Fixes: #74
Fixes: #90
Fixes: #124

@nixuuu
nixuuu enabled auto-merge (squash) November 18, 2026 17:37
@nixuuu
nixuuu disabled auto-merge November 18, 2026 17:38
@nixuuu
nixuuu enabled auto-merge (squash) November 18, 2026 17:40
@nixuuu
nixuuu disabled auto-merge November 18, 2026 17:46
@nixuuu
nixuuu enabled auto-merge (squash) November 18, 2026 17:48
@nixuuu
nixuuu merged commit dd2a32e into dev Nov 18, 2026
16 checks passed
@nixuuu
nixuuu deleted the fix/sanitize-worktree-failures branch November 18, 2026 17:55
nixuuu added a commit that referenced this pull request Nov 19, 2026
## What changed

- Reserve the checkout folder before Git starts. Verify its filesystem
identity, exact registration, attempt-specific lock, branch reflog and
base commit before rollback. On Windows, compare directory identity when
Git and Bun use different 8.3 and long spellings of the path.
- Recover a stopped checkout with an empty `index.lock` and no index or
checkout `.git`. Require confirmation that termination completed before
rollback on a timeout. Check the remaining files against Git blobs
without invoking repository filters.
- Remove only verified files and the attempt's registration. Compare the
branch tip before deleting the unused attempt ref. Preserve unrelated
and stale registrations, changed or untracked files, links, and an index
lock containing data.

## Verification

- Verified final PR head `b0098b9e` on nix-pc (Linux, Git 2.56.0, Bun
1.4.4). `check:tmp` passed 37 tests across checkout failures, process
termination, folder allocation, thread creation progress and worktree
automation. There were no remaining temporary fixtures. Affected package
typechecks, edited-file lint and `git diff --check` passed. The local
test run allowed 20 s per test after an earlier combined automation run
exceeded its 5 s test budget.
- An earlier local scale simulation used real Git and 56,757 tracked
paths with small CRLF files and no LFS. The fixture removed the backlink
and deliberately stalled after 22,067 files appeared. The attempt
directory, registration and ref were removed. Git returned the original
timeout in 8.76 s with a 6 s test checkout limit.
- [Windows 2025
regression](https://github.com/itsoltech/canopy/actions/runs/44524227418/job/135560760665)
passed in a temporary job on `54e04f85` with Git 2.56.1.windows.1 (6
passed, 4 POSIX-only cases skipped). Native Git creates the registration
and the fixture then models the reported stopped state. The test
verified removal, an immediate retry, and protection of unrelated
registrations, files, junctions and a populated index lock. An MSYS
filter in the initial runner attempts outlived the configured checkout
deadline. Linux tests cover the full timeout-to-cleanup sequence. The
reporter's Windows 11 desktop and original repository were not used. The
final head removes the temporary job. The worker code, test code and
pinned dependencies are identical to the Windows-verified revision.
- Copy audit (§8). Existing warning and timeout wording is retained.
Reservation failures use fixed sentences and omit paths, credentials and
raw Git output.

Fixes: #982
nixuuu added a commit that referenced this pull request Nov 21, 2026
Report the applied checkout limit and measured time at the interruption request. Preserve sanitized refusals for other worker errors.

Related: #982
nixuuu added a commit that referenced this pull request Nov 21, 2026
## What changed

- Show the effective checkout limit and the measured time when the Git
timeout triggers. The measurement ends when Canopy requests
interruption, before it waits for process exit or starts cleanup.
- Carry the detail through the existing thread preparation errors and
`spawn_thread`. The gateway accepts only the fixed timeout wording and
numeric durations for `spawn_thread`. Unmeasured timeouts, output
limits, other Git errors and worker RPC deadlines keep their existing
messages.
- The checkout limit policy and cleanup logic stay as before.

Thanks @janek-normalnie for reporting the interrupted Windows checkout
and suggesting both values.

Related: #982

## Verification

- Local on nix-pc after rebasing onto #1071, at
`86fa1f0685dedbc1871251fb1d70ebdc923ba288`: 53 tests passed with
`check:tmp` across process governor, worktree creation failures,
worktree automation, thread creation progress and worktrees. This covers
1.5 s and 3.5 s limits, a deliberately delayed timeout callback, a real
checkout timeout through the worker link to the UI stream, saved failure
and `spawn_thread`, redaction and distinct failure messages, and a
successful checkout past the old 90-second worker deadline.
- Integration test typecheck, lint and formatting of edited TypeScript,
and the Git diff check passed.
- Chromium, before the rebase: started a new worktree in an isolated dev
stack and confirmed both values under **Show details**. Checked short,
typical and long durations at 390 and 800 px in both themes, plus the
actual flow at desktop width. The existing composer intercepted a
pointer click at 1280 × 577. Keyboard activation opened the disclosure.
- Native mobile receives the same failure through
`CreateThreadWithProgress` and renders its detail in **Show details**.
Verified the stream and traced the native code path. Manual Android
verification was unavailable because device automation could not
establish ownership of the emulator.
- GitHub CI owns the full gate.

## Copy audit

“Git exceeded its time limit.” → “Git timed out after 60.012 s while
creating the worktree. The limit was 60 s.” Two short sentences name the
operation and the limit. The existing failure instructions and **Return
to draft** action stay available. The detail uses the existing
disclosure, worktree terminology and spaced time units. All durations
wrap in the checked widths, and no meaning depends on color or icons.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant