fix(flowext): I blamed the screen lock. It was a DENIED Automation grant.

The -1712 "AppleEvent timed out" on m3ultra was not the screen lock (2236a96 is wrong).
The user TCC db says it plainly:

  m3ultra:  /bin/sh -> com.google.Chrome    auth_value=0   DENIED
            (no row at all for /bin/sh -> com.brave.Browser)
  ultra:    /bin/sh -> com.brave.Browser    auth_value=2   allowed

The launchd job IS `/bin/sh -c exec launch.sh`, so that one row kills it, and a DENIED
Automation grant surfaces as a ~2-minute hang then -1712, never a clean -1743. The
`sshd-keygen-wrapper -> {finder,systemevents,Brave,Chrome} = 0` rows are why AppleEvents
also failed from ssh on BOTH Macs — which is what made the lock look causal.

Two corrections to my own reasoning:
 * `name`/`version`/`running` of an application are answered from the app bundle WITHOUT
   sending an AppleEvent, so "app-level AE works, window-level hangs" was never evidence.
 * the lock guard could wrongly stop a working rig (a locked screen was never shown to
   break a granted AppleEvent). Removed the gate.

launch.sh now attempts the AppleScript and, only on failure, reads the TCC row for
(/bin/sh -> this browser's bundle id) and prints which of the three states it is:
denied / allowed-but-unresponsive / never-prompted.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
type-two 2026-07-08 21:33:54 +10:00
parent 2236a96ed4
commit 5dabd86ad5

View File

@ -38,19 +38,10 @@ fi
# Must name the browser the EXTENSION is loaded into. ultra = Brave, m3ultra = Chrome.
BROWSER="${FLOW_BROWSER:-Brave Browser}"
# A LOCKED SCREEN wedges every AppleScript window/tab query for ~2 min, then -1712
# "AppleEvent timed out". Not a browser bug: with the screen locked, Finder, System Events
# and Brave all hang on `count of windows` identically. Bail out loudly instead.
if ioreg -n Root -d1 -r | tr -d ' ' | grep -q '"CGSSessionScreenIsLocked"=Yes'; then
echo "screen is LOCKED on $(hostname -s) — cannot drive $BROWSER (every window query would" \
"hang, then -1712). Unlock it; for an unattended rig also set System Settings >" \
"Lock Screen > 'Require password after screen saver begins' = Never."
exit 0 # not an error: the 10-min tick retries once someone unlocks
fi
# `open location` hands the URL to the DEFAULT browser (Brave here) — never to $BROWSER.
# Make the tab inside the target app instead. Timeout so a wedged app can't hold the job.
osascript <<OSA
# Make the tab inside the target app instead. Timeout so a wedged app can't hold the job:
# an Automation denial surfaces as a ~2min hang then -1712, NOT as a clean -1743.
if out=$(osascript <<OSA 2>&1
with timeout of 30 seconds
tell application "$BROWSER"
set found to false
@ -73,4 +64,23 @@ with timeout of 30 seconds
end tell
end timeout
OSA
echo "$BROWSER focused on Flow. With Auto-start ticked, the rinse begins on load."
); then
echo "$BROWSER focused on Flow. With Auto-start ticked, the rinse begins on load."
else
# Don't guess. The TCC row for (this launchd job's /bin/sh) -> (this browser) says which it is.
echo "cannot drive $BROWSER: $out"
BUNDLE=$(osascript -e "id of app \"$BROWSER\"" 2>/dev/null) # no AppleEvent — reads the bundle
DB="$HOME/Library/Application Support/com.apple.TCC/TCC.db"
AUTH=$(sqlite3 "$DB" "select auth_value from access where service='kTCCServiceAppleEvents'
and client='/bin/sh' and indirect_object_identifier='$BUNDLE';" 2>/dev/null)
case "$AUTH" in
0) echo " → Automation is DENIED for /bin/sh -> $BUNDLE (someone clicked Don't Allow)." \
"Fix: System Settings > Privacy & Security > Automation > sh > enable \"$BROWSER\"." ;;
2) echo " → Automation is ALLOWED, so $BROWSER itself is not answering AppleEvents." \
"Screen locked? $(ioreg -n Root -d1 -r | tr -d ' ' | grep -q '"CGSSessionScreenIsLocked"=Yes' \
&& echo yes || echo no). Try quitting and reopening $BROWSER." ;;
*) echo " → No Automation grant yet for /bin/sh -> $BUNDLE: a consent dialog is waiting on" \
"$(hostname -s)'s screen. Unlock it and click Allow." ;;
esac
exit 0 # not an error — the 10-min tick retries once a human fixes it
fi