Skip to content

Commit e9b47cc

Browse files
lzyyzznlclaude
andcommitted
fix(heartbeat): keep private-text final replies from leaking to channel in message_tool_only mode
When visibleReplies is set to message_tool and the agent produces a text final reply without calling the heartbeat response tool, the heartbeat runner was falling through to the normal delivery path, leaking private heartbeat text to the channel. Now checks usesHeartbeatResponseTool && !heartbeatToolResponse and silently dismisses the turn, matching the user's privacy configuration. Payloads marked with deliverDespiteSourceReplySuppression (e.g. Codex runtime failure notices) still deliver normally. Fixes #94053 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 5b7cf46 commit e9b47cc

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎src/infra/heartbeat-runner.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
stripHeartbeatToken,
4343
type HeartbeatTask,
4444
} from "../auto-reply/heartbeat.js";
45+
import { getReplyPayloadMetadata } from "../auto-reply/reply-payload.js";
4546
import { replaceGenericExternalRunFailureText } from "../auto-reply/reply/agent-runner-failure-copy.js";
4647
import { resolveDefaultModel } from "../auto-reply/reply/directive-handling.defaults.js";
4748
import {
@@ -1849,6 +1850,39 @@ export async function runHeartbeatOnce(opts: {
18491850
const ackMaxChars = resolveHeartbeatAckMaxChars(cfg, heartbeat);
18501851
const responsePrefix = resolveHeartbeatResponsePrefix();
18511852

1853+
if (
1854+
usesHeartbeatResponseTool &&
1855+
!heartbeatToolResponse &&
1856+
!getReplyPayloadMetadata(replyPayload ?? {})?.deliverDespiteSourceReplySuppression
1857+
) {
1858+
await restoreHeartbeatUpdatedAt({
1859+
storePath,
1860+
sessionKey,
1861+
updatedAt: previousUpdatedAt,
1862+
});
1863+
1864+
const okSent = await maybeSendHeartbeatOk();
1865+
emitHeartbeatEvent({
1866+
status: "ok-token",
1867+
reason: opts.reason,
1868+
preview: replyPayload?.text?.slice(0, 200) ?? "",
1869+
durationMs: Date.now() - startedAt,
1870+
channel: delivery.channel !== "none" ? delivery.channel : undefined,
1871+
accountId: delivery.accountId,
1872+
silent: !okSent,
1873+
indicatorType: visibility.useIndicator ? resolveIndicatorType("ok-token") : undefined,
1874+
});
1875+
await markCommitmentsStatus({
1876+
cfg,
1877+
ids: dueCommitmentIds,
1878+
status: "dismissed",
1879+
nowMs: startedAt,
1880+
});
1881+
await updateTaskTimestamps();
1882+
consumeInspectedSystemEvents();
1883+
return { status: "ran", durationMs: Date.now() - startedAt };
1884+
}
1885+
18521886
if (heartbeatToolResponse && !heartbeatToolResponse.notify) {
18531887
await restoreHeartbeatUpdatedAt({
18541888
storePath,

0 commit comments

Comments
 (0)