diff --git a/src/auto-reply/reply/commands-status.test.ts b/src/auto-reply/reply/commands-status.test.ts index b8017601831..24f7eeb285d 100644 --- a/src/auto-reply/reply/commands-status.test.ts +++ b/src/auto-reply/reply/commands-status.test.ts @@ -160,4 +160,22 @@ describe("buildStatusReply subagent summary", () => { expect(reply?.text).not.toContain("🤖 Subagents: 1 active"); expect(reply?.text).not.toContain("stale old parent child"); }); + + it("counts controller-owned runs even when the latest child requester differs", async () => { + addSubagentRunForTests({ + runId: "run-status-controller-owned", + childSessionKey: "agent:main:subagent:status-controller-owned", + requesterSessionKey: "agent:main:requester-only", + requesterDisplayKey: "requester-only", + controllerSessionKey: "agent:main:main", + task: "controller-owned status worker", + cleanup: "keep", + createdAt: Date.now() - 60_000, + startedAt: Date.now() - 60_000, + }); + + const reply = await buildStatusReplyForTest({}); + + expect(reply?.text).toContain("🤖 Subagents: 1 active"); + }); }); diff --git a/src/auto-reply/reply/commands-status.ts b/src/auto-reply/reply/commands-status.ts index f2bdc720742..b1dd3dd28d0 100644 --- a/src/auto-reply/reply/commands-status.ts +++ b/src/auto-reply/reply/commands-status.ts @@ -6,11 +6,8 @@ import { } from "../../agents/agent-scope.js"; import { resolveFastModeState } from "../../agents/fast-mode.js"; import { resolveModelAuthLabel } from "../../agents/model-auth-label.js"; -import { - countPendingDescendantRuns, - getLatestSubagentRunByChildSessionKey, - listSubagentRunsForRequester, -} from "../../agents/subagent-registry.js"; +import { listControlledSubagentRuns } from "../../agents/subagent-control.js"; +import { countPendingDescendantRuns } from "../../agents/subagent-registry.js"; import { resolveInternalSessionKey, resolveMainSessionAlias, @@ -32,7 +29,7 @@ import type { ElevatedLevel, ReasoningLevel, ThinkLevel, VerboseLevel } from ".. import type { ReplyPayload } from "../types.js"; import type { CommandContext } from "./commands-types.js"; import { getFollowupQueueDepth, resolveQueueSettings } from "./queue.js"; -import { resolveSubagentLabel, sortSubagentRuns } from "./subagents-utils.js"; +import { resolveSubagentLabel } from "./subagents-utils.js"; // Some usage endpoints only work with CLI/session OAuth tokens, not API keys. // Skip those probes when the active auth mode cannot satisfy the endpoint. @@ -190,19 +187,7 @@ export async function buildStatusReply(params: { if (sessionKey) { const { mainKey, alias } = resolveMainSessionAlias(cfg); const requesterKey = resolveInternalSessionKey({ key: sessionKey, alias, mainKey }); - const seenChildSessionKeys = new Set(); - const runs = sortSubagentRuns(listSubagentRunsForRequester(requesterKey)).filter((entry) => { - if (seenChildSessionKeys.has(entry.childSessionKey)) { - return false; - } - const latest = getLatestSubagentRunByChildSessionKey(entry.childSessionKey); - const latestRequesterSessionKey = latest?.requesterSessionKey?.trim(); - if (!latest || latest.runId !== entry.runId || latestRequesterSessionKey !== requesterKey) { - return false; - } - seenChildSessionKeys.add(entry.childSessionKey); - return true; - }); + const runs = listControlledSubagentRuns(requesterKey); const verboseEnabled = resolvedVerboseLevel && resolvedVerboseLevel !== "off"; if (runs.length > 0) { const active = runs.filter(