Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

fix(island): queued requests stay out of sight until their turn

Claudea356780050d6
diff --git a/windows/src/island/hooks.ts b/windows/src/island/hooks.ts
index b2b8a3ff..31d7e27d 100644
--- a/windows/src/island/hooks.ts
+++ b/windows/src/island/hooks.ts
@@ -19,17 +19,42 @@ import { N_, t } from "../i18n/i18n";
const CLAUDE_ID = "integration_claude";
const CURSOR_ID = "agent_cursor";
-/** Clears the approval card if no decision was made before the hook gave up. */
-let pendingTimeout: number | null = null;
+/** Most requests waiting at once, the one on the card included (Mac ApprovalQueue.maxPending). */
+const MAX_PENDING = 5;
+
+/**
+ * Each request gives up on its own clock: 110 s after it arrived, whether it
+ * is on the card or still in line, it goes (the relay has stopped waiting by
+ * then). Checked by id, so it can never take down a request that came later.
+ */
+function armRequestTimeout(island: Island, requestId: string) {
+ window.setTimeout(() => {
+ if (State.pendingApproval?.requestId === requestId) dropPendingCard(island);
+ else dropQueued((x) => x.requestId === requestId);
+ }, 110_000);
+}
+
+/** Takes requests out of the line (their relay is released by the caller or gone). */
+function dropQueued(match: (x: ApprovalInfo) => boolean): ApprovalInfo[] {
+ const gone = State.approvalQueue.filter(match);
+ if (gone.length === 0) return gone;
+ State.approvalQueue = State.approvalQueue.filter((x) => !match(x));
+ for (const pill of new Set(gone.map((x) => x.pillId))) {
+ if (!State.approvalQueue.some((x) => x.pillId === pill)) State.setPillBadge(pill, null);
+ }
+ State.notify();
+ return gone;
+}
/** Takes the approval or question card down and gives the island back. */
export function dropPendingCard(island: Island): void {
if (!State.pendingApproval) return;
State.endApproval();
if (State.pendingApproval) {
+ // The next request in line takes the card, the way a new one comes up.
const view = State.pendingApproval.questions ? "question" : "approval";
- island.setView(view);
Sound.play(view);
+ island.alert(view);
State.notify();
return;
}
@@ -253,10 +278,8 @@ export function registerHookHandlers(island: Island) {
// The relay stopped waiting without a decision and the terminal has taken
// over: a card still up for that request would be lying (#857).
void onEvent<string>("approval-expired", (requestId) => {
- State.approvalQueue = State.approvalQueue.filter((x) => x.requestId !== requestId);
+ dropQueued((x) => x.requestId === requestId);
if (State.pendingApproval?.requestId !== requestId) return;
- if (pendingTimeout != null) window.clearTimeout(pendingTimeout);
- pendingTimeout = null;
dropPendingCard(island);
});
}
@@ -324,6 +347,13 @@ function handleHook(island: Island, payload: HookPayload) {
if (cancelStopTimer(agentId)) State.setPillBadge(agentId, null);
};
+ // Requests of a turn that is over still in line are moot: released at once,
+ // before the card below goes, so none of them can take its place.
+ if (TURN_OVER.has(name)) {
+ const moot = dropQueued((x) => x.pillId === agentId && x.sessionId === (payload.session_id ?? ""));
+ for (const x of moot) if (x.requestId) void Bridge.approvalDecline(x.requestId);
+ }
+
// The turn that asked for a permission is over — answered in the terminal,
// interrupted, or a new prompt — so the card would be lying. It goes, and the
// relay is released without a decision. Same rule as the Mac.
@@ -334,8 +364,6 @@ function handleHook(island: Island, payload: HookPayload) {
pending.pillId === agentId &&
pending.sessionId === (payload.session_id ?? "")
) {
- if (pendingTimeout != null) window.clearTimeout(pendingTimeout);
- pendingTimeout = null;
if (pending.requestId) void Bridge.approvalDecline(pending.requestId);
dropPendingCard(island);
}
@@ -395,8 +423,6 @@ function handleHook(island: Island, payload: HookPayload) {
State.pendingApproval?.questions &&
State.pendingApproval.sessionId === (payload.session_id ?? "")
) {
- if (pendingTimeout != null) window.clearTimeout(pendingTimeout);
- pendingTimeout = null;
dropPendingCard(island);
}
State.updateTask(agentId, "working");
@@ -512,9 +538,11 @@ function handleHook(island: Island, payload: HookPayload) {
break;
}
- // Max 5 concurrent requests waiting (matching macOS ApprovalQueue.maxPending)
+ // Several requests can wait at once (several sessions or agents): they
+ // queue and the card shows the oldest. Past the cap, the newest goes back
+ // to its own terminal.
const totalPending = (State.pendingApproval ? 1 : 0) + State.approvalQueue.length;
- if (totalPending >= 5) {
+ if (totalPending >= MAX_PENDING) {
if (requestId) void Bridge.approvalDecline(requestId);
break;
}
@@ -523,6 +551,9 @@ function handleHook(island: Island, payload: HookPayload) {
supersedeStop();
const tool = payload.tool_name ?? "Tool";
const input = payload.tool_input ?? {};
+ // Claude Code asking a question is not a permission to grant: the island
+ // shows the options and sends back the one that was picked. Only Claude
+ // Code asks questions this way.
const questions = isExternalAgent ? null : askedQuestions(tool, input);
const view = questions ? "question" : "approval";
@@ -535,27 +566,29 @@ function handleHook(island: Island, payload: HookPayload) {
...(questions ? { questions } : {}),
};
- if (!State.pendingApproval) {
- if (pendingTimeout != null) window.clearTimeout(pendingTimeout);
- State.beginApproval(info);
- if (requestId) void Bridge.approvalAck(requestId);
- State.updateTask(agentId, view);
- Sound.play(view);
- } else {
- // Queue behind the currently showing request
+ // Coucou answers within 108 s or not at all; after that the terminal has
+ // taken over and the card would be lying.
+ armRequestTimeout(island, requestId);
+ Sound.play(view);
+ if (State.pendingApproval) {
+ // Another card is up: this one waits in line, its pill badged, and the
+ // card on screen stays as it is.
State.approvalQueue.push(info);
+ State.setPillBadge(agentId, "approval");
if (requestId) void Bridge.approvalAck(requestId);
+ break;
}
- Sound.play(view);
+ // The card always comes up, even over another pill or an island that is
+ // already open: its pill comes to the front, and the one you were on
+ // comes back once you answer (Mac #117, #120).
+ State.beginApproval(info);
+ // The relay's short ack window closes in 800 ms; everything below this
+ // line is synchronous, so the card really is up by the time it lands.
+ if (requestId) void Bridge.approvalAck(requestId);
+ State.updateTask(agentId, view);
// Any agent's card (Claude Code, Codex, Copilot CLI, Muse Code) comes up
// the same way: beginApproval brought its pill to the front.
island.alert(view);
- // Coucou answers within 108 s or not at all; after that the terminal has
- // taken over and the card would be lying.
- pendingTimeout = window.setTimeout(() => {
- pendingTimeout = null;
- dropPendingCard(island);
- }, 110_000);
break;
}
diff --git a/windows/tests/hooks.test.mjs b/windows/tests/hooks.test.mjs
index 0ecbb9dd..464068b6 100644
--- a/windows/tests/hooks.test.mjs
+++ b/windows/tests/hooks.test.mjs
@@ -38,6 +38,8 @@ beforeEach(() => {
State.paused = false;
State.isPinned = false;
State.pendingApproval = null;
+ State.approvalQueue = [];
+ State.focusBeforeApproval = null;
State.settings = { ...DEFAULT_SETTINGS };
State.loadIntegrationTasks();
});
@@ -542,6 +544,53 @@ test("a second request is queued in line: it waits for the first card to finish
assert.deepEqual(sent("approval_decline"), [{ requestId: "r7" }]);
});
+test("a request waiting in line leaves the card on screen as it is, and sounds once", (context) => {
+ const sound = context.mock.method(Sound, "play", () => {});
+ ask("r1");
+ assert.deepEqual(sound.mock.calls.map((call) => call.arguments), [["approval"]]);
+ hook({ hook_event_name: "SessionStart", session_id: "d2", coucou_agent: "codex" });
+ asked = [];
+ hook({
+ hook_event_name: "PermissionRequest", request_id: "q1", session_id: "s2", tool_name: "AskUserQuestion",
+ tool_input: { questions: [{ question: "Which?", options: [{ label: "A" }, { label: "B" }] }] },
+ });
+ hook({ hook_event_name: "PermissionRequest", request_id: "c1", session_id: "d2", coucou_agent: "codex", tool_name: "Bash" });
+ // No alert: the island stays on r1's approval card, not on the question's view.
+ assert.deepEqual(asked, []);
+ assert.equal(State.pendingApproval.requestId, "r1");
+ assert.equal(task("agent_codex").pillBadge, "approval");
+ assert.deepEqual(sound.mock.calls.map((call) => call.arguments), [["approval"], ["work"], ["question"], ["approval"]]);
+});
+
+test("the next request in line comes up when the card is dropped, and keeps its own clock", () => {
+ ask("r1");
+ seconds(60);
+ ask("r2", { session_id: "s2", tool_name: "Bash", tool_input: { command: "ls" } });
+ emit("approval-expired", "r1");
+ assert.equal(State.pendingApproval.requestId, "r2");
+ assert.deepEqual(asked.at(-1), "alert:approval");
+ // r1's 110 s run out: r2, which arrived 60 s later, is still on the card.
+ seconds(50);
+ assert.equal(State.pendingApproval?.requestId, "r2");
+ seconds(60);
+ assert.equal(State.pendingApproval, null);
+});
+
+test("a turn that ends takes its requests out of the line and releases them", () => {
+ ask("r1");
+ ask("r2", { session_id: "s2", tool_name: "Bash", tool_input: { command: "ls" } });
+ ask("r3", { session_id: "s2", tool_name: "Bash", tool_input: { command: "pwd" } });
+ hook({ hook_event_name: "Stop", session_id: "s2" });
+ assert.deepEqual(State.approvalQueue, []);
+ assert.deepEqual(sent("approval_decline"), [{ requestId: "r2" }, { requestId: "r3" }]);
+ assert.equal(State.pendingApproval.requestId, "r1");
+ // And when the card's own turn ends, nothing of it is left to come up.
+ ask("r4", { tool_name: "Bash", tool_input: { command: "ls" } });
+ hook({ hook_event_name: "Stop", session_id: "s1" });
+ assert.equal(State.pendingApproval, null);
+ assert.deepEqual(State.approvalQueue, []);
+});
+
test("the same request arriving twice is acknowledged again, not declined", () => {
ask("r1");
ask("r1");