Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/main/ipc/notifications-subject-retirement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,36 @@ describe('notifications:dismiss by acknowledged subject', () => {
expect(dismissMobileNotification).toHaveBeenCalledWith('agent:phone-only')
})

// Reads rebuild ids for turns that never alerted; each forwarded one was a silent push and a store slot.
it('clears on the phone only alerts that reached it, including ones sent before a restart', async () => {
const directory = mkdtempSync(join(tmpdir(), 'orca-clear-delivered-'))
const original = new RuntimeMobileNotificationController()
const restarted = new RuntimeMobileNotificationController()
try {
original.configureDismissalStore(directory)
original.dispatch({
type: 'notification',
source: 'agent-task-complete',
title: 'Done',
body: '',
notificationId: 'agent:sent'
})
await original.closeDismissals()
restarted.configureDismissalStore(directory)
const events: MobileNotificationEvent[] = []
restarted.onDispatched((event) => events.push(event))
register({ suppressWhenFocused: false }, restarted)
getDismissHandler()({}, ['agent:never-sent', 'agent:sent'], [PANE])
getDismissHandler()({}, ['agent:sent'], [PANE])
expect(events.map((event) => [event.type, event.notificationId])).toEqual([
['dismiss', 'agent:sent']
])
} finally {
await restarted.closeDismissals()
rmSync(directory, { recursive: true, force: true })
}
})

it('records nothing for a request neither the desktop nor the phone announced', async () => {
const { dismissMobileNotification } = register({ suppressWhenFocused: false })
const dispatch = getDispatchHandler()
Expand Down
20 changes: 14 additions & 6 deletions src/main/runtime/mobile-notification-dismissal-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,19 @@ export class MobileNotificationDismissalStore {
return this.flush()
}

/** Unreadable history cannot rule a delivery out. */
hasLiveDelivery(notificationId: string): boolean {
const now = Date.now()
return (
this.unreadable ||

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.

Minor · Functional Correctness · Quick win

Treat malformed history as uncertain.

If the saved JSON is malformed, JSON.parse throws, but isUnreadableError returns false for the parse error. The store then reports no live deliveries and suppresses clears for pre-restart alerts. Treat an invalid snapshot as unknown history and forward those clears. (raw.githubusercontent.com)

this.entries.some((entry) => entry.notificationId === notificationId && isLive(entry, now))
)
}

liveDeliveries(prefix = ''): DeliveredNotificationRecord[] {
const now = Date.now()
return this.entries
.filter(
(entry) =>
entry.expiresAt > now &&
entry.notificationId.startsWith(prefix) &&
entry.dismissedThrough < entry.notificationSeq
)
.filter((entry) => entry.notificationId.startsWith(prefix) && isLive(entry, now))
.map(({ notificationId, notificationEpoch, notificationSeq, structuredOrigin }) => ({
notificationId,
notificationEpoch,
Expand All @@ -153,6 +157,10 @@ export class MobileNotificationDismissalStore {
}
}

function isLive(entry: RecordEntry, now: number): boolean {
return entry.expiresAt > now && entry.dismissedThrough < entry.notificationSeq

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.

Minor · Functional Correctness · Quick win

Do not expire undismissed deliveries after seven days.

A phone can still show an alert after its store entry expires. A desktop read then skips its clear, even when the entry was not evicted. Keep undismissed entries until they are retired or reach the accepted capacity limit. Also update the pruning in record. (developer.apple.com)

}

/** Keep records with unknown future origin kinds, degrading only their origin to none. */
function readEntry(value: unknown): RecordEntry[] {
if (!isEntry(value)) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/runtime/runtime-mobile-notification-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ export class RuntimeMobileNotificationController {
}

dismiss(notificationId: string): void {
// Reads rebuild ids for alerts that never went out (chat panes, silenced workers); each would cost a silent push.
if (this.dismissalStore && !this.dismissalStore.hasLiveDelivery(notificationId)) {
return
}
this.dispatch({ type: 'dismiss', notificationId })
}

Expand Down
Loading