Fix two races in the notification popup and history handling (#6735)
* Replay the history a dismissal or a clear was still being written into The popup files a replay reads are written by a serialized queue of shell jobs, and the read ran as its own process alongside it. A dismissal issued a moment earlier could still be queued when the directory was read, leaving the notification out of the replay it was the newest entry of, and a clear issued a moment earlier could still be queued too, replaying entries it was about to remove. The read now waits for the queue to go idle, so the replay shows the history as of the moment it was asked for rather than whichever jobs happened to have landed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Catch up on an update that arrived before its popup had a row Watching a notification for in-place updates starts the moment it is handed over, but the row those updates write to is inserted a tick later, deferred to keep a mid-incubation Repeater from being mutated underneath. A client fast enough to update inside that window found no row to write to, and a property that has already changed does not change again — so the toast and its file sat on the superseded content until something else moved. The row is now refreshed from the live notification once it exists. That reads the same object the signals would have, so an update that beat the insert is picked up and one that did not costs nothing: a refresh whose content matches the row it would write is dropped, which also collapses the several signals a single multi-property update emits into one rewrite. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Hold queued file work behind the replay's read, not just ahead of it The read waited for everything queued before it, but nothing stopped the queue from running on while it worked. A clear or an archive issued during the read could delete or move files out from under awk mid-glob, so a replay could still show a partial history — some of what a clear was in the middle of emptying. The read is a barrier in both directions now: the queue holds until it exits, and it releases on exit rather than on output, so a read that comes back empty or fails cannot park the queue behind it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Queue the replay's read instead of waiting for the queue to empty Waiting for the queue to go idle before starting the read still let work overtake it. A clear or an archive enqueued after the replay was asked for, while the current job was running, was dequeued the moment that job exited — the read only starts once nothing is left — so the replay showed the state after those jobs, which is the race this was meant to close. Unbroken file traffic could postpone the read indefinitely for the same reason. The read is now an entry in that queue rather than a process running beside it. It takes its place in line behind the work queued before the request and ahead of everything queued after, so no later job can overtake it and no amount of traffic can push it back. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
fd23ca023a
commit
9b8bf1da71
@@ -170,6 +170,18 @@ assertEqual(
|
||||
'12345-12.json',
|
||||
'notifications keep the persisted file name across an in-place update'
|
||||
)
|
||||
assert(
|
||||
!notifications.popupRowChanged(replacement, replacement),
|
||||
'notifications skip a refresh that matches the row it would write'
|
||||
)
|
||||
assert(
|
||||
notifications.popupRowChanged(replacement, Object.assign({}, replacement, { body: 'message 3' })),
|
||||
'notifications refresh a row whose content moved on'
|
||||
)
|
||||
assert(
|
||||
!notifications.popupRowChanged(replacement, Object.assign({}, replacement, { timestamp: 999 })),
|
||||
'notifications ignore identity fields when deciding whether a refresh has work'
|
||||
)
|
||||
|
||||
const settings = notifications.parseSettings(JSON.stringify({ version: 3, dnd: true }))
|
||||
assertEqual(settings.dnd, true, 'notifications parse the persisted DND state')
|
||||
@@ -371,9 +383,33 @@ assert(
|
||||
'notifications service refreshes the popup from every property the card draws'
|
||||
)
|
||||
assert(
|
||||
/popupModel\.setProperty\(i, "summary", updated\.summary\)[\s\S]{0,600}?persistPopupFile\(updated\)/.test(serviceQml),
|
||||
/popupModel\.setProperty\(i, roles\[r\], updated\[roles\[r\]\]\)[\s\S]{0,600}?persistPopupFile\(updated\)/.test(serviceQml),
|
||||
'notifications service rewrites both the row and its file when a notification is updated in place'
|
||||
)
|
||||
assert(
|
||||
/if \(!NotificationLogic\.popupRowChanged\(row, updated\)\) return/.test(serviceQml),
|
||||
'notifications service leaves the row and its file alone when a refresh finds nothing changed'
|
||||
)
|
||||
assert(
|
||||
/popupModel\.insert\(0, snapshot\)[\s\S]{0,300}?service\.refreshPopup\(notification, snapshot\.originalId, snapshot\.timestamp\)/.test(serviceQml),
|
||||
'notifications service catches up on an update that beat the deferred row insert'
|
||||
)
|
||||
assert(
|
||||
/function showRecentHistory\(\)[\s\S]{0,300}?enqueueHistoryRead\(\)/.test(serviceQml),
|
||||
'notifications service reads history from its place in the file queue'
|
||||
)
|
||||
assert(
|
||||
/if \(job\.read\) \{\s*\n\s*startHistoryRead\(\)/.test(serviceQml),
|
||||
'notifications service runs the queued read when its turn comes'
|
||||
)
|
||||
assert(
|
||||
/function runNextPopupFileJob\(\) \{\s*\n\s*if \(readHistoryProc\.running \|\| popupFileProc\.running\) return/.test(serviceQml),
|
||||
'notifications service holds queued file work until a history read finishes'
|
||||
)
|
||||
assert(
|
||||
/id: readHistoryProc[\s\S]{0,300}?onExited: service\.runNextPopupFileJob\(\)/.test(serviceQml),
|
||||
'notifications service releases the file queue even when a history read comes back empty'
|
||||
)
|
||||
assert(
|
||||
/onSummaryChanged: cardSlot\.remainingLifetime = 1\.0/.test(serviceQml),
|
||||
'notifications service restarts the countdown when a toast is updated under it'
|
||||
|
||||
Reference in New Issue
Block a user