Skip to content

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

Rust

fix(coding-agent): propagate descendant heartbeat status (#471)

kt5acfd0c09d22
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 5c347973ee..23327ba124 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -2,6 +2,7 @@
## [Unreleased]
+- Fixed agents with heartbeat-owning subagents appearing completed and showing completion checkmarks in the Agents View.
- Fixed daemon backpressure triggering redundant catch-up snapshots for events already queued by the socket.
- Fixed incompatible daemon builds crashing startup or respawning after shutdown, with capability negotiation, verified provenance, and convergent force shutdown ([ENG-4687](https://linear.app/primeintellect/issue/ENG-4687/make-daemon-version-mismatches-self-healing)).
- Changed tool-result and announcement images to show compact metadata instead of terminal graphics ([#437](https://github.com/PrimeIntellect-ai/prime-agent/pull/437) by [@snimu](https://github.com/snimu)).
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 0ebd01c5ce..5c2862816c 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
@@ -135,6 +135,7 @@ export function buildAgentsViewRows(
);
const rowsByKey = buildRowKeyMap(baseRows);
const childrenByParent = new Map<MutableAgentsViewRow, MutableAgentsViewRow[]>();
+ const parentByChild = new Map<MutableAgentsViewRow, MutableAgentsViewRow>();
const nestedRows = new Set<MutableAgentsViewRow>();
for (const row of baseRows) {
@@ -146,6 +147,7 @@ export function buildAgentsViewRows(
if (!parent || parent === row) {
continue;
}
+ parentByChild.set(row, parent);
if (row.summary.activity === "working") {
parent.runningSubagentCount += 1;
}
@@ -153,6 +155,7 @@ export function buildAgentsViewRows(
siblings.push(row);
childrenByParent.set(parent, siblings);
}
+ propagateHeartbeatStateToAncestors(baseRows, parentByChild);
const roots = baseRows.filter((row) => !nestedRows.has(row));
const flattened: AgentsViewRow[] = [];
@@ -188,6 +191,25 @@ export function buildAgentsViewRows(
return flattened;
}
+function propagateHeartbeatStateToAncestors(
+ rows: readonly MutableAgentsViewRow[],
+ parentByChild: ReadonlyMap<MutableAgentsViewRow, MutableAgentsViewRow>,
+): void {
+ for (const row of rows) {
+ if (!row.summary.hasActiveHeartbeat) {
+ continue;
+ }
+ const visited = new Set<MutableAgentsViewRow>([row]);
+ let ancestor = parentByChild.get(row);
+ while (ancestor && !visited.has(ancestor)) {
+ visited.add(ancestor);
+ ancestor.section = "heartbeats";
+ ancestor.statusLabel = getSessionStatusLabel(ancestor.summary, true);
+ ancestor = parentByChild.get(ancestor);
+ }
+ }
+}
+
type MutableAgentsViewRow = AgentsViewRow;
function createSubagentSummaryRow(
@@ -395,7 +417,7 @@ function getSessionSubtitle(summary: SessionSummary): string {
return parts.join(" ");
}
-function getSessionStatusLabel(summary: SessionSummary): string {
+function getSessionStatusLabel(summary: SessionSummary, hasActiveHeartbeat = summary.hasActiveHeartbeat): string {
if (summary.isCompacting) {
return "compacting";
}
@@ -408,7 +430,7 @@ function getSessionStatusLabel(summary: SessionSummary): string {
if (summary.lifecycle === "archived") {
return "archived";
}
- if (summary.hasActiveHeartbeat) {
+ if (hasActiveHeartbeat) {
return "heartbeat active";
}
if (summary.activity === "working") {
diff --git a/packages/coding-agent/test/agents-view-state.test.ts b/packages/coding-agent/test/agents-view-state.test.ts
index 6da3176971..12b3fdd1d7 100644
--- a/packages/coding-agent/test/agents-view-state.test.ts
+++ b/packages/coding-agent/test/agents-view-state.test.ts
@@ -234,6 +234,7 @@ describe("agents view state", () => {
parentActiveSessionId: "parent-active",
hasActiveHeartbeat: true,
activity: "idle",
+ taskState: "completed",
messageCount: 2,
}),
makeSummary({
@@ -242,13 +243,20 @@ describe("agents view state", () => {
sessionId: "parent-session",
sessionName: "Parent",
activity: "idle",
+ taskState: "completed",
messageCount: 2,
}),
];
const collapsed = buildAgentsViewRows(summaries);
+ expect(collapsed[0]).toMatchObject({
+ kind: "agent",
+ section: "heartbeats",
+ statusLabel: "heartbeat active",
+ });
expect(collapsed[1]).toMatchObject({
kind: "subagent-summary",
+ section: "heartbeats",
title: "1 subagent · 1 heartbeat active",
});
const expanded = buildAgentsViewRows(summaries, new Set([collapsed[0]?.identity ?? ""]));
@@ -259,6 +267,58 @@ describe("agents view state", () => {
});
});
+ test("propagates a descendant heartbeat through completed subagent ancestors", () => {
+ const summaries = [
+ makeSummary({
+ id: "heartbeat-grandchild",
+ activeSessionId: "heartbeat-grandchild",
+ sessionId: "heartbeat-grandchild-session",
+ sessionName: "Heartbeat grandchild",
+ runtimeKind: "subagent",
+ parentActiveSessionId: "child-active",
+ hasActiveHeartbeat: true,
+ activity: "idle",
+ taskState: "completed",
+ }),
+ makeSummary({
+ id: "child-active",
+ activeSessionId: "child-active",
+ sessionId: "child-session",
+ sessionName: "Child",
+ runtimeKind: "subagent",
+ parentActiveSessionId: "root-active",
+ activity: "idle",
+ taskState: "completed",
+ }),
+ makeSummary({
+ id: "root-active",
+ activeSessionId: "root-active",
+ sessionId: "root-session",
+ sessionName: "Root",
+ activity: "idle",
+ taskState: "completed",
+ }),
+ ];
+
+ const rootIdentity = buildAgentsViewRows(summaries)[0]?.identity ?? "";
+ const oneLevel = buildAgentsViewRows(summaries, new Set([rootIdentity]));
+ const child = oneLevel.find((row) => row.title === "Child");
+ expect(oneLevel[0]).toMatchObject({ section: "heartbeats", statusLabel: "heartbeat active" });
+ expect(child).toMatchObject({ section: "heartbeats", statusLabel: "heartbeat active" });
+
+ const childIdentity = child?.identity ?? "";
+ const expanded = buildAgentsViewRows(summaries, new Set([rootIdentity, childIdentity]));
+ expect(
+ expanded
+ .filter((row) => row.kind === "agent" || row.kind === "subagent")
+ .map((row) => [row.title, row.section, row.statusLabel]),
+ ).toEqual([
+ ["Root", "heartbeats", "heartbeat active"],
+ ["Child", "heartbeats", "heartbeat active"],
+ ["Heartbeat grandchild", "heartbeats", "heartbeat active"],
+ ]);
+ });
+
test("expands subagent rows for expanded parents and collapses otherwise", () => {
const summaries = [
makeSummary({