Skip to content

fix(worktrees): remove verified partial checkouts after timeout - #1026

Merged
nixuuu merged 8 commits into
devfrom
fix/worktree-timeout-cleanup
Nov 19, 2026
Merged

nixuuu merged 8 commits into
devfrom
fix/worktree-timeout-cleanup

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

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 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
nixuuu marked this pull request as ready for review November 19, 2026 12:32
@nixuuu
nixuuu enabled auto-merge (squash) November 19, 2026 12:32
@nixuuu
nixuuu disabled auto-merge November 19, 2026 12:33
@nixuuu
nixuuu marked this pull request as draft November 19, 2026 12:33
@nixuuu
nixuuu marked this pull request as ready for review November 19, 2026 12:34
@nixuuu
nixuuu enabled auto-merge (squash) November 19, 2026 12:34
@nixuuu
nixuuu merged commit 4733252 into dev Nov 19, 2026
18 checks passed
@nixuuu
nixuuu deleted the fix/worktree-timeout-cleanup branch November 19, 2026 12:41
nixuuu added a commit that referenced this pull request Nov 21, 2026
## Changes

- Allow 240 seconds for `git worktree add` after Git starts. The report
showed 22,067 of 56,756 files written when the 60-second limit expired
on Windows. At that rate, checkout would take roughly 154 seconds. Four
minutes leaves room for variations in file sizes and write speed.
- Give the worker up to 35 seconds to start checkout, including
repository and process queues and the optional fetch. Reserve 40 seconds
for termination, verification, rollback and delivery within the
315-second gateway wait. Use the same worker path for creation,
continuation and `spawn_thread`. Mixed-version gateway and worker pairs
retain the 60-second checkout and 90-second gateway wait.
- Align web/desktop, native mobile, draft delivery and linked gateway
deadlines for creation that may need checkout. The Claude agent bus has
a 330-second deadline.

## Verification

- Verified PR head `fa8819fa` on nix-pc (Linux, Git 2.56.0, Bun 1.4.5).
The 92-second checkout completed via gRPC and started a usable thread.
The same test verified that an expired queued request returned promptly
and created no branch. The worktree and `spawn_thread` integration
suites also covered normal checkout and cleanup after a real process
timeout.
- Ran the production checkout path with a blocked Git hook. The old and
new timers stopped Git after 60.71 and 240.21 seconds. Both runs removed
the checkout, Git registration and branch. Targeted `check:tmp` covered
58 cases with no temp leaks. An existing continuation test reached its
5-second test harness limit under load and passed in the isolated
continuation run with a 20-second harness limit. Gateway, worker, web
and mobile typechecks, edited-file lint, and diff checks passed.
- The native mobile integration tests passed on nix-pc. They exercised
the app’s creation stream, unary fallback, and draft recovery over
Connect through a real gateway and worker. The device tool could not
establish ownership of the Android runtime, so no in-app device test was
possible.
- The Windows CI job runs a slow Git checkout, verifies it unlocks, and
tests cleanup using real Git for Windows worktree metadata and a staged
incomplete checkout. A live timeout of a Windows process tree and a
reproduction on the reported Windows 11 repository are unverified.
- Copy audit (§8). The preparation deadline adds a short reason and
retry action. The checkout timeout keeps its existing wording. Both
messages contain no paths or variable labels.

Thanks to @janek-normalnie for reproducing the timeout and sharing the
file counts and Git version.

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

- Settings → Worktrees offers **Clean up…** for locked checkouts from a
verified failed Canopy setup. The confirmation identifies the folder and
explains that cleanup removes the worktree directory and its Git
registration while keeping the local branch.
- The worker records proof after the checkout process tree has stopped
and automatic rollback has left an incomplete checkout. It verifies the
original directory identities, registration, branch and contents again
before deleting. A matching Git backlink is accepted, and the reported
state without a backlink or index and with an empty `index.lock` is
covered. Older entries without proof show why cleanup is unavailable.
- Cleanup checks for saved worktrees, workspace paths and active
threads, and rejects stale confirmations or worker connections. The
worker verifies both directories again after moving them aside and
reports where any retained files can be found. The checkout timeout
behavior and copy on `dev` are preserved.

Thanks @janek-normalnie for reporting the incomplete checkout and
suggesting a manual cleanup action.

## Verification

- On nix-pc (Linux, Git 2.56.0, Bun 1.4.5), 88 focused tests passed on
`ed80fec8` through `check:tmp`, with no leftover temporary fixtures.
They cover successful and failed checkout creation, the existing
rollback, refusal for foreign or changed data, branch and metadata
races, concurrent confirmations, owner and workspace scope, link
replacement and expiry, and ordinary worktree lifecycle. A real Git
checkout also timed out with its backlink present and was cleaned after
a transient error prevented automatic rollback. A separate Linux fixture
cleaned 22,000 remaining CRLF files from a 55,000-path repo with the Git
backlink and index absent.
- Worker, gateway and integration-test typechecks passed on the final
revision. Web and mobile typechecks passed on the unchanged UI
implementation. Editing-scope lint, format and diff checks passed.
Protobuf outputs were regenerated after updating the branch from `dev`.
- Chromium exercised eligible and ineligible rows, cancel, stale
confirmation, server refusal and successful refresh at 1440 and 390 px
in light and dark themes. On the native Android 16 development client,
verified Settings → Worktrees, the cleanup confirmation, a specific
server refusal and refresh after a successful cleanup response. Both UI
checks used isolated response fixtures. The gateway–worker tests used a
real repository.
- CI runs the checkout and cleanup regression with native Git on the
Windows Server runner. Jan’s Windows 11 device and original repository
were unavailable.
- Copy audit (§8). The eligible row now reads “Canopy setup failed ·
Locked worktree”. “Clean up…” and “Clean up worktree” use the same verb.
The confirmation describes the consequences, and a refusal shows its
reason beside the refresh action. Checked short, typical and long names
at desktop and phone widths.

Related: #1026
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