Skip to content

fix(notifications): remove delivered macOS notifications by id and pane group - #26833

Closed
maxmilian wants to merge 1 commit into
stablyai:mainfrom
maxmilian:fix/macos-notification-remove-26732
Closed

maxmilian wants to merge 1 commit into
stablyai:mainfrom
maxmilian:fix/macos-notification-remove-26732

Conversation

@maxmilian

Copy link
Copy Markdown
Contributor

ELI5

On macOS, Orca's notifications could only be cleared while Orca still held them in memory, and it lets go of them after five minutes (and loses them on restart). After that, viewing the pane left old notifications stuck in Notification Center, one per turn. Now each notification has a name and a per-pane group that macOS knows about, so Orca can remove them by name at any time.

What Changed

  • native-notification-identity.ts (new): on macOS, builds { id, groupId } for each native notification. id = the existing notificationId; terminal bells (which had none) get a stable terminal-bell:<paneKey>. groupId = pane:<paneKey>.
  • native-notification-delivery.ts: passes that identity to new Notification().
  • notifications.ts (notifications:dismiss): after the existing in-memory close() loop, calls Notification.remove(ids) for every id it retires and Notification.removeGroup(pane:<paneKey>) for every acknowledged pane. These work by identifier, with no live object, so they still work after the five-minute release or a restart.
  • Positioned structured alerts (structuredOrigin) get an id but no groupId: they are only retired by a read that covers them (existing subject-retirement rule), and a pane-wide removeGroup would otherwise clear them on any pane read.
  • Windows/Linux are unchanged: on Windows id/groupId map to toast Tag/Group (length-limited, different replace semantics), so that path keeps close().

Before: notifications older than five minutes, or from before a restart, could not be dismissed; bells piled up one per ring. After: viewing a pane removes all of its plain notifications from Notification Center; a repeated bell replaces the previous one.

Point 4 of the issue (optional "one notification per pane until viewed" setting) is a product call and is not included.

Why

