Repository navigation
perf(notifications): stop every Windows notification from freezing Orca - #27731
Conversation
Every agent notification recorded its id in mobile-notification-dismissals.json through the secure-file writer. On Windows that writer runs about five synchronous icacls launches per write, so each notification froze every Orca window (STA-9692). The file holds notification ids, sequence numbers and session ids, not credentials, so it now goes through the existing AtomicSnapshotWriter: async temp-plus-rename, mode 0600, bursts coalesced into one write of the latest entries. Memory stays authoritative, so delivery and retirement are unchanged. The pending write is flushed in the quit barrier after chat and RPC teardown, and in the pre-relaunch hook, since renderer relaunch exits without the quit pipeline.
…ts down orcad never runs the desktop quit barrier, so its cleanup list awaits the pending dismissal write after RPC stops.
… ends AtomicSnapshotWriter cleared its pending-write promise one microtask after the drain loop saw no more requests. A write() in that gap set writeRequested, got the settling promise back, and nothing drained it, so the newest bytes stayed unwritten and waitForPendingWrite() (the dismissal store's flush) resolved without them. The drain now clears the pending promise in the same tick its loop exits, on success and failure, so a later write() always starts a new drain.
…e dirs Dismissal history now saves asynchronously, and the writer recreates its directory before each write. Tests that deleted their temp dir with a write still pending left recreated dirs behind in the system temp folder and could race the delete on Windows. They now await the controller's flush first.
The shutdown flush only waited for writes already queued. A notification recorded after it (orcad cleanups still running, or the 150 ms before a renderer relaunch calls app.exit) started an async write the exit dropped, so the phone could keep an alert the desktop could no longer withdraw. The store's flush() becomes close(): it waits for the pending write, and every later record saves synchronously through the snapshot writer's existing writeSync (plain fs, no icacls; a failure only warns). It is called only where the exit can no longer be vetoed: the will-quit teardown, a new exit-only hook that app:relaunch runs before app.exit(0) (restart and profile switches share onBeforeRelaunch but quit through will-quit), and orcad's cleanup after RPC stops. The quit test now holds chat teardown and RPC stop and proves the close starts only after both settle, in either order. The orcad push-startup runtime mock gains the method the entry now calls.
app:relaunch waited on the dismissal store's close with no limit, so a stalled userData disk left Restart stuck on "Restarting…" with a half-quit app saving synchronously. The close now races a 2 s cap through the existing settleWithinMs helper, the same cap the restart path's auth preservation uses, and logs when it gives up.
…eads Mid-test disk reads used closeDismissals() as a barrier, which switched every later record to the exit-only synchronous path. The store gains a non-closing flush() (close() = mark closed + flush), exposed on the controller as flushDismissals for tests; mid-test barriers use it, and close stays only where a test simulates an exit or teardown. Also notes why the writer's pendingWrite assignment is safe, renames a store test to what it covers, and groups the orcad cleanup-order test under a describe.
|
Every agent notification could freeze all Orca windows on Windows because saving phone dismissal history synchronously launched the file-permission tool about five times. This PR moves that ordinary bookkeeping file to Orca’s existing background snapshot writer, so notifications and dismissals update memory immediately and bursts save the latest history together. Normal quit, the Restart button, and headless shutdown preserve pending history; the file format and phone protocol are unchanged. The earlier three-round review fixed a dropped-write race in the shared writer, cleanup tests that deleted folders before background saves finished, shutdown ordering and late records, and an unbounded Restart wait. A fresh independent correctness review and issue-first architecture challenge found no new issue and recommended keeping the design; no code changes were needed in this independent loop. The final reviewed commit remains Review status: Ready, with the deferred limitations below. Verified:
Deferred: a graphics-crash restart can lose the last background snapshot and re-show a phone alert; a late shutdown record still performs a synchronous plain file write, so a stalled disk can block exit timers, as synchronous writes did on main. One pending promise handler per event while storage is stalled, duplicate save-failure warnings, one extra retained serialized snapshot (entry count capped at 4096; bytes depend on identifiers), and minor test-maintenance issues remain nonblocking. The pre-existing shared writer’s equality cache can become stale after mixed async/sync writes; it reproduces on main too, and dismissal history does not enable that equality shortcut. The ordinary asynchronous persistence and atomic replacement follow the common pattern. The memory-first delivery policy, burst coalescing, and committed-exit synchronous fallback are intended choices for this notification history; the fallback’s stalled-disk limitation is explicit above. The original PR body is preserved with corrected QA evidence appended. All helper tasks are settled, the dedicated remote QA worktree is removed, and the shared QA slot is free. The reviewed commit is unchanged; PR stays open, ready, and unmerged. |
📝 Walkthrough
Priority: ⬆️ High Severity of issue fixed: Medium Merge Risk: 🔵 Low · up to The cleanup-order test may need maintenance after a harmless source edit, but no production failure is established. The change is mergeable with that bounded concern understood. Pre-merge checks |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/orcad/orcad-entry.test.ts (1)
174-184: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSource-text assertion is brittle.
The test checks string positions in
orcad-entry.ts. A formatter change or an arrow-function rewrite breaks it without a behavior change. The test also passes if either string moves into a comment. The comment on line 175 acknowledges this. Prefer a behavioral test if the cleanup runner can be exercised in isolation.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
abc140ee-6998-4ab0-b520-76e6d8fc3582
📒 Files selected for processing (26)
mobile/src/notifications/push-original-delivery-retirement.test.tssrc/main/ipc/app.test.tssrc/main/ipc/app.tssrc/main/ipc/notifications-subject-retirement.test.tssrc/main/ipc/register-core-handlers/register-core-handlers.test.tssrc/main/ipc/register-core-handlers/register-core-handlers.tssrc/main/orcad/orcad-entry.test.tssrc/main/orcad/orcad-entry.tssrc/main/orcad/orcad-push-startup.test.tssrc/main/persistence/atomic-snapshot-writer.test.tssrc/main/persistence/atomic-snapshot-writer.tssrc/main/runtime/mobile-notification-dismissal-read-failure.test.tssrc/main/runtime/mobile-notification-dismissal-store.test.tssrc/main/runtime/mobile-notification-dismissal-store.tssrc/main/runtime/rpc/methods/structured-agent-session-attention-ack.test.tssrc/main/runtime/runtime-mobile-notification-controller.tssrc/main/runtime/runtime-service-command-surface.tssrc/main/runtime/structured-agent-session-mobile-restore.test.tssrc/main/runtime/structured-agent-session-mobile-retirement.test.tssrc/main/runtime/structured-attention-original-delivery.test-fixture.tssrc/main/startup/main-process-quit-pending-writer.test.tssrc/main/startup/main-process-quit.tstests/e2e/structured-attention-host-read-retirement.unit.test.tstests/e2e/structured-attention-prompt-relay.unit.test.tstests/e2e/structured-attention-read-retirement.test-fixture.tsxtests/e2e/structured-attention-read-retirement.unit.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
…ca (#27731) * perf(notifications): save mobile dismissal history off the main thread Every agent notification recorded its id in mobile-notification-dismissals.json through the secure-file writer. On Windows that writer runs about five synchronous icacls launches per write, so each notification froze every Orca window (STA-9692). The file holds notification ids, sequence numbers and session ids, not credentials, so it now goes through the existing AtomicSnapshotWriter: async temp-plus-rename, mode 0600, bursts coalesced into one write of the latest entries. Memory stays authoritative, so delivery and retirement are unchanged. The pending write is flushed in the quit barrier after chat and RPC teardown, and in the pre-relaunch hook, since renderer relaunch exits without the quit pipeline. * perf(notifications): flush dismissal history when a headless host shuts down orcad never runs the desktop quit barrier, so its cleanup list awaits the pending dismissal write after RPC stops. * fix(persistence): drain a snapshot write requested just after a drain ends AtomicSnapshotWriter cleared its pending-write promise one microtask after the drain loop saw no more requests. A write() in that gap set writeRequested, got the settling promise back, and nothing drained it, so the newest bytes stayed unwritten and waitForPendingWrite() (the dismissal store's flush) resolved without them. The drain now clears the pending promise in the same tick its loop exits, on success and failure, so a later write() always starts a new drain. * test(notifications): flush dismissal writes before deleting temp state dirs Dismissal history now saves asynchronously, and the writer recreates its directory before each write. Tests that deleted their temp dir with a write still pending left recreated dirs behind in the system temp folder and could race the delete on Windows. They now await the controller's flush first. * perf(notifications): close dismissal history at committed exits The shutdown flush only waited for writes already queued. A notification recorded after it (orcad cleanups still running, or the 150 ms before a renderer relaunch calls app.exit) started an async write the exit dropped, so the phone could keep an alert the desktop could no longer withdraw. The store's flush() becomes close(): it waits for the pending write, and every later record saves synchronously through the snapshot writer's existing writeSync (plain fs, no icacls; a failure only warns). It is called only where the exit can no longer be vetoed: the will-quit teardown, a new exit-only hook that app:relaunch runs before app.exit(0) (restart and profile switches share onBeforeRelaunch but quit through will-quit), and orcad's cleanup after RPC stops. The quit test now holds chat teardown and RPC stop and proves the close starts only after both settle, in either order. The orcad push-startup runtime mock gains the method the entry now calls. * fix(notifications): bound the dismissal close before a renderer relaunch app:relaunch waited on the dismissal store's close with no limit, so a stalled userData disk left Restart stuck on "Restarting…" with a half-quit app saving synchronously. The close now races a 2 s cap through the existing settleWithinMs helper, the same cap the restart path's auth preservation uses, and logs when it gives up. * test(notifications): keep async dismissal writes under test between reads Mid-test disk reads used closeDismissals() as a barrier, which switched every later record to the exit-only synchronous path. The store gains a non-closing flush() (close() = mark closed + flush), exposed on the controller as flushDismissals for tests; mid-test barriers use it, and close stays only where a test simulates an exit or teardown. Also notes why the writer's pendingWrite assignment is safe, renames a store test to what it covers, and groups the orcad cleanup-order test under a describe. (cherry picked from commit 3fb4b06) Backport to 1.4.224: this base has no AtomicSnapshotWriter (src/main/persistence/atomic-snapshot-writer.ts, added by #26822, is not on 1.4.224), so the dismissal store saves through the existing StatsSnapshotWriter, its predecessor with the same async temp-plus-rename and writeSync. StatsSnapshotWriter gains an optional fileMode (0o600 for the dismissal file; stats unchanged) and the PR's drain-race fix; the writer regression test moves to a new stats-snapshot-writer.test.ts. The two conflicting e2e tests keep 1.4.224's shape with the PR's async liveDeliveries()/closeDismissals() edits applied, and the same edit is applied to structured-attention-relay-settlement.unit.test.ts, which exists only on this base.
ELI5
On Windows, Orca freezes for a moment every time an agent sends a notification. While it saves a small bookkeeping file, it waits for Windows' file-permission tool to run about five times, and nothing else in the app can respond until that finishes. This PR saves that file in the background instead, so notifications stop freezing the app.
What Changed
The problem users saw. On Windows, every agent notification (a prompt is waiting, a task finished) froze all Orca windows: typing, clicking and terminal output stopped until it passed. On machines with antivirus or endpoint security, each pause can last seconds (#26027, Linear STA-9692).
Why it happened. Every notification records its id in
mobile-notification-dismissals.json, so a paired phone can later learn which alerts were already dismissed. That file was saved with the writer Orca uses for credentials. On Windows, that writer runsicacls.exesynchronously about five times per save to lock down the file's permissions: check, reset and grant on the temporary file, check again, then one more check after the rename. Orca's main process handles every window's input and every terminal, so it was stuck for the whole time. It ran on every notification and every dismissal, whether or not a phone was paired.What changes for the user. Notifications no longer freeze Orca on Windows. Nothing else changes: phones still get the same dismissal history, and it still survives a restart.
The mechanism.
AtomicSnapshotWriter, the same writer that already saves agent status (last-status.json). It writes a temporary file in the background, then renames it over the old one, with file mode 0600. Several notifications in a row collapse into one save of the latest list.Why
The file contains notification ids, sequence numbers and session ids. It holds no titles, message text, tokens or keys, so it doesn't need the credential writer's per-file permission lockdown. On Windows the new file inherits the permissions of Orca's user-data folder. That folder is under
%APPDATA%, so by default only the current user, SYSTEM and Administrators can open it, which are the same three principals the credential writer grants. The Windows box measurement below shows the file's real permissions after the change.last-status.json, which holds prompt text, has used this writer with the same mode for a long time.Alternatives considered:
icaclsprocesses per notification, only without waiting for them. This file doesn't need them, and this PR doesn't build a second shared writer while that PR is open. Moving actual credential stores (device registry, pairing) off the main thread is separate, held follow-up work.Once Orca is committed to exiting (quit, the Restart button, or a headless server stopping), the store waits for its pending save and then saves any later notification immediately with a plain file write, so notifications recorded during shutdown are saved too. The Restart button waits at most 2 seconds for the pending save, the same cap its other pre-restart step uses. Known gap: the automatic restart after a graphics crash exits without this step, so a save still in progress at that moment is lost and the phone may show that one alert again. Before this PR that save would have completed synchronously.
Linked Issue
Fixes #26027. Refs #20497. Linear: STA-9692 (also STA-7408, the sync-spawn umbrella).
Visual Proof
Measured on a real Windows 11 machine ("Windows high spec", NTFS, Defender on). Both builds came from one checkout and ran back to back in the same session, alternating before, after, before, after.
9d305f3ce4f. After: final PR head5e4bbc11dbd.electron-vite build --mode e2e, launched through the repo's hidden e2e harness (ORCA_E2E_HEADLESS=1,ORCA_BACKGROUND_LAUNCH=1, isolated user-data and home folders). No window was shown or focused.notifications:dispatchIPC with desktop banners off, so nothing popped up and the mobile bookkeeping still recorded every one. 3 runs per build, plus one discarded warm-up run per build.event-loop-delay.ndjson, one window per second) gives the main-process delay over the same period.f9011be40b2(before the review fixes) matched: 89.4 ms → 0.5 ms.File permissions, read with
icaclsat the end of a run:BUILTIN\Administrators:(F),NT AUTHORITY\SYSTEM:(F),<user>:(F).BUILTIN\Administrators:(I)(F),NT AUTHORITY\SYSTEM:(I)(F),<user>:(I)(F).Same three principals, nobody else.
Raw JSON per run, the spec and the runner are kept with the lane's QA notes, outside the repo.
Testing
tscfor the node and web projects is clean, the mobile test-typecheck ratchet passes, and the repo's CI static checks pass apart from two local-environment-only failures.Review
Three review rounds plus the readiness checklist and a performance scan; no P0–P2 remain. Details, fixes and deferred items are in the review-summary comment below.
Agent skill upstream boundary
Notes
Checklist
pnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (CI will cover the full suites)Rendered QA — macOS hidden headless E2E
Independent visual QA on head
5e4bbc11dbd, run through the Electron headless E2E harness (ORCA_E2E_HEADLESS=1,ORCA_BACKGROUND_LAUNCH=1,--use-mock-keychain --password-store=basic, isolated profile/home; everyBrowserWindowasserted hidden before any interaction). Desktop banners were turned off through the rendered Settings switch, and the main-side setting was read back as disabled, so all 40 realnotifications:dispatchcalls returned{delivered:false, reason:"disabled"}. The file read at the end held all 40 records with 40 unique notification ids and the latest sequence retained (one epoch); threenotifications:dismisscalls recorded dismissal watermarks 41/42/43. This run did not instrument how many disk writes produced that file, so it makes no claim about write count — only that all 40 records persisted.Typing overlap was verified from renderer-clock timestamps, not wall-clock inference. 40 bounded dispatches were paced ~15–20 ms apart (median 22 ms) while text was typed into the real rendered settings search field, recording
performance.now()at every input event and every dispatch call: 14 dispatch calls landed between the first and last input event (the spec asserts at least 2), and typing spanned ~344 ms, so real notification traffic genuinely overlapped real input. No main-process block was observable on macOS; the Windowsicaclsstall this PR removes is Windows-only, so its measurement stays in the section above.A clean quit kept all 30 entries and a relaunch on the same profile reloaded them (31 entries after one new notification, two sequence epochs). That flow waited for the initial write to reach disk before quitting, so it demonstrates retained and reloaded history across restart, not a still-pending-write quit barrier; the unit and shutdown tests cover the quit-time flush itself.