Skip to content

fix(cron): announce runs miss the channel's formatting rules - #157877

Merged
obviyus merged 2 commits into
mainfrom
fix/cron-channel-formatting-hints
Sep 25, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/cron-channel-formatting-hints

Conversation

@obviyus

@obviyus obviyus commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #108264

What Problem This Solves

Fixes: scheduled (cron) runs that announce to a channel get none of that channel's formatting rules. For example, a daily job that posts to a Telegram chat with richMessages: true never sees the rich-message contract. The model guesses the markup, so the same job sends a <table> on one day and a <pre> block on another.

#108264 moved the Telegram rich contract out of the core system prompt and into the channel's inbound formatting hints. Those hints are only built for turns that start from an incoming message (and for heartbeats, which carry their delivery channel in the same context). Isolated cron runs never build them, so they lost the contract.

User Impact

User impact: a cron job that announces to a channel now gets the same formatting rules as a normal reply on that channel and account. For Telegram, this is the rich contract when richMessages is on and the "rich OFF" rules when it is off. Jobs with delivery.mode: "none" or a webhook get no channel rules. Inbound replies do not change.

Why This Change Was Made

  • The channel plugin's inboundFormattingHints stays the only source of the rule text.
  • Cron delivery resolution now also resolves the plugin that will send the output, with the same outbound lookup that delivery uses. This includes a plugin that is loaded on demand for the first announcement after startup. The hints come from that plugin for the delivering account.
  • An announce run adds a short trusted ### Delivery Context block (openclaw.delivery_meta.v1) to its extra system prompt. This is the same path that fix(telegram): deliver rich-message authoring contract to every runtime via inbound formatting hints #108264 uses to reach every runtime (embedded, Codex, CLI). The block stays in system metadata, not in the transcript.
  • The block only exists when the job requests delivery, the target resolves to a chat, and the plugin has hints. For each job it is the same on every run, so the prompt prefix stays cache-friendly. CLI session binding hashes the same block, so a CLI session and its media-wake continuation keep resuming.

Evidence

  • New src/cron/isolated-agent/run.delivery-formatting.test.ts runs the real cron preparation, delivery resolution and executor. The Telegram plugin is not active and is loaded on demand, as on a cold Gateway. Rich ON adds the rich contract for the delivering account, rich OFF adds the OFF rules, and mode: "none" adds nothing. The ON and OFF cases fail on main. They also fail with a lookup that reads only the active plugin registry.
  • Neighboring cron suites pass: message-tool policy and source-delivery guard.
  • Cost of the new test file: pnpm test src/cron/isolated-agent/run.delivery-formatting.test.ts --maxWorkers=1 measures about 4.7 s of test time (33 s wall, most of it cold transform).
  • Live check on the Telegram Test Server with a real-user recorder: an isolated cron job announces to the test chat with richMessages: true and a mock provider that records requests.
    • main: the model request has no delivery context and no markdown_telegram_rich.
    • This branch (current head): the developer-role system context of the model request contains the openclaw.delivery_meta.v1 block with text_markup: "markdown_telegram_rich" and the full rule list.
    • On both, the Telegram user received the reply as a native rich message with a table block. The mock reply is fixed, so this shows delivery still works. It does not show a change in model behavior.
  • Not live-tested: the CLI and Codex runtimes. They get the same extra-system-prompt input as the embedded runtime that was tested.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus
obviyus marked this pull request as ready for review September 25, 2026 03:52
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 1:40 AM ET / 05:40 UTC (Revision 4).

ClawSweeper review

What this changes

Cron announcements add the delivering channel plugin’s account-specific formatting rules to agent context, with tests for Telegram rich-on, rich-off, and disabled delivery.

Regression provenance

Possible regression — suspected (known regression link). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Current main still omits channel formatting rules from isolated cron announcements. The latest head addresses the earlier cold-plugin finding through the outbound resolver, and this review found no definite introduced defect.

Priority: P2
Reviewed head: 2f97909c33338b006e4a203863afa416463ea632

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The focused repair has credible live prompt-path evidence, and the latest head resolves the prior actionable finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body reports a real Telegram Test Server cron run with a fixed mock provider: this head’s model request contained the account’s rich formatting rules where main’s did not, and Telegram delivery completed. That directly covers prompt composition, the changed behavior; it does not establish improved model-generated markup. The persisted continuation field used for prompt hashing was already optional, with no stored-data contract change.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports a real Telegram Test Server cron run with a fixed mock provider: this head’s model request contained the account’s rich formatting rules where main’s did not, and Telegram delivery completed. That directly covers prompt composition, the changed behavior; it does not establish improved model-generated markup. The persisted continuation field used for prompt hashing was already optional, with no stored-data contract change.
Evidence reviewed 8 items Current main gap: Current main resolves the cron delivery target without obtaining channel formatting hints or building a delivery prompt.
Latest-head repair: For a requested, resolved chat delivery, the PR asks the outbound resolver for an activated plugin with bootstrap allowed and obtains formatting hints for the resolved account.
Prior finding checked: The outbound resolver favors an activated runtime plugin over a setup shell; existing resolver tests cover bootstrapping when a setup shell is present. The new cron test exercises bootstrap through the runner, although it does not install an active setup shell itself.
Findings None None.
Security None None.

