Skip to content

Commit 6d04fe5

Browse files
authored
fix(heartbeat): avoid claiming excluded outcomes were recorded (#125207)
* fix(heartbeat): report accepted outcomes honestly * test(heartbeat): refresh response tool snapshots * fix(heartbeat): align tool catalog wording
1 parent 785c5bd commit 6d04fe5

8 files changed

Lines changed: 33 additions & 27 deletions

‎extensions/codex/src/app-server/dynamic-tools.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,11 +2856,11 @@ describe("createCodexDynamicToolBridge", () => {
28562856
expect(bridge.telemetry.messagingToolSentTargets).toEqual([]);
28572857
});
28582858

2859-
it("records heartbeat response tool outcomes", async () => {
2859+
it("accepts heartbeat response tool outcomes", async () => {
28602860
const bridge = createBridgeWithToolResult(
28612861
HEARTBEAT_RESPONSE_TOOL_NAME,
2862-
textToolResult("Recorded.", {
2863-
status: "recorded",
2862+
textToolResult("Accepted.", {
2863+
status: "accepted",
28642864
outcome: "needs_attention",
28652865
notify: true,
28662866
summary: "Build is blocked.",
@@ -2878,7 +2878,7 @@ describe("createCodexDynamicToolBridge", () => {
28782878
arguments: {},
28792879
});
28802880

2881-
expect(result).toEqual(expectInputText("Recorded."));
2881+
expect(result).toEqual(expectInputText("Accepted."));
28822882
expect(bridge.telemetry.heartbeatToolResponse).toEqual({
28832883
outcome: "needs_attention",
28842884
notify: true,

‎src/agents/embedded-agent-subscribe.block-reply-rejections.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe("subscribeEmbeddedAgentSession block reply rejections", () => {
150150
toolCallId: "heartbeat-1",
151151
result: {
152152
details: {
153-
status: "recorded",
153+
status: "accepted",
154154
outcome: "no_change",
155155
notify: false,
156156
summary: "Nothing needs attention.",

‎src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.subscribeembeddedagentsession.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,7 +1679,7 @@ describe("subscribeEmbeddedAgentSession", () => {
16791679
});
16801680
});
16811681

1682-
it("notifies the runner once when a heartbeat response tool result is recorded", async () => {
1682+
it("notifies the runner once when a heartbeat response tool result is accepted", async () => {
16831683
const { session, emit } = createStubSessionHarness();
16841684
const onHeartbeatToolResponse = vi.fn();
16851685
const subscription = subscribeEmbeddedAgentSession({
@@ -1691,7 +1691,7 @@ describe("subscribeEmbeddedAgentSession", () => {
16911691

16921692
const result = {
16931693
details: {
1694-
status: "recorded",
1694+
status: "accepted",
16951695
outcome: "no_change",
16961696
notify: false,
16971697
summary: "Nothing needs attention.",

‎src/agents/tool-catalog.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ const CORE_TOOL_DEFINITIONS: CoreToolDefinition[] = [
344344
{
345345
id: "heartbeat_respond",
346346
label: "heartbeat_respond",
347-
description: "Record heartbeat outcomes",
347+
description: "Accept heartbeat outcomes for post-turn handling",
348348
sectionId: "automation",
349349
profiles: [],
350350
includeInOpenClawGroup: true,

‎src/agents/tools/heartbeat-response-tool.test.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe("createHeartbeatResponseTool", () => {
4141
expect(priority).not.toHaveProperty("anyOf");
4242
});
4343

44-
it("records a quiet heartbeat outcome", async () => {
44+
it("accepts a quiet no-change outcome without claiming persistence", async () => {
4545
const tool = createHeartbeatResponseTool();
4646

4747
const result = await tool.execute("call-1", {
@@ -52,10 +52,13 @@ describe("createHeartbeatResponseTool", () => {
5252

5353
expect(tool.name).toBe(HEARTBEAT_RESPONSE_TOOL_NAME);
5454
const details = result.details as HeartbeatResponseDetails;
55-
expect(details.status).toBe("recorded");
55+
expect(details.status).toBe("accepted");
5656
expect(details.outcome).toBe("no_change");
5757
expect(details.notify).toBe(false);
5858
expect(details.summary).toBe("Nothing needs attention.");
59+
expect(result.content).toEqual([
60+
expect.objectContaining({ text: expect.stringContaining('"status": "accepted"') }),
61+
]);
5962
});
6063

6164
it("rejects repeated heartbeat responses from the same tool instance", async () => {
@@ -75,7 +78,7 @@ describe("createHeartbeatResponseTool", () => {
7578
notify: false,
7679
summary: "Nothing needs attention.",
7780
}),
78-
).rejects.toThrow("heartbeat_respond already recorded");
81+
).rejects.toThrow("heartbeat_respond already accepted");
7982
});
8083

8184
it("captures scratch without echoing future prompt content to the model", async () => {
@@ -98,7 +101,7 @@ describe("createHeartbeatResponseTool", () => {
98101
]);
99102
});
100103

101-
it("accepts notification text and optional scheduling metadata", async () => {
104+
it("accepts an urgent notification without claiming persistence", async () => {
102105
const tool = createHeartbeatResponseTool();
103106

104107
const result = await tool.execute("call-1", {
@@ -111,13 +114,16 @@ describe("createHeartbeatResponseTool", () => {
111114
});
112115

113116
const details = result.details as HeartbeatResponseDetails;
114-
expect(details.status).toBe("recorded");
117+
expect(details.status).toBe("accepted");
115118
expect(details.outcome).toBe("needs_attention");
116119
expect(details.notify).toBe(true);
117120
expect(details.summary).toBe("Build is blocked.");
118121
expect(details.notificationText).toBe("Build is blocked on missing credentials.");
119122
expect(details.priority).toBe("high");
120123
expect(details.nextCheck).toBe("2026-05-01T17:00:00Z");
124+
expect(result.content).toEqual([
125+
expect.objectContaining({ text: expect.stringContaining('"status": "accepted"') }),
126+
]);
121127
});
122128

123129
it("rejects missing notify because quiet vs visible delivery must be explicit", async () => {

‎src/agents/tools/heartbeat-response-tool.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Heartbeat response tool.
33
*
4-
* Auto-reply heartbeat turns use this tool to record the agent's outcome,
4+
* Auto-reply heartbeat turns use this tool to accept the agent's outcome,
55
* notification decision, and next-check metadata exactly once per turn.
66
*/
77
import { isRecord } from "@openclaw/normalization-core/record-coerce";
@@ -45,7 +45,7 @@ function readRequiredBoolean(params: Record<string, unknown>, key: string): bool
4545
return raw;
4646
}
4747

48-
/** Creates the one-shot heartbeat response recording tool for an auto-reply turn. */
48+
/** Creates the one-shot heartbeat response tool for an auto-reply turn. */
4949
export function createHeartbeatResponseTool(): AnyAgentTool {
5050
let recorded = false;
5151
return {
@@ -54,9 +54,9 @@ export function createHeartbeatResponseTool(): AnyAgentTool {
5454
// Heartbeat prompts instruct the model to call this one-shot tool; hiding
5555
// it behind tool search would break the heartbeat contract.
5656
catalogMode: "direct-only",
57-
displaySummary: "Record heartbeat outcome/notify choice.",
57+
displaySummary: "Accept heartbeat outcome/notify choice.",
5858
description:
59-
"Record heartbeat result. `notify=false` no visible send. `notify=true` needs concise notificationText. Scratch is monitor prose only; manage recurring tasks with cron.",
59+
"Accept heartbeat result for post-turn handling. `notify=false` no visible send. `notify=true` needs concise notificationText. Scratch is monitor prose only; manage recurring tasks with cron.",
6060
parameters: HeartbeatResponseToolSchema,
6161
execute: async (_toolCallId, args) => {
6262
if (!isRecord(args)) {
@@ -79,12 +79,12 @@ export function createHeartbeatResponseTool(): AnyAgentTool {
7979
if (recorded) {
8080
// One heartbeat turn should produce one decision; repeated calls can
8181
// otherwise overwrite the notify/no-notify choice.
82-
throw new ToolInputError("heartbeat_respond already recorded for this turn");
82+
throw new ToolInputError("heartbeat_respond already accepted for this turn");
8383
}
8484
recorded = true;
8585
const { scratch, ...publicResponse } = response;
86-
const details = { status: "recorded" as const, ...publicResponse } as typeof response & {
87-
status: "recorded";
86+
const details = { status: "accepted" as const, ...publicResponse } as typeof response & {
87+
status: "accepted";
8888
};
8989
if (scratch !== undefined) {
9090
// Keep future prompt content out of model-visible tool output and logs;
@@ -94,7 +94,7 @@ export function createHeartbeatResponseTool(): AnyAgentTool {
9494
return textResult(
9595
JSON.stringify(
9696
{
97-
status: "recorded",
97+
status: "accepted",
9898
...publicResponse,
9999
...(scratch !== undefined
100100
? {

‎test/fixtures/agents/prompt-snapshots/codex-runtime-happy-path/codex-dynamic-tools.heartbeat-turn.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "openclaw_direct",
77
"tools": [
88
{
9-
"description": "Record heartbeat result. `notify=false` no visible send. `notify=true` needs concise notificationText. Scratch is monitor prose only; manage recurring tasks with cron.",
9+
"description": "Accept heartbeat result for post-turn handling. `notify=false` no visible send. `notify=true` needs concise notificationText. Scratch is monitor prose only; manage recurring tasks with cron.",
1010
"inputSchema": {
1111
"additionalProperties": false,
1212
"properties": {

‎test/fixtures/agents/prompt-snapshots/codex-runtime-happy-path/telegram-heartbeat-codex-tool.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ This is the deterministic model-bound layer stack OpenClaw can snapshot for the
222222
"roughTokens": 0
223223
},
224224
"dynamicToolsJson": {
225-
"chars": 54227,
226-
"roughTokens": 13557
225+
"chars": 54250,
226+
"roughTokens": 13563
227227
},
228228
"openClawDeveloperInstructions": {
229229
"chars": 3370,
@@ -234,8 +234,8 @@ This is the deterministic model-bound layer stack OpenClaw can snapshot for the
234234
"roughTokens": 6950
235235
},
236236
"totalWithDynamicToolsJson": {
237-
"chars": 82027,
238-
"roughTokens": 20507
237+
"chars": 82050,
238+
"roughTokens": 20513
239239
},
240240
"userInputText": {
241241
"chars": 1271,
@@ -690,7 +690,7 @@ Full tool overrides: `codex-dynamic-tools.heartbeat-turn.json` (base: `codex-dyn
690690
"type": "function"
691691
},
692692
{
693-
"description": "Record heartbeat result. `notify=false` no visible send. `notify=true` needs concise notificationText. Scratch is monitor prose only; manage recurring tasks with cron.",
693+
"description": "Accept heartbeat result for post-turn handling. `notify=false` no visible send. `notify=true` needs concise notificationText. Scratch is monitor prose only; manage recurring tasks with cron.",
694694
"inputSchema": {
695695
"additionalProperties": false,
696696
"properties": {

0 commit comments

Comments
 (0)