You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(client-runtime): a branch switch shared by many archived threads reloads the archive once - #38336
Cause: WorktreeBranchSync dispatches one thread.metadata.update per thread sharing the worktree, archived ones included. Each update of an archived thread reaches active-shell subscribers as a removal, which replaces EnvironmentShellState.removedAt, and the archivedShellSnapshot query's refreshTrigger refreshed (and interrupted the in-flight request) on every such change. Fix: the archivedShellSnapshot refresh trigger in packages/client-runtime/src/state/orchestration.ts now waits until removedAt has been quiet for 500 ms (an Effect.sleep in a runtime atom that restarts on each change), so a burst of archived-thread changes reloads the archive once, after the last change. The trigger keeps the current value until then, so mounting causes no extra reload. User actions (unarchive, delete) still refresh explicitly through refreshArchivedThreadsForEnvironment, so they are not delayed. The change is in shared client-runtime code, so it covers web, desktop and mobile (ThreadRelationshipsPanel, Settings > Archived threads, mobile useArchivedThreadSnapshots). Measured on Linux with triage's seed driver on a fresh T3CODE_DEV_SEED=0 dev database (one active coordinator plus 300 archived threads sharing one worktree, 2,700 other archived threads), Settings > Archived threads open, then git switch -c in the shared worktree, reading the server trace for 90 s. BEFORE (main b387e3a): 1 reconcile, 301 dispatch.threadMutation, 36 ws.rpc.orchestration.getArchivedShellSnapshot requests in 27.2 s (30 Interrupted, 6 Success, median 145 ms), 132 ProjectionStore.readShellSnapshotRows (112 completed despite cancellation). AFTER: 1 reconcile, 301 dispatch.threadMutation, 1 getArchivedShellSnapshot request (Success, 162 ms), issued about 0.54 s after the last mutation, 51 readShellSnapshotRows in total. Triage counted about 130 requests with the thread details panel open; my run used the Settings page, which mounts the same atom. No new regex or parser.
Commit 13ecf5b (origin/main). Ran T3CODE_DEV_SEED=0 vp run dev on a fresh database. A scratch driver (uploaded: https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/7e5113fbb78ffe54/seed-38321.ts) used the server's HTTP API and WebSocket RPC to create a project on a new git repo, one active 'coordinator' thread plus 300 archived threads all with worktreePath = one git worktree on branch feature-a, and 2,700 archived threads without a worktree (3,000 archived total). In the web client (preview browser) I paired, opened the coordinator thread with the thread details panel (Lineage section) visible, and confirmed one getArchivedShellSnapshot load (420 ms server-side). Then I ran git switch -c another-branch in the shared worktree and read the server trace (all rotated server.trace.ndjson files) for the following ~90 s. Observed: one WorktreeBranchSync.reconcile run dispatched 301 separate thread mutations (302 orchestrationV2.dispatch spans, 301 dispatch.threadMutation); the web client sent 130 ws.rpc.orchestration.getArchivedShellSnapshot requests within 21.0 s, of which 129 ended Interrupted and 1 Success; per-request server duration median 138 ms, min 49 ms, max 575 ms at 3,000 archived threads. 101 ProjectionStore.readShellSnapshotRows reads still completed with Success during the burst while nearly every RPC was interrupted, so most cancelled reloads still cost a full read. Baseline before the switch: 1 archived snapshot request in total. At the reporter's scale (~8,000 archived, 48 GB DB, 17-25 s per read) the same one-read-per-updated-thread pattern accounts for the sustained CPU they measured.
Evidence
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests
vp test run src/state/runtime.test.ts in packages/client-runtime: 42/42 pass. The extended case 're-reads an open archive when a thread leaves the shell' fails on main (expected true to be false) and passes with the fix. vp run check:changed: format, lint, knip, typecheck (7 packages) and test all pass.
Not in this change
WorktreeBranchSync.reconcile still dispatches one thread.metadata.update per sharing thread, archived included. A batched command would make the server side cheaper but adds a new command type.
Archived-thread removals spaced more than 500 ms apart each still reload the archive. Making refreshOnSignalWhileRead defer instead of interrupting an in-flight read would bound that, but it is a generic runtime change.
…reloads the archive once
A branch switch in a worktree that many archived threads share updates each
thread with its own command, and every update reached clients as a removal
that re-requested, and interrupted, the whole archived thread list.
The archived snapshot now reloads once removals have been quiet for 500 ms,
so a burst of archived-thread changes costs one read instead of one per thread.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Macroscope's review found this PR approvable — Archive refreshes now wait for 500 ms of quiet after removal events, avoiding repeated full-archive reads during bulk updates. The change is limited to client-side refresh timing and does not alter stored archive data.
You can add or adjust custom eligibility rules. Learn more.
No actionable comments were generated in the recent review.
Walkthrough
Archived shell snapshot refreshes now wait for a 500 ms quiet period after removal updates. Runtime tests provide a controllable clock and verify that updates within the period result in one reload.
The refresh trigger waits 500 ms after the latest removal update before exposing it. The test runtime uses the active clock, and tests verify the debounce and subsequent reload behavior.
Archived-thread list refreshes are now debounced, so a burst of thread updates produces one reload instead of many. No merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the fix (archived-thread reload after a branch switch in a shared worktree) and matches the main change, which debounces the archived-shell snapshot refresh so a burst of removals relo…
Description check
The description covers the problem (WorktreeBranchSync dispatching one update per sharing thread, each triggering an archive reload), the change (500 ms quiet period in the refresh trigger), scope (li…
Linked Issues check
Issue #38321 requires that a branch switch in a shared worktree stop reloading the whole archived list once per updated thread. Its diagnosis names the chain: archived-thread removals replace removedA…
Out of Scope Changes check
The whole-PR diff (merge base b387e3a to head 6a3abe5) changes packages/client-runtime/src/state/orchestration.ts. The change adds the AsyncResult import, the ARCHIVE_REFRESH_QUIET_MS constant, and …
Full details: Title check
Explanation
The title names the fix (archived-thread reload after a branch switch in a shared worktree) and matches the main change, which debounces the archived-shell snapshot refresh so a burst of removals reloads once. It is specific, conventional-commit formatted, and at 93 characters it is slightly long but still readable.
Full details: Description check
Explanation
The description covers the problem (WorktreeBranchSync dispatching one update per sharing thread, each triggering an archive reload), the change (500 ms quiet period in the refresh trigger), scope (linked issue #38321, explicit user actions unaffected), verification (before/after trace measurements and test results), and out-of-scope items. The 'Evidence' section is a placeholder stating it will be filled in before merge, so the template's before/after requirement for UI-visible behavior is not yet met. Minor template deviation: the 'Scope' section links an issue, which satisfies the requirement.
Resolution
Complete the 'Evidence' section with the before/after proof described as pending, or confirm that the existing trace measurements satisfy the template's verification requirement before merge.
Full details: Linked Issues check
Explanation
Issue #38321 requires that a branch switch in a shared worktree stop reloading the whole archived list once per updated thread. Its diagnosis names the chain: archived-thread removals replace removedAt, removedAt is the refreshTrigger of archivedShellSnapshot, and each change reloads and interrupts the in-flight request. The issue lists 'reload the archived list at most once per interval while removals keep arriving' as one possible fix and states that it does not require a particular implementation.
The reviewed head breaks this chain in packages/client-runtime/src/state/orchestration.ts. The refresh trigger now derives from an Atom that sleeps for ARCHIVE_REFRESH_QUIET_MS (500 ms) after each removedAt change. Each new change restarts the sleep. A burst of removals therefore produces one trigger value after the last change. While the sleep runs, the trigger returns the previous settled value through AsyncResult.getOrElse, and the initial read returns the current value through get.once. Mounting therefore does not cause an extra reload.
The issue's server-side point (#32805, reads continue after cancellation) is not a stated requirement of this issue's fix list. It is excluded from this change, as the PR description states.
The automated test requirement is supported by the PR's reported test changes in packages/client-runtime/src/state/runtime.test.ts (debounce case for removals 400 ms apart). I did not read that test file directly, so the test result rests on the reported run. The empty Evidence section in the PR description does not affect coding compliance.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff (merge base b387e3a to head 6a3abe5) changes packages/client-runtime/src/state/orchestration.ts. The change adds the AsyncResult import, the ARCHIVE_REFRESH_QUIET_MS constant, and the debounced refresh trigger for archivedShellSnapshot. These changes implement issue #38321.
The reported test change in runtime.test.ts adds the Clock service to the test runtimes and a debounce test. This supports the implemented behavior. The PR description and objectives state that the change does not batch WorktreeBranchSync.reconcile, does not change server-side read cancellation, and does not alter the explicit refreshArchivedThreadsForEnvironment path. The diff shows no unrelated changes in the inspected scope.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size:S10-29 changed lines (additions + deletions).vouch:trustedAuthor is trusted by repo permissions or the VOUCHED list.
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cause: WorktreeBranchSync dispatches one thread.metadata.update per thread sharing the worktree, archived ones included. Each update of an archived thread reaches active-shell subscribers as a removal, which replaces EnvironmentShellState.removedAt, and the archivedShellSnapshot query's refreshTrigger refreshed (and interrupted the in-flight request) on every such change. Fix: the archivedShellSnapshot refresh trigger in packages/client-runtime/src/state/orchestration.ts now waits until removedAt has been quiet for 500 ms (an Effect.sleep in a runtime atom that restarts on each change), so a burst of archived-thread changes reloads the archive once, after the last change. The trigger keeps the current value until then, so mounting causes no extra reload. User actions (unarchive, delete) still refresh explicitly through refreshArchivedThreadsForEnvironment, so they are not delayed. The change is in shared client-runtime code, so it covers web, desktop and mobile (ThreadRelationshipsPanel, Settings > Archived threads, mobile useArchivedThreadSnapshots). Measured on Linux with triage's seed driver on a fresh T3CODE_DEV_SEED=0 dev database (one active coordinator plus 300 archived threads sharing one worktree, 2,700 other archived threads), Settings > Archived threads open, then
git switch -cin the shared worktree, reading the server trace for 90 s. BEFORE (main b387e3a): 1 reconcile, 301 dispatch.threadMutation, 36 ws.rpc.orchestration.getArchivedShellSnapshot requests in 27.2 s (30 Interrupted, 6 Success, median 145 ms), 132 ProjectionStore.readShellSnapshotRows (112 completed despite cancellation). AFTER: 1 reconcile, 301 dispatch.threadMutation, 1 getArchivedShellSnapshot request (Success, 162 ms), issued about 0.54 s after the last mutation, 51 readShellSnapshotRows in total. Triage counted about 130 requests with the thread details panel open; my run used the Settings page, which mounts the same atom. No new regex or parser.Fixes #38321
Reproduction on main
Commit 13ecf5b (origin/main). Ran
T3CODE_DEV_SEED=0 vp run devon a fresh database. A scratch driver (uploaded: https://gh-file-drop-api-prod-mi5fy3sowv63ufte.pinglabs.workers.dev/f/7e5113fbb78ffe54/seed-38321.ts) used the server's HTTP API and WebSocket RPC to create a project on a new git repo, one active 'coordinator' thread plus 300 archived threads all with worktreePath = one git worktree on branch feature-a, and 2,700 archived threads without a worktree (3,000 archived total). In the web client (preview browser) I paired, opened the coordinator thread with the thread details panel (Lineage section) visible, and confirmed one getArchivedShellSnapshot load (420 ms server-side). Then I rangit switch -c another-branchin the shared worktree and read the server trace (all rotated server.trace.ndjson files) for the following ~90 s. Observed: one WorktreeBranchSync.reconcile run dispatched 301 separate thread mutations (302 orchestrationV2.dispatch spans, 301 dispatch.threadMutation); the web client sent 130 ws.rpc.orchestration.getArchivedShellSnapshot requests within 21.0 s, of which 129 ended Interrupted and 1 Success; per-request server duration median 138 ms, min 49 ms, max 575 ms at 3,000 archived threads. 101 ProjectionStore.readShellSnapshotRows reads still completed with Success during the burst while nearly every RPC was interrupted, so most cancelled reloads still cost a full read. Baseline before the switch: 1 archived snapshot request in total. At the reporter's scale (~8,000 archived, 48 GB DB, 17-25 s per read) the same one-read-per-updated-thread pattern accounts for the sustained CPU they measured.Evidence
Being captured: before and after in the real app. This section is filled in before the pull request can merge.
Tests
vp test run src/state/runtime.test.ts in packages/client-runtime: 42/42 pass. The extended case 're-reads an open archive when a thread leaves the shell' fails on main (expected true to be false) and passes with the fix. vp run check:changed: format, lint, knip, typecheck (7 packages) and test all pass.
Not in this change
Who did the work
Run by the t3code factory in T3 Code.