Skip to content

Catch the bar clock up when the system clock jumps - #13541

Open
stevederico wants to merge 7 commits into
omacom:quattrofrom
stevederico:fix/clock-stale-after-resume
Open

stevederico wants to merge 7 commits into
omacom:quattrofrom
stevederico:fix/clock-stale-after-resume

Conversation

@stevederico

@stevederico stevederico commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #13504

After a suspend, the bar clock keeps showing the time from before it for up to a minute. Quickshell's SystemClock waits out the rest of the minute on a timer that stops during sleep.

This adds a user timer, omarchy-clock-resync.timer, with OnClockChange=yes and OnTimezoneChange=yes. systemd waits on a TFD_TIMER_CANCEL_ON_SET timerfd for it, and the kernel cancels that timerfd whenever CLOCK_REALTIME jumps against CLOCK_MONOTONIC: timekeeping_resume() calls timerfd_resume(), which calls timerfd_clock_was_set(). So one timer covers a resume, an NTP step, timedatectl set-time and a timezone change, with no resident process and no polling. It runs omarchy-shell -q omarchy.clock resync, which re-enables the label's SystemClock and the calendar's. The calendar restarts its own clock instead of calling refresh(), so a month you are browsing stays put.

New installs enable the timer with the other user units, and a migration enables it for existing ones. Both link the two unit files from default/systemd/user/ into ~/.config/systemd/user (omarchy-audio-tuning also puts its unit there from default/), so the links follow the shipped files and never go stale.

Tested: clock-resync-test.sh, clock-test.sh and the bar widget contract fixture fail on quattro and pass here. systemd-analyze --user verify passes, and the timer goes active (waiting) with no countdown. With a shim that moves only the wall clock, the real widget caught up about 0.1s after the resync call. I did not set the system clock or suspend a real machine.

Related: #12277 refreshes on logind's PrepareForSleep(false) through a resident dbus-monitor; it misses clock steps and timezone changes, and its refresh() sends a browsed month back to today. #10138 checks the wall clock once a second from a new singleton (about one wakeup per second while idle); this adds no timer and reacts to the event itself.

@llstrk

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

Outcome: While the machine is awake, the new poll can put the label back to the previous minute for about 5 seconds.

The poll can undo SystemClock's minute tick

SystemClock's minute timer fires on a whole second of the monotonic clock, which is offset from wall-clock seconds, and it snaps to the minute when within 500 ms, so the label often turns up to half a second before the wall clock does. clockMinuteIsStale uses !==, so a poll in that gap sees the label as stale, and refresh() writes the previous minute back until the next poll. On Qt 6.11.2 with Quickshell's clock.cpp this repeated at every minute once the poll's timing lined up with the tick.

Suggested change: Treat a label less than 1 s ahead of now as current, or detect the wall-clock jump and restart SystemClock (enabled = false; enabled = true).

Reproducer (fails at 4309fba)

Reproducer: the catch-up poll can put the label back a minute

Reviewed head: 4309fba

1. Test case in the PR's style

