From 3ec29b10cc5707d3165ceebfe0a6036dc093ab4f Mon Sep 17 00:00:00 2001 From: ThinkOff Date: Mon, 6 Jul 2026 11:39:22 +0300 Subject: [PATCH] fix(gemini-nudge): make GUI wake reliable + fail loud instead of silent no-op MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two hardening fixes to the AppleScript that brings a target app to the front before keystroking a nudge (silent wake drops traced to this). - Force focus more reliably: `open -a` (forces launch + focus even when the app is hidden/minimized or another app holds focus — full-screen, Mission Control, a modal) followed by `activate`, instead of relying on `activate` alone. - Give the focus loop more budget: 5x0.2s (1s) -> 15x0.5s (7.5s). Stuck-poller incidents (2026-05-04) were ABORTs that cleared on the next nudge because activate needs longer when the user is across spaces / in another full-screen window. - Fail loud: on give-up, throw an AppleScript error (exit non-zero) instead of `return` (exit 0). Previously wake.sh logged "nudge sent" for what was actually a no-op (confirmed 3+ hours of silent ABORTs, 2026-05-05). No behavior change on the happy path. Co-Authored-By: Claude Opus 4.8 --- tools/gemini_gui_nudge.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tools/gemini_gui_nudge.sh b/tools/gemini_gui_nudge.sh index b9689be..abd36c1 100755 --- a/tools/gemini_gui_nudge.sh +++ b/tools/gemini_gui_nudge.sh @@ -61,9 +61,19 @@ on run argv -- gone to the wrong app. petrus saw silent wake drops because of -- this. New: ACTIVATE → SET FRONTMOST → VERIFY → keystroke. Bail -- without typing if we can't make target frontmost in 5 tries. - do shell script "open -a " & quoted form of appName + -- Use `open -a` first: it forces a launch + focus more reliably than + -- AppleScript's `activate` when the app is hidden/minimized or another + -- app is holding focus (full-screen, Mission Control, modal). + try + do shell script "open -a " & quoted form of appName + end try + tell application appName to activate delay 0.3 + -- Bumped 5x0.2s (1s budget) to 15x0.5s (7.5s budget). Stuck-poller + -- incidents on 2026-05-04 traced to ABORTs that cleared on the very + -- next nudge — the activate path needs more time when the user is + -- across spaces or in another full-screen window. set focusOk to false set focusAttempts to 0 repeat while focusAttempts < 15 @@ -89,7 +99,12 @@ on run argv if not focusOk then log "gui_nudge: ABORT — could not bring " & appName & " to front after 15 attempts" - return + -- Throw an AppleScript error so osascript exits non-zero and the + -- outer wake.sh can distinguish 'failed silently' from 'nudge sent'. + -- Without this the previous code did `return`, osascript exited 0, + -- and wake.sh logged 'nudge sent' for what was actually a no-op. + -- Confirmed bite on 2026-05-05 (3+ hours of silent ABORTs). + error "gui_nudge could not bring " & appName & " to front" number 100 end if try