Skip to content

Stop the idle service starting a cycle on top of the lock it just asked for - #7131

Open
omarchybot wants to merge 4 commits into
quattrofrom
fix/issue-6995
Open

omarchybot wants to merge 4 commits into
quattrofrom
fix/issue-6995

Conversation

@omarchybot

Copy link
Copy Markdown
Collaborator

lockSystem() clears idledThisCycle and then spawns omarchy-system-lock as a subprocess (shell/plugins/services/idle/Service.qml:76, :79). Reaching the lock service from there takes about a second — bash, then bin/omarchy-shell, then a qs ipc round trip into beginLock() — 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; because screensaverDelaySeconds is 0 whenever screensaver <= lock (the normal configuration), that cycle launches a second screensaver immediately, 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 reporter's timeline shows the gap exactly: process-start: lock at 15:01:13.428, idle-cycle-start and process-start: screensaver at 15:01:14.406, and lock-requested only 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, and omarchy-shell prints 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 pkill destroying the first screensaver's window, but that pkill runs after omarchy-shell lock lock returns (bin/omarchy-system-lock:8, :23), i.e. after lock-requested — so it cannot have caused an idle event 56ms earlier. The cause is simpler and broader: lockSystem() re-arms startIdleCycle() 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. And isLocked does already cover the pending phase — locked is lockRequested || sessionLock.locked || sessionLock.secure (shell/plugins/lock/Service.qml:37) and lockRequested is set at the top of beginLock() — 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 ttfx still aborts rather than exiting cleanly on EIO. It removes the third race, where the screensaver is created after the lock has started.

Fixes #6995

…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>

Copilot AI left a comment

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.

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 derived lockInFlight flag in the idle service.
  • Gate startIdleCycle() and launchScreensaver() when lockInFlight is 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-process lockInFlight, 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 the omarchy-shell invocation 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.

Comment thread test/shell.d/idle-test.sh Outdated
Comment on lines +39 to +62

// 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),
Comment on lines +302 to +310
Timer {
id: lockCommandTimer
interval: 15000
repeat: false
onTriggered: {
root.lockCommandPending = false
root.logEvent("lock-command-timeout")
}
}
Comment thread shell/plugins/services/idle/Service.qml Outdated
Comment on lines +29 to +32
// 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
@omarchybot

Copy link
Copy Markdown
Collaborator Author

Checked the four Copilot findings against source and ran the suite on a worker.

The 15s timeout clearing lockCommandPending (raised twice, on Service.qml) — real, but the suggested fix would undo the timer. It is true that lockCommandTimer drops the in-flight state unconditionally, so a lock command still running at 15s reopens the window this PR closes. But folding lockProcess.running into lockInFlight, as suggested, means a lock command that never returns parks idle handling for the rest of the session — which is the failure the timer exists to bound, and which idle-test.sh asserts against directly ("a lock command that never exits stops being pending on its own"). lockProcess.onExited already clears the flag on the normal path, so the timer only ever fires for a hung command.

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.

interval: 15000 as an unexplained magic number — naming, not a defect. Worth doing whenever the value is next tuned; note it would need the idle-test.sh assertion updated alongside, since that pins the literal.

idle-test.sh asserting on exact source formatting — this is the house pattern rather than something this PR introduced: 44 files under test/shell.d/ assert against QML source text this way, because the shell suite cannot instantiate QML. Loosening it is a repo-wide question and does not belong in this PR.

No changes pushed. idle-test.sh passes on a worker, 8/8, including all five new assertions.

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>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Sep 28, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator Author

Re-checked against current quattro (3faafba) and pushed one fix: 7013fb3.

What was wrong. The in-process read of the lock state could never work on current quattro. The lock plugin is an authentication service, and since third-party plugin capabilities were restricted, ensureService() keeps it in AuthServiceStore rather than the shell's service table (shell/shell.qml:924). As a result, shell.serviceFor("omarchy.lock") always returns null. I confirmed it on a worker running this branch merged onto quattro: with the session locked and omarchy-shell lock isLocked answering true, omarchy-shell idle status still reported lockInFlight: false. The only thing guarding the race was ever the pending lock command. 7013fb3 removes the lookup, guards on lockCommandPending directly, and swaps the test's assertion on the lookup for one that it is absent. The pending-command guard is unchanged, and that is what closes the race: omarchy-system-lock returns only after beginLock() has set lockRequested, so from then on the existing isLocked shell-out sees the lock.

Reproduced on a worker. A probe loads the real idle Service.qml, calls lockSystem(), and 500ms later re-asserts idle while a stand-in omarchy-system-lock is still running. On quattro a screensaver is launched into the pending lock. With this branch merged, the cycle is skipped (idle-cycle-skip: lock-in-flight). With the two guards reverted, the screensaver is launched again.

