Fix #12767: Heartbeat strip responsePrefix before HEARTBEAT_OK suppression

This commit is contained in:
Jean Carlos Nunez
2026-02-16 17:03:25 -05:00
committed by Peter Steinberger
parent feed570984
commit f476c8b48b
2 changed files with 60 additions and 7 deletions

View File

@@ -40,6 +40,7 @@ import { getQueueSize } from "../process/command-queue.js";
import { CommandLane } from "../process/lanes.js";
import { normalizeAgentId, toAgentStoreSessionKey } from "../routing/session-key.js";
import { defaultRuntime, type RuntimeEnv } from "../runtime.js";
import { escapeRegExp } from "../utils.js";
import { formatErrorMessage } from "./errors.js";
import { isWithinActiveHours } from "./heartbeat-active-hours.js";
import {
@@ -62,7 +63,7 @@ import {
} from "./outbound/targets.js";
import { peekSystemEventEntries } from "./system-events.js";
type HeartbeatDeps = OutboundSendDeps &
export type HeartbeatDeps = OutboundSendDeps &
ChannelHeartbeatDeps & {
runtime?: RuntimeEnv;
getQueueSize?: (lane?: string) => number;
@@ -355,7 +356,13 @@ function normalizeHeartbeatReply(
responsePrefix: string | undefined,
ackMaxChars: number,
) {
const stripped = stripHeartbeatToken(payload.text, {
const rawText = typeof payload.text === "string" ? payload.text : "";
// Normalize away responsePrefix so a prefixed HEARTBEAT_OK still strips.
const prefixPattern = responsePrefix?.trim()
? new RegExp(`^${escapeRegExp(responsePrefix.trim())}\\s*`, "i")
: null;
const textForStrip = prefixPattern ? rawText.replace(prefixPattern, "") : rawText;
const stripped = stripHeartbeatToken(textForStrip, {
mode: "heartbeat",
maxAckChars: ackMaxChars,
});