Skip to content

Commit 629e59d

Browse files
committed
fix(heartbeat): explain target-none skips
1 parent f5add81 commit 629e59d

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎src/infra/heartbeat-events.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@ describe("heartbeat events", () => {
4848
});
4949
});
5050

51+
it("adds a delivery-disabled message to target-none events without changing the reason", () => {
52+
const listener = vi.fn();
53+
const unsubscribe = onHeartbeatEvent(listener);
54+
55+
emitHeartbeatEvent({ status: "skipped", reason: "target-none" });
56+
57+
const expected = {
58+
ts: 1767960000000,
59+
status: "skipped",
60+
reason: "target-none",
61+
message: "Heartbeat delivery is disabled by configuration (target: none).",
62+
};
63+
expect(getLastHeartbeatEvent()).toEqual(expected);
64+
expect(listener).toHaveBeenCalledWith(expected);
65+
66+
unsubscribe();
67+
});
68+
69+
it("preserves an explicit message for target-none events", () => {
70+
emitHeartbeatEvent({
71+
status: "skipped",
72+
reason: "target-none",
73+
message: "custom diagnostic",
74+
});
75+
76+
expect(getLastHeartbeatEvent()).toMatchObject({
77+
reason: "target-none",
78+
message: "custom diagnostic",
79+
});
80+
});
81+
5182
it("delivers events to listeners, isolates listener failures, and supports unsubscribe", () => {
5283
const seen: string[] = [];
5384
const unsubscribeFirst = onHeartbeatEvent((evt) => {

‎src/infra/heartbeat-events.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { notifyListeners, registerListener } from "../shared/listeners.js";
44

55
export type HeartbeatIndicatorType = "ok" | "alert" | "error";
66

7+
const TARGET_NONE_MESSAGE = "Heartbeat delivery is disabled by configuration (target: none).";
8+
79
export type HeartbeatEventPayload = {
810
ts: number;
911
status: "sent" | "ok-empty" | "ok-token" | "skipped" | "failed";
@@ -13,6 +15,8 @@ export type HeartbeatEventPayload = {
1315
durationMs?: number;
1416
hasMedia?: boolean;
1517
reason?: string;
18+
/** Operator-facing companion to the machine-stable reason code. */
19+
message?: string;
1620
/** The channel this heartbeat was sent to. */
1721
channel?: string;
1822
/** Whether the message was silently suppressed (showOk: false). */
@@ -51,7 +55,13 @@ const state = resolveGlobalSingleton<HeartbeatEventState>(HEARTBEAT_EVENT_STATE_
5155
}));
5256

5357
export function emitHeartbeatEvent(evt: Omit<HeartbeatEventPayload, "ts">) {
54-
const enriched: HeartbeatEventPayload = { ts: Date.now(), ...evt };
58+
const enriched: HeartbeatEventPayload = {
59+
ts: Date.now(),
60+
...evt,
61+
...(evt.reason === "target-none" && evt.message === undefined
62+
? { message: TARGET_NONE_MESSAGE }
63+
: {}),
64+
};
5565
state.lastHeartbeat = enriched;
5666
notifyListeners(state.listeners, enriched);
5767
}

‎test/e2e/qa-lab/runtime/gateway-rpc-automation.e2e.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,15 @@ describe("Gateway task and automation RPCs", () => {
406406
ts: number;
407407
status: string;
408408
reason?: string;
409+
message?: string;
409410
preview?: string;
410411
}>("last-heartbeat", {});
411412
return (
412413
lastHeartbeat.ts >= wakeRequestedAt &&
413414
lastHeartbeat.status === "skipped" &&
414415
lastHeartbeat.reason === "target-none" &&
416+
lastHeartbeat.message ===
417+
"Heartbeat delivery is disabled by configuration (target: none)." &&
415418
lastHeartbeat.preview === `Heartbeat handled: ${wakeText}`
416419
);
417420
},

0 commit comments

Comments
 (0)