Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix(coding-agent): count active retained subagents (#634)

Sebastian Müllerc97977f38e3f
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 2dc064dd20..1c51369411 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -4,6 +4,7 @@
- Changed self-updates to report the previous and new Prime Agent versions.
- Changed agent messages to always use steering delivery and removed delivery-mode options from the Python, CLI, RPC, and connection APIs.
+- Fixed the subagent summary showing retained children as idle while they run follow-up work.
## [0.6.1] - 2026-08-05
diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.ts
index 3ddf6a2904..1699088f9a 100644
--- a/packages/coding-agent/src/core/agent-session.ts
+++ b/packages/coding-agent/src/core/agent-session.ts
@@ -9726,7 +9726,13 @@ export class AgentSession {
this._emit(event);
return;
}
- if (event.type === "message_end" && event.message.role === "assistant") {
+ if (event.type === "agent_start") {
+ activity = { kind: "waiting" };
+ emitChildUpdate();
+ } else if (event.type === "agent_end") {
+ activity = undefined;
+ emitChildUpdate();
+ } else if (event.type === "message_end" && event.message.role === "assistant") {
const assistant = event.message as AssistantMessage;
if (assistant.stopReason !== "error" && assistant.stopReason !== "aborted") {
attributeChildUsage(parentAssistantForUsage?.usage ?? emptyUsage(), assistant.usage);
diff --git a/packages/coding-agent/src/modes/daemon/daemon-session-list.ts b/packages/coding-agent/src/modes/daemon/daemon-session-list.ts
index f42a745bc2..edc1ca652a 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-session-list.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-session-list.ts
@@ -394,6 +394,7 @@ function rlmChildSnapshotForActiveSession(
? parent?.runtime.session.getRlmChildRunStatus(metadata.rlmChildId)
: undefined;
const status = runStatus ?? (session.isSessionActive ? "running" : "done");
+ const isActive = status === "running" || session.isSessionActive;
return {
id: metadata.rlmChildId ?? activeSession.activeSessionId,
parentId: parentNodeId,
@@ -407,7 +408,7 @@ function rlmChildSnapshotForActiveSession(
tokenCount: session._contextTokensForCurrentMessages(),
recap: session.getCurrentRecap(),
sessionDir: metadata.sessionDir ?? session.sessionManager.getSessionDir(),
- activity: status === "running" ? { kind: session.isStreaming ? "writing" : "waiting" } : undefined,
+ activity: isActive ? { kind: session.isStreaming ? "writing" : "waiting" } : undefined,
};
}
diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
index 28232c2b94..ccfef6a4d5 100644
--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts
+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
@@ -349,7 +349,10 @@ function mergeSubagentSnapshot(
// Active updates may omit a previously known daemon session id, but a
// terminal update without one means the child is no longer resident.
activeSessionId: active ? (incoming.activeSessionId ?? previous.activeSessionId) : incoming.activeSessionId,
- activity: active ? (incoming.activity ?? previous.activity) : undefined,
+ // A completed retained child can become active again when it receives a
+ // follow-up. Its RLM run status stays terminal, so activity must remain an
+ // independent projection of the live session state.
+ activity: active ? (incoming.activity ?? previous.activity) : incoming.activity,
};
}
diff --git a/packages/coding-agent/test/agent-session-recursion.test.ts b/packages/coding-agent/test/agent-session-recursion.test.ts
index fcec93f766..f066f02b11 100644
--- a/packages/coding-agent/test/agent-session-recursion.test.ts
+++ b/packages/coding-agent/test/agent-session-recursion.test.ts
@@ -1390,6 +1390,47 @@ describe("AgentSession rlm recursion", () => {
);
});
+ it("projects retained child follow-up turns into parent child-update activity", async () => {
+ let releaseInitial: () => void = () => {};
+ const initialGate = new Promise<void>((resolve) => {
+ releaseInitial = resolve;
+ });
+ let releaseFollowUp: () => void = () => {};
+ const followUpGate = new Promise<void>((resolve) => {
+ releaseFollowUp = resolve;
+ });
+ const events: Array<{ status: string; activity?: { kind: string } }> = [];
+ const root = createSession({
+ streamFn: (_model, context) => {
+ const text = userText(context);
+ const stream = createAssistantMessageEventStream();
+ void (text === "initial" ? initialGate : followUpGate).then(() => {
+ stream.push({ type: "done", reason: "stop", message: assistantMessage(`answer: ${text}`) });
+ });
+ return stream;
+ },
+ });
+ root.subscribe((event) => {
+ if (event.type === "rlm_child_update") {
+ events.push({ status: event.child.status, activity: event.child.activity });
+ }
+ });
+
+ const spawned = await root.runRlmChild("initial");
+ await waitFor(() => events.some((event) => event.status === "running" && event.activity?.kind === "waiting"));
+ releaseInitial();
+ await waitFor(() => root.getRlmChildSession(spawned.rlm_child_id) !== undefined);
+ await waitFor(() => events.at(-1)?.status === "done" && events.at(-1)?.activity === undefined);
+
+ const child = root.getRlmChildSession(spawned.rlm_child_id);
+ if (!child) throw new Error("Missing retained child session");
+ const followUp = child.prompt("follow-up");
+ await waitFor(() => events.at(-1)?.status === "done" && events.at(-1)?.activity?.kind === "waiting");
+ releaseFollowUp();
+ await followUp;
+ await waitFor(() => events.at(-1)?.status === "done" && events.at(-1)?.activity === undefined);
+ });
+
it("lists a completed child with its parent-scoped messaging identity until disposal", async () => {
let daemonChildId = "";
const root = createSession({
diff --git a/packages/coding-agent/test/daemon-session-list.test.ts b/packages/coding-agent/test/daemon-session-list.test.ts
index f07004737a..a332372bfb 100644
--- a/packages/coding-agent/test/daemon-session-list.test.ts
+++ b/packages/coding-agent/test/daemon-session-list.test.ts
@@ -589,6 +589,28 @@ describe("buildRlmChildSnapshots", () => {
expect(snapshots.map((snapshot) => [snapshot.id, snapshot.status])).toEqual([["sub-aaa", "running"]]);
});
+ it("keeps terminal run status while projecting a retained child's active follow-up", () => {
+ const parent = makeState({
+ activeSessionId: "parent",
+ childRunStatuses: { "sub-aaa": "done" },
+ });
+ const activeRetainedChild = makeState({
+ activeSessionId: "child",
+ isStreaming: true,
+ metadata: {
+ kind: "subagent",
+ createdAt: 1,
+ parentActiveSessionId: "parent",
+ rlmChildId: "sub-aaa",
+ },
+ });
+
+ expect(buildRlmChildSnapshots("parent", [parent, activeRetainedChild])[0]).toMatchObject({
+ status: "done",
+ activity: { kind: "writing" },
+ });
+ });
+
it("includes in-flight assistant output in child snapshots", () => {
const parent = makeState({ activeSessionId: "parent" });
const child = makeState({
diff --git a/packages/coding-agent/test/subagent-summary-line.test.ts b/packages/coding-agent/test/subagent-summary-line.test.ts
index 19964c7ca3..03839caa01 100644
--- a/packages/coding-agent/test/subagent-summary-line.test.ts
+++ b/packages/coding-agent/test/subagent-summary-line.test.ts
@@ -113,6 +113,35 @@ describe("SubagentSummaryLine", () => {
expect(stripAnsi(line.render(100).join("\n"))).toContain("0 running · 1 idle · 0 inactive");
});
+ it("counts a retained completed child as running while a follow-up turn is active", () => {
+ const line = new SubagentSummaryLine();
+ const mode = Object.create(InteractiveMode.prototype) as InteractiveMode & Record<string, unknown>;
+ Object.assign(mode, {
+ subagentSnapshots: new Map<string, AgentConnectionRlmChildAgentSnapshot>(),
+ rlmNodeId: undefined,
+ heartbeatCatalog: [],
+ subagentSummaryLine: line,
+ updateScopedHeartbeats: vi.fn(),
+ updateWorkingPulse: vi.fn(),
+ syncWorkingLoader: vi.fn(),
+ updateWorkingLoaderMessage: vi.fn(),
+ ui: { requestRender: vi.fn() },
+ });
+ const update = Reflect.get(InteractiveMode.prototype, "updateSubagentSummary") as (
+ this: typeof mode,
+ value: AgentConnectionRlmChildAgentSnapshot,
+ ) => void;
+
+ update.call(mode, child("worker", "done", { activeSessionId: "resident-worker" }));
+ expect(stripAnsi(line.render(100).join("\n"))).toContain("0 running · 1 idle · 0 inactive");
+
+ update.call(mode, child("worker", "done", { activeSessionId: "resident-worker", activity: { kind: "waiting" } }));
+ expect(stripAnsi(line.render(100).join("\n"))).toContain("1 running · 0 idle · 0 inactive");
+
+ update.call(mode, child("worker", "done", { activeSessionId: "resident-worker" }));
+ expect(stripAnsi(line.render(100).join("\n"))).toContain("0 running · 1 idle · 0 inactive");
+ });
+
it("refreshes counts when startup seeding follows an early live child update", () => {
const line = new SubagentSummaryLine();
const mode = Object.create(InteractiveMode.prototype) as InteractiveMode & Record<string, unknown>;