Skip to content

Treat idle timeout 0 as disabled, not immediate - #12538

Merged
dhh merged 4 commits into
omacom:quattrofrom
paulogeyer:fix/10860-idle-timeout-zero
Oct 4, 2026
Merged

dhh merged 4 commits into
omacom:quattrofrom
paulogeyer:fix/10860-idle-timeout-zero

Conversation

@paulogeyer

@paulogeyer paulogeyer commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Setting idle.screensaver / idle.lock to 0 ("disabled") still fed 0 into Math.min(), so IdleMonitor's timeout became 0.
  • Releasing a Wayland idle inhibitor (e.g. SDL's default screensaver inhibit on app exit) then reported idle immediately and locked the session.
  • Treat 0 as disabled when picking the first idle deadline; don't start that action; leave IdleMonitor off if both timeouts are 0.

Fixes #10860

Test plan

  • bash test/shell.d/idle-test.sh (stock fail → patch pass)
  • Local verify: research/pr-verify/10860.md on the bughunt machine

Fixes #7178

idle.screensaver / idle.lock of 0 was included in Math.min(), so
IdleMonitor's timeout became 0. Releasing a Wayland idle inhibitor
(SDL's default screensaver inhibit) then reported idle immediately and
locked the session even when lock had been "disabled" by setting it to 0.

Treat 0 as disabled when computing the first idle deadline, do not start
the corresponding action, and leave IdleMonitor off when both timeouts
are 0.

Fixes omacom#10860
@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 addresses the root cause of #10860. On the base, Math.min(screensaver, lock) passed a 0 s timeout to IdleMonitor. Quickshell forwards that as a 0 ms ext-idle-notify-v1 notification, and Hyprland 0.56.2 reports idle at once for a 0 ms notification whenever no inhibitor is active. When an SDL app released its inhibitor on exit, the service ran a zero-delay idle cycle and lock-timeout-immediate, which matches the journal in the issue. With this PR, a 0 value turns that action off. Positive timeouts behave as before.

Config (screensaver/lock) Base This PR
0/0 locks at shell start and on inhibitor release monitor off, no screensaver, no lock
150/0 locks on inhibitor release screensaver at 150 s, never locks
0/300 screensaver at once on inhibitor release lock at 300 s, no screensaver
150/300 and other positive pairs unchanged identical to base

One remaining edge case: the new "0 means off" rule applies when an idle cycle starts, but not to a cycle that is already running.

Changing timeouts during a running idle cycle can lock early

lockTimer.interval is bound to lockDelaySeconds (Service.qml:275). When a running Qt Timer gets a new interval, it restarts with that interval. If shell.json changes while the screensaver is showing and a lock is pending, the lock time is recomputed from the moment of the edit:

Start 150/300. Idle 150 s, screensaver shows, lockTimer pending (150 s left).
Edit shell.json while still idle:

edit                 base                            this PR
screensaver -> 0     firstIdle 0,   lockDelay 300    firstIdle 300, lockDelay 0
(lock stays 300)     lock 300 s after the edit       lock at the edit (before the configured 300 s)
lock -> 0            lockDelay 0 -> locks at once    lockDelay 0 -> locks at once
                                                     (onTriggered does not check lockEnabled)

The first row is new with this PR. The second row behaved the same on the base, but now contradicts the intent stated in this PR: a 0 lock timeout should mean no lock. If both values become 0 during a cycle, handleIdleChanged() returns early and does not cancel the pending timer, so the lock still fires.

Impact: an unexpected immediate lock, but only when shell.json is changed while the machine is already idle with the screensaver up, for example by a script, a dotfile sync or a remote session. The normal and reported cases are not affected. If the screensaver window is gone when the edit lands, the cycle is cancelled and the early lock does not occur.

Suggested change: fix the lock delay when the cycle starts, and check that the lock is still enabled when the timer fires:

// startIdleCycle(), lock branch
else {
  lockTimer.interval = root.lockDelaySeconds * 1000
  lockTimer.restart()
}

// Timer: static interval instead of the live binding
onTriggered: if (root.idleEnabled && root.idledThisCycle && root.lockEnabled) root.lockSystem("lock-timeout")

In a QML test harness, this variant locked at the configured deadline in the first case, did not lock in the second, and normal timed locks still fired. The trade-off is that timing edits made during a cycle take effect from the next cycle. Another option is to cancel and restart the cycle when the timeouts change. A lockEnabled check on its own fixes only the second row.

Optional test improvement: the new Service.qml assertions match source text. Deleting the if (root.screensaverEnabled) guard still passes all 20 checks, even though that guard is what prevents a screensaver at the lock deadline with a 0/300 config. Moving the per-action decision (monitor enabled, monitor timeout, per-action delay or off) into a pure IdleModel.js function would let the test cover both guards directly.

Documentation: the manual (manual/13-toggles-idle-screensaver.md), docs/omarchy-shell.md and shell/README.md do not say that 0 turns an action off. Because secondsFromConfig() floors values, null, false, "" and values below 1 (for example 0.5) now also count as off. A sentence in the manual would make the new behavior discoverable.


Review information

Test scope: Source review of the PR at 14921a9 against its base, plus the Quickshell IdleMonitor source and Hyprland 0.56.2 IdleNotify source. The repository idle test ran in an isolated sandbox. The real base and PR Service.qml ran in Qt's QML test runner with real Qt timers. The Quickshell modules were stubbed, and the compositor's idle notifications were simulated from the cited source. Timing results came from shortened timeouts. No live Hyprland session or SDL reproduction was run.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments with targeted follow-up questions, 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
omarchybot and others added 2 commits October 1, 2026 11:29
The timers' intervals are bound to the configured delays, so setting the lock or screensaver to 0 while the screensaver is up turns a pending timer's interval to 0 and it fires at once. Check the action is still enabled when its timer fires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With 0 meaning off, setting the screensaver to 0 while the screensaver is up moves the first idle deadline to the lock's, which turns the pending lock's bound interval to 0 and locks at once, minutes early. Set each timer's interval when the cycle starts, so a change to shell.json takes effect from the next cycle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Changes idle timeout logic for screensaver and lock.

The PR does not appear ready to merge because re-enabling lock during an active idle cycle can still leave the session unlocked.

Findings

  1. P1 Re-enabled lock misses deadline ▶
  2. P2 Disabled screensaver stays visible ▶
  3. P2 Timer behavior remains untested ▶

Summary

The PR excludes disabled (zero) actions from the first idle deadline, disables the monitor when both actions are off, and captures timer delays at cycle start.

  • It adds helper assertions and source-text checks for the timeout behavior.
  • One new cancellation path can leave an already-visible screensaver on screen.

Reviews (2) · Last reviewed commit: "End a running idle cycle when both timeo..."

interval: root.lockDelaySeconds * 1000
repeat: false
onTriggered: if (root.idleEnabled && root.idledThisCycle) root.lockSystem("lock-timeout")
onTriggered: if (root.idleEnabled && root.idledThisCycle && root.lockEnabled) root.lockSystem("lock-timeout")

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.

P1 Re-enabled lock misses deadline

If the lock timeout is set to 0 during an active idle cycle while the screensaver remains enabled, the running one-shot lock timer fires with its new zero interval, and this guard suppresses the lock. Setting the timeout back to a positive value does not restart the timer while the monitor remains idle, so the session stays unlocked until another idle cycle begins. Reschedule the lock when its timeout is re-enabled.

Comment thread test/shell.d/idle-test.sh
Comment on lines +37 to +43
/id: screensaverTimer[\s\S]*?onTriggered: if \(root\.screensaverEnabled\) root\.launchScreensaver\(\)/.test(serviceSource),
'idle does not launch a pending screensaver once its timeout is set to 0'
)
assert(
/id: lockTimer[\s\S]*?onTriggered: if \([^)]*root\.lockEnabled\) root\.lockSystem\("lock-timeout"\)/.test(serviceSource),
'idle does not fire a pending lock once its timeout is set to 0'
)

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 Timer behavior remains untested

