Surface cross-workspace subagents in their workspaces (#2061)

* fix(workspaces): show provider subagent activity

Provider subagent lifecycle lives outside managed agent snapshots, so workspace aggregation dropped it after the parent turn finished. Count running provider subagents against the delegation root and emit workspace updates when their status changes.

* fix(workspaces): surface cross-workspace subagents
This commit is contained in:
Mohamed Boudra
2026-07-14 14:22:14 +02:00
committed by GitHub
parent c0b801b805
commit 1f5283f5a3
14 changed files with 295 additions and 38 deletions
@@ -131,6 +131,32 @@ describe("workspace agent visibility", () => {
expect(result.knownAgentIds).toEqual(new Set(["child-agent", "parent-agent"]));
});
it("auto-opens a subagent whose parent belongs to another workspace", () => {
const parent = makeAgent({
id: "parent-agent",
cwd: "/repo",
workspaceId: "ws-parent",
});
const child = makeAgent({
id: "child-agent",
cwd: "/repo/worktree",
workspaceId: WORKSPACE_ID,
parentAgentId: parent.id,
});
const result = deriveWorkspaceAgentVisibility({
sessionAgents: new Map<string, Agent>([
[parent.id, parent],
[child.id, child],
]),
workspaceId: WORKSPACE_ID,
});
expect(result.activeAgentIds).toEqual(new Set(["child-agent"]));
expect(result.autoOpenAgentIds).toEqual(new Set(["child-agent"]));
expect(result.knownAgentIds).toEqual(new Set(["child-agent"]));
});
it("keeps archived agents out of activeAgentIds but present in knownAgentIds", () => {
const visible = makeAgent({
id: "visible-agent",
@@ -1,6 +1,6 @@
import type { Agent } from "@/stores/session-store";
import type { WorkspaceTabSnapshot } from "@/stores/workspace-layout-actions";
import { shouldAutoOpenAgentTab } from "@/subagents/policies";
import { isWorkspaceRootAgent } from "@/subagents/policies";
import { normalizeWorkspaceOpaqueId } from "@/utils/workspace-identity";
export interface WorkspaceAgentVisibility {
@@ -31,6 +31,10 @@ export function deriveWorkspaceAgentVisibility(input: {
const activeAgentIds = new Set<string>();
const autoOpenAgentIds = new Set<string>();
const knownAgentIds = new Set<string>();
const agentsById = new Map<string, Agent>([
...(agentDetails?.entries() ?? []),
...(sessionAgents?.entries() ?? []),
]);
for (const agent of sessionAgents?.values() ?? []) {
if (!agentBelongsToWorkspace(agent, workspaceId)) {
continue;
@@ -38,7 +42,8 @@ export function deriveWorkspaceAgentVisibility(input: {
knownAgentIds.add(agent.id);
if (!agent.archivedAt) {
activeAgentIds.add(agent.id);
if (shouldAutoOpenAgentTab(agent)) {
const parentAgent = agent.parentAgentId ? agentsById.get(agent.parentAgentId) : undefined;
if (isWorkspaceRootAgent(agent, parentAgent)) {
autoOpenAgentIds.add(agent.id);
}
}