Repository navigation
Resync the clock when the wall clock is stepped - #13347
ChaseC-130 wants to merge 7 commits into
Conversation
Automated AI review
Verified: For suspend and wall-clock steps, the change does what the description says. The stated cause matches Quickshell 0.3.1 and Qt 6.11.2 source: Headless Quickshell 0.3.1 run loading the PR's
|
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. resync() leaves a clock its owner has disabled alone. Enabling one is already a re-read, so there is nothing there to force, and writing the property would both start a clock that was deliberately stopped and — since assigning a property from JavaScript replaces any binding on it — take the binding that was holding it stopped. Neither clock in the tree binds enabled, so this changes nothing for them; it is the pattern the documentation hands to plugins that needed the guard, and the docs now say that resync() writes enabled at all. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016DKT4jSou6grTnSjV46BJv
51d4279 to
4ca1505
Compare
|
Useful review, thanks. Three points became changes, one a PR body fix, one is a maintainer call.
|
| mutant | at the head | now |
|---|---|---|
watchdog running: false |
survived | killed |
interval: 60000 |
survived | killed |
threshold: 0 |
survived | killed |
lastTick never reassigned |
survived | killed |
pragma Singleton removed |
survived | killed |
widget SystemClock id renamed |
survived | killed |
panel SystemClock id renamed |
survived | killed |
Plus one for the early return above, so a later cleanup cannot quietly restore the binding-stripping write.
Fixes #13275 -> Refs #13275 — changed in the PR body
Fair, and I should not have claimed it. #13275 is a Try Omarchy VM on an M2 with a bar clock "often incorrect, running slow and does not update for many minutes at a time" — no mention of suspend, no comparison against date. A paused or migrated VM does produce exactly this bug, CLOCK_MONOTONIC stopping while the guest's realtime is corrected behind it, so this is a plausible fix for it but not a confirmed one. Switched to Refs so merging leaves the issue open for the reporter.
Related open PRs #12277 / #9509 — maintainer call, no change here
The interaction is real. Worth adding that the approaches are not interchangeable: both of those hook a resume event, so an NTP step after a long time offline leaves the same stale clock with nothing to hook. This PR reacts to the step itself, whatever moved it. #10138 is my own, superseded by this one.
If one of those is preferred alongside this, the small version is for it to call Wallclock.resync() instead of Panel.refresh() while the panel is open — Wallclock is a qs.Commons singleton, so it is reachable from either path, and that keeps a browsed month put. Happy to rebase whichever way the maintainers want to go.
Automated AI review
Outcome: Follow-up at
#13275 looks like a wrong guest clock, not a stale barThe reporter has since shown Suggested change: Drop the #13275 reference and link #7608 and #13504, which match this PR's symptom. DetailsThe reporter's reply: #13275 (comment) ( Related PRs. All four are open and reach The reconciliation in the author reply (the other paths calling Verified:
Reproducer: resync and a bound enabledHeadless Quickshell 0.3.1 (Qt 6.11.2), offscreen platform, no compositor. Run from the root of a checkout; it copies that checkout's #!/bin/bash
# Run from the root of an omarchy checkout. Needs quickshell (0.3.1 here); no
# compositor: the platform is offscreen and nothing opens a window.
set -u
dir=$(mktemp -d)
cp -r shell/Commons "$dir/Commons"
cat > "$dir/shell.qml" <<'QML'
import QtQuick
import Quickshell
import qs.Commons
ShellRoot {
id: root
property bool paused: false // clock A: enabled bound to false
property bool shown: true // clock B: enabled bound to true
property bool wanted: false // clock D: disabled from the start
property int changesA: 0
property int changesB: 0
function out(key, value) { console.log("RESULT " + key + " " + JSON.stringify(value)) }
function hms(d) { return Qt.formatDateTime(d, "HH:mm:ss") }
SystemClock { id: clockA; precision: SystemClock.Seconds; enabled: root.paused; onDateChanged: root.changesA++ }
SystemClock { id: clockB; precision: SystemClock.Seconds; enabled: root.shown; onDateChanged: root.changesB++ }
SystemClock { id: clockD; precision: SystemClock.Seconds; enabled: root.wanted }
Timer {
interval: 2500
running: true
onTriggered: {
var a0 = root.changesA
Wallclock.resync(clockA)
root.out("A resync on enabled:false-bound clock", { enabled: clockA.enabled, dateChanged: root.changesA - a0 })
root.paused = true; root.out("A binding -> true", { enabled: clockA.enabled })
root.paused = false; root.out("A binding -> false", { enabled: clockA.enabled })
var b0 = root.changesB
Wallclock.resync(clockB)
root.out("B resync on enabled:true-bound clock", { enabled: clockB.enabled, dateChanged: root.changesB - b0 })
root.shown = false; root.out("B binding -> false", { enabled: clockB.enabled })
var whileDisabled = root.hms(clockD.date), now = root.hms(new Date())
root.wanted = true
root.out("D disabled clock", { readWhileDisabled: whileDisabled, now: now, readAfterEnable: root.hms(clockD.date) })
Qt.quit()
}
}
}
QML
QT_QPA_PLATFORM=offscreen timeout 30 quickshell -p "$dir" --no-color 2>&1 | grep RESULTAt the PR head At the previously reviewed head Clock A (paused through a binding) is left alone at the head and keeps its binding; at the previous head the resync started it and dropped the binding. Clock B (bound Optional test improvementOptional test improvement: Five small breakages still pass all 175 assertions: assert(/^import "WallclockMath\.js" as Detect$/m.test(wallclockCode), 'Wallclock imports the tested predicate')
assert(/^\s*signal jumped\(real deltaMs\)$/m.test(wallclockCode), 'Wallclock declares the signal the clocks listen for')
assert(/var elapsed = now - root\.lastTick\s*\n\s*root\.lastTick = now\s*\n\s*if \(Detect\.isDiscontinuity\(elapsed, root\.interval, root\.threshold\)\) root\.jumped\(elapsed\)/.test(wallclockCode), 'each tick measures from the previous one and reports a step')Reproducer: unpinned watchdog linesPR #13347 head Each of the five one-line edits below leaves the watchdog unable to report a step (or, for the negated predicate, makes it fire on every ordinary tick), and each still passes all 175 assertions. The second half adds three assertions in the test's own style; they pass on the unchanged head (178) and fail on each edit. #!/bin/bash
# Run from the root of an omarchy checkout at 4ca1505b (PR #13347 head).
# Breaks one line of Wallclock's watchdog at a time, runs clock-test.sh, and
# restores the file. Then adds three assertions and repeats.
set -u
tmp=$(mktemp -d)
wc=shell/Commons/Wallclock.qml
test=test/shell.d/clock-test.sh
cp "$wc" "$tmp/Wallclock.qml.orig"
cp "$test" "$tmp/clock-test.sh.orig"
check() {
bash "$test" >"$tmp/out" 2>&1
local status=$?
printf ' %-34s exit=%s ok=%s\n' "$1" "$status" "$(grep -c '^ok - ' "$tmp/out")"
}
mutate() {
local name=$1; shift
"$@"
if cmp -s "$wc" "$tmp/Wallclock.qml.orig"; then echo " $name: NOT APPLIED"; else check "$name"; fi
cp "$tmp/Wallclock.qml.orig" "$wc"
}
run_all() {
check 'unchanged'
mutate 'jumped never emitted' perl -pi -e 's/\) root\.jumped\(elapsed\)$/) console.log(elapsed)/' "$wc"
mutate 'predicate negated' perl -pi -e 's/if \(Detect\.isDiscontinuity\(/if (!Detect.isDiscontinuity(/' "$wc"
mutate 'baseline taken before subtracting' perl -0pi -e 's/( var elapsed = now - root\.lastTick\n)( root\.lastTick = now\n)/$2$1/' "$wc"
mutate 'WallclockMath import removed' perl -ni -e 'print unless /^import "WallclockMath\.js" as Detect$/' "$wc"
mutate 'jumped signal removed' perl -ni -e 'print unless /^ signal jumped\(real deltaMs\)$/' "$wc"
}
echo "clock-test.sh as in the PR:"
run_all
cat > "$tmp/extra.js" <<'JSX'
// The emit itself, and what it needs: without these, a watchdog that never
// raises `jumped` still passes every assertion above.
assert(/^import "WallclockMath\.js" as Detect$/m.test(wallclockCode), 'Wallclock imports the tested predicate')
assert(/^\s*signal jumped\(real deltaMs\)$/m.test(wallclockCode), 'Wallclock declares the signal the clocks listen for')
assert(/var elapsed = now - root\.lastTick\s*\n\s*root\.lastTick = now\s*\n\s*if \(Detect\.isDiscontinuity\(elapsed, root\.interval, root\.threshold\)\) root\.jumped\(elapsed\)/.test(wallclockCode), 'each tick measures from the previous one and reports a step')
JSX
awk -v f="$tmp/extra.js" '$0 == "JS" { while ((getline l < f) > 0) print l } { print }' "$tmp/clock-test.sh.orig" > "$test"
echo "clock-test.sh with the three assertions added:"
run_all
cp "$tmp/clock-test.sh.orig" "$test"Output (Node v26.7.0, bash 5.3): More findings:
|
quattro registered ShellIpc in shell/Commons/qmldir where this branch registers Wallclock; both registrations are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The wiring assertions checked that the predicate is called and that the baseline is updated, but not that the result raises `jumped`, nor that elapsed is measured before the baseline moves. Dropping the emit, negating the predicate, swapping those two lines, or removing the import or the signal each left every assertion passing while the bar stayed stale after a step; each now fails the test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Codex Medium <noreply@openai.com>
|
Reviewed and verified on a disposable VM built from the Omarchy ISO, running the shell from this branch. Reproduction. With NTP off, I stepped the wall clock forward ten minutes just after a minute turned. This creates the same gap between wall-clock time and Tests. Pushed to the branch:
Second opinion. Codex Medium reviewed the change in two rounds. It confirmed against Quickshell's source that toggling Issues. This fixes #13504 and #7608, the stale bar clock after resume, and is now linked to close them. #13275 is the VM guest clock itself running wrong, with Competing fixes. Four other open PRs fix the same bug: #12277 (logind Waiting on the maintainer to choose between this and #12277; only one of them should land. |
[Medium impact] The PR appears safe to merge; the remaining automated-test gap is non-blocking. Findings
SummaryAdds a shared watchdog that notices wall-clock jumps and refreshes the bar clock and calendar.
|
| assert(/singleton Wallclock 1\.0 Wallclock\.qml/.test(fs.readFileSync(root + '/shell/Commons/qmldir', 'utf8')), 'Wallclock is registered as a Commons singleton') | ||
| assert(/isDiscontinuity\(elapsed, root\.interval, root\.threshold\)/.test(wallclockCode), 'Wallclock reports a step using the tested predicate') | ||
| assert(/clock\.enabled = false\s*\n\s*clock\.enabled = true/.test(wallclockCode), 'Wallclock.resync toggles SystemClock off and back on to force a re-read') | ||
|
|
||
| assert(/target: Wallclock\s*\n\s*function onJumped\(\) \{ Wallclock\.resync\(clock\) \}/.test(widgetSource), 'clock widget resyncs when the wall clock steps') | ||
| assert(/target: Wallclock\s*\n\s*function onJumped\(\) \{ Wallclock\.resync\(clock\) \}/.test(panelCode), 'calendar panel resyncs when the wall clock steps') |
There was a problem hiding this comment.
Clock wiring lacks runtime coverage The new tests run the jump-detection calculation, but check the QML timer and resync wiring only by matching source text. A timer that never fires, or a clock that does not update after resync, could still pass. This is a non-blocking test gap; please add a QML test that runs the timer and checks that a jump updates a SystemClock.
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!
quattro's locale tests landed in clock-test.sh where this branch adds its Wallclock assertions, and both declare panelCode the same way; keep quattro's block, then the Wallclock assertions without the second declaration.
|
This branch stopped merging after Re-verified at be4e94a on a disposable VM built from the Omarchy ISO, running the shell from this branch. With NTP off, I stepped the wall clock forward ten minutes just after a minute turned and cropped the bar clock about every 1.5 s. On Tests. Second opinion. Codex Medium reviewed the merge. It found the conflict resolution loses no assertion from either side. It also found that both connections still reach the What it waits on. Same as before: #12277 fixes the same bug through logind's |
quattro's omacom#16334 removed the clock test's source-regex assertions, which conflicted with the Wallclock wiring assertions this branch appended after them. Resolved in the same spirit: the Wallclock source-regex assertions go too, and the six behavioural isDiscontinuity checks against WallclockMath.js stay.
|
The branch stopped merging after #16334 removed the source-text assertions from Re-verified at 20c89dc on a disposable VM built from the Omarchy ISO, running the shell from each tree. With NTP off, I stepped the wall clock forward ten minutes 2–4 s after a minute turned, then cropped the bar clock every 1.5 s for 19 s. On Tests. Second opinion. Codex Medium and muse-wonder (via pi, thinking high) reviewed the merge. Both found the conflict resolution loses nothing from A collision with #16684. That PR, the fix for the daylight-saving log flood, replaces both For the maintainer. |
omacom#16684 replaced SystemClock with a Timer-based WallClock, which has no enabled property, so Wallclock.resync returned early and both connections did nothing. WallClock now re-reads the time and re-arms from now when asked.
|
#16684 has merged, and as the last comment here expected, it left this fix doing nothing. It replaced both of the clock plugin's Re-verified at be1fdf7 on a disposable VM built from the Omarchy ISO, running the shell from each tree. With NTP off, I stepped the wall clock forward ten minutes 2 s after a minute turned, then cropped the bar clock every 1.5 s for 19 s. On Tests. Second opinion. Codex Medium and muse-wonder (via pi, thinking high) reviewed the merge and the new commit. Both found nothing lost from For the author. The description no longer matches the branch. It describes the plugin's clocks as For the maintainer. The choice from the last comment still stands, and this waits on it. |
|
No new commits here since be1fdf7, and the branch still merges cleanly onto today's A correction to the last comment. #12277 has been updated since. It now catches up through a new Competing fixes. Codex Medium compared the seven open fixes for #7608 (#9509, #10138, #12277, this one, #13541, #13804 and the new #18892) at their current heads, without being told which to prefer, and picked #12277. I checked its reasoning against the source and agree. #12277 is the older of the two that work on
Both differences are small, and neither is a defect that settles the choice. What happens next. This waits on the maintainer to choose between this and #12277: a once-a-second watchdog in the shell, or a shell-side |




Close a laptop lid and open it again, and the bar clock still reads the time the lid closed at (or the previous day if suspended overnight across midnight, such as showing Friday instead of Saturday).
datein 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.
Refs #13275 — a Try Omarchy VM whose bar clock is "often incorrect, running slow and does not update for many minutes at a time". A paused or migrated VM steps the guest's wall clock the same way a suspend does, so this is a plausible fix for that report, but the issue does not mention suspend or compare the bar against
date, so it is not referenced as closing.Supersedes #10138 (rebased on current
quattrowith documentation merge conflict resolved).Cause
SystemClockcomputes the delay to the top of the next minute from wall-clock time and arms aQTimerwith that relative delay (schedule()in Quickshell). Relative Qt timers are measured onCLOCK_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. An NTP correction after a long time offline steps the clock the same way.
Fix
Wallclock, aqs.Commonssingleton, watches for the wall-clock step and reports it.Wallclock.resync(clock)makes aSystemClockre-read the wall clock and reschedule from now — togglingenabledis the lever the type exposes for that. A clock its owner has disabled is left alone: enabling one is already a re-read, and writing the property would start a clock that was deliberately stopped and, since an assignment from JavaScript replaces a binding, take the binding that stopped it.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 becauserefresh()callsgoToToday(), and waking the machine is no reason to drag a calendar left open on another month back to this one.Testing
test/shell.d/clock-test.shpasses with all step-detection predicate and wiring assertions (175 checks).enabledkeeps the binding across a resync while disabled, and a disabledSystemClockre-reads the wall clock when it is enabled again.Wallclock's own wiring (running,interval,threshold, thelastTickupdate,pragma Singleton, and each clock's id) now fail the test; all seven passed it before.Fixes #13504
Fixes #7608