From d241c247766dd8b841247bd38a5ab0965d034b05 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Sat, 9 May 2026 18:23:20 +0700 Subject: [PATCH] fix(app): never auto-focus subagents on workspace open pickAttentionAgent now skips agents with a parentAgentId. The workspace auto-focus path was opening subagents as tabs when they needed attention, breaking the rule that subagents only become tabs when the user explicitly clicks them. --- .../app/src/utils/agent-attention.test.ts | 34 +++++++++++++++++++ packages/app/src/utils/agent-attention.ts | 4 +++ 2 files changed, 38 insertions(+) diff --git a/packages/app/src/utils/agent-attention.test.ts b/packages/app/src/utils/agent-attention.test.ts index e05759306..2fc70a20b 100644 --- a/packages/app/src/utils/agent-attention.test.ts +++ b/packages/app/src/utils/agent-attention.test.ts @@ -213,6 +213,40 @@ describe("pickAttentionAgent", () => { ).toBe("older-permission-agent"); }); + it("ignores subagents even when they require attention", () => { + expect( + pickAttentionAgent([ + createAgent({ + id: "subagent", + parentAgentId: "parent-agent", + requiresAttention: true, + attentionReason: "permission", + attentionTimestamp: new Date("2026-01-01T00:00:00.000Z"), + }), + createAgent({ + id: "top-level-agent", + requiresAttention: true, + attentionReason: "finished", + attentionTimestamp: new Date("2026-01-02T00:00:00.000Z"), + }), + ]), + ).toBe("top-level-agent"); + }); + + it("returns null when only subagents require attention", () => { + expect( + pickAttentionAgent([ + createAgent({ + id: "subagent", + parentAgentId: "parent-agent", + requiresAttention: true, + attentionReason: "permission", + attentionTimestamp: new Date("2026-01-01T00:00:00.000Z"), + }), + ]), + ).toBeNull(); + }); + it("ignores agents with requiresAttention true but null reason", () => { expect( pickAttentionAgent([ diff --git a/packages/app/src/utils/agent-attention.ts b/packages/app/src/utils/agent-attention.ts index 8db905a49..a3e5df627 100644 --- a/packages/app/src/utils/agent-attention.ts +++ b/packages/app/src/utils/agent-attention.ts @@ -38,6 +38,10 @@ export function pickAttentionAgent(agents: Agent[]): string | null { continue; } + if (agent.parentAgentId) { + continue; + } + const priority = getAttentionPriority(agent.attentionReason); if (priority === null) { continue;