Skip to content

notifications: honor expireTimeout for critical alerts - #13100

Closed
surim0n wants to merge 2 commits into
omacom:quattrofrom
surim0n:fix/critical-notifications
Closed

surim0n wants to merge 2 commits into
omacom:quattrofrom
surim0n:fix/critical-notifications

Conversation

@surim0n

@surim0n surim0n commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • durationFor() mapped NotificationUrgency.Critical to duration 0 unconditionally, discarding the sender's expireTimeout
  • A critical toast that asked for a finite timeout (e.g. omarchy battery low, which sends -u critical -t 30000) never expired on screen, its state file was never archived, and restorePopups() re-showed it with a fresh lifetime on every shell restart, indefinitely
  • The sender asked for a timeout, so honour it. This also restores the behaviour under the earlier mako setup, where a positive timeout on a critical notification was respected and the default-timeout=0 rule only applied when none was given
  • Critical alerts sent without a timeout (-1 or 0) still never expire and are still restored across restarts
  • A timed critical toast is floored at the normal duration and capped at maxPopupDuration, so it is never the shortest-lived toast on screen

Fixes #12911

Test plan

  • bash test/shell.d/notifications-test.sh passes, including the new critical-branch assertion
  • Repro from the issue: omarchy notification send -u critical -t 30000 "Repro" "critical + 30s timeout", restart shell, confirm the toast expires instead of resurrecting

The freedesktop spec says expireTimeout == 0 means "never expire", but
a non-zero value should be honored regardless of urgency. The service
mapped critical to duration 0 unconditionally, so a sender that asked
for a finite timeout (e.g. `omarchy battery low` with `-t 30000`) got an
immortal toast that survived every restart until manually dismissed.

Critical alerts still never expire when the sender passes timeout 0.

Fixes omacom#12911
@llstrk

llstrk commented Sep 25, 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: the change fixes #12911 and no correctness defect was found in the reviewed scope. A critical notification with a positive expireTimeout now gets a finite duration (capped at 30 s). The same durationFor() value drives both the on-screen countdown and the popupExpired() check in restorePopups(). So the issue's persisted battery toast (critical, expireTimeout 30000, 18 h old) is archived on the next restore instead of reappearing. Toast files left stuck by the old code are cleared the same way on the first restore after the change.

Verified: critical alerts sent without a timeout (-1, the omarchy-notification-send default, or 0) still never expire and are still restored across restarts. Low and normal durations, Do Not Disturb handling, history replay (historyEntry forces expireTimeout: 0) and in-place updates are unchanged.

Only the in-repo critical senders that pass -t change behavior:

Sender Request Before After
bin/omarchy-battery-low -t 30000 until dismissed 30 s
bin/omarchy-capture-screenrecording (lines 26, 79) -t 3000 until dismissed 3 s
bin/omarchy-capture-screenrecording (line 234) -t 5000 until dismissed 5 s
bin/omarchy-capture-screenrecording-with-webcam -t 3000 until dismissed 3 s

The battery warning is sent once per discharge, so an unattended one now leaves the screen after 30 s and stays in history. If that warning should stay on screen, the lever is the sender's -t 30000, not durationFor().

Short critical timeouts are now the shortest-lived toasts

durationFor() floors low and normal requests but not critical ones:

durationFor(urgency, 3000) at this head
  Low       -> 5000 ms   (floor 5000)
  Normal    -> 8000 ms   (floor 8000)
  Critical  -> 3000 ms   (no floor)

The screen-recording errors ("Screen recording directory does not exist", "No webcam devices found", "Recording process had to be force-killed. Video may be corrupted.") therefore show for 3 to 5 s, shorter than a low-urgency toast with the same request. docs/notifications.md promises at least 5 s (low) and 8 s (normal).

Impact: visibility only. Hovering pauses the countdown and the toasts still reach history. The same senders passed -t 3000 under the earlier mako setup (before c101591), where mako honored a positive timeout on critical notifications. So a 3 s critical error matches that earlier behavior.

Suggested change: decide which behavior is intended. To keep critical alerts at least as visible as normal ones, floor positive critical requests the way normal ones are floored:

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

Otherwise, keep the pass-through and document that explicitly timed critical toasts use the sender's timeout as given.

Documentation: docs/notifications.md (Toast lifecycle) still says toasts live "forever (critical)". The comment above popupExpired() in NotificationLogic.js ("duration 0 means the popup never expires (critical urgency)") and the test label 'critical popups never expire on restore' in test/shell.d/notifications-test.sh now apply only to critical alerts without a timeout.

