Skip to content

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

Rust

fix(coding-agent): separate heartbeat sessions (#440)

kt1a41fb27e567
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 378d115863..add0243f2a 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -5,6 +5,7 @@
- Changed shell commands to use discoverable agent, schedule, package, model, session, update, doctor, and full-shutdown verbs without exposing the background daemon hierarchy ([ENG-4538](https://linear.app/primeintellect/issue/ENG-4538/standardize-bash-command-conventions-and-improve-command-discovery)).
- Fixed unsupported Node versions crashing before startup by requiring Node 22.8.0 or newer and showing upgrade guidance before loading the CLI ([ENG-4260](https://linear.app/primeintellect/issue/ENG-4260/incorrect-node-version-breaks-first-launch)).
- Added `@` file-path autocomplete to new-agent and reply prompts in the Agents View.
+- Fixed active heartbeat sessions appearing under Needs Input or Completed instead of a dedicated Heartbeats section ([ENG-4654](https://linear.app/primeintellect/issue/ENG-4654/categorize-heartbeat-sessions-as-working)).
- Fixed stashed prompts being lost when leaving and reopening a session from the Agents View ([ENG-4659](https://linear.app/primeintellect/issue/ENG-4659/stashed-prompts-should-persist)).
- Added a combined heartbeat indicator and manager for pausing, resuming, or stopping user and agent heartbeats ([ENG-4536](https://linear.app/primeintellect/issue/ENG-4536/add-heartbeat-observability-and-management-ui)).
diff --git a/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts b/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
index 721d679ddb..120fe40d2a 100644
--- a/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
+++ b/packages/coding-agent/src/modes/agents-view/agents-view-mode.ts
@@ -105,6 +105,7 @@ const DEFAULT_PROMPT_PLACEHOLDER = "Describe a task for a new session";
const REPLY_PROMPT_FALLBACK_PLACEHOLDER = "Write a reply to this agent";
const COMPLETED_ROW_ICON = "✓";
const NEEDS_INPUT_ROW_ICON = "●";
+const HEARTBEAT_ROW_ICON = "♥";
const SELECTED_ROW_MARKER = "\0agents-view-selected-row\0";
// Tags a spawn-code line so finalize can wrap the whole row in a panel
// background, visually segmenting the program from the agent rows.
@@ -2037,7 +2038,11 @@ class AgentsViewMode implements Component, Focusable {
if (counts["needs-input"] > 0) {
parts.push(`${counts["needs-input"]} needs input`);
}
- parts.push(`${counts.working} working`, `${counts.completed} completed`);
+ parts.push(`${counts.working} working`);
+ if (counts.heartbeats > 0) {
+ parts.push(`${counts.heartbeats} heartbeats`);
+ }
+ parts.push(`${counts.completed} completed`);
return parts.join(", ");
}
@@ -2250,6 +2255,8 @@ class AgentsViewMode implements Component, Focusable {
return workingIconFrame(this.workingIconFrame);
case "needs-input":
return NEEDS_INPUT_ROW_ICON;
+ case "heartbeats":
+ return HEARTBEAT_ROW_ICON;
case "completed":
return COMPLETED_ROW_ICON;
default: {
@@ -2265,6 +2272,8 @@ class AgentsViewMode implements Component, Focusable {
return theme.bold(icon);
case "needs-input":
return theme.fg("warning", icon);
+ case "heartbeats":
+ return theme.fg("error", icon);
case "completed":
return theme.fg("success", icon);
default: {
@@ -2283,7 +2292,7 @@ type DisplayItem =
function buildDisplayItems(rows: readonly AgentsViewRow[]): DisplayItem[] {
const items: DisplayItem[] = [];
- const sections: AgentsViewSection[] = ["needs-input", "working", "completed"];
+ const sections: AgentsViewSection[] = ["needs-input", "working", "heartbeats", "completed"];
for (const [index, section] of sections.entries()) {
if (index > 0) {
items.push({ type: "spacer" });
@@ -2322,6 +2331,7 @@ function countRowsBySection(rows: readonly AgentsViewRow[]): Record<AgentsViewSe
return {
working: agents.filter((row) => row.section === "working").length,
"needs-input": agents.filter((row) => row.section === "needs-input").length,
+ heartbeats: agents.filter((row) => row.section === "heartbeats").length,
completed: agents.filter((row) => row.section === "completed").length,
};
}
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 b5a009521a..4889c501aa 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
@@ -1,7 +1,7 @@
import { basename } from "node:path";
import type { SessionSummary } from "../daemon/daemon-session-list.js";
-export type AgentsViewSection = "working" | "needs-input" | "completed";
+export type AgentsViewSection = "working" | "needs-input" | "heartbeats" | "completed";
export type AgentsViewRowKind = "agent" | "subagent-summary" | "subagent" | "subagent-code";
@@ -29,6 +29,9 @@ export interface AgentsViewRow {
}
export function classifyAgentsViewSession(summary: SessionSummary): AgentsViewSection {
+ if (summary.hasActiveHeartbeat) {
+ return "heartbeats";
+ }
if (summary.activity === "working") {
return "working";
}
@@ -50,6 +53,8 @@ export function sectionTitle(section: AgentsViewSection): string {
return "Working";
case "needs-input":
return "Needs Input";
+ case "heartbeats":
+ return "Heartbeats";
case "completed":
return "Completed";
default: {
@@ -141,7 +146,7 @@ export function buildAgentsViewRows(
if (!parent || parent === row) {
continue;
}
- if (row.section === "working") {
+ if (row.summary.activity === "working") {
parent.runningSubagentCount += 1;
}
const siblings = childrenByParent.get(parent) ?? [];
@@ -341,8 +346,10 @@ function sectionRank(section: AgentsViewSection): number {
return 0;
case "working":
return 1;
- case "completed":
+ case "heartbeats":
return 2;
+ case "completed":
+ return 3;
default: {
const _exhaustive: never = section;
return _exhaustive;
@@ -391,6 +398,9 @@ function getSessionStatusLabel(summary: SessionSummary): string {
if (summary.lifecycle === "archived") {
return "archived";
}
+ if (summary.hasActiveHeartbeat) {
+ return "heartbeat active";
+ }
if (summary.activity === "working") {
return "classifying";
}
diff --git a/packages/coding-agent/src/modes/daemon/daemon-mode.ts b/packages/coding-agent/src/modes/daemon/daemon-mode.ts
index 32fac7cf5b..8d262ffa41 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-mode.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-mode.ts
@@ -2071,9 +2071,10 @@ export class AgentDaemon {
return undefined;
case "list": {
const activeSessions = Array.from(this.sessions.values());
+ const scheduledJobs = this.cronStore.list();
if (!command.all) {
return success(command.id, "list", {
- sessions: buildSessionList(activeSessions, []),
+ sessions: buildSessionList(activeSessions, [], scheduledJobs),
});
}
const defaultConfig = this.options.defaultSessionConfig;
@@ -2081,7 +2082,7 @@ export class AgentDaemon {
if (command.cwd) {
const savedSessions = await SessionManager.list(resolve(command.cwd), listSessionDir);
return success(command.id, "list", {
- sessions: buildSessionList(activeSessions, savedSessions),
+ sessions: buildSessionList(activeSessions, savedSessions, scheduledJobs),
});
}
const savedSessions =
@@ -2089,7 +2090,7 @@ export class AgentDaemon {
? await SessionManager.listAll(undefined, listSessionDir)
: await SessionManager.listAll();
return success(command.id, "list", {
- sessions: buildSessionList(activeSessions, savedSessions),
+ sessions: buildSessionList(activeSessions, savedSessions, scheduledJobs),
});
}
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 e219d80abb..063bccc8d2 100644
--- a/packages/coding-agent/src/modes/daemon/daemon-session-list.ts
+++ b/packages/coding-agent/src/modes/daemon/daemon-session-list.ts
@@ -5,6 +5,7 @@ import type { Api, Model } from "@earendil-works/pi-ai";
import { compactRlmText, rlmChildLabel } from "../../core/agent-session.js";
import type { AgentSessionRuntimeMetadata } from "../../core/agent-session-runtime.js";
import type { AgentSessionRuntimeDiagnostic } from "../../core/agent-session-services.js";
+import { type AgentCronJob, isHeartbeatCronJob } from "../../core/cron-jobs.js";
import type { AgentTaskState, SessionInfo } from "../../core/session-manager.js";
import type { AgentConnectionRlmChildAgentSnapshot } from "../agent-connection/types.js";
import type { ActiveSessionState } from "./active-session-state.js";
@@ -27,6 +28,7 @@ export interface SessionSummary {
id: string;
lifecycle: SessionLifecycle;
activity: SessionActivity;
+ hasActiveHeartbeat?: boolean;
runtimeKind?: "top-level" | "subagent";
activeSessionId?: string;
sessionId: string;
@@ -88,8 +90,14 @@ export function resolveAttachModelFallbackMessage(
export function buildSessionList(
activeSessions: readonly ActiveSessionState[],
savedSessions: readonly SessionInfo[],
+ scheduledJobs: readonly AgentCronJob[] = [],
): SessionSummary[] {
const activeBySessionFile = new Map<string, ActiveSessionState>();
+ const heartbeatSessionIds = new Set(
+ scheduledJobs
+ .filter((job) => job.status === "active" && isHeartbeatCronJob(job))
+ .map((job) => job.activeSessionId),
+ );
for (const activeSession of activeSessions) {
const sessionFile = activeSession.runtime.session.sessionFile;
@@ -104,7 +112,13 @@ export function buildSessionList(
const sessionFile = resolve(savedSession.path);
const activeSession = activeBySessionFile.get(sessionFile);
if (activeSession) {
- entries.push(summaryForActiveSession(activeSession, savedSession));
+ entries.push(
+ summaryForActiveSession(
+ activeSession,
+ savedSession,
+ heartbeatSessionIds.has(activeSession.activeSessionId),
+ ),
+ );
seenActiveSessionIds.add(activeSession.activeSessionId);
continue;
}
@@ -113,7 +127,9 @@ export function buildSessionList(
for (const activeSession of activeSessions) {
if (!seenActiveSessionIds.has(activeSession.activeSessionId)) {
- entries.push(summaryForActiveSession(activeSession));
+ entries.push(
+ summaryForActiveSession(activeSession, undefined, heartbeatSessionIds.has(activeSession.activeSessionId)),
+ );
}
}
return entries;
@@ -123,7 +139,11 @@ function effectivePendingMessageCount(session: ActiveSessionState["runtime"]["se
return session.pendingMessageCount + (session.hasAcceptedPromptInFlight ? 1 : 0);
}
-export function summaryForActiveSession(activeSession: ActiveSessionState, savedSession?: SessionInfo): SessionSummary {
+export function summaryForActiveSession(
+ activeSession: ActiveSessionState,
+ savedSession?: SessionInfo,
+ hasActiveHeartbeat = false,
+): SessionSummary {
const session = activeSession.runtime.session;
const pendingMessageCount = effectivePendingMessageCount(session);
const metadata = activeSession.runtime.metadata ?? { kind: "top-level" as const };
@@ -140,6 +160,7 @@ export function summaryForActiveSession(activeSession: ActiveSessionState, saved
id: activeSession.activeSessionId,
lifecycle: activeLifecycleForSession(activeSession),
activity: activeActivityForSession(activeSession),
+ hasActiveHeartbeat: hasActiveHeartbeat || undefined,
runtimeKind: metadata.kind,
activeSessionId: activeSession.activeSessionId,
sessionId: session.sessionId,
diff --git a/packages/coding-agent/test/agents-view-state.test.ts b/packages/coding-agent/test/agents-view-state.test.ts
index c54f91e038..6492bc3e69 100644
--- a/packages/coding-agent/test/agents-view-state.test.ts
+++ b/packages/coding-agent/test/agents-view-state.test.ts
@@ -28,6 +28,7 @@ import {
getAgentsViewSelectionKey,
resolveAgentsViewSelectionIndex,
type SessionSummary,
+ sectionTitle,
shouldShowAgentsViewSession,
} from "../src/modes/index.js";
import type { InteractiveModeUiServices } from "../src/modes/interactive/interactive-mode-services.js";
@@ -56,6 +57,23 @@ describe("agents view state", () => {
expect(classifyAgentsViewSession(makeSummary({ activity: "idle", taskState: undefined }))).toBe("needs-input");
});
+ test("active heartbeats use their own section regardless of current activity", () => {
+ expect(classifyAgentsViewSession(makeSummary({ activity: "working", hasActiveHeartbeat: true }))).toBe(
+ "heartbeats",
+ );
+ expect(
+ classifyAgentsViewSession(makeSummary({ activity: "idle", taskState: "completed", hasActiveHeartbeat: true })),
+ ).toBe("heartbeats");
+
+ const [row] = buildAgentsViewRows([makeSummary({ activity: "idle", hasActiveHeartbeat: true })]);
+ expect(row).toMatchObject({ section: "heartbeats", statusLabel: "heartbeat active" });
+ const [busyRow] = buildAgentsViewRows([
+ makeSummary({ activity: "working", hasActiveHeartbeat: true, isStreaming: true, isRunningTools: true }),
+ ]);
+ expect(busyRow).toMatchObject({ section: "heartbeats", statusLabel: "running tools" });
+ expect(sectionTitle("heartbeats")).toBe("Heartbeats");
+ });
+
test("defaults an idle session with no verdict to needs-input", () => {
// A slow, failed, or absent classification never lingers in Working; only
// an explicit completed verdict moves an idle session out of needs-input.
@@ -83,10 +101,16 @@ describe("agents view state", () => {
isStreaming: true,
modified: "2026-01-02T00:00:00Z",
}),
+ makeSummary({
+ sessionName: "heartbeat",
+ activity: "idle",
+ hasActiveHeartbeat: true,
+ modified: "2026-01-03T00:00:00Z",
+ }),
]);
- expect(rows.map((row) => row.title)).toEqual(["newer working", "older working", "completed"]);
- expect(rows.map((row) => row.section)).toEqual(["working", "working", "completed"]);
+ expect(rows.map((row) => row.title)).toEqual(["newer working", "older working", "heartbeat", "completed"]);
+ expect(rows.map((row) => row.section)).toEqual(["working", "working", "heartbeats", "completed"]);
});
test("summarizes subagents on their parent and omits subagent rows", () => {
@@ -110,6 +134,7 @@ describe("agents view state", () => {
runtimeKind: "subagent",
parentActiveSessionId: "parent-active",
parentSessionId: "parent-session",
+ hasActiveHeartbeat: true,
activity: "working",
}),
makeSummary({
diff --git a/packages/coding-agent/test/daemon-session-list.test.ts b/packages/coding-agent/test/daemon-session-list.test.ts
index 426ad95d15..2f86d486e0 100644
--- a/packages/coding-agent/test/daemon-session-list.test.ts
+++ b/packages/coding-agent/test/daemon-session-list.test.ts
@@ -1,6 +1,7 @@
import { resolve } from "node:path";
import type { AgentMessage } from "@earendil-works/pi-agent-core";
import { describe, expect, it } from "vitest";
+import type { AgentCronJob } from "../src/core/cron-jobs.js";
import type { SessionInfo } from "../src/core/session-manager.js";
import type { ActiveSessionState, DaemonSocketClient } from "../src/modes/daemon/active-session-state.js";
import {
@@ -74,6 +75,34 @@ describe("buildSessionList", () => {
expect(entries[0]?.hasRunningRlmChildren).toBe(true);
});
+ it("marks sessions with active standard or RLM heartbeats", () => {
+ const messages = [{ role: "user", content: "hi" }] as unknown as AgentMessage[];
+ const summaryState = { basedOnMessageCount: 1 } as ActiveSessionState["summaryState"];
+ const activeSessionIds = ["heartbeat", "rlm-heartbeat", "paused-heartbeat", "cron"];
+ const entries = buildSessionList(
+ activeSessionIds.map((activeSessionId) => makeState({ activeSessionId, messages, summaryState })),
+ [],
+ [
+ makeCronJob({ id: "heartbeat-job", activeSessionId: "heartbeat", source: "heartbeat" }),
+ makeCronJob({ id: "rlm-job", activeSessionId: "rlm-heartbeat", source: "rlm_heartbeat" }),
+ makeCronJob({
+ id: "paused-job",
+ activeSessionId: "paused-heartbeat",
+ source: "heartbeat",
+ status: "paused",
+ }),
+ makeCronJob({ id: "cron-job", activeSessionId: "cron", source: "cron" }),
+ ],
+ );
+
+ expect(Object.fromEntries(entries.map((entry) => [entry.id, entry.hasActiveHeartbeat]))).toEqual({
+ heartbeat: true,
+ "rlm-heartbeat": true,
+ "paused-heartbeat": undefined,
+ cron: undefined,
+ });
+ });
+
it("counts accepted in-flight agent prompts as pending work", () => {
const oneMessage = [{ role: "user", content: "hi" }] as unknown as AgentMessage[];
const summary = summaryForActiveSession(
@@ -550,3 +579,21 @@ function makeSessionInfo(overrides: Pick<SessionInfo, "path" | "id"> & Partial<S
agentStatus: overrides.agentStatus,
};
}
+
+function makeCronJob(overrides: Pick<AgentCronJob, "id" | "activeSessionId"> & Partial<AgentCronJob>): AgentCronJob {
+ return {
+ id: overrides.id,
+ status: overrides.status ?? "active",
+ source: overrides.source,
+ activeSessionId: overrides.activeSessionId,
+ sessionId: `session-${overrides.activeSessionId}`,
+ sessionFile: `/tmp/${overrides.activeSessionId}.jsonl`,
+ cwd: "/tmp/project",
+ prompt: "Check for follow-up work",
+ schedule: { kind: "interval", expression: "every 5m", intervalMs: 300_000 },
+ createdAt: "2026-05-01T00:00:00.000Z",
+ updatedAt: "2026-05-01T00:00:00.000Z",
+ nextRunAt: "2026-05-01T00:05:00.000Z",
+ runCount: 0,
+ };
+}