How this fits together

The cron runner turns a scheduled job into an agent request, then delivers its output to the resolved channel and account. Channel plugins supply formatting rules that guide the agent’s response before delivery.

flowchart LR
  A[Scheduled job] --> B[Resolve chat delivery]
  B --> C[Select outbound plugin]
  C --> D[Get account formatting rules]
  D --> E[Agent system context]
  E --> F[Agent response]
  F --> G[Channel delivery]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +65, Tests +141. Total +206 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 5 72 7 +65
Tests 1 141 0 +141
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 213 7 +206

Review metrics

Metric Value Why it matters
Production versus test growth production +65 net lines; tests +141 lines The production growth is directed at reusing the existing plugin rule owner and carrying its prompt through cron execution.

Technical review

Best possible solution:

Restore consistent account-specific authoring rules for scheduled and inbound channel turns while keeping the rules owned by each channel plugin.

Do we have a high-confidence way to reproduce the issue?

Yes. Current-main source lacks the cron formatting-hint path, and the PR reports a before-and-after Telegram Test Server model-request comparison; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing the existing channel-plugin hint hook and activation-aware outbound resolver is a narrow repair that avoids a second formatting-rule owner.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 17e75b2b923e.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports a real Telegram Test Server cron run with a fixed mock provider: this head’s model request contained the account’s rich formatting rules where main’s did not, and Telegram delivery completed. That directly covers prompt composition, the changed behavior; it does not establish improved model-generated markup. The persisted continuation field used for prompt hashing was already optional, with no stored-data contract change.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: The fix addresses inconsistent scheduled-message formatting with limited channel and account scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports a real Telegram Test Server cron run with a fixed mock provider: this head’s model request contained the account’s rich formatting rules where main’s did not, and Telegram delivery completed. That directly covers prompt composition, the changed behavior; it does not establish improved model-generated markup. The persisted continuation field used for prompt hashing was already optional, with no stored-data contract change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports a real Telegram Test Server cron run with a fixed mock provider: this head’s model request contained the account’s rich formatting rules where main’s did not, and Telegram delivery completed. That directly covers prompt composition, the changed behavior; it does not establish improved model-generated markup. The persisted continuation field used for prompt hashing was already optional, with no stored-data contract change.
  • proof: telegram-e2e: This PR needs Telegram Test Server proof with the repository E2E skill. Account-specific rules can change the formatting of scheduled messages visible in Telegram chat.

Evidence

What I checked:

Likely related people:

  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-25T03:59:16.919Z sha 64d7a79 :: needs changes before merge. :: [P3] Report the new test’s measured run cost
  • reviewed 2026-09-25T04:17:18.847Z sha 64d7a79 :: needs changes before merge. :: [P2] Use the resolved channel plugin for cold cron formatting hints
  • reviewed 2026-09-25T05:10:30.837Z sha 7673031 :: needs changes before merge. :: [P2] Use the outbound plugin selected for cold cron runs

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 25, 2026
@obviyus
obviyus force-pushed the fix/cron-channel-formatting-hints branch from 64d7a79 to 7673031 Compare September 25, 2026 05:03
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 25, 2026
@obviyus
obviyus merged commit 2716e9a into main Sep 25, 2026
212 checks passed
@obviyus
obviyus deleted the fix/cron-channel-formatting-hints branch September 25, 2026 06:00
@obviyus

obviyus commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 2716e9a.

  • Bug: cron runs that announce to a channel did not get that channel's formatting rules. Since fix(telegram): deliver rich-message authoring contract to every runtime via inbound formatting hints #108264 these rules come only with inbound messages. So a daily Telegram job chose its own markup.
  • Fix: cron delivery resolution now finds the plugin that sends the output. This includes a plugin that is loaded on demand when the Gateway is cold. The run gets that plugin's formatting hints for the delivering account in trusted openclaw.delivery_meta.v1 system metadata.
  • Proof: new cron test covers a cold plugin load with rich ON, rich OFF and no delivery. Live Telegram Test Server run: on main the model request has no rich contract. On this head it has markdown_telegram_rich, and delivery is unchanged.

