Repository navigation
Stop the idle service starting a cycle on top of the lock it just asked for - #7131
omarchybot wants to merge 4 commits into
Conversation
…ed for lockSystem() clears idledThisCycle and then spawns omarchy-system-lock as a subprocess. Reaching the lock service from there takes about a second -- bash, then omarchy-shell, then a qs ipc round trip into beginLock() -- and for that whole second nothing anywhere reports a lock. The next idle re-assertion is free to start a brand-new cycle, and since screensaverDelaySeconds is 0 whenever screensaver <= lock (the normal configuration), that cycle launches a second screensaver into a session that is already going down. Its ttfx is born inside the lock window and aborts as soon as its terminal is torn out from under it. The only lock check on that path was the shell-out `[[ $(omarchy-shell lock isLocked 2>/dev/null) == "true" ]]`, which cannot see a lock that has not arrived yet and prints nothing at all on stdout when the IPC call times out or the shell is not ready -- so it fails open into the launcher. The lock plugin is a service in this same process, so read its state directly instead. A lock counts as in flight from the moment its command is spawned until the lock service reports it done, and neither a cycle nor a screensaver starts while one is. The spawn half is bounded by a timer so a lock command that never returns cannot park idle handling for the rest of the session. Fixes #6995 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR prevents the idle service from starting a new idle cycle and/or launching a screensaver while a lock is being initiated but not yet visible to the rest of the system (the “lock in flight” gap).
Changes:
- Add in-process lock state reading (
lockService) and a derivedlockInFlightflag in the idle service. - Gate
startIdleCycle()andlaunchScreensaver()whenlockInFlightis true, with logging. - Add a bounded “lock command pending” window via a timer and add snapshot-style tests asserting these behaviors are present in
Service.qml.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| test/shell.d/idle-test.sh | Adds assertions that Service.qml includes in-process lock checks and pending/timeout logic. |
| shell/plugins/services/idle/Service.qml | Implements lockInFlight, blocks idle cycle + screensaver during lock, and adds timeout + logging for lock spawn. |
Suppressed comments (1)
shell/plugins/services/idle/Service.qml:81
- Now that
launchScreensaver()is guarded by in-processlockInFlight, the extra shell-out/IPC check (omarchy-shell lock isLocked) is redundant work on every screensaver start and was previously called out as unreliable when the shell/IPC is busy. Consider simplifying the command to just start the screensaver (or otherwise avoid theomarchy-shellinvocation here) to reduce process spawning overhead and eliminate the “empty stdout means not true” failure mode entirely.
function launchScreensaver() {
if (root.lockInFlight) {
logEvent("screensaver-skip", "lock-in-flight")
return
}
root.screensaverStartedThisCycle = true
screensaverLaunchGraceTimer.restart()
runProcess(screensaverProcess, "screensaver", "[[ $(omarchy-shell lock isLocked 2>/dev/null) == \"true\" ]] || omarchy-launch-screensaver")
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| // The lock plugin runs in this process, so its state is readable without the | ||
| // shell-out, which reports nothing at all when the IPC call fails. | ||
| assert( | ||
| /readonly property var lockService: shell && shell\.serviceFor \? shell\.serviceFor\("omarchy\.lock"\) : null/.test(serviceQml), | ||
| 'the idle service reads lock state from the lock service in-process' | ||
| ) | ||
|
|
||
| // omarchy-system-lock takes about a second to reach the lock service, and the | ||
| // lock is not visible anywhere until it gets there. | ||
| assert( | ||
| /readonly property bool lockInFlight: lockCommandPending \|\| !!\(lockService && lockService\.locked\)/.test(serviceQml), | ||
| 'a lock counts as in flight from the moment its command is spawned' | ||
| ) | ||
|
|
||
| assert( | ||
| /if \(runProcess\(lockProcess, "lock", "omarchy-system-lock"\)\) \{\s*\n\s*root\.lockCommandPending = true\s*\n\s*lockCommandTimer\.restart\(\)/.test(serviceQml), | ||
| 'spawning the lock command marks it pending' | ||
| ) | ||
|
|
||
| // A lock command that never returns would otherwise park idle handling for the | ||
| // rest of the session. | ||
| assert( | ||
| /id: lockProcess\s*\n\s*onExited: function\(exitCode, exitStatus\) \{\s*\n\s*root\.lockCommandPending = false/.test(serviceQml), |
| Timer { | ||
| id: lockCommandTimer | ||
| interval: 15000 | ||
| repeat: false | ||
| onTriggered: { | ||
| root.lockCommandPending = false | ||
| root.logEvent("lock-command-timeout") | ||
| } | ||
| } |
| // directly. The shell-out guard below cannot see a lock that is still in | ||
| // flight, and reports nothing at all when the IPC call fails. | ||
| readonly property var lockService: shell && shell.serviceFor ? shell.serviceFor("omarchy.lock") : null | ||
| readonly property bool lockInFlight: lockCommandPending || !!(lockService && lockService.locked) |
| interval: 15000 | ||
| repeat: false | ||
| onTriggered: { | ||
| root.lockCommandPending = false |
|
Checked the four Copilot findings against source and ran the suite on a worker. The 15s timeout clearing The residual window is therefore a deliberate bound rather than an oversight. Narrowing it further — terminating the lock process on timeout, or emitting an error event instead of silently dropping the state — is a design call, and worth deciding on its own rather than inside this fix.
No changes pushed. |
The lock service is an authentication service, and since third-party plugin capabilities were restricted it is kept out of the shell's service table, so serviceFor("omarchy.lock") always returns null. The lookup guarded nothing: the in-flight state was only ever the pending lock command. Say so, and guard on that directly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Re-checked against current What was wrong. The in-process read of the lock state could never work on current Reproduced on a worker. A probe loads the real idle Suite. Ran on the worker against the merged tree, with the shell linked to it. Second opinion. Codex Medium reviewed the merged tree at 7013fb3 and found no defect. It agreed that removing the lookup is right, that the change fixes the cause, and that it is proportionate; its agreement is not guaranteed to be independent. It noted one limit, which I agree is not new here: the 15s timeout re-opens idle handling without killing a hung lock command. For the maintainer, two things about the description, which I cannot edit from here. The paragraph saying the idle service reads the lock service directly no longer describes the code. And the sentence "This does not close #6762" contains the keyword Waiting on the maintainer. |
quattro now forbids tests that only read source text (#16334), so the regex assertions on Service.qml go, and a fixture test drives the real idle service instead: it fails when an idle re-assertion during a pending lock command starts a cycle, and when the cycle cannot start again once the command has returned. The window tracking that lockSystem() reset is gone from quattro, so the call goes with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
[Medium impact] The change affects the desktop idle service's lock and screensaver sequence. The PR should not merge until idle actions restart automatically after a failed or stalled lock attempt. Findings
SummaryThe PR blocks new idle cycles and screensaver launches while the idle service’s lock command is running.
No new findings were accepted.
|
| onTriggered: { | ||
| root.lockCommandPending = false | ||
| root.logEvent("lock-command-timeout") | ||
| } |
There was a problem hiding this comment.
If an idle event arrives while lockCommandPending is true, startIdleCycle() drops it. If the lock command then fails or hangs before requesting the lock, clearing the flag here or in onExited does not check whether the user is still idle. lockSystem() has already stopped both timers and cleared idledThisCycle, so the session can remain unlocked with idle actions unarmed until another activity-to-idle change.
Recheck the current idle and lock state when releasing the flag. Add coverage that checks recovery without manually calling startIdleCycle().
|
This pull request had stopped merging cleanly with What the merge changed. Reproduced on a worker. On Suite. Second opinion. Codex Medium and muse-wonder (via pi, thinking high) both reviewed the merged tree. Neither found a defect, and both judged the race real on Waiting on the maintainer. |
quattro's idle service gained retimeIdleMonitor() (#9570) at the spot where lockCommandPending was declared. Both stay; the property moves down beside the rest of the service's state. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
This had stopped merging cleanly again: #9570 added Reproduced on a worker. Suite. On the same worker, Second opinion. Codex Medium and muse-wonder (via pi, thinking high) reviewed 53acd67. Neither found a defect in the merge with #9570: the rearm pulse never runs while the user is idle, and it can't hold The description is out of date and needs editing before merge. It says the fix reads the lock service's state directly, but the code tracks the lock command's own lifetime, because the lock service isn't handed to other plugins. Its line references are also stale. More importantly, its sentence "This does not close #6762" contains GitHub's closing keyword, so GitHub lists #6762 as closed by this pull request and would close it on merge, which is the opposite of what the sentence means. I can't edit the description from this run. Waiting on the maintainer: whether the failed-lock recovery belongs here, and the description fix. |
lockSystem()clearsidledThisCycleand then spawnsomarchy-system-lockas a subprocess (shell/plugins/services/idle/Service.qml:76,:79). Reaching the lock service from there takes about a second —bash, thenbin/omarchy-shell, then aqs ipcround trip intobeginLock()— and for that whole second nothing anywhere reports a lock.startIdleCycle()consults no lock state at all, so the next idle re-assertion starts a brand-new cycle; becausescreensaverDelaySecondsis 0 wheneverscreensaver <= lock(the normal configuration), that cycle launches a second screensaver immediately, into a session that is already going down. Itsttfxis born inside the lock window and aborts as soon as its terminal is torn out from under it.The reporter's timeline shows the gap exactly:
process-start: lockat 15:01:13.428,idle-cycle-startandprocess-start: screensaverat 15:01:14.406, andlock-requestedonly at 15:01:14.462 — the second screensaver went out 56ms before the lock service had any state to report.The only lock check on that path was the shell-out
[[ $(omarchy-shell lock isLocked 2>/dev/null) == "true" ]] || omarchy-launch-screensaver. It cannot see a lock that has not arrived yet, andomarchy-shellprints nothing on stdout when the IPC call times out, when the shell is not ready, or when it is not running (bin/omarchy-shell:13,:62,:74) — with stderr discarded, an empty answer is not"true"and the launcher runs. The guard fails open, at the one moment the shell is busiest bringing a lock surface up.The lock plugin is a service in this same Quickshell process, so read its state directly instead of asking through a subprocess. A lock counts as in flight from the moment its command is spawned until the lock service reports it done, and neither a new idle cycle nor a screensaver starts while one is. The spawn half is bounded by a timer, so a lock command that never returns cannot park idle handling for the rest of the session.
Two notes on the report itself. The reporter attributes the second idle event to the lock script's
pkilldestroying the first screensaver's window, but thatpkillruns afteromarchy-shell lock lockreturns (bin/omarchy-system-lock:8,:23), i.e. afterlock-requested— so it cannot have caused an idle event 56ms earlier. The cause is simpler and broader:lockSystem()re-armsstartIdleCycle()the moment it fires, and the service already documents that screensaver window churn makes the compositor report activity (Service.qml:160), so idle re-assertions during a screensaver cycle are routine. AndisLockeddoes already cover the pending phase —lockedislockRequested || sessionLock.locked || sessionLock.secure(shell/plugins/lock/Service.qml:37) andlockRequestedis set at the top ofbeginLock()— so the issue title's "isLocked guard passes while lock-pending" is not what happens. The window is before the lock service is reached at all, plus the guard's fail-open behaviour.This does not close #6762 / #6764 or omacom/ttfx#10: a screensaver that was already up when the lock fires is still killed by the lock script's teardown, and
ttfxstill aborts rather than exiting cleanly on EIO. It removes the third race, where the screensaver is created after the lock has started.Fixes #6995