close() needs the live Notification object, which retainNotificationUntilRelease drops after NOTIFICATION_RELEASE_FALLBACK_MS (5 min); the announced-notification registry still knows the ids, but nothing could act on them. Electron 43 (already shipped) exposes id/groupId and the macOS statics Notification.remove() / removeGroup() (electron/electron#50097, #51182, backported in #51690), which act on UNUserNotificationCenter delivered notifications by identifier. Extending the in-memory retention instead would still fail after a restart and keep objects alive indefinitely.

Linked Issue

Fixes #26732

Visual Proof

macOS 26 Notification Center, dev build (Orca Dev), same scenario on main and on this branch: pane A gets agent turn 1, two terminal bells, agent turn 2; pane B gets one agent notification. Wait past the 5-minute in-memory release, then acknowledge pane A (notifications:dismiss(['<turn-2 id>'], [paneA]), which is what the renderer sends when the pane is viewed). Both runs return { dismissed: 0 } because the live objects are already released.

Before (main): all five still in Notification Center After (this PR): pane A cleared, pane B kept
nc-before nc-after

After this PR, before the dismiss (each pane is its own thread, and the second bell replaced the first):

nc-after-before-dismiss

Testing

  • New src/main/ipc/notifications-macos-removal.test.ts (6 cases): id/groupId on dispatch; stable bell id; dismiss after the 5-minute release removes by id and pane group; dismiss in a fresh process (restart) removes by id and group; positioned structured alert stays out of the group; Linux keeps the close() path. 5 of 6 fail on main (the Linux guard passes on both), all pass with the fix.
  • vitest over src/main/ipc + src/main/notifications: 543 files / 5455 tests pass. pnpm typecheck, pnpm lint, check:code-quality:changed pass. pnpm build not run locally.
  • macOS 26 (Apple silicon), dev build: ran the Visual Proof scenario end to end through the real notifications:dispatch / notifications:dismiss IPC (driven from the renderer over CDP), waiting the real five minutes. Delivered list (Notification.getHistory() from a separate process) after the dismiss:
    • main: 5 entries, all random-UUID ids with empty groupId.
    • this PR: only agent:…:b1 (group pane:<pane B>) is left. Before the dismiss, pane A held agent:…:a1, terminal-bell:<pane A> (ring 2 had replaced ring 1) and agent:…:a2, all in group pane:<pane A>.
  • Also on macOS 26: Notification.remove(id) from a different process of the same bundle removes the notification, so removal does not depend on the process that posted it (the restart case). I could not reproduce the restart pile-up itself with the dev build: quitting the dev app removed its delivered notifications in my runs, so that path is covered by the unit test plus this cross-process check.
  • Lower-level Electron probe (same bundle): posted notifications the way this PR does, dropped every Notification reference, then dismissed the way the new IPC does:
    • after post: [<random-uuid legacy>, agent:…turn1, agent:…turn2, terminal-bell:<pane>, agent:…other] (a second bell with the same id replaced the first)
    • after remove(['agent:…turn2']): turn2 gone
    • after removeGroup('pane:<pane>'): only the legacy notification and the other pane's remain
  • I manually tested these changes locally (macOS 26; Windows/Linux paths unchanged and covered by the platform-guard test)
  • Automated tests added/updated

AI Disclosure

Implemented with Claude Code (Claude Opus 5.5), including the tests, the macOS Notification Center runs and the Electron probe described above; the diff was reviewed before opening this PR.

Review

AI review summary:

  • Cross-platform: macOS-only via process.platform === 'darwin' in both the identity builder and the removal call; Windows/Linux behaviour is byte-for-byte the old path.
  • SSH/remote/local: notifications are raised and dismissed by the desktop main process; remote hosts only feed dispatch requests, unchanged.
  • Agent/integration compatibility: agent ids are the existing notificationIds; structured (journal-positioned) alerts keep their read-boundary semantics by staying out of the pane group.
  • Mobile: mobile fan-out and dismissMobileNotification are untouched; the bell id is native-only.
  • Performance: one remove() call plus one removeGroup() per acknowledged pane per dismiss.
  • Security: identifiers are built from ids/paneKeys main already holds; no new IPC surface.

Agent skill upstream boundary

  • Not applicable

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (lint + typecheck + notification/main vitest pass locally; full pnpm test and pnpm build not run)

🤖 Generated with Claude Code

https://claude.ai/code/session_01WuRWooMLGXysyySZsUMNVH

…ne group

notifications:dismiss only closed Notification objects still held in memory,
which main releases after five minutes and loses on restart, so older
notifications piled up per pane in Notification Center.

On macOS, give each native notification an id (UNNotificationRequest
identifier) and a per-pane groupId (threadIdentifier), and have dismiss call
Notification.remove(ids) and Notification.removeGroup(pane) so delivery no
longer depends on a live object. Terminal-bell notifications get a stable
pane-scoped id so a repeat replaces the previous one. Positioned structured
alerts keep their id but stay out of the pane group, so a pane read that does
not cover them still leaves them. Windows/Linux keep the close() path.

Refs stablyai#26732

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WuRWooMLGXysyySZsUMNVH
@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 19db0cec-b47b-44b7-9da7-0e4922d084d7

📥 Commits

Reviewing files that changed from the base of the PR and between 7b1242b and 7255492.


📒 Files selected for processing (5)
  • src/main/ipc/native-notification-delivery.ts
  • src/main/ipc/native-notification-identity.ts
  • src/main/ipc/notifications-macos-removal.test.ts
  • src/main/ipc/notifications-test-harness.ts
  • src/main/ipc/notifications.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.



📝 Walkthrough

Walkthrough

On macOS, native notifications receive IDs and pane group IDs. Terminal-bell notifications without an ID receive a pane-scoped ID. The dismissal handler now requests removal of delivered notifications by ID and pane group after handling active in-memory notifications. Tests cover notification identity, dismissal after the in-memory release period, structured alerts, and Linux behavior.

Fixed issue severity: <fixed_issue_severity>Medium</fixed_issue_severity>


Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 72554

Pane dismissal does not appear to clear unread alerts or notifications in other panes. No actionable merge-blocking risk remains on the supplied evidence.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: removing delivered macOS notifications by identifier and pane group.
Description check Passed The description is complete and relevant. It explains the user impact, implementation, rationale, linked issue, visual proof, testing, platform considerations, AI disclosure, and scope. It also clearl…
Linked Issues check Passed The PR meets the coding requirements in #26732. buildNativeNotificationIdentity assigns macOS IDs, assigns terminal-bell:<paneKey> for bells, and assigns pane:<paneKey> to plain pane notificatio…
Out of Scope Changes check Passed The changes stay within #26732. The new identity helper, dismissal integration, Electron test mocks, and focused macOS removal tests directly support identifier-based removal, pane grouping, bell repl…


  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@maxmilian

Copy link
Copy Markdown
Contributor Author

@Jinwoo-H I noticed #26732 was assigned to you after this PR went up. In case it saves you some time: this already covers points 1–3 of the issue (stable id plus a per-pane groupId on macOS, and Notification.remove / removeGroup on dismiss), with before/after Notification Center captures from a real 5-minute wait in the description. If you'd rather take it in a different direction, let me know and I'll close this.

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Thanks for this, @maxmilian. We shipped this approach in #28425, with you credited as co-author. It keeps your per-pane grouping and leaves native-chat alerts out of it. We dropped the fixed bell id, because Electron sends a click to the first notification ever shown with a given id, so a repeat bell after the 5-minute release could do nothing when clicked. Closing this in favour of that. Much appreciated.

@Jinwoo-H Jinwoo-H closed this Oct 14, 2026
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.

macOS: notifications can't be cleared after 5 minutes or a restart and pile up per pane; use Electron id/groupId and Notification.remove()

2 participants