Skip to content

Resync the clock when the wall clock is stepped - #10138

Open
evindor wants to merge 2 commits into
omacom:quattrofrom
evindor:fix-clock-stale-after-resume
Open

evindor wants to merge 2 commits into
omacom:quattrofrom
evindor:fix-clock-stale-after-resume

Conversation

@evindor

@evindor evindor commented Sep 4, 2026

Copy link
Copy Markdown

Close a laptop lid and open it again, and the bar clock still reads the time the lid closed at. date in a terminal is correct the whole time.

It does correct itself — but not for up to a full minute, and most of that minute passes behind the lock screen, so what you actually see is a stale clock on the bar you unlock into.

Cause

SystemClock computes the delay to the top of the next minute from wall-clock time and arms a QTimer with that relative delay (schedule()). Relative Qt timers are measured on CLOCK_MONOTONIC, which does not advance while the machine is suspended.

So a clock with four seconds left to run when the lid closes still has four seconds left when it opens. How long the machine slept makes no difference — an eight-hour suspend and a ten-second one leave the same remainder to burn down. On the machine this was found on, CLOCK_BOOTTIME - CLOCK_MONOTONIC had reached 36.4 hours over a single boot: that is how much scheduling time every timer in the shell had lost.

An NTP correction after a long time offline steps the clock the same way and leaves the same gap. (A timezone change does not — it moves the offset, not the epoch — and omarchy-menu-timezone already refreshes the clock over IPC when it changes one.)

Quickshell has not fixed this upstream: #559 is this exact report, closed as user error, and #107 is open and stale. So the shell has to notice for itself.

Fix

Wallclock, a new qs.Commons singleton, watches for the step and reports it. Wallclock.resync(clock) makes a SystemClock re-read the wall clock and reschedule from now — toggling enabled is the only lever the type exposes for that.

Checking the wall clock when a timer fires is the cheaper move, and it is the one plugins/lock/Service.qml already makes before blanking a freshly woken screen: a countdown that spanned a suspend is discarded and re-armed, for no extra wakeups at all. That pattern does not transfer here, and the reason is worth stating plainly — SystemClock already implements it. setTime and schedule both fall back to the current time when the tick they were waiting for turns out to be more than 500ms stale, and that is exactly why the clock rights itself a minute after waking rather than staying wrong forever. It cannot do better, because the check only runs when the late tick finally arrives, and waiting for that tick is the whole bug.

So the check has to run on a schedule of its own. Nothing else will raise it: logind announces a resume on the system bus, but the shell has no D-Bus of its own, and a clock stepped by NTP announces nothing anywhere. The cost is one 1 Hz timer doing two subtractions and a compare — and one, not one per widget: each bar instantiates its own clock widget and calendar panel, which is what the singleton is for. It is also symmetric, unlike the lock service's one-sided check, so a clock stepped backwards is caught too.

Resyncing on unlock instead would be free and would cover the lid-close case, since the lock surface covers the bar for most of the stale minute. It was rejected because it cannot help a clock drawn on the lock screen itself — third-party lock clocks exist — and it misses both suspends that never locked and steps that happen while the session is in use.

The calendar panel resyncs too, though only a panel left open across a suspend that crossed midnight can reach it — open() already refreshes. It resyncs rather than refreshing because refresh() calls goToToday(), and waking the machine is no reason to drag a calendar left open on another month back to this one.

Third-party plugins that display a time have the same problem and can hook the same signal; docs/omarchy-shell.md says how.

Testing

  • ./test/shell passes. test/shell.d/clock-test.sh gains six Node assertions covering the detection predicate itself (on-time tick, tick running late under load, either side of the threshold, an eight-hour gap, a clock stepped backwards) plus wiring assertions, including one that pins the panel to resyncing rather than refreshing.
  • Verified in a live Quickshell instance running the same wiring shape as the bar widget: a stalled SystemClock keeps painting the pre-suspend time, no step is reported while time passes normally, a step is reported exactly once, and the label lands on the real wall-clock time.

The bar clock keeps showing the time the lid closed at for up to a
minute after it opens.

SystemClock schedules its next tick as the delay to the top of the next
minute, and delays are measured on CLOCK_MONOTONIC, which stops while
the machine is suspended. A clock with four seconds left to run when the
lid closes still has four seconds left when it opens. How long the
machine slept makes no difference — an eight-hour suspend and a
ten-second one leave the same remainder to burn down. Most of that
minute passes behind the lock screen; what is left of it lands on the
bar the user unlocks into. An NTP correction after a long time offline
steps the clock the same way.