Rationale wording: the PR description says the freedesktop spec requires honoring a non-zero timeout "regardless of urgency". Specification 1.3's urgency section says critical notifications "should not automatically expire", so the previous critical-means-0 rule was not a spec violation. The firmer basis for the change is the explicit sender request, and that it restores the stock mako behavior from before c101591: mako honored a positive timeout on critical notifications, and [urgency=critical] default-timeout=0 applied only when no timeout was given.

Optional test improvement: the new assertion is a regex over the Service.qml source. It fails on the base code and passes at head. It still matches if requested is forced to 0, which reintroduces the bug, and it rejects a behavior-identical rewrite. It also never exercises the restore path where #12911 shows up. NotificationLogic.js already takes urgency enum values as parameters (shouldBypassDnd, serializePopup). Moving the duration policy there would allow a behavioral test: critical 30000 gives 30000, critical 0/-1 gives 0, critical 60000 gives 30000, and popupExpired() returns true for the issue's persisted entry 18 h later.


Review information

Test scope: Source review of the notification service, NotificationLogic.js, in-repo critical senders and docs at the PR head versus its merge-base. Upstream sources read: Quickshell v0.2.1 and v0.3.1 (the D-Bus timeout is passed through in milliseconds), the Desktop Notifications Specification 1.3, libnotify 0.8.7 and mako v1.11.0. In an isolated sandbox, test/shell.d/notifications-test.sh passed at head, passed at base, and failed only at the new assertion when the head test ran over the base code. It ran under Deno's Node compatibility because Node was not available. A behavioral harness evaluated durationFor() extracted verbatim, the unmodified NotificationLogic.js and a JavaScript mirror of the restorePopups() decision: 302 of 302 source-derived predictions matched. The live shell was not run: the on-screen countdown, NotificationClosed signalling and archiving after a real restart were not observed.

AI process: Opus 5.5 Medium coordination and synthesis; independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, with a targeted follow-up to confirm points only one of them had established; Opus 5.5 Medium editorial check.

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

@surim0n

surim0n commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, in 2d19a2e timed critical toasts are floored at the normal duration, so they are never the shortest-lived toast. Updated docs/notifications.md, the popupExpired comment and the test label to say untimed critical alerts are the ones that never expire. Description reworded per your note: the basis is the sender's explicit request and parity with the earlier mako behaviour, not a spec violation.

@llstrk

llstrk commented Sep 27, 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.

Follow-up to the earlier review (at 6b95224) and the author's reply, checked at head 2d19a2e.

Verified: 2d19a2e and the edited PR description resolve the short-critical-timeout finding, the stale documentation and the PR description's spec rationale. The optional test improvement still applies. No regression from 2d19a2e was found, and the #12911 fix still holds: the issue's persisted battery toast (critical, 30000 ms, 18 h old) is archived on restore.

Earlier note Status at 2d19a2e
Short critical timeouts are the shortest-lived toasts Resolved
Documentation (docs/notifications.md, popupExpired() comment, test label) Resolved
Rationale wording in the PR description Resolved
Optional test improvement (source regex) Still applies

Verified, short critical timeouts: the critical branch of durationFor() now uses the suggested floor:

durationFor(Critical, requested) at 2d19a2e1
  1 .. 7999 ms   -> 8000 ms   (normal floor)
  8000 .. 29999  -> as requested
  >= 30000       -> 30000 ms  (cap)
  -1, 0          -> 0         (until dismissed, unchanged)

Low and normal results are identical at base, the earlier head and this head.

Correction to the earlier sender table: the three screen-recording rows no longer hold. bin/omarchy-capture-screenrecording (lines 26, 79 and 234) and bin/omarchy-capture-screenrecording-with-webcam request 3000 or 5000 ms and now show for 8 s, not 3 or 5 s. The bin/omarchy-battery-low row (30 s) still holds. The earlier remark that a 3 s critical error "matches that earlier behavior" also no longer holds: under mako those errors showed for 3 s. Parity with mako now covers requests from 8 to 30 s, and the PR description states the floor and the cap.

Verified, documentation: docs/notifications.md (Toast lifecycle), the comment above popupExpired() and the test label now limit "never expires" to critical alerts sent without a timeout, matching the code.

Verified, rationale: the PR description now rests on the sender's explicit request and the earlier mako behavior, with no spec-violation claim. The message of commit 6b95224 still presents honoring a non-zero timeout "regardless of urgency" as what the freedesktop spec says. That sentence enters history if the commit is merged as is.

Optional test improvement (still applies): the updated assertion is still a regex over the Service.qml source. It fails on the base and earlier-head code, so it pins the new expression. It still passes when requested is forced to 0, which brings #12911 back, and when restorePopups() is given duration 0. It fails a behavior-identical rewrite of the expression. Moving the duration policy into NotificationLogic.js, as suggested earlier, would allow behavioral tests (for example critical 3000 gives 8000, 30000 gives 30000, 0/-1 gives 0, 60000 gives 30000, and popupExpired() is true for the issue's 18 h old entry). Those would catch the forced-zero case and accept equivalent rewrites. The restorePopups() call site would still need its own check.

Related open PRs: #12964, #13041, #13159, #13161 and #8675 also edit the critical branch of durationFor(), so they will conflict with this PR. In #13159, critical alerts from omarchy-action keep lifetime 0. omarchy-action is the default app name of omarchy-notification-send, which omarchy-battery-low uses, so resolving the conflict toward #13159 would make the battery toast permanent again. #12964 and #13041 pass short critical timeouts through without the 8 s floor. #13161 moves the policy into NotificationLogic.js, where this PR's source regex would no longer match.

Narrower earlier statement, in-place updates: the earlier review listed in-place updates as unchanged. One narrow case changed from the first commit on. A replaces_id update that keeps the summary, body and image but raises urgency to a timed critical now inherits the remaining fraction of the old countdown. For example, a normal toast with about 100 ms left, updated to critical -t 30000, closes about 400 ms later. At base it stayed until dismissed. Low and normal updates already rescale this way at base. The only in-repo replaces_id sender, bin/omarchy-display-text-size, sends low urgency without a timeout, so it never hits this case.


Review information

Test scope: Source review of the incremental and full diff at 2d19a2e, the notification service, NotificationLogic.js, the in-repo critical senders, the docs, the related open PRs, the freedesktop specification 1.3, Quickshell v0.3.1 and mako v1.11.0. In an isolated sandbox with Node, test/shell.d/notifications-test.sh passed at head. The head test failed only its new assertion on the base and earlier-head code. Mutation runs covered forced-zero requested, a zero restore duration and an equivalent rewrite. A harness ran durationFor(), requestedDuration() and restorePopups() verbatim from each revision, with the real NotificationLogic.js: 835 checks, 0 mismatches against predictions. A second harness modeled history replay and the card's countdown on in-place updates. The live shell, the QML engine and D-Bus were not run, so the on-screen countdown, hover pause and close signalling were not observed.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

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

@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
cursor Bot pushed a commit to AnPod/omarchy that referenced this pull request Sep 29, 2026
Critical toasts always used duration 0, so senders like omarchy-battery-low
(-t 30000) never expired and were restored forever. Keep untimed critical
immortal; honour a positive expireTimeout (omacom#13100).

Co-authored-by: AnPod <AnPod@users.noreply.github.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 2d19a2e. The bug is real and still present on current quattro: 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 (#12911). This change fixes that, and critical notifications sent without a timeout still stay until dismissed.

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

Two things separate this pull request from #12964:

Claude Opus 5.5 and Codex Medium each judged #12964 the one to carry forward. Codex Medium was asked separately and without Claude's answer, but its independence from this review is not guaranteed. Both noted that this pull request has one thing #12964 lacks. docs/notifications.md and the comment above popupExpired() here correctly say that only untimed critical toasts last forever, while #12964 still says critical toasts last forever.

This waits on the maintainer. If the 8s floor is what they want, this pull request is the better match, but it would need a test that calls the duration logic itself instead of matching the source text. Otherwise #12964 needs this pull request's documentation change, and the rest can be closed.

@aholbreich

Copy link
Copy Markdown
Contributor

Thanks @surim0n, this fixes #12911 and the documentation wording is useful. We compared the five direct candidates on current quattro. #12964 is older, and its tests run the real duration helper and the restore expiry: putting back an early "critical is always sticky" return makes #12964's suite fail, while this branch's source-regex test still passes. We've recommended #12964 to the maintainers, with your docs wording carried into the merge and credited to you, so this one would close as a duplicate when it lands.

omarchybot added a commit to kvnloo/omarchy that referenced this pull request Oct 9, 2026
The docs, the popupExpired comment and a test label still said every critical toast stays until dismissed, which stopped being true when a sender's timeout began to be honoured. Wording from omacom#13100.

Co-Authored-By: surim0n <suritech@gmail.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ryanrhughes

Copy link
Copy Markdown
Collaborator

Thanks @surim0n! 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

5 participants