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.
This commit is contained in:
Mohamed Boudra
2026-05-09 18:32:43 +07:00
parent ca503c1560
commit d241c24776
2 changed files with 38 additions and 0 deletions
@@ -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([
@@ -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;