Skip to content

Commit 99c3637

Browse files
committed
fix(heartbeat): keep plain text replies private when heartbeat response tool is not used (closes #94053)
1 parent 8f295f1 commit 99c3637

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎src/infra/heartbeat-runner.tool-response.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,27 @@ describe("runHeartbeatOnce heartbeat response tool", () => {
310310
});
311311
});
312312

313+
it("keeps plain text replies private when heartbeat response tool is not invoked in message-tool mode", async () => {
314+
await withTempTelegramHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
315+
const cfg = createConfig({ tmpDir, storePath, visibleReplies: "message_tool" });
316+
await seedMainSessionStore(storePath, cfg, {
317+
lastChannel: "telegram",
318+
lastProvider: "telegram",
319+
lastTo: TELEGRAM_GROUP,
320+
});
321+
replySpy.mockResolvedValue({ text: "Nothing to report HEARTBEAT_OK" });
322+
const sendTelegram = vi.fn().mockResolvedValue({ messageId: "m1" });
323+
324+
const result = await runHeartbeatOnce({
325+
cfg,
326+
deps: createDeps({ sendTelegram, getReplyFromConfig: replySpy }),
327+
});
328+
329+
expect(result.status).toBe("ran");
330+
expect(sendTelegram).not.toHaveBeenCalled();
331+
});
332+
});
333+
313334
it("rewrites foreground generic runner failure payloads before heartbeat delivery", async () => {
314335
await withTempTelegramHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
315336
const cfg = createConfig({ tmpDir, storePath });

‎src/infra/heartbeat-runner.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
resolveHeartbeatToolResponseFromReplyResult,
3333
type HeartbeatToolResponse,
3434
} from "../auto-reply/heartbeat-tool-response.js";
35+
import { getReplyPayloadMetadata } from "../auto-reply/reply-payload.js";
3536
import {
3637
DEFAULT_HEARTBEAT_ACK_MAX_CHARS,
3738
isHeartbeatContentEffectivelyEmpty,
@@ -1829,6 +1830,9 @@ export async function runHeartbeatOnce(opts: {
18291830
const replyResult = await getReplyFromConfig(ctx, replyOpts, cfg);
18301831
const heartbeatToolResponse = resolveHeartbeatToolResponseFromReplyResult(replyResult);
18311832
const replyPayload = resolveHeartbeatReplyPayload(replyResult);
1833+
const replyPayloadDeliverableDespiteSuppression =
1834+
replyPayload != null &&
1835+
getReplyPayloadMetadata(replyPayload)?.deliverDespiteSourceReplySuppression === true;
18321836
if (
18331837
!heartbeatToolResponse &&
18341838
(!replyPayload || !hasOutboundReplyContent(replyPayload)) &&
@@ -1934,8 +1938,14 @@ export async function runHeartbeatOnce(opts: {
19341938
normalized.text = replacement.text;
19351939
normalized.shouldSkip = false;
19361940
}
1941+
const suppressMainBecauseToolNotUsed =
1942+
usesHeartbeatResponseTool &&
1943+
!heartbeatToolResponse &&
1944+
!replyPayloadDeliverableDespiteSuppression;
19371945
const shouldSkipMain =
1938-
normalized.shouldSkip && !normalized.hasMedia && !hasRelayableExecCompletion;
1946+
(normalized.shouldSkip || suppressMainBecauseToolNotUsed) &&
1947+
!normalized.hasMedia &&
1948+
!hasRelayableExecCompletion;
19391949
if (shouldSkipMain && reasoningPayloads.length === 0) {
19401950
await restoreHeartbeatUpdatedAt({
19411951
storePath,

0 commit comments

Comments
 (0)