Skip to content

idle: clamp Timer intervals to avoid 32-bit overflow - #11136

Open
leftydevkit wants to merge 1 commit into
omacom:quattrofrom
leftydevkit:fix/idle-timer-int32-overflow
Open

leftydevkit wants to merge 1 commit into
omacom:quattrofrom
leftydevkit:fix/idle-timer-int32-overflow

Conversation

@leftydevkit

Copy link
Copy Markdown

Problem

Service.qml computes the idle screensaver/lock timer intervals as seconds * 1000 into a 32-bit int property. secondsFromConfig() only validates finite and >= 0, so a large idle.lock overflows it:

lock = 2592000  ->  lockDelaySeconds = 2591850
                ->  interval = 2,591,850,000 ms   (> INT_MAX 2,147,483,647)
                ->  wraps to -1,703,117,296

Qt clamps the negative interval to 1 ms and logs QBasicTimer::start: negative intervals aren't allowed on every restart. The shell log then grows without bound (3.28 GB observed), filling the /run/user/<uid> tmpfs. Once full, systemd-run --user fails with ENOSPC, silently breaking launchers that use it (e.g. omarchy-launch-browser — the SUPER+SHIFT+ENTER keybind exits without opening the browser).

The overflow is latent in both timers — lockTimer and screensaverTimer.

Fix

Clamp both intervals to maxTimerIntervalMs (2³¹ − 1). The multiplication happens in JS doubles, so clamping before the int assignment avoids the wrap; values below the limit are unchanged.

readonly property int maxTimerIntervalMs: 2147483647
...
interval: Math.min(root.screensaverDelaySeconds * 1000, root.maxTimerIntervalMs)
...
interval: Math.min(root.lockDelaySeconds * 1000, root.maxTimerIntervalMs)

Testing

  • With "idle": { "screensaver": 150, "lock": 2592000 }: before, the shell floods QBasicTimer::start: negative intervals aren't allowed from the first idle cycle (150 s) and the log fills the tmpfs. With the clamp applied locally, the interval is 2,146,850,000 ms (within range) and the flood does not occur.
  • Values below the limit are unaffected (Math.min returns the original).

Fixes #11135

Filed by deepseek-v4.1-flash via Oh My Pi (omp).

The idle screensaver and lock timers compute their interval as
`seconds * 1000` into a 32-bit int property. secondsFromConfig() only
validates finite and >= 0, so a large timeout (e.g. lock=2592000)
overflows: 2,591,850,000 ms > INT_MAX (2,147,483,647) wraps negative.
Qt then clamps to 1 ms and logs "QBasicTimer::start: negative intervals
aren't allowed" on every restart, flooding the shell log until the
/run/user tmpfs fills.

Clamp both intervals to maxTimerIntervalMs (2^31 - 1).

Fixes omacom#11135
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 8b193d0 and reproduced on an Omarchy ISO worker with the shell linked to the tree under test. The bug is real, and this change fixes the case it describes.

  • Base (8ea5151, this PR's parent), idle: {screensaver: 5, lock: 2592000}: once the idle cycle started, the shell logged QBasicTimer::start: negative intervals aren't allowed; the interval will be set to 1ms about 1,000 times a second, and the log reached 3.8 MB within a minute.
  • Head, same config: no warnings, a 2.3 KB log, and the lock timer still armed. With lock: 15, the lock still fired 10 s after the screensaver, as configured. ./test/cli passed, and so did test/shell.d/idle-test.sh (9/9).

There is a competing fix, #13921, which I think is the better of the two. It caps the value in IdleModel.secondsFromConfig, so every reader stays in range, not just the two Timer intervals. Here the seconds properties are still QML ints, and a large enough value wraps before the clamp is reached. On this head, lock: 3000000000 reads back as lockTimeoutSeconds = -1294967296, which makes firstIdleTimeoutSeconds negative, and that value goes to the IdleMonitor timeout. #13921 also adds unit asserts for the cap and a line in the manual saying a huge value is not "never". Both are proportionate, and both only change values above about 24.8 days.

The canonical issue is #7506; #11135, which this PR closes, was closed as its duplicate.

Reviewed by Claude Opus 5.5. The second opinion (Codex Medium) did not run: the reviewer answered, but today's review budget was already spent. So this comparison is one model's judgement. Choosing between this and #13921 is the maintainer's decision, so this is waiting on them.

@jandrusk

Copy link
Copy Markdown

The overflow bug is real, but this branch looks stale against current quattro.

Idle timers no longer set interval: on the Timer objects declaratively — beginIdleCycle assigns:

screensaverTimer.interval = root.screensaverDelaySeconds * 1000
lockTimer.interval = root.lockDelaySeconds * 1000

So clamping only the old property initializers won't help. Prefer #14581 (cap in IdleModel.secondsFromConfig), or also clamp those two assignments:

screensaverTimer.interval = Math.min(root.screensaverDelaySeconds * 1000, root.maxTimerIntervalMs)
lockTimer.interval = Math.min(root.lockDelaySeconds * 1000, root.maxTimerIntervalMs)

Happy to close this in favor of #14581 if that one's preferred.

@omarchybot

Copy link
Copy Markdown
Collaborator

Rechecked against current quattro (492b883) after @jandrusk's note, and it is right: this branch no longer fixes the bug where it would land.

  • It conflicts. A trial merge of quattro into 8b193d0 conflicts in shell/plugins/services/idle/Service.qml, both in the property block (now built from IdleModel.firstIdleTimeout/delayAfterFirstIdle) and in the two Timer blocks.
  • The lines it clamps are gone. quattro removed the declarative interval: bindings and now sets each cycle's deadline once in beginIdleCycle: screensaverTimer.interval = root.screensaverDelaySeconds * 1000 and lockTimer.interval = root.lockDelaySeconds * 1000. Those assignments overwrite any binding, so with screensaver: 150, lock: 2592000 the lock timer is still handed 2,591,850,000 ms. A port would have to clamp those assignments instead, and it would still leave the seconds properties able to wrap before any clamp, as noted earlier.

Two other open pull requests cap the value in IdleModel.secondsFromConfig instead, which quattro's current code reads before anything is stored or multiplied: #13921 (opened 2026-10-01, with a test and a manual line) and #14581 (opened 2026-10-08), which caps it the same way with broader model tests. Because #13921 is the older of the two equivalent fixes and this one misses those cases on quattro, #13921 is the one that should land. Nothing in this branch is verified on the current base, since there is nothing to run until it is ported.

Reviewed by Claude Opus 5.5 by reading the source and doing the trial merge; nothing was run on a worker this time. The second opinion (Codex Medium) was given the three diffs and current quattro without my conclusion, and reached the same one independently, including the overwritten beginIdleCycle assignments. It could read this session's notes, so its independence is not guaranteed. Whether to close this in favour of #13921 is the maintainer's call, so this is waiting on them.

@das6ng

das6ng commented Oct 28, 2026

Copy link
Copy Markdown

+1 — hit this in the wild today on 4.0.6-1 with idle.lock: 3000000
(a natural "never lock" value, in my config since Oct 13). Two weeks of
latency before the tmpfs actually filled, so the connection to this PR was
not obvious. Adding a few downstream symptoms not covered above.

Blast radius beyond the quickshell log

1. uwsm app breaks with misleading "App failure" desktop notifications.
Once the tmpfs fills, the app daemon dies mid-request:

                                                                                                                                                                                      
uwsm_app-daemon[1178119]: sent: error 'Invalid arguments: '                                                                       
uwsm_app-daemon[1178119]: [Errno 28] No space left on device                                                                                                                          
                                                                                                                                                                                      

uwsm-app clients eval that error reply and each one fires a
notify-send "App failure" "Invalid arguments: " notification. End users
see a stack of "App failure — Invalid arguments:" popups pointing at their
apps, with nothing connecting it to the idle service. On my machine those
notifications were the only visible symptom — the timer storm itself was
invisible.

2. journald gets flooded in parallel, not just the shell log:
~770 warnings/s sustained → a 128 MB journal file every ~8 min,
3.9 GB of /var/log/journal within hours (197k+ of these lines in one
boot).

3. The overflowed timer survives the config fix. Correcting
shell.json (lock: 0) hot-reloads fine, but the already-running timer
keeps spin-restarting: omarchy-shell idle status still reported
timers.lock: true and the warning stream continued at full rate. The
cycle also can't self-cancel: with the screensaver toggled off
(screensaver-off), the screensaver process exits 1 immediately, the
launch-grace path finds the user still idle, and nothing stops the loop
until there's input. Only omarchy restart shell cleared it. Might be
worth stopping/re-arming both timers on config change in addition to
clamping future assignments.

Workaround

"idle": { "lock": 0, "screensaver": 0 } (0 = disabled per
IdleModel.secondsFromConfig) + omarchy restart shell if the storm is
already running.

Happy to attach full evidence (idle status output, daemon journal,
journalctl counts) if useful.

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.

Shell: idle lock timer interval overflows 32-bit int, spamming logs until /run/user tmpfs fills

4 participants