From 403654e8bcec10f32ef0dfec25aee0136da15448 Mon Sep 17 00:00:00 2001 From: Omabot Date: Sun, 16 Aug 2026 04:15:47 -0700 Subject: [PATCH 1/2] Stop the idle service starting a cycle on top of the lock it just asked 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) --- shell/plugins/services/idle/Service.qml | 48 +++++++++++++++++++++++-- test/shell.d/idle-test.sh | 48 +++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) diff --git a/shell/plugins/services/idle/Service.qml b/shell/plugins/services/idle/Service.qml index 488f29611c34..feea9be17f29 100644 --- a/shell/plugins/services/idle/Service.qml +++ b/shell/plugins/services/idle/Service.qml @@ -25,6 +25,13 @@ Item { readonly property bool idleEnabled: stayAwakeStateLoaded && !stayAwake readonly property string screensaverClass: "org.omarchy.screensaver" + // The lock plugin is a service in this same process, so its state is readable + // 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) + + property bool lockCommandPending: false property bool stayAwake: false property bool stayAwakeStateLoaded: false property bool hasPendingStayAwakePersist: false @@ -63,6 +70,11 @@ Item { } 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") @@ -76,7 +88,15 @@ Item { root.idledThisCycle = false root.screensaverStartedThisCycle = false resetScreensaverWindows() - runProcess(lockProcess, "lock", "omarchy-system-lock") + + // omarchy-system-lock takes about a second to reach the lock service, and + // until it gets there the lock is not visible to anything. Cover that with + // the command itself -- bounded, so a lock that never returns cannot park + // idle handling for the rest of the session. + if (runProcess(lockProcess, "lock", "omarchy-system-lock")) { + root.lockCommandPending = true + lockCommandTimer.restart() + } } function startIdleCycle() { @@ -85,6 +105,15 @@ Item { return } + // lockSystem() clears idledThisCycle before the lock exists, so the next + // idle re-assertion is free to start a whole new cycle -- and with the + // usual screensaver <= lock configuration that cycle launches a screensaver + // immediately, into a session that is on its way down. + if (root.lockInFlight) { + logEvent("idle-cycle-skip", "lock-in-flight") + return + } + logEvent("idle-cycle-start", "screensaver=" + root.screensaverTimeoutSeconds + " lock=" + root.lockTimeoutSeconds) root.idledThisCycle = true root.screensaverStartedThisCycle = false @@ -184,6 +213,7 @@ Item { stayAwakeStateLoaded: root.stayAwakeStateLoaded, stayAwakeStatePath: root.stayAwakeStatePath, idle: idleMonitor.isIdle, + lockInFlight: root.lockInFlight, inIdleCycle: root.idledThisCycle, screensaverStarted: root.screensaverStartedThisCycle, screensaver: root.screensaverTimeoutSeconds, @@ -269,6 +299,16 @@ Item { onTriggered: if (root.idleEnabled && root.idledThisCycle) root.lockSystem("lock-timeout") } + Timer { + id: lockCommandTimer + interval: 15000 + repeat: false + onTriggered: { + root.lockCommandPending = false + root.logEvent("lock-command-timeout") + } + } + Timer { id: screensaverLaunchGraceTimer interval: 3000 @@ -291,7 +331,11 @@ Item { } Process { id: lockProcess - onExited: function(exitCode, exitStatus) { root.logEvent("process-exit", "lock exitCode=" + exitCode + " status=" + exitStatus) } + onExited: function(exitCode, exitStatus) { + root.lockCommandPending = false + lockCommandTimer.stop() + root.logEvent("process-exit", "lock exitCode=" + exitCode + " status=" + exitStatus) + } } Process { id: wakeProcess diff --git a/test/shell.d/idle-test.sh b/test/shell.d/idle-test.sh index 62a19c2ce03e..ef7fd70c0861 100644 --- a/test/shell.d/idle-test.sh +++ b/test/shell.d/idle-test.sh @@ -33,6 +33,54 @@ assertDeepEqual( { windows: { a: true }, count: 1 }, 'idle leaves screensaver windows unchanged without an address' ) + +const fs = require('fs') +const serviceQml = fs.readFileSync(path.join(root, 'shell/plugins/services/idle/Service.qml'), 'utf8') + +// 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), + 'the lock command stops being pending when it exits' +) + +assert( + /id: lockCommandTimer\s*\n\s*interval: 15000[\s\S]{0,200}?root\.lockCommandPending = false/.test(serviceQml), + 'a lock command that never exits stops being pending on its own' +) + +// lockSystem() clears idledThisCycle, so the next idle re-assertion would +// otherwise start a fresh cycle on top of the lock it just asked for. +assert( + /if \(root\.lockInFlight\) \{\s*\n\s*logEvent\("idle-cycle-skip", "lock-in-flight"\)\s*\n\s*return\s*\n\s*\}\s*\n\s*logEvent\("idle-cycle-start"/.test(serviceQml), + 'no idle cycle begins while a lock is in flight' +) + +// screensaver <= lock makes screensaverDelaySeconds 0, so a cycle that slips +// through launches a screensaver into the pending lock immediately. +assert( + /function launchScreensaver\(\) \{\s*\n\s*if \(root\.lockInFlight\) \{\s*\n\s*logEvent\("screensaver-skip", "lock-in-flight"\)\s*\n\s*return/.test(serviceQml), + 'no screensaver launches while a lock is in flight' +) JS test_tmp=$(mktemp -d) From 7013fb3688edad680e1040ddab62171be5422f65 Mon Sep 17 00:00:00 2001 From: Omabot Date: Mon, 28 Sep 2026 05:20:43 +0200 Subject: [PATCH 2/2] Drop the idle service's lookup of the lock service 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 --- shell/plugins/services/idle/Service.qml | 14 +++++--------- test/shell.d/idle-test.sh | 19 ++++++------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/shell/plugins/services/idle/Service.qml b/shell/plugins/services/idle/Service.qml index feea9be17f29..876dccd95b98 100644 --- a/shell/plugins/services/idle/Service.qml +++ b/shell/plugins/services/idle/Service.qml @@ -25,12 +25,8 @@ Item { readonly property bool idleEnabled: stayAwakeStateLoaded && !stayAwake readonly property string screensaverClass: "org.omarchy.screensaver" - // The lock plugin is a service in this same process, so its state is readable - // 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) - + // The lock service is never handed to other plugins, so until the lock command + // returns, nothing here can tell that a lock is on its way. property bool lockCommandPending: false property bool stayAwake: false property bool stayAwakeStateLoaded: false @@ -70,7 +66,7 @@ Item { } function launchScreensaver() { - if (root.lockInFlight) { + if (root.lockCommandPending) { logEvent("screensaver-skip", "lock-in-flight") return } @@ -109,7 +105,7 @@ Item { // idle re-assertion is free to start a whole new cycle -- and with the // usual screensaver <= lock configuration that cycle launches a screensaver // immediately, into a session that is on its way down. - if (root.lockInFlight) { + if (root.lockCommandPending) { logEvent("idle-cycle-skip", "lock-in-flight") return } @@ -213,7 +209,7 @@ Item { stayAwakeStateLoaded: root.stayAwakeStateLoaded, stayAwakeStatePath: root.stayAwakeStatePath, idle: idleMonitor.isIdle, - lockInFlight: root.lockInFlight, + lockCommandPending: root.lockCommandPending, inIdleCycle: root.idledThisCycle, screensaverStarted: root.screensaverStartedThisCycle, screensaver: root.screensaverTimeoutSeconds, diff --git a/test/shell.d/idle-test.sh b/test/shell.d/idle-test.sh index ef7fd70c0861..6cdc0a5038a5 100644 --- a/test/shell.d/idle-test.sh +++ b/test/shell.d/idle-test.sh @@ -37,18 +37,11 @@ assertDeepEqual( const fs = require('fs') const serviceQml = fs.readFileSync(path.join(root, 'shell/plugins/services/idle/Service.qml'), 'utf8') -// 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. +// The lock service is never handed to other plugins, so a lookup for it here +// always comes back empty and would guard nothing. 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' + !/serviceFor\("omarchy\.lock"\)/.test(serviceQml), + 'the idle service does not look up the lock service' ) assert( @@ -71,14 +64,14 @@ assert( // lockSystem() clears idledThisCycle, so the next idle re-assertion would // otherwise start a fresh cycle on top of the lock it just asked for. assert( - /if \(root\.lockInFlight\) \{\s*\n\s*logEvent\("idle-cycle-skip", "lock-in-flight"\)\s*\n\s*return\s*\n\s*\}\s*\n\s*logEvent\("idle-cycle-start"/.test(serviceQml), + /if \(root\.lockCommandPending\) \{\s*\n\s*logEvent\("idle-cycle-skip", "lock-in-flight"\)\s*\n\s*return\s*\n\s*\}\s*\n\s*logEvent\("idle-cycle-start"/.test(serviceQml), 'no idle cycle begins while a lock is in flight' ) // screensaver <= lock makes screensaverDelaySeconds 0, so a cycle that slips // through launches a screensaver into the pending lock immediately. assert( - /function launchScreensaver\(\) \{\s*\n\s*if \(root\.lockInFlight\) \{\s*\n\s*logEvent\("screensaver-skip", "lock-in-flight"\)\s*\n\s*return/.test(serviceQml), + /function launchScreensaver\(\) \{\s*\n\s*if \(root\.lockCommandPending\) \{\s*\n\s*logEvent\("screensaver-skip", "lock-in-flight"\)\s*\n\s*return/.test(serviceQml), 'no screensaver launches while a lock is in flight' ) JS