Skip to content

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

Rust

show subagent heartbeat status in chat (#473)

kt97b9fab154ff
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 53c4c3a353..25752c349c 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -8,7 +8,7 @@
- Changed interactive, print, JSON, RPC, piped-stdin, and no-session clients to use the same daemon-owned runtime while preserving their existing commands, output protocols, and lifecycle behavior ([ENG-4685](https://linear.app/primeintellect/issue/ENG-4685)).
- Added RPC controls for schedules, heartbeats, agent messaging, and live session observation ([ENG-4685](https://linear.app/primeintellect/issue/ENG-4685)).
- Fixed daemon-backed headless startup, rollback routing, RPC wire compatibility, and duplicate client runtime preparation ([ENG-4685](https://linear.app/primeintellect/issue/ENG-4685)).
-- Fixed agents with heartbeat-owning subagents appearing completed and showing completion checkmarks in the Agents View.
+- Fixed heartbeat-owning subagents appearing completed, showing completion checkmarks below the prompt, being omitted from active subagent counts, or remaining visible after deletion.
- Fixed the heartbeat tray and manager showing heartbeats from unrelated sessions.
- Fixed daemon backpressure triggering redundant catch-up snapshots for events already queued by the socket.
- Added dedicated stable and beta installers, with stable advancing on version bumps and beta advancing on every commit to `main`.
diff --git a/packages/coding-agent/src/core/agent-session.ts b/packages/coding-agent/src/core/agent-session.ts
index 85e834ff5d..d0d8b875d4 100644
--- a/packages/coding-agent/src/core/agent-session.ts
+++ b/packages/coding-agent/src/core/agent-session.ts
@@ -6550,11 +6550,29 @@ export class AgentSession {
}
}
+ private _emitRlmSubagentRemoval(subagent: RlmSubagentRegistryEntry): void {
+ this._emit({
+ type: "rlm_child_update",
+ child: {
+ id: subagent.rlm_child_id,
+ parentId: this._rlmParentNodeId,
+ activeSessionId: subagent.active_session_id ?? undefined,
+ sessionName: subagent.session_name,
+ label: subagent.session_name,
+ status: "cancelled",
+ sessionDir: subagent.session_dir,
+ error: "Deleted by parent orchestrator",
+ },
+ });
+ }
+
private async _deleteResolvedRlmSubagent(subagent: RlmSubagentRegistryEntry): Promise<RlmDeleteSubagentResult> {
const childId = subagent.rlm_child_id;
const run = this._activeRlmChildRuns.get(childId);
if (run) {
- this._cancelRlmChildRun(run, "Deleted by parent orchestrator");
+ if (!this._cancelRlmChildRun(run, "Deleted by parent orchestrator")) {
+ this._emitRlmSubagentRemoval(subagent);
+ }
const liveSession = run.session;
if (liveSession) {
try {
@@ -6602,6 +6620,8 @@ export class AgentSession {
return { subagent };
}
+ this._emitRlmSubagentRemoval(subagent);
+
const retained = this._retainedRlmChildSessions.get(childId);
if (retained) {
try {
diff --git a/packages/coding-agent/src/modes/agents-view/agents-view-state.ts b/packages/coding-agent/src/modes/agents-view/agents-view-state.ts
index 5c2862816c..7730fc2431 100644
--- a/packages/coding-agent/src/modes/agents-view/agents-view-state.ts
+++ b/packages/coding-agent/src/modes/agents-view/agents-view-state.ts
@@ -148,7 +148,7 @@ export function buildAgentsViewRows(
continue;
}
parentByChild.set(row, parent);
- if (row.summary.activity === "working") {
+ if (row.summary.activity === "working" || row.summary.hasActiveHeartbeat) {
parent.runningSubagentCount += 1;
}
const siblings = childrenByParent.get(parent) ?? [];
diff --git a/packages/coding-agent/src/modes/interactive/components/child-agent-inspector.ts b/packages/coding-agent/src/modes/interactive/components/child-agent-inspector.ts
index 98f3bf8892..10e4532efc 100644
--- a/packages/coding-agent/src/modes/interactive/components/child-agent-inspector.ts
+++ b/packages/coding-agent/src/modes/interactive/components/child-agent-inspector.ts
@@ -38,6 +38,7 @@ export interface ChildAgentInspectorNode {
recap?: string;
sessionDir: string;
activity?: ChildAgentActivity;
+ hasActiveHeartbeat?: boolean;
error?: string;
children?: readonly ChildAgentInspectorNode[];
}
@@ -64,14 +65,14 @@ function isExpandableComponent(component: Component): component is ExpandableCom
}
// Active before finished, so completed agents settle to the bottom.
-function childAgentSortRank(status: ChildAgentStatus): number {
- return status === "running" || status === "queued" ? 0 : 1;
+function childAgentSortRank(node: ChildAgentInspectorNode): number {
+ return node.status === "running" || node.status === "queued" || node.hasActiveHeartbeat ? 0 : 1;
}
function flattenChildAgentNodes(nodes: readonly ChildAgentInspectorNode[]): FlatChildAgentNode[] {
const result: FlatChildAgentNode[] = [];
const walk = (items: readonly ChildAgentInspectorNode[]): void => {
- const ordered = [...items].sort((a, b) => childAgentSortRank(a.status) - childAgentSortRank(b.status));
+ const ordered = [...items].sort((a, b) => childAgentSortRank(a) - childAgentSortRank(b));
for (const node of ordered) {
result.push({ node });
walk(node.children ?? []);
@@ -132,8 +133,11 @@ export function nodeActivityLabel(node: ChildAgentInspectorNode): string {
}
// Subagent list entries mirror the agents view row format: icon, title, right-aligned time.
-function childAgentStatusIcon(status: ChildAgentStatus): string {
- switch (status) {
+function childAgentStatusIcon(node: ChildAgentInspectorNode): string {
+ if (node.hasActiveHeartbeat) {
+ return "♥";
+ }
+ switch (node.status) {
case "queued":
return "◇";
case "running":
@@ -144,14 +148,17 @@ function childAgentStatusIcon(status: ChildAgentStatus): string {
case "cancelled":
return "✗";
default: {
- const _exhaustive: never = status;
+ const _exhaustive: never = node.status;
return _exhaustive;
}
}
}
-function formatChildAgentStatusIcon(status: ChildAgentStatus, icon: string): string {
- switch (status) {
+function formatChildAgentStatusIcon(node: ChildAgentInspectorNode, icon: string): string {
+ if (node.hasActiveHeartbeat) {
+ return theme.fg("error", icon);
+ }
+ switch (node.status) {
case "queued":
return theme.fg("dim", icon);
case "running":
@@ -163,7 +170,7 @@ function formatChildAgentStatusIcon(status: ChildAgentStatus, icon: string): str
case "cancelled":
return theme.fg("warning", icon);
default: {
- const _exhaustive: never = status;
+ const _exhaustive: never = node.status;
return _exhaustive;
}
}
@@ -186,7 +193,7 @@ function formatChildAgentDuration(durationMs: number | undefined): string {
function childAgentRecap(node: ChildAgentInspectorNode): string {
const recap = node.recap?.replace(/\s+/g, " ").trim();
- return recap || nodeActivityLabel(node);
+ return recap || (node.hasActiveHeartbeat ? "Heartbeat active" : nodeActivityLabel(node));
}
function padTableCell(value: string, width: number, ellipsis = ""): string {
@@ -273,8 +280,10 @@ export class ChildAgentSummaryComponent implements Component, Focusable {
}
if (!this.focused || !this.selectedId || !flat.some((entry) => entry.node.id === this.selectedId)) {
this.selectedId =
- flat.find((entry) => entry.node.status === "running" || entry.node.status === "queued")?.node.id ??
- flat[0]?.node.id;
+ flat.find(
+ (entry) =>
+ entry.node.status === "running" || entry.node.status === "queued" || entry.node.hasActiveHeartbeat,
+ )?.node.id ?? flat[0]?.node.id;
}
}
@@ -475,11 +484,12 @@ export class ChildAgentSummaryComponent implements Component, Focusable {
): string {
const indent = " ".repeat(SUMMARY_LIST_INDENT);
// Running rows pulse the shared working glyph; other states stay static.
- const rawIcon =
- entry.node.status === "running"
+ const rawIcon = entry.node.hasActiveHeartbeat
+ ? childAgentStatusIcon(entry.node)
+ : entry.node.status === "running"
? workingIconFrame(getWorkingPulseFrame())
- : childAgentStatusIcon(entry.node.status);
- const icon = formatChildAgentStatusIcon(entry.node.status, rawIcon);
+ : childAgentStatusIcon(entry.node);
+ const icon = formatChildAgentStatusIcon(entry.node, rawIcon);
const agentLabel = `S${number}`;
const agentCell = theme.fg("muted", padTableCell(agentLabel, agentWidth));
const promptCell = this.elidePrompt(this.entryLabel(entry), sharedPrefix, sharedSuffix, promptWidth);
diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
index be29e82cfa..ce39a33592 100644
--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts
+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
@@ -2364,8 +2364,7 @@ export class InteractiveMode {
this.heartbeats = heartbeats;
this.heartbeatManager?.setHeartbeats(heartbeats);
this.scheduleHeartbeatManagerRefresh();
- this.childAgentSummary.invalidate();
- this.ui.requestRender();
+ this.refreshChildAgentInspector();
}
private applyConnectionStateSnapshot(state: AgentConnectionState): void {
@@ -5256,8 +5255,7 @@ export class InteractiveMode {
}
private updateChildAgentInspector(child: AgentConnectionRlmChildAgentSnapshot): void {
- // Cancelled subagents were deliberately stopped; drop them from the
- // viewer instead of keeping a dead row around.
+ // Cancellation is also the lifecycle tombstone for deleted subagents.
if (child.status === "cancelled") {
this.removeChildAgentSnapshot(child.id);
this.refreshChildAgentInspector();
@@ -5669,6 +5667,11 @@ export class InteractiveMode {
}
private buildChildAgentInspectorNodes(): ChildAgentInspectorNode[] {
+ const activeHeartbeatSessionIds = new Set(
+ this.heartbeats
+ .filter((heartbeat) => heartbeat.job.status === "active")
+ .map((heartbeat) => heartbeat.job.activeSessionId),
+ );
const childrenByParent = new Map<string | undefined, AgentConnectionRlmChildAgentSnapshot[]>();
for (const child of this.childAgentSnapshots.values()) {
const siblings = childrenByParent.get(child.parentId) ?? [];
@@ -5690,6 +5693,8 @@ export class InteractiveMode {
recap: child.recap,
sessionDir: child.sessionDir,
activity: child.activity,
+ hasActiveHeartbeat:
+ child.activeSessionId !== undefined && activeHeartbeatSessionIds.has(child.activeSessionId),
error: child.error,
children: childrenByParent.get(child.id)?.map(build),
});
diff --git a/packages/coding-agent/test/agent-session-recursion.test.ts b/packages/coding-agent/test/agent-session-recursion.test.ts
index be2223c70e..bccc80edcc 100644
--- a/packages/coding-agent/test/agent-session-recursion.test.ts
+++ b/packages/coding-agent/test/agent-session-recursion.test.ts
@@ -351,6 +351,12 @@ describe("AgentSession rlm recursion", () => {
child.setSessionName("restored-worker");
const disposeChild = vi.spyOn(child, "disposeAsync");
const root = createSession();
+ const childStatuses: string[] = [];
+ root.subscribe((event) => {
+ if (event.type === "rlm_child_update" && event.child.id === childId) {
+ childStatuses.push(event.child.status);
+ }
+ });
expect(root.retainFinishedRlmChildSession(childId, child)).toBe(true);
expect(root.listRlmSubagents().subagents).toEqual([
@@ -366,6 +372,7 @@ describe("AgentSession rlm recursion", () => {
});
expect(disposeChild).toHaveBeenCalledOnce();
expect(root.listRlmSubagents()).toEqual({ subagents: [] });
+ expect(childStatuses).toEqual(["cancelled"]);
});
it("hides a retained child after failed deletion and keeps it selector-retryable", async () => {
diff --git a/packages/coding-agent/test/agents-view-state.test.ts b/packages/coding-agent/test/agents-view-state.test.ts
index 12b3fdd1d7..c17a429604 100644
--- a/packages/coding-agent/test/agents-view-state.test.ts
+++ b/packages/coding-agent/test/agents-view-state.test.ts
@@ -257,7 +257,8 @@ describe("agents view state", () => {
expect(collapsed[1]).toMatchObject({
kind: "subagent-summary",
section: "heartbeats",
- title: "1 subagent · 1 heartbeat active",
+ title: "1 subagent running · 1 heartbeat active",
+ runningSubagentCount: 1,
});
const expanded = buildAgentsViewRows(summaries, new Set([collapsed[0]?.identity ?? ""]));
expect(expanded[1]).toMatchObject({
@@ -267,6 +268,40 @@ describe("agents view state", () => {
});
});
+ test("counts every idle heartbeating subagent as running", () => {
+ const heartbeatChildren = Array.from({ length: 10 }, (_, index) =>
+ makeSummary({
+ id: `heartbeat-child-${index}`,
+ activeSessionId: `heartbeat-child-${index}`,
+ sessionId: `heartbeat-child-session-${index}`,
+ sessionName: `Heartbeat child ${index}`,
+ runtimeKind: "subagent",
+ parentActiveSessionId: "parent-active",
+ hasActiveHeartbeat: true,
+ activity: "idle",
+ taskState: "completed",
+ }),
+ );
+ const rows = buildAgentsViewRows([
+ ...heartbeatChildren,
+ makeSummary({
+ id: "parent-active",
+ activeSessionId: "parent-active",
+ sessionId: "parent-session",
+ sessionName: "Parent",
+ activity: "idle",
+ taskState: "completed",
+ }),
+ ]);
+
+ expect(rows[0]).toMatchObject({ section: "heartbeats", runningSubagentCount: 10 });
+ expect(rows[1]).toMatchObject({
+ kind: "subagent-summary",
+ title: "10 subagents running · 10 heartbeats active",
+ runningSubagentCount: 10,
+ });
+ });
+
test("propagates a descendant heartbeat through completed subagent ancestors", () => {
const summaries = [
makeSummary({
diff --git a/packages/coding-agent/test/child-agent-summary-list.test.ts b/packages/coding-agent/test/child-agent-summary-list.test.ts
index 02482e9475..3995493a89 100644
--- a/packages/coding-agent/test/child-agent-summary-list.test.ts
+++ b/packages/coding-agent/test/child-agent-summary-list.test.ts
@@ -109,6 +109,17 @@ describe("ChildAgentSummaryComponent inline list", () => {
expect(frame0).not.toBe(frame1);
});
+ it("shows heartbeating completed subagents as active with heartbeat icons", () => {
+ const summary = new ChildAgentSummaryComponent();
+ summary.setNodes([{ ...node("done", "done") }, { ...node("heartbeat", "done"), hasActiveHeartbeat: true }]);
+ const lines = summary.render(80).map(stripAnsi);
+
+ expect(lines[0]).toContain("♥");
+ expect(lines[0]).toContain("heartbeat");
+ expect(lines[0]).toContain("Heartbeat active");
+ expect(lines[1]).toContain("✓");
+ });
+
it("can reselect a node by id when returning from its detail view", () => {
const summary = new ChildAgentSummaryComponent();
summary.focused = true;
diff --git a/packages/coding-agent/test/interactive-heartbeat-management.test.ts b/packages/coding-agent/test/interactive-heartbeat-management.test.ts
index 88bd8948ba..17e649f2aa 100644
--- a/packages/coding-agent/test/interactive-heartbeat-management.test.ts
+++ b/packages/coding-agent/test/interactive-heartbeat-management.test.ts
@@ -29,9 +29,8 @@ interface HeartbeatScopeHarness {
connectionState: { activeSessionId: string; sessionId: string };
childAgentSnapshots: Map<string, AgentConnectionRlmChildAgentSnapshot>;
heartbeatManager: { setHeartbeats(heartbeats: AgentConnectionHeartbeat[]): void } | undefined;
- childAgentSummary: { invalidate(): void };
- ui: { requestRender(): void };
scheduleHeartbeatManagerRefresh(): void;
+ refreshChildAgentInspector(): void;
applyHeartbeatCatalog(heartbeats: AgentConnectionHeartbeat[]): void;
}
@@ -50,6 +49,12 @@ interface HeartbeatRefreshHarness {
scheduleHeartbeatManagerRefresh(): void;
}
+interface HeartbeatChildHarness {
+ heartbeats: AgentConnectionHeartbeat[];
+ childAgentSnapshots: Map<string, AgentConnectionRlmChildAgentSnapshot>;
+ buildChildAgentInspectorNodes(): Array<{ id: string; hasActiveHeartbeat?: boolean }>;
+}
+
function heartbeat(overrides: Partial<AgentCronJob> = {}): AgentCronJob {
return {
id: "heartbeat-1",
@@ -70,6 +75,34 @@ function heartbeat(overrides: Partial<AgentCronJob> = {}): AgentCronJob {
}
describe("interactive heartbeat management", () => {
+ it("maps only active heartbeat jobs onto below-prompt subagent rows", () => {
+ const harness = Object.create(InteractiveMode.prototype) as HeartbeatChildHarness;
+ harness.heartbeats = [
+ { job: { ...heartbeat(), activeSessionId: "active-child" } },
+ { job: { ...heartbeat(), id: "paused", activeSessionId: "paused-child", status: "paused" } },
+ ];
+ harness.childAgentSnapshots = new Map(
+ [
+ ["active", "active-child"],
+ ["paused", "paused-child"],
+ ].map(([id, activeSessionId]) => [
+ id,
+ {
+ id,
+ activeSessionId,
+ label: id,
+ status: "done",
+ sessionDir: `/tmp/${id}`,
+ } satisfies AgentConnectionRlmChildAgentSnapshot,
+ ]),
+ );
+
+ expect(harness.buildChildAgentInspectorNodes()).toEqual([
+ expect.objectContaining({ id: "active", hasActiveHeartbeat: true }),
+ expect.objectContaining({ id: "paused", hasActiveHeartbeat: false }),
+ ]);
+ });
+
it("clears local user-heartbeat state after stopping from the manager", async () => {
const current = heartbeat();
const stopped = { ...current, status: "cancelled" as const, nextRunAt: undefined };
@@ -139,15 +172,15 @@ describe("interactive heartbeat management", () => {
],
]);
harness.heartbeatManager = { setHeartbeats: vi.fn() };
- harness.childAgentSummary = { invalidate: vi.fn() };
- harness.ui = { requestRender: vi.fn() };
harness.scheduleHeartbeatManagerRefresh = vi.fn();
+ harness.refreshChildAgentInspector = vi.fn();
harness.applyHeartbeatCatalog([own, child, unrelated]);
expect(harness.heartbeatCatalog).toEqual([own, child, unrelated]);
expect(harness.heartbeats).toEqual([own, child]);
expect(harness.heartbeatManager.setHeartbeats).toHaveBeenCalledWith([own, child]);
+ expect(harness.refreshChildAgentInspector).toHaveBeenCalledOnce();
});
it("refreshes heartbeat scope when a known subagent gains its active session id", () => {