These assertions match text in Service.qml but never run its timers or idle monitor. They pass even if changing a timeout to 0 and back drops the lock deadline, so they cannot catch a regression in the pending-action behavior they claim to cover. A behavioral test of that transition would make the coverage useful.

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!

With both at 0 the monitor is disabled and handleIdleChanged returns early, so a cycle already running when shell.json changed never cancels: omarchy-system-wake never runs, and if the screensaver never opened a window nothing else ends it. Cancel it the way turning on stay-awake does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 1, 2026
}

// With both timeouts at 0 the monitor stops reporting, so nothing else would end a running cycle.
onIdleTimersEnabledChanged: if (!idleTimersEnabled) cancelIdleCycle("idle-timers-disabled")

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 Disabled screensaver stays visible

When both timeouts are set to 0 while the screensaver is visible, this handler cancels the idle cycle but does not close the screensaver. cancelIdleCycle runs omarchy-system-wake, which restores brightness without closing the screensaver terminal. The disabled screensaver therefore remains on screen until the user dismisses it with input.

@omarchybot omarchybot added the ready Good to merge label Oct 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and verified at 3cebdc3. This fixes #10860 and also #7178, which is now linked.

What ran, on a disposable Omarchy worker running Hyprland and the shell from each tree:

  • The bug. With screensaver: 150, lock: 0, the shell was started while an mpv window held a Wayland idle inhibitor, then mpv was closed. On quattro, lock-timeout-immediate fired 8 ms later. On this branch nothing fired, with 150/0 or with 0/0.
  • Positive timeouts. With 6/0, the screensaver started at 6 s and nothing locked. With 8/20, the screensaver started at 8 s and the lock came at 20 s, as it does on quattro.
  • Tests. ./test/cli passed, and test/shell.d/idle-test.sh passed (25 checks). The test fails on quattro and fails with each of the commits below reverted.

