Skip to content

Honour explicit expireTimeout for critical notifications (#12911) - #13041

Closed
Cid-oe wants to merge 1 commit into
omacom:quattrofrom
Cid-oe:fix/issue-12911-critical-notification-expiry
Closed

Cid-oe wants to merge 1 commit into
omacom:quattrofrom
Cid-oe:fix/issue-12911-critical-notification-expiry

Conversation

@Cid-oe

@Cid-oe Cid-oe commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Closes #12911.

Per the FreeDesktop notification specification, an explicit non-zero expireTimeout should be honoured regardless of urgency. Previously, durationFor() unconditionally returned 0 for Critical notifications, ignoring finite timeouts requested by senders (such as low-battery warnings) and causing toasts to persist indefinitely across reboots.

@llstrk

llstrk commented Sep 24, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: at head e91ca65, the reported case from #12911 is fixed across the full popup lifecycle. A critical notification sent with a positive timeout (for example omarchy-battery-low, -u critical -t 30000) now counts down, is archived into history when it expires, and is no longer restored after a restart once its lifetime has elapsed. A popup file already stuck from before the fix (the persisted entry quoted in the issue) is archived on the first shell start at head, while the base restores it on every start. Critical notifications sent without a timeout (-1 from omarchy-notification-send and notify-send, or 0) still stay until dismissed. Low and normal urgency durations are unchanged.

durationFor(urgency, expireTimeout)     base (c737c49)   head (e91ca65)
Critical, 30000 (battery low)           0 = sticky       30000 ms
Critical, 3000  (screen-recording err)  0 = sticky       3000 ms
Critical, -1 or 0 (no timeout)          0 = sticky       0 = sticky
Normal,   3000                          8000 ms          8000 ms
Low,      3000                          5000 ms          5000 ms

Restore of the issue's 18 h old critical file (-t 30000), 5 restarts:
base: restore, restore, restore, restore, restore
head: archive to history, then nothing to restore

Short critical timeouts get no minimum lifetime

At head, the critical branch returns the requested duration directly, while low and normal toasts are clamped to at least 5 s and 8 s. A critical toast with a short timeout therefore leaves the screen sooner than a normal one with the same timeout (see the 3000 ms rows above). Four in-tree critical callers pass short timeouts: the screen-recording error notifications in bin/omarchy-capture-screenrecording (3000 ms twice, 5000 ms once) and bin/omarchy-capture-screenrecording-with-webcam (3000 ms).

Impact: these error toasts go from staying until dismissed to showing for 3 to 5 seconds, shorter than an ordinary notification with the same timeout.

Suggested change: apply the normal floor when a critical sender requests a timeout, for example return requested > 0 ? Math.max(normalPopupDuration, requested) : 0, or raise the -t values at those call sites. Whether critical toasts should also be capped at maxPopupDuration is a separate product choice.

Documentation: the new code comment and the PR description say the FreeDesktop spec requires honouring a timeout regardless of urgency. Spec 1.3 says -1 means the server decides and that critical notifications "should not automatically expire". Honouring an explicit timeout matches mako and dunst behaviour, so that is a more accurate rationale. docs/notifications.md still describes critical toasts as lasting "forever", and the "(or -1 default for critical)" note does not match the code path, because snapshotOf() in NotificationLogic.js clamps -1 to 0 before durationFor() is called.

Optional test improvement: test/shell.d/notifications-test.sh produced identical results at base and head, because no assertion reaches durationFor(). Moving the duration policy into NotificationLogic.js would allow Node assertions such as critical with 30000 giving 30000, critical with -1 or 0 giving 0, and the issue's stale critical entry being reported as expired on restore.

Note for maintainers: the low-battery warning is sent once per discharge cycle. At head it leaves the screen after 30 seconds (unless hovered) and remains in history. The issue also proposed a narrower alternative that keeps critical toasts on screen but stops restoring them once timestamp + expireTimeout has passed. Which behaviour is preferred is a product decision; the PR is a valid implementation of the first option.


Review information

Test scope: source review of the notification service, NotificationLogic.js, in-tree critical senders, and upstream Quickshell 0.3.1, libnotify 0.8.8 and Desktop Notifications spec 1.3 sources. The repository test test/shell.d/notifications-test.sh ran in a sandbox at base and head (135 of 135 passing in both), under Deno's Node compatibility layer rather than Node. A focused harness ran the snapshot's own duration, expiry and restore logic for base and head, including the issue's persisted file. QML and Quickshell were not run, so on-screen timing and hover behaviour are established from source and the harness model, not from a live desktop session.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@jandrusk

Copy link
Copy Markdown

Small consistency nit (non-blocking): Low/Normal durations clamp with maxPopupDuration, but Critical with requested > 0 returns the raw ms uncapped.

If the intent is “honour the requested timeout but still bound the UI,” consider:

return requested > 0 ? Math.min(maxPopupDuration, requested) : 0

If Critical is deliberately uncapped per the notification spec, ignore this — just flagging the asymmetry.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at e91ca65. The bug is real and still present on current quattro (821ae58): durationFor() in shell/plugins/notifications/Service.qml returns 0 for every critical notification, so omarchy-battery-low's -t 30000 toast never expires and restorePopups() brings it back on every restart. This change fixes that, and untimed critical notifications (-1 or 0) still stay until dismissed.

Two other open pull requests fix the same bug in the same function, so this one was compared against them rather than run on a worker:

What separates this pull request from #13100 is a product choice. Here, a critical toast gets exactly the timeout its sender asked for. So the screen-recording errors in bin/omarchy-capture-screenrecording and bin/omarchy-capture-screenrecording-with-webcam (-t 3000 and -t 5000) last 3–5s, shorter than a normal toast asking for the same timeout, which is floored at 8s, and a critical toast asking for 60s gets 60s. #13100 floors critical toasts at 8s and caps them at 30s, the same as normal toasts.

Claude Opus 5.5 preferred #13100, because it keeps the rule that already applies to low and normal toasts and keeps the docs accurate. Codex Medium, asked separately which of the three was best, preferred this pull request, because it honours what the sender asked for without adding a floor or a cap. It found no functional defect here, and it agreed that the docs and the NotificationLogic.js comment are now stale. The two reviews disagree, so this waits on the maintainer to choose between the approaches. Whichever lands, the other two can be closed.

If this approach is chosen, it needs two follow-ups: the docs/notifications.md line and the popupExpired() comment should say that only untimed critical toasts last forever. The new code comment should also stop citing the spec, which says critical notifications should not expire automatically. Honouring an explicit timeout matches mako's and dunst's behaviour, and that is the better reason to give.

@aholbreich

Copy link
Copy Markdown
Contributor

Thanks @Cid-oe, this fixes the same explicit-critical-timeout bug as #12964. We compared the five direct candidates on current quattro: all merge and fix the 30s battery case, but #12964 is older, caps the request at the existing 30s maximum, and has executable regression tests for both the live duration and restore after restart. We've recommended #12964 to the maintainers, so this one would close as a duplicate when it lands. Credit to you for the minimal implementation.

@omarchybot

Copy link
Copy Markdown
Collaborator

Following up on the earlier comment, which compared this pull request only with #13100 and #13673. #12964 also fixes #12911 in durationFor(), and it was opened a day before this one (2026-09-22), so it is the fix this one should be weighed against. #13673 has since been closed.

#12964 makes the same change as this branch: a critical toast that asks for a positive timeout gets that timeout, with no 8s floor, and an untimed critical toast (-1 or 0) still stays until dismissed. It also caps a timed critical toast at the existing 30s maximum, moves the duration rule into NotificationLogic.js, and adds tests that actually call it. Those tests cover both the live duration and whether a toast that has already expired is restored after a restart. This branch handles no case that #12964 misses, and #12964 has no defect that this one avoids. The older fix wins when two fixes are this close, so #12964 is the one to take forward, and this one adds nothing that needs folding into it.

Nothing was run on a worker for this pull request, because only one of the competing fixes needs verifying. Claude Opus 5.5 compared the diffs of #12964, this pull request, #13100, #13159 and #13161. Codex Medium was asked separately which fix should win, without being told this answer. It also chose #12964 and found no defect that would disqualify it. Its independence from this review is not guaranteed.

This now waits on the maintainer. If #12964 lands, this pull request can be closed.

@ryanrhughes

Copy link
Copy Markdown
Collaborator

Thanks @Cid-oe! In the new notification engine (#15932) that's deliberate: critical means "stays until you dismiss it" (durationFor in Service.qml, and docs/notifications.md). Low and normal get 5s / 8s, stretched up to 30s by expire_timeout. Closing for that reason, but I appreciate the careful write-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

notifications: critical-urgency toasts never expire and resurrect on every reboot

6 participants