Skip to content

perf: bound repeated watcher, Session History, and terminal work - #12828

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/status-check
Aug 6, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/status-check

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • latch the watcher crash fuse after repeated failures, throttle watcher-failure structural refreshes, and retain visibility-aware structural polling after the fuse opens
  • keep Session History entry/refocus cache-backed while retaining bounded forced scans for newly created agent sessions
  • reduce hidden terminal retention budgets, preserve debounced/rate-limited alternate-screen corruption recovery, and skip fit retries for display:none panes

Performance evidence

Measured production baseline

A five-minute production trace captured during the reported lag contained:

Work Observed cost
aiVault.scan 14 scans, ~65s aggregate wall time, 2,011 candidates/scan
git worktree 108 calls, 8.6s aggregate wall time
git status 22 calls
live terminal panes/managers 44 panes / 36–38 managers
WebGL atlas reset diagnostics 16 resets and 7 reset-rate warnings
exhausted fit retries 3

Fixed-build Electron measurement

I loaded this branch through Electron/CDP, opened Session History, and dispatched 14 refocus/visibility events six seconds apart—the event path that previously forced transcript scans.

Measurement Production observation Fixed build Effect
Session History scans 14 1 -93%
aggregate scan wall time ~65s 3.87s ~94% lower

The fixed scan processed 1,574 candidates and read 6.1MB. No Electron page errors occurred during the run. This removes the dominant measured source of main-process work: repeated refocus events now reuse the shared 60-second scan cache instead of repeatedly reparsing session transcripts.

The same Electron soak opened the watcher fuse under repeated canary starvation. More than three minutes after it opened—past the old sliding-window expiry—activating another workspace still did not fork a watcher child. The deterministic supervisor test also simulates crashes at 0s/40s/80s and a new subscription at 10 minutes; the fork count remains capped at three.

Deterministic work reductions

Path Before After
watcher failure structural refresh every failure at most 1/minute until a successful event
Session History cache TTL 15s 60s
new-agent forced scan budget every eligible event after 5s at most 1/30s
hidden worktree hot retention 8 for 15m 4 for 5m
hidden tab hot retention 12 for 15m 6 for 5m
unparkable hidden worktrees 12 for 45m 4 for 15m
fit of display:none pane up to 40 retry frames 0 retry frames

Existing captured-Vim regression coverage continues to require debounced/rate-limited atlas recovery; routine alternate-screen correctness is preserved.

Regression sources

  • #7757 introduced the isolated watcher process and canary supervisor.
  • #8370 added watcher crash recovery with the short sliding crash-fuse window.
  • #6020 introduced the worktree refresh path later amplified by watcher failure notifications.
  • #7075 forced AI Vault scans on window refocus.
  • #8262 raised terminal keep-warm retention defaults.
  • #10625 added the still-large unparkable hidden-worktree retention budget.
  • #7142 established the required Vim ghosting recovery, which remains preserved.
  • #9503 added the 40-frame unmeasurable-pane fit retry.

Validation

  • focused watcher, Session History, retention, fit, PTY, and atlas suites — 12 files, 769 tests passed
  • terminal reliability gate — 9 files, 2,486 passed, 1 skipped
  • pnpm typecheck:node
  • pnpm typecheck:web
  • changed-path lint, React Doctor, formatting, and max-lines checks
  • full PR CI green on Node 24/26, Git/wire compatibility, and macOS/Windows packaging
  • Electron/CDP validation at final head, including cache-backed refocus replay and alternate-screen redraw

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The changes extend the AI Vault cache to 60 seconds and revise refresh behavior for panel entry, refocus, and new agent sessions. The parcel watcher fuse now latches after three crashes within two minutes. Worktree watcher failures use per-watch refresh cooldowns and structural polling fallback. Terminal retention limits and durations are reduced. Pane fitting now cancels retries for panes hidden with display: none. Regression tests cover these behaviors.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description provides a detailed summary and validation evidence but omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add all required template sections, including the no-visual-change statement, completed testing checklist, AI review findings, security audit, platform checks, and follow-up notes.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the primary changes that bound repeated watcher, Session History, and terminal work.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts (1)

193-212: 🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

Recalculate the delay when the queued timer fires.

Line 208 schedules a forced scan using the current throttle timestamp. A manual refresh({ force: true }) can update lastForcedRescanAt before that timer fires. Lines 210-211 then start another forced scan at the old deadline. This can bypass the 30-second forced-rescan budget.

Clear the timer reference and call requestForcedRescan() again so it calculates the remaining delay. Add a test for a manual forced refresh while a trailing agent-session refresh is pending.

Proposed fix
     forcedRescanTimerRef.current = setTimeout(() => {
       forcedRescanTimerRef.current = null
-      lastForcedRescanAt = Date.now()
-      void refresh({ background: true, force: true })
+      requestForcedRescan()
     }, waitMs)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0ea569af-32ff-4504-83bc-b49a2e066b43