Pushed to your branch, three commits:

  • 377b15b. Both timer callbacks now check that their action is still enabled. Without that, a lock set to 0 while one was pending still fired.
  • 3839d0b. The timer intervals are now set when an idle cycle starts instead of being bound to the config. A running Qt Timer restarts when its interval changes. With 0 meaning off, setting the screensaver to 0 while it was showing moved the first idle deadline to the lock's, so the lock delay became 0 and the session locked at once, ahead of its deadline. On the worker, 377b15b locked at the edit, and 3839d0b locked at the configured 20 s. A config change now takes effect from the next idle cycle.
  • 3cebdc3. A running idle cycle is now cancelled when both timeouts are set to 0, the same way turning on stay-awake cancels one. With both at 0 the monitor stops reporting, so the cycle never ended and omarchy-system-wake never ran. The worker showed the cycle left open without the handler, and cancelled with wake run with it.

Second opinion: Codex Medium reviewed each round. It found the early lock and the uncleared cycle above, and its last round on 3cebdc3 found nothing. It can read this session's working notes, so its independence is not guaranteed.

Greptile's notes on this head:

  • "Re-enabled lock misses deadline." This was about the bound interval, which is gone. A lock set to 0 and back before its deadline now fires on time. One left at 0 past its deadline does not lock that cycle, which is what 0 means.
  • "Disabled screensaver stays visible." A screensaver that is already showing stays up the same way when stay-awake is turned on, and input dismisses it as before.
  • Tests match source text. That is true. The runtime behaviour above was checked on the worker instead.

#9170 also changes what a 0 timeout does, but keeps 0 as "fire immediately", so it would not fix #10860. It also conflicts with quattro. This pull request is the one brought forward for #10860.

Nothing is left for the author; this waits on the maintainer.

@dhh
dhh merged commit 7901d7d into omacom:quattro Oct 4, 2026
1 check passed
omarchybot added a commit to Coding-Sparrow/omarchy that referenced this pull request Oct 7, 2026
quattro's idle-timeout-zero fix (omacom#12538) added its own assertions beside the ones this branch adds to test/shell.d/idle-test.sh; both sets are kept. The cap in secondsFromConfig still covers both Timer intervals, which quattro now sets imperatively from the same delay properties.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ryanrhughes pushed a commit that referenced this pull request Oct 16, 2026
Treat idle timeout 0 as disabled, not immediate

(cherry picked from commit 7901d7d)
@emirb emirb added this to the 4.0.5 milestone Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready Good to merge verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

5 participants