Added to test/shell.d/clock-test.sh inside the run_node_test block (the
PR's own cases are unchanged):

// SystemClock's minute tick is a QTimer of 20 s or more, which Qt runs as a
// whole-second timer, and SystemClock snaps to the minute when the tick lands
// within 500 ms of it. So the label can turn up to half a second before the
// wall clock does. A poll in that gap must not roll it back.
assert(!calendar.clockMinuteIsStale(new Date(2026, 8, 27, 14, 6, 0), new Date(2026, 8, 27, 14, 5, 59, 700)), 'clock leaves a label SystemClock published just before the minute turned')

Actual output at the reviewed head (bash test/shell.d/clock-test.sh, exit 1):

not ok - clock leaves a label SystemClock published just before the minute turned

With clockMinuteIsStale returning true here, the Timer calls
root.refresh(), which sets displayDate = new Date(), a time that is still in
the previous minute.

2. Real Qt run

Setup: Qt 6.11.2, a headless QCoreApplication (no window). It uses Quickshell's
SystemClock (src/core/clock.cpp and clock.hpp from v0.3.1, unchanged) and a
QML object that copies the widget's displayDate, refresh(), SystemClock
handler and the PR's Timer with the PR's Model.js. Differences: logging, a
chosen Timer start time, no calendar panel, and a fixed minute format (HH:mm). CLOCK_MONOTONIC was offset in a
private time namespace so that monotonic minus wall time is 450 ms mod 1 s, one
possible state after any boot or resume. Times are in ms from the wall-clock
minute:

  -445  systemclock date=04:24:00.000      label=04:24
  -349  poll stale=true                    label=04:24
  -348  label-changed                      label=04:23
  -348  refresh                            label=04:23
 +4652  poll stale=true                    label=04:23
 +4652  label-changed                      label=04:24
 +4652  refresh                            label=04:24

The same sequence repeated at the next minute (−445 / −349 / +4652). The label
shows the previous minute until 4.65 s after the minute has changed.

A poll that fires in the same millisecond as SystemClock's tick, just after it
(Qt's coarse rounding moves both to the same whole monotonic second), does the
same thing:

  -445  systemclock date=04:24:00.000      label=04:24
  -445  poll stale=true                    label=04:24
  -445  label-changed                      label=04:23
 +4555  label-changed                      label=04:24

Controls from the same run:

  • SystemClock without the PR's Timer published the minute 390–394 ms early,
    with no rollback. The early tick is SystemClock's own behaviour, and it is
    harmless on its own.
  • The same poll timing with the helper changed to ignore a label that is less
    than 1 s ahead: poll stale=false, no rollback.
  • A poll 1.5 s after the tick: no rollback.

Sweep: at a 250 ms phase, 1 of 20 poll timings (250 ms steps across the 5 s
period) rolled the label back, at every minute boundary of the run
(3 of 3). The run ended before the third recovered; the other two were right
again 4756 ms after the minute. At a 750 ms phase,
SystemClock ticked about 252 ms late from the second minute on: 0 of 20 timings rolled back, and 1 of 20
caused an extra refresh().

More findings

The new tests pass with a broken helper or a disabled Timer

A helper comparing only getMinutes() passes, since no case has the same minute in another hour, and so does a commented-out Timer, because the wiring check reads the raw file instead of the comment-stripped widgetSource.

Suggested change: Add a same-minute, earlier-hour case and run the wiring regex against widgetSource.

Reproducer (mutants pass at 4309fba)

Reproducer: the new tests pass with a broken helper or a disabled Timer

Reviewed head: 4309fba. Each mutant is a
throwaway copy of the head. The test is the PR's test/shell.d/clock-test.sh,
unchanged.

Mutant 1: the helper compares only the minute of the hour

shell/plugins/panels/clock/Model.js:

function clockMinuteIsStale(shown, now) {
  return shown.getMinutes() !== now.getMinutes()
}

Result: bash test/shell.d/clock-test.sh exits 0 with every check ok, the
same 159 ok lines as the unmodified head. A label from 14:05 is then not
stale at 15:05:30, so a suspend of a whole number of hours (to within the
minute) would leave the old label up until SystemClock's delayed tick, up to a minute,
as before this PR.

This assertion catches it (it passes at the head):

assert(calendar.clockMinuteIsStale(new Date(2026, 8, 27, 14, 5, 0), new Date(2026, 8, 27, 15, 5, 30)), 'clock sees a label from the same minute of an earlier hour as stale')

On the mutant: not ok - clock sees a label from the same minute of an earlier hour as stale

Mutant 2: the whole catch-up Timer commented out

In shell/plugins/panels/clock/BarWidget.qml, each line from Timer { to its
closing } gets the prefix // .

Result: the PR's test still prints
ok - clock checks for a stale minute and refreshes the label and exits 0.
The new assertion reads BarWidget.qml raw (clockWidget) instead of the
file's widgetSource, which strips comment lines for this reason (lines 11–14
of the test).

The same regex run against widgetSource catches it (it passes at the head):

assert(/Timer \{[^}]*running: !root\.showsSeconds[^}]*clockMinuteIsStale\(root\.displayDate, new Date\(\)\)\) root\.refresh\(\)/.test(widgetSource), 'clock checks for a stale minute in live (uncommented) code')

On the mutant: not ok - clock checks for a stale minute in live (uncommented) code

Controls

  • Deleting the Timer outright fails the PR's test:
    not ok - clock checks for a stale minute and refreshes the label.
  • The PR's test run against the merge-base code fails with
    TypeError: calendar.clockMinuteIsStale is not a function, as the PR says.
  • Also not pinned: interval: 60000 passes the PR's test (minor).
Details

Verified

  • After a resume the poll corrects a stale label within one 5 s poll (from source; no real suspend was run).
  • The helper compares epoch minutes. Offsets were whole minutes in all 418 ICU zones on four 2026 dates, and a scan across DST changes in 9 zones (including +05:45 and Lord Howe's 30-minute shift) found no missed label change.
  • The PR's tests fail on the base code and pass at the head.

Optional notes

  • refresh() also calls the panel's goToToday(), so a calendar left open on another month jumps back to the current month after a resume in which the minute changed, and on a rolled-back minute (from source).
  • In Model.js, the new function sits between clockNeedsSeconds's doc comment and clockNeedsSeconds, which is now left without its comment.

Related open PRs: #12277, #13347 and #10138 fix the same problem in other ways and conflict with this PR in BarWidget.qml. #9509 and #13658 refresh the clock over IPC on wake; they touch other files.


Review information

Test scope: Source code, sandboxed node tests and a headless Qt harness running Quickshell's SystemClock, at 4309fba; not tested across a real suspend.

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.

@stevederico

Copy link
Copy Markdown
Contributor Author

Thanks, confirmed with your test: it failed on 4309fba. Fixed in 06501d1: a label less than a second ahead of now counts as current, and a label further ahead (wall clock set back) still refreshes. Added your case, plus a set-back case, to clock-test.sh.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 06501d1 by Claude Opus 5.5, with Codex at medium effort as a second opinion. Five other open pull requests fix the same bug as this one (#13504) in different ways: #12277, #13347, #10138, #9509 and #13658. Codex was asked which of the six is best without being given my answer. It ranked #13347 first and #12277 third, ahead of this one. I agree that this one should not be the fix that goes forward, though Codex may have read my reasoning, so its agreement is not a fully independent check.

What I found, checked against the source:

  • The poll repairs the label but not the clock. refresh() only sets displayDate. SystemClock's own timer still waits out the minute it was counting down before the suspend. It catches up on its own after that, but Catch the bar clock up when the machine wakes from suspend #12277 and Resync the clock when the wall clock is stepped #13347 fix it at the cause by restarting the clock (enabled = false; enabled = true), which also re-arms the next minute.
  • A catch-up can reset the calendar's month. refresh() in BarWidget.qml also calls the panel's refresh(), which runs goToToday() (Panel.qml:128-131). So a user browsing another month in the open calendar gets sent back to today on every wake. The same happens on an ordinary minute boundary when SystemClock ticks slightly late and the 5-second poll gets there first. The panel's own onDateChanged deliberately keeps a browsed month.
  • What it does well: it needs no extra process and no IPC. It covers every wake path and a wall clock set forward or back. Since 06501d1, clockMinuteIsStale also no longer rolls back a minute that SystemClock publishes early.

I ran nothing on a worker. That would only spend a worker proving a fix that is not the one going forward. Codex ran the clock tests in its read-only checkout, and they passed.

This now waits on the maintainer to choose between the competing fixes. #12277 is already labelled ready; #13347 is the one Codex ranked first.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; only the earlier non-blocking Markdown formatting finding remains.

Findings

  1. P2 Markdown uses hard wraps ▶

Summary

Adds a user timer that asks the bar clock to catch up after suspend, clock jumps, or timezone changes.

  • The bar clock catches up after system time changes.

Reviews (8) · Last reviewed commit: "Catch WallClock up on resync instead of ..." · Reviewed by Greptile

Comment thread test/shell.d/clock-test.sh Resolved
@omarchybot

Copy link
Copy Markdown
Collaborator

Looked at again at c6de2c0, by Claude Opus 5.5 with Codex Medium as the second opinion.

The two findings from the last review are fixed. I checked both against the source. resyncClock() now restarts the widget's SystemClock (enabled = false; enabled = true), so the next tick is scheduled from the current time. Before, the old countdown kept running. The calendar's catch-up goes through its own clock and onDateChanged (Panel.qml:243-248). That handler only goes back to today when the calendar was already showing the current month, so a month the user is browsing stays put. Codex read the diff and found no defects.

Competing fixes. This one still does not go forward. That is not because of a defect in it. An older fix now does the same thing: #10138 (opened September 4) also restarts both clocks from the current time, catches every resume without depending on unlock, and keeps a browsed month. It does this with a one-second wall-clock check. The rule for competing fixes is that the oldest wins unless a newer one is clearly better. This one adds two things: it also catches wall-clock steps shorter than #10138's three-second threshold, and it adds no new singleton. Neither is a case where #10138 leaves the bug unfixed. I asked Codex to compare all seven open fixes for #13504 without giving it my answer, and it reached the same conclusion for the same reason. It may have read my reasoning, so its agreement is not a fully independent check.

I did not run this branch on a worker, because that would spend a worker proving a fix that is not the one going forward. Codex ran clock-test.sh in its read-only checkout, and it passed.

Next. This waits on the maintainer to choose among the competing fixes for #13504. #12277 already carries ready, #13347 is a later copy of #10138, and #10138 is the oldest of the fixes that restart the clock.

@stevederico
stevederico force-pushed the fix/clock-stale-after-resume branch from c6de2c0 to 819855c Compare October 18, 2026 22:21
@stevederico stevederico changed the title Catch the bar clock up after a suspend Catch the bar clock up when the system clock jumps Oct 18, 2026
@stevederico
stevederico force-pushed the fix/clock-stale-after-resume branch from 819855c to 8b686fb Compare October 18, 2026 22:23
Comment thread test/shell.d/clock-resync-test.sh Resolved
@omarchybot omarchybot removed the bug Something isn't working label Oct 18, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Looked at this again at 8b686fb, where it takes a new approach: a user timer with OnClockChange=yes and OnTimezoneChange=yes runs omarchy-shell -q omarchy.clock resync, which restarts the label's and the calendar's SystemClock, with a migration and the first-run script enabling the timer. The classification at this head is unsettled, so the bug label is off and nothing was run on a worker.

Two models classified it separately: Claude Opus 5.5 read it as bug, since it fixes the label and the calendar keeping the time from before a suspend for up to a minute (#13504). Codex Medium read it as enhancement, and the diff gives it grounds: the fix arrives as new machinery, a user timer and service, a new resync IPC method on omarchy.clock, and a migration, and it also reacts to NTP steps, timedatectl set-time and timezone changes, which go beyond the reported bug.

One thing stands regardless of the classification: #10138, #12277, #13347, #9509 and #13658 are still open and fix the same bug in other ways, so which one goes forward remains the maintainer's choice. The comparison among them was not re-run at this head, since an unsettled classification stops the review here.

This waits on the maintainer to decide what it is.

@stevederico
stevederico force-pushed the fix/clock-stale-after-resume branch from 8b686fb to 500c04f Compare October 29, 2026 16:59
Comment thread test/shell.d/clock-resync-test.sh Resolved
Comment thread test/shell.d/clock-resync-test.sh Resolved
Comment thread docs/file-layout.md Outdated
Comment on lines +338 to +339
`omarchy-crash-watch.service`, `omarchy-clock-resync.timer`) so they run in the
first session too.

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.

P2 Markdown uses hard wraps

The added text in file-layout.md splits a sentence across lines. The Markdown style instruction requires full lines, with breaks only at structural boundaries. Join the changed sentence before merging to meet that requirement.

Suggested change
`omarchy-crash-watch.service`, `omarchy-clock-resync.timer`) so they run in the
first session too.
`omarchy-crash-watch.service`, `omarchy-clock-resync.timer`) so they run in the first session too.

File Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@stevederico
stevederico force-pushed the fix/clock-stale-after-resume branch from 500c04f to d2b447e Compare October 30, 2026 15:55
@omarchybot omarchybot added the bug Something isn't working label Nov 2, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Looked at this again at d2b447e, by Claude Opus 5.5 with Codex Medium as the second opinion. Both models classified it separately as bug this time, so the bug label is back on. It fixes the clock staying on the pre-suspend time for up to a minute, which #7608 tracks (#13504 was closed as its duplicate).

The approach holds up from the source. Codex read the units, the migration, the first-run change and the QML resync and found no correctness problem. It also checked the mechanism against the kernel and systemd sources: timekeeping_resume() reaches timerfd_clock_was_set(), so a resume does fire an OnClockChange=yes timer. The resync restarts both SystemClocks, and the calendar keeps a browsed month. I agree with that reading. Nothing was run on a worker, for the reason below.

Which fix goes forward is still the maintainer's call, and this time the two models disagree. Six fixes for this bug are open: #9509, #10138, #12277, #13347, this one and #13804. The rule here is that the oldest wins unless a newer one fixes a case the older one misses. I asked Codex to rank all six without giving it my answer.

#12277 already carries ready and #13347 is verified, so this one does not get ready. If two fixes for one bug both carried ready, merging one would leave the other conflicting.

This waits on the maintainer to choose among the open fixes for #7608.