Suite. Ran on the worker against the merged tree, with the shell linked to it. ./test/cli passed 86 with 1 failure, and quattro has the same failure. ./test/shell passed 3893 with 5 failures, including all 14 idle-test.sh checks. Run on quattro in the same worker, those five fail identically: ascii, branding-about-animation, kernel-headers-migration, network-captive-portal and passwordless-grant-lifecycle. omarchy-kernel-migration-test.sh hangs in a grep reading stdin and fails on quattro too. None of these touch idle or lock code, but the suite is not green, so this is not marked ready. The pull request has no CI checks.

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 close #6762, so GitHub has linked #6762 as closed by this pull request and would close it on merge. The description says #6762 is not fixed by this change, and I agree. #9152 adds a lookup of the same lock service with the same problem, and touches the same property block, so the two will conflict.

Waiting on the maintainer.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 31, 2026
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>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 31, 2026
@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P1 Idle actions never restart ▶

Summary

The PR blocks new idle cycles and screensaver launches while the idle service’s lock command is running.

  • Idle cycles and screensavers pause while a lock command is pending.

No new findings were accepted.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A["lockSystem() starts the lock command"] --> B["Set lockCommandPending"]
  B --> C["Skip new cycles and screensavers"]
  C --> D{"Command exits or 15 seconds pass"}
  D --> E["Clear lockCommandPending"]
Loading

Reviews (2) · Last reviewed commit: "Merge quattro into fix/issue-6995" · Reviewed by Greptile

Comment on lines +278 to +281
onTriggered: {
root.lockCommandPending = false
root.logEvent("lock-command-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 Idle actions never restart

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().

@omarchybot

Copy link
Copy Markdown
Collaborator Author

This pull request had stopped merging cleanly with quattro, so I merged current quattro (e4fffc6) into the branch and pushed it as 7f047f1. The fix itself is unchanged: from the moment omarchy-system-lock is spawned until it exits (at most 15s), no new idle cycle starts and no screensaver launches.

What the merge changed. quattro no longer tracks screensaver windows, so the resetScreensaverWindows() call in lockSystem() is gone. quattro also no longer allows tests that only read source text (#16334), so the regex checks on Service.qml are gone from test/shell.d/idle-test.sh. A fixture test now runs the real idle service instead (test/shell.d/fixtures/idle-lock-pending/shell.qml). It asks for a lock while a stub lock command is still running, re-asserts idle, and checks that no cycle or screensaver starts. Then it checks that a cycle does start once the command has exited. The service runs its commands through bash -lc, and a login shell on an Omarchy install puts the real bin/ back at the front of PATH. So the test uses the same bash shim as the scratch shell, and it refuses to run if the stub lock command doesn't resolve, so it can never lock the session it runs in.

Reproduced on a worker. On quattro the test fails because a screensaver is launched while the lock command is still running. On this head it passes. With the two guards removed, it fails again. On quattro the screensaver is the native Wayland one, not ttfx in a terminal, so this race no longer causes the ttfx abort from #6995. It now launches a screensaver that the lock script immediately kills.

Suite. ./test/cli passed on the worker, and CI's test check passed. ./test/shell passed 7162 checks and failed 4: ascii, branding-about-animation, first-run and runtime-smoke. All four fail the same way on quattro in the same worker, and none touches idle or lock code. Because the worker suite isn't green, this isn't marked ready.

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 quattro and the change proportionate; their agreement is not guaranteed to be independent. muse-wonder raised two limits, and I agree neither is new or worth changing here. First, a lock command that exits without locking (for example, when PAM isn't configured) leaves the swallowed idle re-assertion unreplayed until the user is active again. Second, after the 15s bound the guard lifts even if a hung lock command is still running. Both follow from bounding the guard so that a lock that never returns can't park idle handling.

Waiting on the maintainer.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 16, 2026
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>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 16, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator Author

This had stopped merging cleanly again: #9570 added retimeIdleMonitor() to shell/plugins/services/idle/Service.qml right where lockCommandPending was declared. I merged quattro (e19607f) into the branch, kept both sides, and pushed it as 53acd67. It merges cleanly now. The fix itself is unchanged.

Reproduced on a worker. test/shell.d/idle-test.sh drives the real idle service. With quattro's Service.qml it fails 1 of 13, because a cycle starts on top of the pending lock. On this head it passes 13 of 13, and with the two guards removed it fails the same check again.

Suite. On the same worker, ./test/cli passed. ./test/shell passed 7611 and failed 5: ascii, branding-about-animation, first-run, provision-owner-keyboard and runtime-smoke. All five fail the same way on quattro e19607f in that worker, and none of them touches idle or lock code. CI is green.

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 lockCommandPending set. On Greptile's point both agree that the mechanism is real. If an idle re-assertion arrives while the lock command is running, it is dropped. If that command then fails, nothing re-arms the screensaver or lock until the user is active and idle again. Codex rates this P2: in that case quattro would start a replacement cycle that retries the lock. muse-wonder calls it an accepted trade-off, since quattro has the same hole whenever no re-assertion arrives. Both say the suggested fix (start a cycle on release while still idle) is unsafe. After a successful lock the user is still idle, so with lockDelaySeconds at 0 it would re-lock in a loop. omarchy-system-lock's exit status doesn't tell success from failure. A safe recovery has to check lock state, and that is a design choice, so I left it for the maintainer rather than pushing it. Their agreement is not guaranteed to be independent.

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.

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

Labels

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

Projects

None yet

2 participants