Skip to content

fix(worktrees): refresh cleanup scans and stabilize integration waits - #482

Merged
nixuuu merged 1 commit into
devfrom
test/flaky-worktree-subscriptions
Nov 10, 2026
Merged

nixuuu merged 1 commit into
devfrom
test/flaky-worktree-subscriptions

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 10, 2026

Copy link
Copy Markdown
Member

Cleanup previews could reuse Git output cached for one second by the process governor, showing a dirty checkout immediately after external changes were removed, or a clean checkout immediately after files were added. ScanWorktrees now uses the existing freshGit boundary while preserving process admission, background priority and removal safety checks. The automation test warms the scan, changes files outside Canopy, and asserts immediate dirty → clean → dirty → clean results before cleanup. The worktree documentation describes this freshness guarantee.

The worktree fixture also waited only for thread.status === idle. threadReady can set that before the automation turn or its command has settled. It now waits for the worktree's actual busy state before deleting or archiving; preview assertions immediately after delete/settings changes remain direct assertions, without retries. A controlled delayed-ack run reproduced the original refusal with clean Git state, a cancelled turn and a pending startTurn. The original CI log reports only wouldRemove, so it cannot distinguish that refusal from stale scan state.

The desktop/phone CI failure in run 42786085102, attempt 1, rejected a valid transient syncing update after both clients' items and turns already matched. The test now waits for completion of the specific reply turn and convergence after recovery, with 100 ms revision probes exercising resubscriptions. Local baseline runs exposed another fixture race: after the parent interruption, its queued question turn could start while holdTurns was still enabled and block the final reply forever. Releasing the hold before ending the parent, then observing the question turn complete, removes that race. A controlled run reproduced the stuck interaction turn and queued final message. No production subscription behavior changes.

Validation:

Separate sequential file runs Before After
worktree-automation.test.ts 28 passed / 2 failed 30 passed / 0 failed
thread-multiclient.test.ts 29 passed / 1 failed 30 passed / 0 failed

Each file ran 30 times before and after, one file at a time. All 30 final phone runs exercised revision resubscription. The local baseline phone failure was the held-question timeout, distinct from CI's invalid no-syncing assertion. An intermediate readiness-only revision failed 8/8 worktree runs and exposed the cached Git result; those failures are excluded from the final counts.

bun install, bun run typecheck, bun run lint, bun run format:check, and git diff --check passed. Verification was scoped to the requested integration files and static checks under the supplied execution limits; the full suite, generation check and web build were not run. Scratch logs and fault-injection diagnostics remain outside the repository and are not committed. No schema, proto, UI copy or UI test changes; copy audit is not applicable.

Fixes: #124
Related: #473, #478

Bypass cached Git output for ScanWorktrees so cleanup previews immediately
reflect external file changes. Preserve process admission and safety checks.

Wait for automation turns and commands to settle before delete or archive.
Allow thread revision recovery and release fixture holds before parent
question turns start; compare completed desktop and phone state.

Fixes: #124
Related: #473, #478
@nixuuu
nixuuu merged commit 8931b82 into dev Nov 10, 2026
9 checks passed
@nixuuu
nixuuu deleted the test/flaky-worktree-subscriptions branch November 10, 2026 09:55
nixuuu added a commit that referenced this pull request Nov 10, 2026
The alias-checkout test can observe `threadReady` / `idle` before the
`createThread` command acknowledgment is persisted. Its final branch
switch can therefore correctly fail with “A thread is using this
directory.” This is a fixture readiness race: holding that
acknowledgment reproduced `idle` with a pending command and the exact
refusal; releasing it allowed the switch. No product lock remained held
after settlement.

Add a shared fixture wait for idle, terminal turns and acknowledged
admission commands, including checkout aliases without a worktree ID.
Also wait for the worktree inventory to stop reporting busy and, for
managed worktrees, provide a scan status. Reuse it in tree setup, branch
switching, lifecycle/automation cleanup and local/linked
external-worktree adoption. Poll only observations; branch-switch and
post-delete/settings cleanup assertions remain direct, with no sleeps or
mutation retries.

Validation:
- `thread-branches.test.ts`, sequential file runs: unchanged baseline
30/30; final version 30/30 (8 tests per run). The natural flake did not
reproduce in the baseline; the acknowledgment-gated diagnostic
reproduced its failure window. An earlier implementation also passed
30/30 before the external-worktree scan condition was corrected.
- All 67 tests in 11 other fixture-consumer files passed, one file at a
time, on the final version.
- `bun run typecheck`, `bun run lint`, `bun run format:check` and `git
diff --check` passed.
- Full-suite `check:tmp`, generation checks and web build were not run
locally in this focused verification scope.

Based on `dev` after #482 merged. CI evidence:
https://github.com/itsoltech/canopy/actions/runs/42792779962/attempts/1

Related: #481
Related: #482
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