vincentkoc added a commit that referenced this pull request Sep 25, 2026
…4-prep

* commit '8fe893da516ebdc817692fb2d272e27bc3c88376': (31 commits)
  fix(test): wait for reload admission before restart polling (#157964)
  refactor(mattermost): reuse DM retry option selection (#157800)
  chore(i18n): refresh native locales (#157850)
  perf(sessions): reuse current participants across transcript appends (#157622)
  refactor(signal): share pending transport migration results (#157777)
  fix(tui): open model pickers without waiting for the Gateway (#157839)
  fix(gateway): apply config despite delayed file notifications (#157906)
  fix(auth): clear deleted account selections and support account recovery (#157745)
  fix: plugin reloads lose tool results and strand subagent settlement (#157339)
  fix(gateway): avoid preview errors during worker metadata updates (#157943)
  refactor(diffs): reuse native promisify for compression (#157835)
  fix(models): keep current choices on the first picker page (#157869)
  fix(plugins): retain existing quarantine across unrelated reloads (#157907)
  fix(openai): prioritize ChatGPT sign-in and clarify auth choices (#157792)
  chore(ui): refresh control ui locales (#157955)
  fix(ui): refresh connected accounts after auth changes (#157950)
  fix(scripts): avoid redundant npm version process in package checks (#157809)
  refactor(usage): capture hosted pricing once per operation (#157838)
  refactor(ui): share slash-command failure results (#157649)
  fix(cron): announce runs miss the channel's formatting rules (#157877)
  ...
obviyus added a commit that referenced this pull request Sep 25, 2026
…158028)

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.

- 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 (#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 (#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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
…w#157877)

Related: openclaw#108264

## What Problem This Solves

Fixes: scheduled (cron) runs that announce to a channel get none of that channel's formatting rules. For example, a daily job that posts to a Telegram chat with `richMessages: true` never sees the rich-message contract. The model guesses the markup, so the same job sends a `<table>` on one day and a `<pre>` block on another.

openclaw#108264 moved the Telegram rich contract out of the core system prompt and into the channel's inbound formatting hints. Those hints are only built for turns that start from an incoming message (and for heartbeats, which carry their delivery channel in the same context). Isolated cron runs never build them, so they lost the contract.

## User Impact

User impact: a cron job that announces to a channel now gets the same formatting rules as a normal reply on that channel and account. For Telegram, this is the rich contract when `richMessages` is on and the "rich OFF" rules when it is off. Jobs with `delivery.mode: "none"` or a webhook get no channel rules. Inbound replies do not change.

## Why This Change Was Made

- The channel plugin's `inboundFormattingHints` stays the only source of the rule text.
- Cron delivery resolution now also resolves the plugin that will send the output, with the same outbound lookup that delivery uses. This includes a plugin that is loaded on demand for the first announcement after startup. The hints come from that plugin for the delivering account.
- An announce run adds a short trusted `### Delivery Context` block (`openclaw.delivery_meta.v1`) to its extra system prompt. This is the same path that openclaw#108264 uses to reach every runtime (embedded, Codex, CLI). The block stays in system metadata, not in the transcript.
- The block only exists when the job requests delivery, the target resolves to a chat, and the plugin has hints. For each job it is the same on every run, so the prompt prefix stays cache-friendly. CLI session binding hashes the same block, so a CLI session and its media-wake continuation keep resuming.

## Evidence

- New `src/cron/isolated-agent/run.delivery-formatting.test.ts` runs the real cron preparation, delivery resolution and executor. The Telegram plugin is not active and is loaded on demand, as on a cold Gateway. Rich ON adds the rich contract for the delivering account, rich OFF adds the OFF rules, and `mode: "none"` adds nothing. The ON and OFF cases fail on `main`. They also fail with a lookup that reads only the active plugin registry.
- Neighboring cron suites pass: message-tool policy and source-delivery guard.
- Cost of the new test file: `pnpm test src/cron/isolated-agent/run.delivery-formatting.test.ts --maxWorkers=1` measures about 4.7 s of test time (33 s wall, most of it cold transform).
- Live check on the Telegram Test Server with a real-user recorder: an isolated cron job announces to the test chat with `richMessages: true` and a mock provider that records requests.
  - `main`: the model request has no delivery context and no `markdown_telegram_rich`.
  - This branch (current head): the developer-role system context of the model request contains the `openclaw.delivery_meta.v1` block with `text_markup: "markdown_telegram_rich"` and the full rule list.
  - On both, the Telegram user received the reply as a native rich message with a table block. The mock reply is fixed, so this shows delivery still works. It does not show a change in model behavior.
- Not live-tested: the CLI and Codex runtimes. They get the same extra-system-prompt input as the embedded runtime that was tested.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant