Repository navigation
fix(agents): delivered turns get the channel formatting rules once - #158028
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 6:20 AM ET / 10:20 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch gives delivered reply, cron, and agent-command turns one account-specific channel formatting block, removes duplicate Telegram details guidance, and updates the plugin contract documentation and tests. Merge readiness✅ Ready for maintainer review Keep open. Current main covers Telegram replies and cron announcements but still lacks formatting guidance for delivered agent-command turns. The latest documentation addresses the prior cross-channel review finding, and the submitted Telegram Test Server comparison supports the changed prompt behavior. Priority: P2 Review scores
Verification
How this fits togetherChannel plugins provide formatting rules for each account. OpenClaw adds those rules to an agent turn’s model context before the selected channel delivers its output. flowchart LR
A[Reply or scheduled turn] --> C[Delivery target and account]
B[Agent-command turn] --> C
C --> D[Channel plugin formatting rules]
D --> E[Model prompt]
E --> F[Delivered channel output]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +1, Tests +195, Docs +6, Other -1. Total +201 across 18 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one plugin-owned formatting contract per channel and account, and inject it for the turn’s resolved delivery target across supported agent runtimes. Do we have a high-confidence way to reproduce the issue? Yes. Current-main source shows the distinct prompt paths, and the PR records a Telegram Test Server before-and-after comparison for reply and cron requests. The agent-command gap is source-proven and covered by focused tests, but was not live-tested. Is this the best way to solve the issue? Yes. Reusing the shipped per-account plugin hook through one delivery-format builder addresses the inconsistent prompts without introducing a parallel plugin API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 52d7ce1bbab9. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
35e7b0f to
4c4938a
Compare
…nly delivered runs
4c4938a to
6378ff6
Compare
|
Landed. Every OpenClaw agent turn whose output is delivered to a channel (replies, heartbeats, cron announces, subagent and requester announces, |
…penclaw#158028) Related: openclaw#157877 Related: openclaw#108264 ## What Problem This Solves Fixes: a turn delivered to Telegram gets the channel's formatting rules in a different shape, twice, or not at all, depending on how it started. - Reply turns carry the rules inside the inbound metadata. On an account with `richMessages: true`, they also get a separate "Collapsible Details" section, so the `<details>` rule arrives twice. - Cron announce turns (openclaw#157877) carry the same rules in a second block with a different schema. - Subagent and requester announce turns, and other delivered agent turns (inter-session steps, `openclaw agent --deliver`), get no formatting rules. ## User Impact User impact: every turn whose visible output is delivered to a channel gets that channel's formatting rules once, in one block. This covers replies, heartbeats, cron announces and subagent announces. For Telegram, the rich-message rules apply only when the delivering account has `richMessages: true`. Other accounts get the standard-formatting rules. Turns with no chat delivery get no rules: no delivery, webhook delivery, subagent children, and Control UI chat. Slack announces now get Slack's rules too. No config change is required. ## Why This Change Was Made - One core function builds the block: `buildDeliveryFormatPrompt`. Reply turns read the loaded plugin that received the message, as before. Cron and agent-command turns resolve the delivering plugin with on-demand loading, for example for the first cron announce after startup. It asks the plugin for the delivering account's rules and renders one trusted `### Delivery Format` block (`openclaw.delivery_format.v1`) into the extra system prompt. This is the path every runtime (embedded, Codex, CLI) and its compaction already reads. - Three entry points call this function, each only when its turn has a channel delivery target: - Reply metadata, which also covers heartbeats and system events. - Cron delivery resolution. - Agent-command session preparation, for turns that deliver or use message-tool delivery. It uses the outbound channel and account chosen by delivery preflight, so a turn that starts on one account and delivers through another gets the delivering account's rules. - Removed: - The cron-only builder and its `openclaw.delivery_meta.v1` schema. - The `response_format` field in the inbound metadata. - Telegram's `markdownDetails` capability. The Telegram contract already contains the `<details>` rule. - The block has no per-turn fields, so its bytes are the same for every turn kind on the same channel and contract. It stays in trusted system metadata and never enters the transcript. The CLI session-binding inputs are unchanged: replies still keep this block out of the static binding text, and cron still hashes it. - External ACP agents do not receive OpenClaw's extra system prompt, so they do not get this block. The docs say "OpenClaw agent turn" for that reason. - Upgrade: the old cron `Delivery Context` block (openclaw#157877) is not in any release. Reply turns keep this block out of the CLI session-binding text, as before. A CLI-backed cron session on `main` whose bound prompt text changes resumes with `system-prompt` content drift, not a reset (covered by `src/agents/cli-session.test.ts`, "resumes on content drift"). - Plugin SDK: `inboundFormattingHints` is a shipped field, so this change keeps its name and signature. It is an intentional scope extension: core now calls it for every OpenClaw agent turn whose delivery target is the channel, not only inbound replies. The hook only receives `cfg` and `accountId`, with no inbound message data, so an existing hook returns the same rules it returns today. The SDK docs and type comment describe the new scope. - Control UI keeps its core-owned `markdownDetails` capability, because it has no channel plugin. - Follow-ups, not in this PR: - A `message` tool send to a different channel than the turn's own still gets only the current channel's rules. - `/btw` side answers do not get the block yet. ## Evidence - Focused tests at the real entry points, with a Telegram stub whose rich and plain accounts return different contracts: - `src/auto-reply/reply/get-reply.delivery-format.test.ts`: `getReplyFromConfig` replies on a rich account and on a plain account each get exactly one block with their own contract. A Telegram heartbeat through `runHeartbeatOnce` gets exactly one block. A Control UI reply gets none. - `src/commands/agent.delivery-format.test.ts`: `agentCommandFromIngress` with `deliver: true` (rich account) and with message-tool delivery (plain account) each append exactly one block after the caller's prompt. A turn from the rich account that delivers through the plain account gets the plain rules. An undelivered turn keeps the caller's prompt unchanged. - `src/cron/isolated-agent/run.delivery-formatting.test.ts`: cron announces load the Telegram plugin on demand, as on a cold Gateway. They get exactly one block for rich and plain accounts, and none with `mode: "none"`. - `extensions/telegram/src/channel-actions.contract.test.ts`: in the real Telegram plugin, a rich account and a plain account on the same bot get different contracts, and neither advertises `markdownDetails`. - The tests fail with the old production code restored: both delivered agent-command cases get no block, and the Telegram test finds `markdownDetails`. With the source account used instead of the outbound account, the cross-account case fails. - Test cost with `pnpm test <file> --maxWorkers=1`: about 7.5 s of test time for the agent-command file, 9 s for the reply and heartbeat file, and 4.3 s for the cron file. Most of the wall time is cold transform. - Neighboring suites pass: inbound metadata, prompt session context, reply media-only, agent command, session preparation and the system prompt. Changed-file typecheck, format and line-cap checks pass. - Live Telegram Test Server run with a real user recorder and a recording mock provider, on `main` and on this branch (reply and cron code as in the current head): | Run | Model request system prompt | Telegram result | | --- | --- | --- | | `main`, reply, rich on | rules inside inbound metadata `response_format`, plus a separate `## Collapsible Details` section (the `<details>` rule twice) | rich message | | `main`, cron announce, rich on | rules in `### Delivery Context` (`openclaw.delivery_meta.v1`) | rich message | | this branch, reply, rich on | one `### Delivery Format` block (`openclaw.delivery_format.v1`, `markdown_telegram_rich`), `<details>` rule once, no `Collapsible Details` section, no `response_format` in inbound metadata | rich message | | this branch, cron announce, rich on | the same `### Delivery Format` block, byte for byte; no `Delivery Context` block | rich message | | this branch, reply, rich off | one `### Delivery Format` block with the "Telegram rich OFF" rules | plain text message | The mock reply is fixed, so the Telegram message does not change between `main` and this branch. No screenshots are attached for that reason. - Not live-tested: subagent announces, heartbeats, and the Codex and CLI runtimes. They read the same extra-system-prompt input that the focused tests cover. Co-authored-by: Ayaan Zaidi <[email protected]>
Brings the branch onto current main; GitHub reported it CONFLICTING. inbound-meta.ts conflicted because main rewrote the helpers this branch had moved out of it: openclaw#157000, openclaw#161129, openclaw#164547 and openclaw#166085 trimmed the file, openclaw#158028 dropped its max-lines suppression, and openclaw#167236 merged the transcript sanitizers into sanitizeTranscriptText. The split is re-applied on main's code rather than on the branch's older copies: - inbound-meta.text.ts holds main's normalizePromptMetadataString, normalizePromptMetadataStringArray, sanitizePromptBody, truncateBodyHeadTail and sanitizeTranscriptText, moved verbatim. - inbound-meta.current-message.ts builds both projections with sanitizeTranscriptText(..., "body") in place of the branch's sanitizeTranscriptBody; the inline projection keeps main's bare header. - inbound-meta.ts is main's file minus the moved helpers. - config/max-lines-baseline.txt takes main's side, which already dropped the inbound-meta.ts entry. The carrier projection stays in its own module: get-reply-run.media-only.test.ts and followup-turn-admission.test.ts mock ./inbound-meta.js with closed factories, and prompt-prelude.ts must not import the projection through them.
Related: #157877
Related: #108264
What Problem This Solves
Fixes: a turn delivered to Telegram gets the channel's formatting rules in a different shape, twice, or not at all, depending on how it started.
richMessages: true, they also get a separate "Collapsible Details" section, so the<details>rule arrives twice.openclaw agent --deliver), get no formatting rules.User Impact
User impact: every turn whose visible output is delivered to a channel gets that channel's formatting rules once, in one block. This covers replies, heartbeats, cron announces and subagent announces. For Telegram, the rich-message rules apply only when the delivering account has
richMessages: true. Other accounts get the standard-formatting rules. Turns with no chat delivery get no rules: no delivery, webhook delivery, subagent children, and Control UI chat. Slack announces now get Slack's rules too. No config change is required.Why This Change Was Made
buildDeliveryFormatPrompt. Reply turns read the loaded plugin that received the message, as before. Cron and agent-command turns resolve the delivering plugin with on-demand loading, for example for the first cron announce after startup. It asks the plugin for the delivering account's rules and renders one trusted### Delivery Formatblock (openclaw.delivery_format.v1) into the extra system prompt. This is the path every runtime (embedded, Codex, CLI) and its compaction already reads.openclaw.delivery_meta.v1schema.response_formatfield in the inbound metadata.markdownDetailscapability. The Telegram contract already contains the<details>rule.Delivery Contextblock (fix(cron): announce runs miss the channel's formatting rules #157877) is not in any release. Reply turns keep this block out of the CLI session-binding text, as before. A CLI-backed cron session onmainwhose bound prompt text changes resumes withsystem-promptcontent drift, not a reset (covered bysrc/agents/cli-session.test.ts, "resumes on content drift").inboundFormattingHintsis a shipped field, so this change keeps its name and signature. It is an intentional scope extension: core now calls it for every OpenClaw agent turn whose delivery target is the channel, not only inbound replies. The hook only receivescfgandaccountId, with no inbound message data, so an existing hook returns the same rules it returns today. The SDK docs and type comment describe the new scope.markdownDetailscapability, because it has no channel plugin.messagetool send to a different channel than the turn's own still gets only the current channel's rules./btwside answers do not get the block yet.Evidence
Focused tests at the real entry points, with a Telegram stub whose rich and plain accounts return different contracts:
src/auto-reply/reply/get-reply.delivery-format.test.ts:getReplyFromConfigreplies on a rich account and on a plain account each get exactly one block with their own contract. A Telegram heartbeat throughrunHeartbeatOncegets exactly one block. A Control UI reply gets none.src/commands/agent.delivery-format.test.ts:agentCommandFromIngresswithdeliver: true(rich account) and with message-tool delivery (plain account) each append exactly one block after the caller's prompt. A turn from the rich account that delivers through the plain account gets the plain rules. An undelivered turn keeps the caller's prompt unchanged.src/cron/isolated-agent/run.delivery-formatting.test.ts: cron announces load the Telegram plugin on demand, as on a cold Gateway. They get exactly one block for rich and plain accounts, and none withmode: "none".extensions/telegram/src/channel-actions.contract.test.ts: in the real Telegram plugin, a rich account and a plain account on the same bot get different contracts, and neither advertisesmarkdownDetails.The tests fail with the old production code restored: both delivered agent-command cases get no block, and the Telegram test finds
markdownDetails. With the source account used instead of the outbound account, the cross-account case fails.Test cost with
pnpm test <file> --maxWorkers=1: about 7.5 s of test time for the agent-command file, 9 s for the reply and heartbeat file, and 4.3 s for the cron file. Most of the wall time is cold transform.Neighboring suites pass: inbound metadata, prompt session context, reply media-only, agent command, session preparation and the system prompt. Changed-file typecheck, format and line-cap checks pass.
Live Telegram Test Server run with a real user recorder and a recording mock provider, on
mainand on this branch (reply and cron code as in the current head):main, reply, rich onresponse_format, plus a separate## Collapsible Detailssection (the<details>rule twice)main, cron announce, rich on### Delivery Context(openclaw.delivery_meta.v1)### Delivery Formatblock (openclaw.delivery_format.v1,markdown_telegram_rich),<details>rule once, noCollapsible Detailssection, noresponse_formatin inbound metadata### Delivery Formatblock, byte for byte; noDelivery Contextblock### Delivery Formatblock with the "Telegram rich OFF" rulesThe mock reply is fixed, so the Telegram message does not change between
mainand this branch. No screenshots are attached for that reason.Not live-tested: subagent announces, heartbeats, and the Codex and CLI runtimes. They read the same extra-system-prompt input that the focused tests cover.