Repository navigation
Conversation
…thread MobileNotificationDismissalStore.record() runs on every notification dispatch and dismiss. It persisted through writeSecureJsonFile, which on Windows spawns icacls synchronously two to eight times per write, so every notification stalled the main process and all pending IPC replies. Record into memory immediately and persist asynchronously, with at most one write in flight and later records coalesced into one follow-up write of the latest entries. A failed write is logged and retried by the next record. Add writeSecureJsonFileAsync, which keeps writeSecureFile's restrict-before-publish order but awaits icacls through the existing async ACL lane instead of runProcessSync. Part of stablyai#20497
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Async, coalesced persistence in
MobileNotificationDismissalStore—record()now updates in-memory entries immediately and schedules a serialized write (persisting/persistAgain), instead of callingwriteSecureJsonFilesynchronously; newflush()exposes the in-flight promise. - New
writeSecureJsonFileAsync— mirrorswriteSecureFile's restrict-before-publish order but awaits the existing async icacls lane (bestEffortRestrictWindowsPath) and POSIXchmod 0600, removing the synchronousicaclsspawn from the notification hot path (#20497). secure-file.tsinternals exported —hardenSecurePathOnceandrememberHardenedPathare now exported so the async writer shares the same directory/file hardening caches.- Tests — store coalescing (three records during an in-flight write → exactly two writes, latest state persisted), failed-write retry on next
record(), async writer ordering/failed-ACL/rename-cleanup/POSIX mode, and the read-failure test now awaitsflush().
The concurrency is sound: entries is replaced rather than mutated, so each write stringifies a stable snapshot, and no record() can slip between the while (persistAgain) check and persisting = null (same synchronous turn). Write errors are caught inside persistLatest, so the promise never rejects and there is no unhandled rejection. The restrict-before-publish ordering and return/caching semantics (record success only, no retry-budget throttle — matching the sync write path) are preserved.
ℹ️ Dismissal recorded in the last moment before quit can still be lost
The PR body already accepts this tradeoff, and the impact is a dismissed mobile alert reappearing once after restart. Worth noting for the next reader: the repository already has a quit barrier that joins sidecar flushes — freezeProfileStateWritesAsync / flushCurrentStateAsync in src/main/persistence/loading-store/ already awaits activeViewPreference.flushAsync(). Routing the dismissal store's flush() through that barrier would close the window, though it needs runtime-controller plumbing, so it is reasonable to defer.
Technical details
# Quit-window dismissal loss
## Affected sites
- `src/main/runtime/mobile-notification-dismissal-store.ts:83` — `flush()` exists but has no production caller.
- `src/main/runtime/runtime-mobile-notification-controller.ts:118` — `dispatch()` records, then returns without awaiting persistence.
- `src/main/persistence/loading-store/profile-state-maintenance.ts:36` and `write-flush-barriers.ts:204` — existing quit barrier already joins `ActiveViewPreference.flushAsync()`.
## Required outcome
- None required; this is an accepted, documented tradeoff. If the window should be closed, a shutdown path must `await` the store's in-flight write before process exit.
## Open questions for the human
- Is a duplicate mobile alert after a quit-window dismissal acceptable long-term, or should the store join the existing flush barrier?DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
📝 WalkthroughWalkthroughThe dismissal store now persists updated entries with asynchronous secure JSON writes. It can repeat a write when another record arrives during an active write, and it exposes Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to Dismissal history is now saved without blocking the main thread. However, on Windows, a failed permission restriction can still publish the file with broader inherited permissions, and the store does not warn about it. Fix this before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change remains limited to local notification recovery state and preserves the existing permission-restriction sequence. No new authorization capability was identified. Recording no longer guarantees immediate persistence, so interruption can lose recent dismissal history; Windows permission-failure behavior and production shutdown handling remain incompletely established. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
…-store-write # Conflicts: # src/main/runtime/mobile-notification-dismissal-store.ts
…-store-write # Conflicts: # src/main/runtime/mobile-notification-dismissal-store.test.ts # src/main/runtime/mobile-notification-dismissal-store.ts
…e test The dismissal store now persists asynchronously, so the restore test restarts only once the delivery is durable and polls for the persisted retirement instead of reading the file in the same tick.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
50c73681-d79f-443b-a728-191e2dc6bf37
📒 Files selected for processing (3)
src/main/runtime/mobile-notification-dismissal-store.test.tssrc/main/runtime/mobile-notification-dismissal-store.tssrc/main/runtime/structured-agent-session-mobile-restore.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
|
The synchronous Windows write cost is a real problem, but closing this implementation as not planned. record() now returns before persistence, and flush() is only used in tests, so an immediate normal exit can forget an already dismissed alert and repeat it after restart. That difference was reproduced with the actual current and proposed stores. Any replacement must preserve acknowledgement/persistence ownership and lifecycle flushing; the broader #20497 remains open. |

