mirror of
https://github.com/openclaw/openclaw.git
synced 2026-10-03 17:53:39 +00:00
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 <hi@obviy.us> |
||
|---|---|---|
| .. | ||
| contracts | ||
| e2e | ||
| fixtures | ||
| helpers | ||
| mocks | ||
| plugins | ||
| scripts | ||
| tsconfig | ||
| type-contracts | ||
| vitest | ||
| agent-exec-code-mode.live.test.ts | ||
| AGENTS.md | ||
| apns-worker-test-ownership.test.ts | ||
| appcast.test.ts | ||
| architecture-smells.test.ts | ||
| buzz-account-config-mutation.test.ts | ||
| canonical-descendant.integration.test.ts | ||
| channel-message-read-authority.integration.test.ts | ||
| clawrouter-managed-gateway.e2e.test.ts | ||
| cli-json-stdout.agents.e2e.test.ts | ||
| cli-json-stdout.automation.e2e.test.ts | ||
| cli-json-stdout.config.e2e.test.ts | ||
| cli-json-stdout.e2e.test.ts | ||
| cli-json-stdout.gateway.e2e.test.ts | ||
| cli-json-stdout.hooks.e2e.test.ts | ||
| cli-json-stdout.models.e2e.test.ts | ||
| cli-json-stdout.plugins.e2e.test.ts | ||
| cli-json-stdout.sessions.e2e.test.ts | ||
| cli-json-stdout.skills.e2e.test.ts | ||
| cli-json-stdout.test-support.ts | ||
| cli-message-authority.integration.test.ts | ||
| cli-state-sqlite.e2e.test.ts | ||
| codex-node-cancellation.integration.test.ts | ||
| codex-settled-turn-finalization.integration.test.ts | ||
| control-ui-import-boundary.test.ts | ||
| conversation-tools.codex.integration.test.ts | ||
| copilot-tool-policy-handoff.integration.test.ts | ||
| copilot-tool-policy-handoff.live.test.ts | ||
| cron-conversation-delivery.codex.integration.test.ts | ||
| cron-edit-trigger-preservation.e2e.test.ts | ||
| cron-message-read.integration.test.ts | ||
| discord-live-policy.integration.test.ts | ||
| discord-metadata-read-authority.integration.test.ts | ||
| doctor-copied-state-migration.e2e.test.ts | ||
| doctor-legacy-whatsapp-ack-migration.e2e.test.ts | ||
| dreaming-startup-cleanup.e2e.test.ts | ||
| embedded-transcript-cursor.e2e.test.ts | ||
| extension-import-boundaries.test.ts | ||
| extension-test-boundary.test.ts | ||
| external-script-modules.d.ts | ||
| feishu-message-mutations.integration.test.ts | ||
| feishu-message-read-authority.integration.test.ts | ||
| gateway-a2a.e2e.test.ts | ||
| gateway-account-history.e2e.test.ts | ||
| gateway-cold-agent-abort.e2e.test.ts | ||
| gateway-completion-replay.e2e.test.ts | ||
| gateway-copied-codex-session-resume.e2e.test.ts | ||
| gateway-external-state-ownership.e2e.test.ts | ||
| gateway-hook-concurrency.e2e.test.ts | ||
| gateway-no-op-mutation.e2e.test.ts | ||
| gateway-openai-compaction-replay.e2e.test.ts | ||
| gateway-queued-session-rotation.e2e.test.ts | ||
| gateway-restored-requester-settle.e2e.test.ts | ||
| gateway-rpc-exporters.test.ts | ||
| gateway-session-end-shutdown.e2e.test.ts | ||
| gateway-steer-fifo.e2e.test.ts | ||
| gateway-subagent-restart.live.test.ts | ||
| gateway-widget-restart.live.test.ts | ||
| gateway.multi.e2e.test.ts | ||
| git-hooks-pre-commit-boundaries.test.ts | ||
| git-hooks-pre-commit.test-support.ts | ||
| git-hooks-pre-commit.test.ts | ||
| github-cli-preflight.e2e.test.ts | ||
| huggingface-local-app-openclaw.e2e.test.ts | ||
| image-generation.infer-cli.live.test.ts | ||
| image-generation.runtime.live.test.ts | ||
| imessage-reply-alias.integration.test.ts | ||
| jsdom-compat.mts | ||
| jsdom-compat.test.ts | ||
| jsdom-custom-elements.test.ts | ||
| jsdom-custom-elements.ts | ||
| line-question-gateway.test.ts | ||
| linux-dashboard-recovery.test.ts | ||
| linux-quickchat-stream.test.ts | ||
| loopback-ask-user-telegram-channel.test.ts | ||
| matrix-channel-read-authority.integration.test.ts | ||
| matrix-client-crypto-authority.integration.test.ts | ||
| matrix-transport-read-authority.integration.test.ts | ||
| mcp-show-redact.e2e.test.ts | ||
| msteams-read-authority.integration.test.ts | ||
| msteams-read-target.integration.test.ts | ||
| node-host-launcher.test.ts | ||
| non-isolated-runner.agent-reader-fixtures.ts | ||
| non-isolated-runner.gateway-lifecycle-fixtures.ts | ||
| non-isolated-runner.mock-resolution-fixtures.ts | ||
| non-isolated-runner.sqlite-fixtures.ts | ||
| non-isolated-runner.sqlite.test.ts | ||
| non-isolated-runner.test-api-fixtures.ts | ||
| non-isolated-runner.test.ts | ||
| non-isolated-runner.ts | ||
| npm-publish-plan.test.ts | ||
| oauth-refresh-authority-chain.e2e.test.ts | ||
| official-channel-catalog.test.ts | ||
| onboard-plugin-warnings.e2e.test.ts | ||
| openai-model-discovery-auth-order.test.ts | ||
| openai-onboarding.live.test.ts | ||
| openclaw-launcher-version.e2e.test.ts | ||
| openclaw-launcher.e2e.test.ts | ||
| openclaw-npm-postpublish-verify.test.ts | ||
| openclaw-npm-prepublish-verify.test.ts | ||
| openclaw-npm-release-check.test.ts | ||
| openclaw-prepack.test.ts | ||
| outbound-sanitize-text-delivery.test.ts | ||
| package-manager-config.test.ts | ||
| package-scripts.test.ts | ||
| plugin-clawhub-metadata.test.ts | ||
| plugin-clawhub-release.test.ts | ||
| plugin-cron-registry-owner.e2e.test.ts | ||
| plugin-extension-import-boundary.test.ts | ||
| plugin-npm-package-manifest.test.ts | ||
| plugin-npm-release.test.ts | ||
| plugin-npm-runtime-build.test.ts | ||
| pr111899-accepted-run-transport-loss.e2e.test.ts | ||
| pr119473-real-runtime-proof.e2e.test.ts | ||
| pr126853-heartbeat-visible-lane-proof.e2e.test.ts | ||
| pr142176-real-runtime-proof.e2e.test.ts | ||
| progress-card-channel-literals.integration.test.ts | ||
| provider-auth-method.openai-siwc.integration.test.ts | ||
| provider-auth-method.radius.integration.test.ts | ||
| qa-channel-message-tool-delivery.test.ts | ||
| qa-convex-credential-payload-validation.test.ts | ||
| release-check.test.ts | ||
| release-version.test.ts | ||
| repository-test-api-publications.ts | ||
| runtime-agent.codex-initialization.integration.test.ts | ||
| scripts-update-gateway.test.ts | ||
| setup-home-isolation.test.ts | ||
| setup-openclaw-runtime.plugin-cache.test.ts | ||
| setup-openclaw-runtime.ts | ||
| setup.env.ts | ||
| setup.extensions.ts | ||
| setup.shared.ts | ||
| setup.signal.ts | ||
| setup.ts | ||
| skill-usage.codex.integration.test.ts | ||
| skills-proposal-manual-target.e2e.test.ts | ||
| slack-download-read-authority.integration.test.ts | ||
| slack-outbound-permanent-rejection-loopback.test.ts | ||
| sqlite-test-lifecycle.ts | ||
| stable-release-closeout.test.ts | ||
| status-shared-state-readonly.e2e.test.ts | ||
| subagent-announce-origin.integration.test.ts | ||
| subagent-requester-owner.e2e.test.ts | ||
| system-agent-managed-auth.e2e.test.ts | ||
| talk-browser-defaults.test.ts | ||
| telegram-history-read.integration.test.ts | ||
| telegram-outbound-permanent-rejection-loopback.test.ts | ||
| telegram-question-gateway.test.ts | ||
| telegram-recovery-notice-send.test.ts | ||
| telegram-reply-conversation.test.ts | ||
| test-env.state-lifetime.test.ts | ||
| test-env.test.ts | ||
| test-env.ts | ||
| test-helper-extension-import-boundary.test.ts | ||
| test-home-context.mts | ||
| test-home-policy.mts | ||
| transcripts-discord-audio.integration.test.ts | ||
| transcripts-tool.discord-lifecycle.integration.test.ts | ||
| transcripts-tool.discord-provider.integration.test.ts | ||
| tsconfig.json | ||
| twitch-message-tool-delivery.test.ts | ||
| ui.presenter-next-run.test.ts | ||
| vitest-boundary-config.test.ts | ||
| vitest-cli-ownership.test.ts | ||
| vitest-credential-redaction.test.ts | ||
| vitest-dependency-resolution.test.ts | ||
| vitest-light-paths.test.ts | ||
| vitest-performance-config.test.ts | ||
| vitest-projects-config.test-support.ts | ||
| vitest-projects-config.test.ts | ||
| vitest-redacting-reporter.test.ts | ||
| vitest-reporters-config.test.ts | ||
| vitest-scoped-config.test.ts | ||
| vitest-ui-e2e-config.test.ts | ||
| vitest-ui-e2e-prebuilt.test.ts | ||
| vitest-ui-e2e-preflight.test.ts | ||
| vitest-ui-package-config.test.ts | ||
| vitest-unit-config.test.ts | ||
| vitest-unit-fast-config.test.ts | ||
| vitest-unit-paths.test.ts | ||