Skip to content

Commit 5bcc321

Browse files
authored
Scope Codex heartbeat guidance to heartbeat turns (#76788)
* fix(codex): scope heartbeat guidance to collaboration mode * fix heartbeat tool direct context * test prompt heartbeat collaboration snapshots * fix heartbeat changelog credit
1 parent 8b4808d commit 5bcc321

28 files changed

Lines changed: 379 additions & 133 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Docs: https://docs.openclaw.ai
7676
- CLI/logs: auto-reconnect `openclaw logs --follow` on transient gateway disconnects (WebSocket close, timeout, connection drop) with bounded exponential backoff (up to 8 retries, capped at 30 s) and stderr retry warnings, while still exiting immediately on non-recoverable auth or configuration errors. Fixes #74782. (#75059) Thanks @shashank-poola.
7777
- CLI/logs: announce `--follow` recovery with a `[logs] gateway reconnected` notice once a poll succeeds after a transient outage, and emit JSON `notice` records in `--json` mode for both the retry warning and the reconnect transition, so live monitoring scripts can react to the recovery. Carries forward #75059. (#75372) Thanks @romneyda.
7878
- Codex/WhatsApp: keep the `message` dynamic tool available when Codex source replies are configured for message-tool delivery, so coding-profile chat agents do not complete turns privately without a visible channel reply. Fixes #76660. (#76663) Thanks @VishalJ99.
79+
- Codex/heartbeat: send heartbeat-specific initiative guidance through Codex turn-scoped collaboration-mode instructions, keeping ordinary message-tool chat turns in Default mode without heartbeat prompt leakage. Thanks @pashpashpash.
7980
- Plugins/onboarding: trust optional official plugin and web-search installs selected from the official catalog so npm security scanning treats them like other source-linked official install paths. Thanks @vincentkoc.
8081
- Agents/web_search: keep installed runtime provider discovery enabled when web-search metadata is missing, so externally installed official providers such as Brave remain visible to agent and cron turns instead of falling back to bundled-only lookup. Fixes #76626. Thanks @amknight.
8182
- Tests/plugins: expose the Discord npm onboarding Docker lane as a package script and assert planned Docker lanes point at real scripts, so external-channel onboarding coverage can actually run. Thanks @vincentkoc.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
f829dd720df7c9c8eb9d59eda3b3f879bff278f74b4c00d8d788c1483865b649 plugin-sdk-api-baseline.json
2-
1b3504c8f9ddd00801f095f94f417d469b47370064478eae389d33f4b8e10c76 plugin-sdk-api-baseline.jsonl
1+
2ab0555767ccdff39152923f462b4993f2d8f0ab36b5583a4ecbc2186f97a0dc plugin-sdk-api-baseline.json
2+
527ace06ee6c56f3fd4f0a97e1a6b8a61a87d3aff40c8e91a82367a42e5677f7 plugin-sdk-api-baseline.jsonl

‎docs/concepts/system-prompt.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ selected app-server thread/turn params plus a reconstructed model-bound prompt
117117
layer stack for Telegram direct, Discord group, and heartbeat turns. That stack
118118
includes a pinned Codex `gpt-5.5` model prompt fixture generated from Codex's
119119
model catalog/cache shape, the Codex happy-path permission developer text,
120-
OpenClaw developer instructions, user turn input, and references to the dynamic
121-
tool specs.
120+
OpenClaw developer instructions, turn-scoped collaboration-mode instructions
121+
when OpenClaw provides them, user turn input, and references to the dynamic tool
122+
specs.
122123

123124
Refresh the pinned Codex model prompt fixture with
124125
`pnpm prompt:snapshots:sync-codex-model`. By default, the script looks for
@@ -131,9 +132,9 @@ or `models.json` file.
131132

132133
These snapshots are still not a byte-for-byte raw OpenAI request capture. Codex
133134
can add runtime-owned workspace context such as `AGENTS.md`, environment
134-
context, memories, app/plugin instructions, and future collaboration-mode
135-
instructions inside the Codex runtime after OpenClaw sends thread and turn
136-
params.
135+
context, memories, app/plugin instructions, and built-in Default
136+
collaboration-mode instructions inside the Codex runtime after OpenClaw sends
137+
thread and turn params.
137138

138139
Regenerate them with `pnpm prompt:snapshots:gen` and verify drift with
139140
`pnpm prompt:snapshots:check`. CI runs the drift check in the additional

‎docs/plugins/codex-harness.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ Codex heartbeat turns also get the `heartbeat_respond` tool by default, so the
2626
agent can record whether the wake should stay quiet or notify without encoding
2727
that control flow in final text.
2828

29+
Heartbeat-specific initiative guidance is sent as a Codex collaboration-mode
30+
developer instruction on the heartbeat turn itself. Ordinary chat turns restore
31+
Codex Default mode instead of carrying heartbeat philosophy in their normal
32+
runtime prompt.
33+
2934
If you are trying to orient yourself, start with
3035
[Agent runtimes](/concepts/agent-runtimes). The short version is:
3136
`openai/gpt-5.5` is the model ref, `codex` is the runtime, and Telegram,

‎extensions/codex/prompt-overlay-runtime-contract.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ describe("Codex prompt overlay runtime contract", () => {
1818
expect(contribution?.sectionOverrides?.interaction_style).toContain(
1919
"This is a live chat, not a memo.",
2020
);
21+
expect(contribution?.sectionOverrides?.interaction_style).not.toContain(
22+
"The purpose of heartbeats is to make you feel magical and proactive.",
23+
);
2124
});
2225

2326
it("respects shared GPT-5 prompt overlay config for Codex runs", () => {

‎extensions/codex/prompt-overlay.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
22
GPT5_BEHAVIOR_CONTRACT,
3+
GPT5_HEARTBEAT_PROMPT_OVERLAY,
34
renderGpt5PromptOverlay,
45
resolveGpt5SystemPromptContribution,
56
} from "openclaw/plugin-sdk/provider-model-shared";
67

78
export const CODEX_GPT5_BEHAVIOR_CONTRACT = GPT5_BEHAVIOR_CONTRACT;
9+
export const CODEX_GPT5_HEARTBEAT_PROMPT_OVERLAY = GPT5_HEARTBEAT_PROMPT_OVERLAY;
810

911
export function resolveCodexSystemPromptContribution(
1012
params: Parameters<typeof resolveGpt5SystemPromptContribution>[0],

‎extensions/codex/provider.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,15 @@ describe("codex provider", () => {
348348
).toEqual({
349349
stablePrefix: CODEX_GPT5_BEHAVIOR_CONTRACT,
350350
sectionOverrides: {
351-
interaction_style: expect.stringContaining(
352-
"Quiet monitoring does not satisfy an explicit ongoing-work instruction.",
353-
),
351+
interaction_style: expect.stringContaining("This is a live chat, not a memo."),
354352
},
355353
});
354+
expect(
355+
provider.resolveSystemPromptContribution?.({
356+
provider: "codex",
357+
modelId: "gpt-5.4",
358+
} as never)?.sectionOverrides?.interaction_style,
359+
).not.toContain("The purpose of heartbeats is to make you feel magical and proactive.");
356360
});
357361

358362
it("does not add the GPT-5 prompt overlay to non-GPT-5 Codex provider runs", () => {

‎extensions/codex/src/app-server/run-attempt.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { runCodexAppServerAttempt, __testing } from "./run-attempt.js";
2828
import { readCodexAppServerBinding, writeCodexAppServerBinding } from "./session-binding.js";
2929
import { createCodexTestModel } from "./test-support.js";
3030
import {
31+
buildTurnCollaborationMode,
3132
buildThreadResumeParams,
3233
buildTurnStartParams,
3334
startOrResumeThread,
@@ -2325,10 +2326,40 @@ describe("runCodexAppServerAttempt", () => {
23252326
approvalsReviewer: "guardian_subagent",
23262327
sandboxPolicy: { type: "dangerFullAccess" },
23272328
serviceTier: "flex",
2329+
collaborationMode: {
2330+
mode: "default",
2331+
settings: {
2332+
model: "gpt-5.4-codex",
2333+
reasoning_effort: "medium",
2334+
developer_instructions: null,
2335+
},
2336+
},
23282337
}),
23292338
);
23302339
});
23312340

2341+
it("uses turn-scoped collaboration instructions for heartbeat Codex turns", () => {
2342+
const params = createParams("/tmp/session.jsonl", "/tmp/workspace");
2343+
params.trigger = "heartbeat";
2344+
2345+
expect(buildTurnCollaborationMode(params)).toEqual({
2346+
mode: "default",
2347+
settings: {
2348+
model: "gpt-5.4-codex",
2349+
reasoning_effort: "medium",
2350+
developer_instructions: expect.stringContaining(
2351+
"This is an OpenClaw heartbeat turn. Apply these instructions only to this heartbeat wake",
2352+
),
2353+
},
2354+
});
2355+
expect(buildTurnCollaborationMode(params).settings.developer_instructions).toContain(
2356+
"The purpose of heartbeats is to make you feel magical and proactive.",
2357+
);
2358+
2359+
params.trigger = "user";
2360+
expect(buildTurnCollaborationMode(params).settings.developer_instructions).toBeNull();
2361+
});
2362+
23322363
it("preserves the bound auth profile when resume params omit authProfileId", async () => {
23332364
const sessionFile = path.join(tempDir, "session.jsonl");
23342365
const workspaceDir = path.join(tempDir, "workspace");

‎extensions/codex/src/app-server/thread-lifecycle.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import {
22
embeddedAgentLog,
33
type EmbeddedRunAttemptParams,
44
} from "openclaw/plugin-sdk/agent-harness-runtime";
5-
import { renderCodexPromptOverlay } from "../../prompt-overlay.js";
5+
import {
6+
CODEX_GPT5_HEARTBEAT_PROMPT_OVERLAY,
7+
renderCodexPromptOverlay,
8+
} from "../../prompt-overlay.js";
69
import { isModernCodexModel } from "../../provider.js";
710
import { isCodexAppServerConnectionClosedError, type CodexAppServerClient } from "./client.js";
811
import { codexSandboxPolicyForTurn, type CodexAppServerRuntimeOptions } from "./config.js";
@@ -205,9 +208,33 @@ export function buildTurnStartParams(
205208
model: params.modelId,
206209
...(options.appServer.serviceTier ? { serviceTier: options.appServer.serviceTier } : {}),
207210
effort: resolveReasoningEffort(params.thinkLevel, params.modelId),
211+
collaborationMode: buildTurnCollaborationMode(params),
212+
};
213+
}
214+
215+
type CodexTurnCollaborationMode = NonNullable<CodexTurnStartParams["collaborationMode"]>;
216+
217+
export function buildTurnCollaborationMode(
218+
params: EmbeddedRunAttemptParams,
219+
): CodexTurnCollaborationMode {
220+
return {
221+
mode: "default",
222+
settings: {
223+
model: params.modelId,
224+
reasoning_effort: resolveReasoningEffort(params.thinkLevel, params.modelId),
225+
developer_instructions:
226+
params.trigger === "heartbeat" ? buildHeartbeatCollaborationInstructions() : null,
227+
},
208228
};
209229
}
210230

231+
function buildHeartbeatCollaborationInstructions(): string {
232+
return [
233+
"This is an OpenClaw heartbeat turn. Apply these instructions only to this heartbeat wake; ordinary chat turns should stay in Codex Default mode.",
234+
CODEX_GPT5_HEARTBEAT_PROMPT_OVERLAY,
235+
].join("\n\n");
236+
}
237+
211238
function fingerprintDynamicTools(dynamicTools: CodexDynamicToolSpec[]): string {
212239
return JSON.stringify(dynamicTools.map(fingerprintDynamicToolSpec));
213240
}

‎extensions/openai/index.test.ts‎

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import plugin from "./index.js";
1313
import {
1414
OPENAI_FRIENDLY_PROMPT_OVERLAY,
1515
OPENAI_GPT5_BEHAVIOR_CONTRACT,
16+
OPENAI_HEARTBEAT_PROMPT_OVERLAY,
1617
shouldApplyOpenAIPromptOverlay,
1718
} from "./prompt-overlay.js";
1819

@@ -70,6 +71,9 @@ async function registerOpenAIPluginWithHook(params?: { pluginConfig?: Record<str
7071
function expectOpenAIPromptContribution(
7172
provider: ProviderPlugin,
7273
sectionOverrides: Record<string, unknown>,
74+
contextOverrides: Partial<
75+
Parameters<NonNullable<ProviderPlugin["resolveSystemPromptContribution"]>>[0]
76+
> = {},
7377
) {
7478
expect(
7579
provider.resolveSystemPromptContribution?.({
@@ -82,6 +86,7 @@ function expectOpenAIPromptContribution(
8286
runtimeChannel: undefined,
8387
runtimeCapabilities: undefined,
8488
agentId: undefined,
89+
...contextOverrides,
8590
}),
8691
).toEqual({
8792
stablePrefix: OPENAI_GPT5_BEHAVIOR_CONTRACT,
@@ -442,6 +447,17 @@ describe("openai plugin", () => {
442447
interaction_style: OPENAI_FRIENDLY_PROMPT_OVERLAY,
443448
},
444449
});
450+
expect(
451+
openaiProvider.resolveSystemPromptContribution?.({
452+
...contributionContext,
453+
trigger: "heartbeat",
454+
}),
455+
).toEqual({
456+
stablePrefix: OPENAI_GPT5_BEHAVIOR_CONTRACT,
457+
sectionOverrides: {
458+
interaction_style: `${OPENAI_FRIENDLY_PROMPT_OVERLAY}\n\n${OPENAI_HEARTBEAT_PROMPT_OVERLAY}`,
459+
},
460+
});
445461
expect(
446462
openaiProvider.resolveSystemPromptContribution?.({
447463
...contributionContext,
@@ -472,46 +488,49 @@ describe("openai plugin", () => {
472488
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
473489
'Use brief first-person feeling language when it helps the interaction feel human: "I\'m glad we caught that", "I\'m excited about this direction", "I\'m worried this will break", "that\'s frustrating".',
474490
);
475-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
491+
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).not.toContain(
492+
"The purpose of heartbeats is to make you feel magical and proactive.",
493+
);
494+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
476495
"The purpose of heartbeats is to make you feel magical and proactive. Come to life and start proactively doing things that are important.",
477496
);
478-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
497+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
479498
"Treat a heartbeat as a proactive wake-up, not as a demand to produce visible output. Re-orient to what would actually be useful now.",
480499
);
481-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
500+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
482501
"Have some variety in what you do when that creates more value. Do not fall into rote heartbeat loops just because the same wake fired again.",
483502
);
484-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
503+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
485504
"Do not confuse orientation with accomplishment. Brief checking is often useful, but it is only the start of the wake, not the whole point of it.",
486505
);
487-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
506+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
488507
"If HEARTBEAT.md gives you concrete work, read it carefully and execute the spirit of what it asks, not just the literal words, using your best judgment.",
489508
);
490-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
509+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
491510
"If HEARTBEAT.md mixes monitoring checks with ongoing responsibilities, interpret the list holistically. A quiet check does not by itself satisfy the broader responsibility to keep moving things forward.",
492511
);
493-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
512+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
494513
"Quiet monitoring does not satisfy an explicit ongoing-work instruction. If HEARTBEAT.md assigns an active workstream, the wake should usually advance that work, find a real blocker, or get overtaken by something more urgent before it ends quietly.",
495514
);
496-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
515+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
497516
"If HEARTBEAT.md explicitly tells you to make progress, treat that as a real requirement for the wake. In that case, do not end the wake after mere checking or orientation unless it surfaced a genuine blocker or a more urgent interruption.",
498517
);
499-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
518+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
500519
"Use your judgment and be creative and tasteful with this process. Prefer meaningful action over commentary.",
501520
);
502-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
521+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
503522
'A heartbeat is not a status report. Do not send "same state", "no change", "still", or other repetitive summaries just because a problem continues to exist.',
504523
);
505-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
524+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
506525
"Notify the user when you have something genuinely worth interrupting them for: a meaningful development, a completed result, a real blocker, a decision they need to make, or a time-sensitive risk.",
507526
);
508-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
527+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
509528
"If the current state is materially unchanged and you do not have something genuinely worth surfacing, either do useful work, change your approach, dig deeper, or stay quiet.",
510529
);
511-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
530+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
512531
"If there is a clear standing goal or workstream and no stronger interruption, the wake should usually advance it in some concrete way. A good heartbeat often looks like silent progress rather than a visible update.",
513532
);
514-
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(
533+
expect(OPENAI_HEARTBEAT_PROMPT_OVERLAY).toContain(
515534
"Heartbeats are how the agent goes from a simple reply bot to a truly proactive and magical experience that creates a general sense of awe.",
516535
);
517536
expect(OPENAI_FRIENDLY_PROMPT_OVERLAY).toContain(

0 commit comments

Comments
 (0)