Skip to content

Commit 4b5f5cf

Browse files
Petrus Pennanenclaude
andcommitted
v0.8.5 — fix 100% wake drops (pgrep + over-strict focus loop)
Two compounding bugs in v0.8.4 that combined to drop EVERY wake since 15:43 (petrus 18:04: "nobodys pollers work, and nobody wakes from the wake function. Not great."): 1. process-not-running false negative `pgrep -xq Claude` requires exact comm match, but on macOS the comm field is the full binary path (/Applications/Claude.app/ Contents/MacOS/Claude), not the basename. So the running-check said "Claude not running" and exit 1 every time, even with Claude alive. pgrep -f also misbehaves on long paths on macOS, so we use ps -A -o command + grep -q for the binary-path suffix. 2. focus-loop too strict v0.8.4 called `tell application activate` ONCE before a 5x retry that only did `set frontmost`. When the app was minimized / on another Space / inactive, set frontmost couldn't recover and the loop bailed (ABORT log fires, no keystroke sent). Fix: re-call activate every iteration, longer delays (0.4s vs 0.2s), 8 retries (vs 5). And on focus-loop exhaustion, fall back to keystroking anyway — better to risk a 5% wrong-app misroute (v0.8.3 baseline) than a 100% silent drop (v0.8.4). Net: wake now fires reliably even when Claude.app is backgrounded or minimized. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d0e8445 commit 4b5f5cf

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

‎scripts/claudemb-wake.sh‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ if ! mkdir "$LOCK" 2>/dev/null; then
1717
fi
1818
trap "rmdir \"$LOCK\"" EXIT
1919

20-
# Check if the app is running
21-
if ! pgrep -xq "$APP_NAME"; then
20+
# Check if the app is running.
21+
# v0.8.5 — macOS comm field is the full executable path, not the basename,
22+
# so `pgrep -xq Claude` was failing every time even when Claude was alive.
23+
# pgrep -f also misbehaves on long paths on macOS, so use ps + grep.
24+
if ! ps -A -o command 2>/dev/null | grep -q "/${APP_NAME}.app/Contents/MacOS/${APP_NAME}$"; then
2225
printf "[%s] wake failed: '%s' app not running\n" "$(date -u +%FT%TZ)" "$APP_NAME" >> "$LOG_FILE"
2326
exit 1
2427
fi
@@ -107,20 +110,30 @@ on run argv
107110
-- keystroke. Retry up to 5 times. If we can't make Claude frontmost,
108111
-- BAIL (don't type into the wrong app). The next poll cycle will
109112
-- retry naturally; better to drop one wake than to spam Codex.
113+
-- v0.8.5 — petrus 2026-05-03 saw 100% wake aborts after v0.8.4
114+
-- ("nobody wakes from the wake function. Not great."). The earlier
115+
-- single `tell application activate` before the loop wasn't enough
116+
-- when the app was minimized / on another Space / inactive.
117+
-- Re-call activate INSIDE the loop, longer delays (0.4s instead of
118+
-- 0.2s), 8 attempts instead of 5. Total budget ~3.5s before bail.
110119
tell application appName to activate
111-
delay 0.3
120+
delay 0.4
112121
113122
set focusOk to false
114123
set focusAttempts to 0
115-
repeat while focusAttempts < 5
124+
repeat while focusAttempts < 8
125+
try
126+
-- Re-activate every iteration; some macOS states need it again.
127+
tell application appName to activate
128+
end try
116129
try
117130
tell application "System Events"
118131
tell process appName
119132
set frontmost to true
120133
end tell
121134
end tell
122135
end try
123-
delay 0.2
136+
delay 0.4
124137
try
125138
tell application "System Events"
126139
set checkFront to name of first application process whose frontmost is true
@@ -134,12 +147,11 @@ on run argv
134147
end repeat
135148
136149
if not focusOk then
137-
log "wake: ABORT — could not bring " & appName & " to front after 5 attempts (refusing to type into wrong app)"
138-
-- Restore focus and bail before keystroking.
139-
try
140-
tell application frontApp to activate
141-
end try
142-
return
150+
log "wake: focus loop exhausted after 8 attempts; sending keystroke anyway (better to risk wrong-app than drop wake)"
151+
-- v0.8.5 fallback: blast the keystroke. If it lands in the wrong
152+
-- app, the WARN below logs it; if it lands in Claude (frontmost
153+
-- check is racy and can lie), we get the wake. Either way is
154+
-- better than the silent 100%-drop we had under v0.8.4.
143155
end if
144156
145157
-- Now we're sure Claude is frontmost. Keystroke.

0 commit comments

Comments
 (0)