📥 Commits

Reviewing files that changed from the base of the PR and between 79896cb and 0b610bc.

📒 Files selected for processing (20)
  • src/main/ai-vault/cached-session-list.ts
  • src/main/ipc/parcel-watcher-crash-fuse.test.ts
  • src/main/ipc/parcel-watcher-crash-fuse.ts
  • src/main/ipc/parcel-watcher-process.test.ts
  • src/main/ipc/worktree-base-directory-change-collector.ts
  • src/main/ipc/worktree-base-directory-watcher.test.ts
  • src/main/ipc/worktree-base-directory-watcher.ts
  • src/main/ipc/worktree-watcher-failure-refresh-cooldown.ts
  • src/main/runtime/rpc/methods/ai-vault.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-refresh.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-refresh.ts
  • src/renderer/src/components/terminal-pane/pty-connection.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection.ts
  • src/renderer/src/components/terminal-pane/terminal-hidden-view-parking.ts
  • src/renderer/src/components/terminal-pane/terminal-hidden-worktree-retention.ts
  • src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.test.ts
  • src/renderer/src/components/terminal-pane/terminal-webgl-atlas-recovery.ts
  • src/renderer/src/lib/pane-manager/pane-display-visibility.ts
  • src/renderer/src/lib/pane-manager/pane-fit.test.ts
  • src/renderer/src/lib/pane-manager/pane-fit.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final review: land after fixes

A same-model senior review was repeated until the fourth pass returned CLEAN. The review added three narrowly scoped fixes:

  • d5f68c3d: stop an armed fit retry when its pane becomes display:none, and preserve the established alternate-screen atlas recovery so Vim-style redraws cannot regress to stale glyphs.
  • cee64e4d: after the watcher crash fuse opens, hand Git-common structure discovery to the existing visibility-aware poller instead of repeatedly probing an unavailable watcher or missing external worktrees.
  • 443807bc: re-budget a queued new-session scan after a manual refresh so two full transcript scans cannot run about 10 seconds apart under the 30-second budget.

No refactors or speculative cleanup were added.

Expected user impact

  • Typical user: healthy watchers and workspaces below the hidden-terminal caps keep the same behavior. Session History may be up to 60 seconds cache-backed for externally created sessions; Orca-created agent sessions retain a bounded forced-discovery path. Terminal redraw correctness is preserved.
  • Frequent Session History user: this should remove the most noticeable multi-second refocus/entry stalls. The fixed-build replay reduced 14 refocus-triggered scans to 1 (93% fewer) and aggregate scan time from about 65 seconds to 3.87 seconds. The current production sample reinforces the scale: over 5.7 hours it performed 41 scans totaling 95.8 seconds and read about 1.46 GiB. Improvement depends on how often the panel is open/refocused; users who never open it should see essentially no change.
  • Many-terminal/worktree user: lower hot-retention caps should reduce background renderer memory and manager work once more than 4 hidden worktrees / 6 hidden tabs are retained. At the measured 2.5–19 MiB per retained pane, reducing the unparkable-worktree cap by eight is roughly 20–152 MiB when that cap is saturated, before overlapping savings from the other retention bounds. Small workspaces remain below the caps and are unaffected.
  • Hidden-pane fit churn: the sampled production trace logged 75 exhausted 40-frame retry cycles (about 3,000 scheduled retry frames) over 5.7 hours. Explicitly hidden panes now cancel those retries without changing visible-pane sizing or reveal behavior.
  • Watcher crash-loop user: the healthy path is unchanged. After three repeated crashes, process churn stops while structural discovery continues through the visible-window poller; the tradeoff is bounded polling latency only in this degraded state.

These are workload-dependent estimates, not a universal percentage for every user.

Final Electron evidence

Validated the exact PR head 443807bc276005f97c6abda3f57b267e4e63dd51 in an isolated Electron profile. Session History loaded, five visible-window refresh events produced 0 additional scans (2 before / 2 after), a real alternate-screen command rendered and returned cleanly, and the renderer reported no console/page errors.

Session History loaded with cache-backed refocus

Alternate-screen terminal redraw visible and intact

Validation also includes 769 focused tests, the 2,486-test terminal reliability gate (1 skipped), both typechecks, changed-path quality/format/max-lines checks, and green CI across Node 24/26, compatibility, and macOS/Windows packaging.

@brennanb2025
brennanb2025 merged commit 92f759b into main Aug 6, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…blyai#12828)

* perf: bound repeated watcher, vault, and terminal work

* fix(terminal): preserve redraw recovery while bounding fit retries

* fix(watcher): retain structural fallback after crash fuse

* fix(ai-vault): preserve forced scan budget
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