Checking the wall clock when a timer fires is the cheaper fix, and it is
the one the lock service already makes before blanking a freshly woken
screen. It does not transfer here, because SystemClock already does it:
setTime and schedule both fall back to the current time when the tick
they were waiting for turns out to be stale, which is why the clock
rights itself a minute after waking rather than staying wrong. It cannot
do better, because that check only runs when the late tick arrives, and
waiting for the tick is the bug.

So Wallclock runs the check on a schedule of its own — nothing else will
raise it, as logind announces a resume on a bus the shell does not
speak and a stepped clock announces nothing anywhere — and resync()
makes a SystemClock re-read the wall clock and reschedule from now. One
timer rather than one per widget is what the singleton is for: every bar
instantiates its own clock widget and calendar panel.

The calendar panel resyncs too, though only a panel left open across a
suspend that crossed midnight can reach it: open() already refreshes.
It resyncs rather than refreshing because refresh() calls goToToday(),
and waking the machine is no reason to drag a calendar left open on
another month back to this one.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016DKT4jSou6grTnSjV46BJv
Resolves the conflict in docs/omarchy-shell.md by keeping both the new Wall-clock jumps section and quattro's Elsewhen section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and tested on a worker built from the Omarchy ISO. The fix works; what it waits on is the maintainer choosing between several open fixes for this bug, and a second opinion that could not run today.

Merge conflict resolved. This branch conflicted with quattro in docs/omarchy-shell.md. I merged quattro into it and kept both sections, the new Wall-clock jumps and quattro's Elsewhen. That merge, cb1f760, is pushed here. The fix itself is unchanged.

Reproduced, then fixed. On the worker I stepped the wall clock forward two hours, five seconds into a minute. That uses the same mechanism as a resume: SystemClock's deadline is still counting down on the monotonic clock while the wall clock has moved on.

  • On quattro (393a43d) the bar still read the old minute 5 and 15 seconds after the step.
  • With this branch linked as the running shell, it showed the new time within 5 seconds.
  • A two-hour step backwards was also corrected within 5 seconds.
  • Reverting the fix gives exactly quattro's tree, which is the run that failed.

An actual suspend could not be exercised: the QEMU worker did not wake from rtcwake.

Tests. test/shell.d/clock-test.sh passes 167 of 167. In the full shell suite, eight files fail on this head (ascii, base, branding-about-animation, kernel-headers-migration, network-captive-portal, omarchy-kernel-migration, passwordless-grant-lifecycle, video-background). The same eight fail on quattro and none of them touch the clock. test/cli matches quattro: 91 pass, and the same one vscode theme test fails on both.

Competing fixes. Several open pull requests fix the same bug, #13504:

This one is the oldest. Choosing between them is the maintainer's decision.

Second opinion: did not run. Codex Medium answered a ping, but its daily review quota was spent before it could review this pull request. Nothing here has been checked by a second model. The classification also could not be re-confirmed after the merge commit, so the issue link and the verified label wait for a run where it can.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Adds wall-clock step detection to the clock display.

The PR appears safe to merge, though the public resync helper should preserve clocks that callers have paused.

Findings

  1. P2 Resync restarts paused clocks ▶

Summary

The PR adds a shared wall-clock watchdog and connects the bar clock and calendar to it so they can resync after suspend or a clock step.

  • Registers Wallclock in qs.Commons and extracts its detection predicate for Node tests.
  • Documents the signal for third-party time plugins.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  T[Wallclock timer] --> D{Elapsed wall time differs from interval?}
  D -->|Yes| J[jumped signal]
  J --> B[Bar SystemClock resync]
  J --> P[Calendar SystemClock resync]
  B --> L[Update bar label]
  P --> C[Update today while preserving browsed month]
Loading

Reviews (1) · Last reviewed commit: "Merge quattro into fix-clock-stale-after..."

Comment on lines +53 to +56
function resync(clock) {
clock.enabled = false
clock.enabled = true
}

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 Resync restarts paused clocks

If a third-party plugin pauses its SystemClock with enabled: false and connects it to Wallclock.jumped as documented, resync() turns it back on after a clock jump. The paused clock then resumes ticking and sending updates when its owner expects it to stay stopped.

Suggested change
function resync(clock) {
clock.enabled = false
clock.enabled = true
}
function resync(clock) {
if (!clock.enabled) return
clock.enabled = false
clock.enabled = true
}

Knowledge Base Used: Shell UI and desktop interactions

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants