From f1222be4b3ac1e2a91a5dfaacae656efdd8bbd22 Mon Sep 17 00:00:00 2001 From: juju812 Date: Fri, 20 Nov 2026 15:25:02 +0800 Subject: [PATCH] fix(panel): include ancestor processes in macOS relaunch pgrep/pkill On macOS, BSD pgrep and pkill exclude ancestor processes by default unless -a is passed. Because the detached relaunch shell is spawned from the sidecar under Antigravity, pgrep -x and pkill -x silently missed the running host process, causing open -a --args --remote-debugging-port=0 to fire before the old instance exited (or while it was still running). Use pgrep -ax and pkill -{TERM,KILL} -ax, and add a brief 0.4s pause after process exit so LaunchServices finishes deregistering before relaunch. --- sidecars/panel/backend/desktop-launcher-config.mjs | 7 ++++--- sidecars/panel/test/window-bridge.test.mjs | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/sidecars/panel/backend/desktop-launcher-config.mjs b/sidecars/panel/backend/desktop-launcher-config.mjs index 8ad0004..5c39af5 100644 --- a/sidecars/panel/backend/desktop-launcher-config.mjs +++ b/sidecars/panel/backend/desktop-launcher-config.mjs @@ -2005,10 +2005,11 @@ export async function triggerDesktopHostRelaunch({ bundleDerivedName || (hostInfo.kind === 'ide' ? 'Antigravity IDE' : 'Antigravity'); const shScript = [ 'sleep 0.45', - 'if osascript -e \'on run argv\' -e \'tell application (item 1 of argv) to quit\' -e \'end run\' -- "$AGY_APP_NAME" >/dev/null 2>&1; then i=0; while [ $i -lt 25 ] && pgrep -x "$AGY_APP_NAME" >/dev/null 2>&1; do sleep 0.2; i=$((i+1)); done; fi', - 'if pgrep -x "$AGY_APP_NAME" >/dev/null 2>&1; then pkill -TERM -x "$AGY_APP_NAME" >/dev/null 2>&1 || killall -TERM "$AGY_APP_NAME" >/dev/null 2>&1 || true; j=0; while [ $j -lt 20 ] && pgrep -x "$AGY_APP_NAME" >/dev/null 2>&1; do sleep 0.2; j=$((j+1)); done; fi', - 'if pgrep -x "$AGY_APP_NAME" >/dev/null 2>&1; then pkill -KILL -x "$AGY_APP_NAME" >/dev/null 2>&1 || killall -KILL "$AGY_APP_NAME" >/dev/null 2>&1 || true; k=0; while [ $k -lt 15 ] && pgrep -x "$AGY_APP_NAME" >/dev/null 2>&1; do sleep 0.2; k=$((k+1)); done; fi', + 'if osascript -e \'on run argv\' -e \'tell application (item 1 of argv) to quit\' -e \'end run\' -- "$AGY_APP_NAME" >/dev/null 2>&1; then i=0; while [ $i -lt 25 ] && pgrep -ax "$AGY_APP_NAME" >/dev/null 2>&1; do sleep 0.2; i=$((i+1)); done; fi', + 'if pgrep -ax "$AGY_APP_NAME" >/dev/null 2>&1; then pkill -TERM -ax "$AGY_APP_NAME" >/dev/null 2>&1 || killall -TERM "$AGY_APP_NAME" >/dev/null 2>&1 || true; j=0; while [ $j -lt 20 ] && pgrep -ax "$AGY_APP_NAME" >/dev/null 2>&1; do sleep 0.2; j=$((j+1)); done; fi', + 'if pgrep -ax "$AGY_APP_NAME" >/dev/null 2>&1; then pkill -KILL -ax "$AGY_APP_NAME" >/dev/null 2>&1 || killall -KILL "$AGY_APP_NAME" >/dev/null 2>&1 || true; k=0; while [ $k -lt 15 ] && pgrep -ax "$AGY_APP_NAME" >/dev/null 2>&1; do sleep 0.2; k=$((k+1)); done; fi', 'old_ifs="$IFS"; set -f; IFS=":"; for f in $AGY_STALE_PORT_FILES; do [ -n "$f" ] && rm -f "$f"; done; set +f; IFS="$old_ifs"', + 'sleep 0.4', 'open -a "$AGY_RELAUNCH_APP" --args --remote-debugging-port=0 >/dev/null 2>&1', ].join('; '); await spawner('/bin/sh', ['-c', shScript], { diff --git a/sidecars/panel/test/window-bridge.test.mjs b/sidecars/panel/test/window-bridge.test.mjs index 6b9ea45..2c7bbbc 100644 --- a/sidecars/panel/test/window-bridge.test.mjs +++ b/sidecars/panel/test/window-bridge.test.mjs @@ -5504,9 +5504,9 @@ test('Issue #26: Antigravity Desktop 2.33.0+ automatic shortcut/launcher provisi assert.equal(relaunchMacRes.ok, true); assert.equal(macSpawnArgs.env.AGY_RELAUNCH_APP, '/Applications/Antigravity.app'); assert.equal(macSpawnArgs.env.AGY_APP_NAME, 'Antigravity'); - assert.match(macSpawnArgs.args[1], /if osascript .* then .* fi/); - assert.match(macSpawnArgs.args[1], /pkill -TERM -x "\$AGY_APP_NAME"/); - assert.match(macSpawnArgs.args[1], /pkill -KILL -x "\$AGY_APP_NAME"/); + assert.match(macSpawnArgs.args[1], /if osascript .* then .* pgrep -ax "\$AGY_APP_NAME".* fi/); + assert.match(macSpawnArgs.args[1], /pkill -TERM -ax "\$AGY_APP_NAME"/); + assert.match(macSpawnArgs.args[1], /pkill -KILL -ax "\$AGY_APP_NAME"/); assert.match(macSpawnArgs.args[1], /open -a "\$AGY_RELAUNCH_APP" --args --remote-debugging-port=0/); // macOS TCC-blocked osascript falls back to ps -axo comm= and derives custom .app name