Repository navigation
Conversation
…us churn Spinner-in-title agents (e.g. the Claude Code braille spinner) flip a PTY title several times per second. Each flip called touchMobileSessionSnapshotsForPty, which bumped every PTY-backed snapshot's version and immediately fanned a fresh session.tabs emit out to every subscriber — where the ws layer JSON.stringifies it per client. That is O(clients × snapshot size) of churn work with no debounce, while files.watch batches at 150ms and native-chat debounces at 40ms. Route the title/status churn path through a small per-worktree trailing-edge coalescer (50ms window, 250ms max-wait cap). Clients gate on snapshotVersion freshness, so collapsing intermediate versions is safe — the emit re-reads the latest snapshot, so only the freshest version ships. Structural changes (tab add/remove/activate) still emit immediately and cancel any pending coalesced notify. Pending notifies flush on subscription close and are dropped on worktree removal so no final state is lost or lands stale.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds a per-worktree coalescer for mobile session tab notifications with trailing delays and a maximum wait. Runtime title and status updates are coalesced, while structural changes emit immediately and cancel pending notifications. Pending notifications are flushed during listener teardown and canceled when worktrees are removed. Unit and integration tests cover scheduling, flushing, cancellation, disposal, churn, and subscription behavior. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
Summary
Spinner-in-title agents (e.g. the Claude Code braille spinner) flip a PTY title several times per second. On every flip,
touchMobileSessionSnapshotsForPtybumped each PTY-backed snapshot'ssnapshotVersionand immediately callednotifyMobileSessionTabsChanged, which rebuilds thesession.tabsresult and fans it out to every subscriber — where the ws layer thenJSON.stringifys it per client. That isO(clients × snapshot size)of stringify/emit work on every title tick, with no debounce, even though clients only ever apply the newestsnapshotVersionper worktree. (For contrast:files.watchbatches at 150ms; native-chat debounces at 40ms.)This routes the title/status churn path through a small purpose-named per-worktree trailing-edge coalescer (
mobile-session-tabs-notify-coalescer.ts, modeled onfile-watch-event-batcher.ts). The emit re-reads the latest stored snapshot, so collapsing intermediate versions is safe and correct — clients gate onsnapshotVersionfreshness (shouldApplyWebSessionTabsSnapshot), so a dropped intermediate version is exactly what they'd discard anyway.Chosen delay: 50ms trailing window, 250ms max-wait cap. Title/status is latency-sensitive UI, so this is tighter than
files.watch's 150ms but looser than native-chat's 40ms; the 250ms cap guarantees a title that never stops spinning still emits at least every 250ms rather than starving indefinitely.Correctness constraints honored:
snapshotVersionmonotonicity preserved — the stored map is bumped per touch as before; only the emit is coalesced, and it always reads the freshest stored version.notifyMobileSessionTabsChangedemits immediately and cancels any pending coalesced notify so it can't re-emit a superseded frame.removed:trueframe).Before / after emit counts
Deterministic repro: seed one PTY-backed worktree snapshot, register a
session.tabslistener, flip the title 20× within ~200ms (10ms apart), then let the window elapse.The three integration tests all fail on
main(pre-fix: emit-per-flip) and pass with this change — verified by stashing the runtime wiring and re-running.Screenshots
No visual change.
Testing
pnpm lint(oxlint clean on all changed files; max-lines ratchet OK)pnpm typecheck(exit 0)pnpm test— newmobile-session-tabs-notify-coalescer.test.ts(8/8), new churn cases inmobile-subscribe-integration.test.ts, plussession-tabs*+web-session-tabs-syncsuites (84/84)pnpm buildmain)AI Review Report
Reviewed: (1) coalescing correctness against the client freshness gate — confirmed
shouldApplyWebSessionTabsSnapshotonly accepts a strictly-newersnapshotVersionwithin the samepublicationEpoch, so dropping intermediate versions cannot regress client state; (2) no unbounded first-emit delay (250ms max-wait cap); (3) structural-change promptness (immediate emit + cancel-pending); (4) lifecycle leaks — timers areunref()'d, cancelled on worktree removal, and flushed on subscription close. Cross-platform: pure JS timers (setTimeout/unref), no path/shell/shortcut/Electron surface touched — identical on macOS/Linux/Windows. SSH/remote: this is on the shared-control emit path used by both SSH remote-runtime and remote Orca Server, and reduces per-client stringify fan-out on exactly that connection.Security Audit
No new input handling, command execution, path handling, auth, secrets, dependency, or IPC surface. The change only debounces an existing internal notification; payload contents are unchanged. No follow-up needed.
Notes
The
notifyMobileSessionTabsChanged(undefined)full-fan-out path (used during broad navigation) is intentionally left immediate and does not cancel per-worktree pending notifies; a subsequent coalesced emit would re-publish the same-or-newer version, which the client freshness gate discards — no correctness impact. Adispose()is provided on the coalescer for teardown/tests; the runtime is process-lifetime and its timers areunref()'d, so no explicit runtime-level dispose call is required.Made with Orca 🐋