SystemClock waits out the rest of the minute on a timer that stops while
the machine sleeps, so after a wake the label and the calendar's today
kept the time from before it for up to a minute (omacom#13504).

Add an omarchy.clock resync IPC method that re-enables the label's
SystemClock and the calendar's. A re-enabled SystemClock re-reads the
time and schedules its next tick from now, and onDateChanged puts the
result on screen. The calendar restarts its own clock rather than going
through refresh(), so a month the user is browsing stays put.
A user timer with OnClockChange=yes and OnTimezoneChange=yes starts a
oneshot that runs omarchy-shell -q omarchy.clock resync. systemd waits on
a TFD_TIMER_CANCEL_ON_SET timerfd for it, so nothing resident and nothing
polling. The kernel cancels that timerfd when CLOCK_REALTIME jumps against
CLOCK_MONOTONIC, which a resume from suspend does as well as an NTP step
or timedatectl set-time, so one timer covers all of them.

New installs enable the timer with the other user units, and a migration
enables it for existing ones. Both link the units from default/ into
~/.config/systemd/user, so they follow the shipped files.

Fixes omacom#13504
@stevederico
stevederico force-pushed the fix/clock-stale-after-resume branch from d2b447e to 8e70643 Compare November 21, 2026 19:02
@omarchybot

Copy link
Copy Markdown
Collaborator

Read the updated diff, clock implementation, tests, existing reviews and linked reports at 8e7064391e6830379eed8d22f3625589beee3bbc. GPT-6 in Codex (effort setting unavailable) classifies this as a bug fix, but the configured second classifier, deepseek-v4p1-flash (effort setting unavailable), returned no class. Classification is therefore unsettled at this head, and this pass stops before testing or pushing changes. No second code review ran in this pass; the general reviewers answered their availability check.

The source also confirms the two API mismatches Greptile reported: BarWidget.qml:49 and Panel.qml:127 assign clock.enabled, while both clocks now use the Timer-based WallClock, which has no such property. The widget fixture at line 77 still searches for precision and enabled. The catch-up methods and fixture need adapting to WallClock before verification.

No worker tests ran, and nothing was pushed or marked verified. This waits for classification to be settled; the choice among the competing clock fixes also remains with the maintainer.

@omarchybot omarchybot removed the bug Something isn't working label Nov 21, 2026
@stevederico

Copy link
Copy Markdown
Contributor Author

@omarchybot The second classifier (deepseek-v4p1-flash) returned no class, and your own call is bug. Please classify again. After a suspend the bar clock keeps showing the pre-sleep time for up to a minute (#13504), so the clock is wrong right when you open the lid. Classification: bug.

@omarchybot

Copy link
Copy Markdown
Collaborator

Read the updated commit at e8702b9d02ae79c4499dd17068b3f41378726508, the full diff, existing reviews and linked reports. The two API mismatches from the previous review are fixed in the source: both widgets call WallClock.resync(), which reads the current date and re-arms the timer, and the widget fixture now finds the actual WallClock objects.

GPT-6 in Codex (effort setting unavailable) again classifies this as a bug fix. The configured second classifier, deepseek-v4p1-flash (effort setting unavailable), again returned no class, leaving classification unsettled at this head. The queue procedure requires this pass to stop there. No second code review or worker tests ran, and nothing was pushed or marked verified. This waits for classification to be settled.

@omarchybot omarchybot added the bug Something isn't working label Nov 26, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Classification is now agreed as bug, and the label is back on. While this pass was comparing the fixes, #20255 merged into quattro at 0f240028bab0c8e78588fec43c610c57fcdbf1c6. Comparing both diffs and the merged tree shows that this PR’s bar, calendar, WallClock.resync() and resync service are byte-for-byte identical to what landed. The timer has the same settings; only its comment differs.

The merged version enables the timer at first run and replaces this PR’s user-level unit links with packaged units and migration 1795692660.sh. The packaging change, omacom/omarchy-pkgs#3621, has also merged; package publication was not checked here. The merged widget fixture includes this PR’s checks plus a guard for the resync method. No additional clock behavior or useful test needs carrying over from this head.

GPT-6 in Codex (effort setting unavailable) checked the source comparison. Opus 5.5 High and muse-wonder via pi, thinking high reviewed it and agreed that no code change remains here; independence from the first review is not guaranteed. No worker or runtime tests ran in this pass, and nothing was pushed or marked verified. Thank you, @stevederico, for the fix carried into #20255. This remains open for the maintainer to close or retain.

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.

Bar clock shows pre-suspend time for up to a minute after resume

3 participants