fix: skip heartbeat wake for subagent exec completions

When sub-agents run many exec commands (e.g., during builds), each
completion triggers requestHeartbeatNow() which wakes the main session.
With only 250ms coalesce, this causes heartbeat spam in the main session.

This change skips the heartbeat wake when the exec belongs to a subagent
session (sessionKey contains ":subagent:"). The system event is still
enqueued for the subagent session, but the main session is not woken.

Fixes heartbeat spam when sub-agents run background builds or other
multi-exec workflows.
This commit is contained in:
Zarian Lewis 2026-01-28 09:30:57 -06:00
parent 01e0d3a320
commit 2ba26bc4e9

View File

@ -318,7 +318,10 @@ function maybeNotifyOnExit(session: ProcessSession, status: "completed" | "faile
? `Exec ${status} (${session.id.slice(0, 8)}, ${exitLabel}) :: ${output}`
: `Exec ${status} (${session.id.slice(0, 8)}, ${exitLabel})`;
enqueueSystemEvent(summary, { sessionKey });
requestHeartbeatNow({ reason: `exec:${session.id}:exit` });
// Skip heartbeat for subagent exec completions - prevents main session spam
if (!sessionKey.includes(":subagent:")) {
requestHeartbeatNow({ reason: `exec:${session.id}:exit` });
}
}
function createApprovalSlug(id: string) {
@ -337,7 +340,10 @@ function emitExecSystemEvent(text: string, opts: { sessionKey?: string; contextK
const sessionKey = opts.sessionKey?.trim();
if (!sessionKey) return;
enqueueSystemEvent(text, { sessionKey, contextKey: opts.contextKey });
requestHeartbeatNow({ reason: "exec-event" });
// Skip heartbeat for subagent exec events
if (!sessionKey.includes(":subagent:")) {
requestHeartbeatNow({ reason: "exec-event" });
}
}
async function runExecProcess(opts: {