Skip to content

Commit 136b80d

Browse files
committed
fix(heartbeat): suppress raw reply delivery in message_tool_only mode
When visibleReplies is set to message_tool, the heartbeat runner was delivering the raw agent reply text to the channel even when the heartbeat response tool was not called. This leaked private replies. Suppress the delivery unless the reply is an error/failure notice that explicitly opts into source-suppression delivery. Closes #94053
1 parent 21aefb8 commit 136b80d

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎src/infra/heartbeat-runner.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { resolveModelRefFromString, type ModelRef } from "../agents/model-select
1818
import { resolveEmbeddedSessionLane } from "../agents/pi-embedded-runner/lanes.js";
1919
import { formatReasoningMessage } from "../agents/pi-embedded-utils.js";
2020
import { DEFAULT_HEARTBEAT_FILENAME } from "../agents/workspace.js";
21+
import { getReplyPayloadMetadata } from "../auto-reply/reply-payload.js";
2122
import { resolveHeartbeatReplyPayload } from "../auto-reply/heartbeat-reply-payload.js";
2223
import {
2324
getHeartbeatToolNotificationText,
@@ -1857,8 +1858,20 @@ export async function runHeartbeatOnce(opts: {
18571858
normalized.text = replacement.text;
18581859
normalized.shouldSkip = false;
18591860
}
1861+
// When message_tool_only mode is active and the heartbeat response tool was
1862+
// not called, suppress the raw reply to prevent private text from leaking to
1863+
// the channel (e.g. Telegram). The model must explicitly call the response
1864+
// tool with notify:true to send a visible reply.
1865+
// Error/failure notices that opt into source-suppression delivery (e.g.
1866+
// Codex usage limits) are still delivered.
1867+
const leakMessageToolOnlyReply =
1868+
usesHeartbeatResponseTool &&
1869+
!heartbeatToolResponse &&
1870+
replyPayload &&
1871+
!getReplyPayloadMetadata(replyPayload)?.deliverDespiteSourceReplySuppression;
18601872
const shouldSkipMain =
1861-
normalized.shouldSkip && !normalized.hasMedia && !hasRelayableExecCompletion;
1873+
leakMessageToolOnlyReply ||
1874+
(normalized.shouldSkip && !normalized.hasMedia && !hasRelayableExecCompletion);
18621875
if (shouldSkipMain && reasoningPayloads.length === 0) {
18631876
await restoreHeartbeatUpdatedAt({
18641877
storePath,

0 commit comments

Comments
 (0)