ELI5
Every time an agent sends a notification, Orca saves a small "which mobile alerts were dismissed" file. On Windows that save ran a permission tool (
icacls) and made the whole window wait for it. On a slow or busy machine the window froze, and a few times it never came back. This PR does that save in the background instead.What Changed
Before:
MobileNotificationDismissalStore.record()runs on every notification dispatch and dismiss, on the main process. It calledwriteSecureJsonFile, which on Windows spawnsicaclssynchronously at least twice per save (verify the staged file, verify the published file), and up to eight times when the ACL has to be rewritten. While those spawns ran, every pending IPC reply waited, so the window stopped responding (the mechanism described in #20497).After:
record()updates the in-memory entries immediately and schedules the write. It no longer blocks on disk or onicacls.record().writeSecureJsonFileAsync(src/shared/secure-file-async-write.ts) keeps the existing order ofwriteSecureFile— write a temp file, restrict it, rename, then restrict the published path — but awaitsicaclsthrough the existing async lane (bestEffortRestrictWindowsPath) instead ofrunProcessSync. POSIX keepschmod 0600.secure-file.tsonly exports two existing internals (hardenSecurePathOnce,rememberHardenedPath) so the async writer shares the same directory and file hardening caches.Why
writeSecureJsonFileitself would touch every credential store and their callers at once.icaclswithout stdio pipes, on the theory that a pipe held open by another process keptspawnSyncwaiting past its 5s timeout (see Evidence). I could not prove that theory, so this PR only removes the blocking call from the hot path.Evidence (Windows 11, Orca 1.4.211, antivirus + DLP agent installed): the window stopped responding three times in one day (11:18, 12:03, 14:27). Each time,
%APPDATA%\Orcaheld a leftovermobile-notification-dismissals.json.<pid>.<ts>.tmpand%TEMP%held a matchingorca-acl-<same pid>-*.sddl, written within a second of each other. The main thread sat idle at ~0% CPU, and noicacls.exeprocess remained, soverifySync→runProcessSyncnever returned, even pastACL_TIMEOUT_MS. Only killing the main process recovered. On the same machine, the unmodified store's unit tests spend ~3.5s inside three synchronousrecord()calls.Tradeoff: a dismissal recorded in the last moment before quit may not reach disk. The store already treats missing history as "not dismissed", so the worst case is that a mobile alert the user already dismissed shows once more after a restart.
flush()is available if a shutdown path should await it.Linked Issue
Part of #20497. This fixes one sync-spawn call site. The other sites listed there are unchanged, and
getCurrentWindowsUserSidstill runswhoamisynchronously once per process.Related symptom reports: #11363, #7175
Visual Proof
N/A: no UI change. The difference is that the window keeps responding while notifications are recorded.
Testing
vitest runon the changed suites (mobile-notification-dismissal-store,mobile-notification-dismissal-read-failure,secure-file): 41 passed, 3 POSIX-only skipped on WindowsNew tests:
record()returns before anything reaches disk, three records during an in-flight write produce exactly two writes, and the latest state is persistedrunProcessSyncfor ACLs, restricts the staged.tmpbefore the published path, returnsfalsewhen the ACL apply fails, removes the staged file when the rename fails, and publishes0600on POSIXRegression check: with the store change reverted, the new "records without waiting on disk" test fails (the file is written synchronously).
pnpm run typecheck,oxlint,oxfmt --check, andpnpm run check:code-quality:changedpass.Platforms: Windows 11 locally. The POSIX-only test is skipped on Windows and will run in CI. This machine has no Visual Studio build tools, so native modules could not be rebuilt:
pnpm buildand thepnpm testwrapper are left to CI, and I ranvitestdirectly.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Not manually tested in a packaged build: the freeze depends on host timing (antivirus/EDR holding the spawn), and I could not reproduce it on demand. The unit tests cover the mechanism instead.
AI Disclosure
Investigation, implementation, and tests were done with Claude Code (Claude Opus 5.5) and reviewed by me before submitting.
Review
AI self-review summary:
fs.promises.chmod. Paths usenode:path.userDataonly. No wire or RPC change.falseon a failed ACL apply, and records retry-budget success only on success, like the sync path. Persisted content is not a credential.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Security, cross-platform, SSH, mobile, and backwards-compatibility impact are considered above. The on-disk format is unchanged.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)