Skip to content

Commit b316c9c

Browse files
authored
fix(channels): honor explicit preview streaming settings
Explicit Telegram and Discord preview modes now override inherited block streaming while explicit channel block settings remain authoritative. Co-authored-by: Syu <[email protected]>
1 parent ad37e91 commit b316c9c

18 files changed

Lines changed: 262 additions & 50 deletions

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ ba41c40956d6b4565605fa38c2d12f4b8471a0f8afe842798716b9032ee4d74a module/channel
3434
df567ce2f4a4ba8a0937f825c46e83763412a724e36b72ce727dc4203c7dd134 module/channel-ingress-runtime
3535
0e6efb79730fae59bb549ad00d9af2848c139b4bb1762e83b66886284e1c1421 module/channel-lifecycle
3636
159d034b431d113f3a6dc41ec0bcadba2d6664051f158330b0e3dd3da8b5d42f module/channel-logging
37-
1c7230faa8acc20731781a605d71f991bb3743bec8208650991b45973a9bfdc5 module/channel-message
38-
f04a59d4231b2df8800bf3a6b18183664574d7d145df48fa41f2e3da1ec4697d module/channel-outbound
37+
2d2b4b0440e61ef3697891883ca114f2b4bc4fff09c375b86e8d3bfec5f59bb5 module/channel-message
38+
d22cd6190bb3d0d0914466f3b5e1fe1787930572b5c212774a716fe2136112f0 module/channel-outbound
3939
930beff13ed42a138f65164013c82f4f4c96422292c5fc634a5edee1dce71367 module/channel-pairing
4040
ee4292b069d4d48cce4fc2dc26df5b5c87eb1fa4769f1f6be9a10c3e1221e1a9 module/channel-plugin-common
4141
94ef57c8f6087fcaa56e59e493c391a04377ed03f23c681edd8d8f6e2d64e0da module/channel-policy
@@ -46,7 +46,7 @@ bba5540be7cf9613a163663decdb2affe2af9bbd3ad7914989ab186f9c2abec1 module/channel
4646
7c90157a95bc0523fc66b1f78ce140f7ec7dbf809dfa3a480244efc01f972754 module/channel-send-result
4747
fb123c1b557ed2527e335f13c3d6de41ab0c3305151001cf2b1075d1da8034c5 module/channel-setup
4848
aeac9bb8127faf636dde79772a577d9cb003660ef3d1df03ddf606101020c402 module/channel-status
49-
d904e33114f056022ef9fec184edcfe37c30b539b268e28b0ff485f0a02b9c59 module/channel-streaming
49+
f008d1d9ea73cd17e9833143bd117436599438523041fd157b6b6cb17500ac06 module/channel-streaming
5050
14f0103adb14627b662fbe9fdd5ed08596ed702a250853e8beb8bb8dd1361588 module/cli-argv
5151
c89ec1b194b76f67a6f4dd108dccf460da6065646cba31374c8aa748f23a39e4 module/collection-runtime
5252
391e6f0c77da2e17a058fc5aea87fd193830b2a14e12fae77c7f63b0226f0bb5 module/command-auth

‎docs/channels/discord.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ See [Slash commands](/tools/slash-commands) for the command catalog and behavior
722722

723723
- `off` disables Discord preview edits.
724724
- `partial` edits a single preview message as tokens arrive.
725-
- `block` emits draft-sized chunks; tune size and breakpoints with `streaming.preview.chunk` (`minChars`, `maxChars`, `breakPreference`), clamped to `textChunkLimit`. When block streaming is explicitly enabled, OpenClaw skips the preview stream to avoid double-streaming.
725+
- `block` emits draft-sized chunks; tune size and breakpoints with `streaming.preview.chunk` (`minChars`, `maxChars`, `breakPreference`), clamped to `textChunkLimit`. An explicit non-`off` preview mode overrides inherited `agents.defaults.blockStreamingDefault: "on"`; explicit `streaming.block.enabled: true` overrides the preview. If a turn cannot use previews, inherited block delivery still applies.
726726
- `progress` keeps one editable status draft until final delivery. It shows the agent's latest preamble or narration as a status headline, with the compact tool rows underneath and no generated label.
727727
- Media, error, and explicit-reply finals cancel pending preview edits.
728728
- `streaming.preview.toolProgress` and `streaming.progress.toolProgress` both default to `true` in every mode. Tool rows such as `🛠️ Bash: run tests` or `🔎 Web Search: for "query"` appear without config; set either key to `false` to keep the status headline only.

‎docs/channels/telegram.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ curl "https://api.telegram.org/bot<bot_token>/getUpdates"
395395

396396
For text-only replies: short previews get the final edit in place; long finals that split into multiple messages reuse the preview as the first chunk, then send only the remainder; progress-mode finals clear the status draft and use normal final delivery; if the final edit fails before completion is confirmed, OpenClaw falls back to normal final delivery and cleans up the stale preview. For complex replies (media payloads), OpenClaw always falls back to normal final delivery and cleans up the preview.
397397

398-
Preview streaming and block streaming are mutually exclusive — when block streaming is explicitly enabled, OpenClaw skips the preview stream to avoid double-streaming.
398+
Preview streaming and block streaming are mutually exclusive. An explicit non-`off` preview mode overrides inherited `agents.defaults.blockStreamingDefault: "on"`; explicit `streaming.block.enabled: true` overrides the preview. If a turn cannot use previews, inherited block delivery still applies.
399399

400400
Reasoning: `/reasoning stream` streams reasoning into the live preview while generating, then deletes the reasoning preview after final delivery (use `/reasoning on` to keep it visible). The final answer is sent without reasoning text.
401401

‎docs/concepts/streaming.md‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,18 @@ replies**, not final replies or tool summaries.
145145
once, possibly multiple chunks if very long).
146146
- **No block streaming:** `blockStreamingDefault: "off"` (only final reply).
147147

148-
Block streaming is **off unless** `*.streaming.block.enabled` is explicitly
149-
set to `true` (exception: QQ Bot has no `streaming.block` keys and streams
150-
block replies unless `channels.qqbot.streaming.mode` is `"off"`). Channels can
151-
stream a live preview (`channels.<channel>.streaming.mode`) without block
152-
replies. The `blockStreaming*` defaults live under `agents.defaults`, not the
153-
config root.
148+
Block streaming follows `agents.defaults.blockStreamingDefault` unless a
149+
channel or account sets `*.streaming.block.enabled` explicitly. QQ Bot has no
150+
`streaming.block` keys and streams block replies unless
151+
`channels.qqbot.streaming.mode` is `"off"`. Channels can stream a live preview
152+
(`channels.<channel>.streaming.mode`) without block replies. The
153+
`blockStreaming*` defaults live under `agents.defaults`, not the config root.
154+
155+
For Discord and Telegram, an explicitly configured non-`off` preview mode
156+
takes precedence over inherited `agents.defaults.blockStreamingDefault: "on"`.
157+
Set that channel's `streaming.block.enabled: true` when block replies should
158+
override its preview. If the preview is unavailable for a turn, inherited block
159+
delivery still applies.
154160

155161
## Preview streaming modes
156162

‎extensions/discord/src/config-ui-hints.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export const discordChannelConfigUiHints = {
2222
chunkMode:
2323
'Chunking mode for outbound Discord text delivery: "length" (default) or "newline".',
2424
"block.enabled":
25-
'Enable chunked block-style Discord preview delivery when channels.discord.streaming.mode="block".',
25+
"Enable normal Discord block replies. This takes precedence over editable preview delivery.",
2626
"block.coalesce": "Merge streamed Discord block replies before final delivery.",
2727
"preview.chunk.minChars":
2828
'Minimum chars before emitting a Discord stream preview update when channels.discord.streaming.mode="block" (default: 200).',

‎extensions/discord/src/monitor/message-handler.draft-preview.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,17 @@ export function createDiscordDraftPreviewController(params: {
5555
(hookRunner?.hasHooks("message_sending") ?? false)
5656
);
5757
const draftMaxChars = Math.min(params.textLimit, 2000);
58-
const accountBlockStreamingEnabled =
59-
resolveChannelStreamingBlockEnabled(params.discordConfig) ??
60-
params.cfg.agents?.defaults?.blockStreamingDefault === "on";
6158
const canStreamProgressDraftForToolOnlySource =
6259
params.sourceRepliesAreToolOnly && discordStreamMode === "progress";
63-
const canStreamDraft =
60+
const previewAvailable =
6461
allowProviderPreview &&
6562
(!params.sourceRepliesAreToolOnly || canStreamProgressDraftForToolOnlySource) &&
66-
discordStreamMode !== "off" &&
67-
!accountBlockStreamingEnabled;
63+
discordStreamMode !== "off";
64+
const accountBlockStreamingEnabled = resolveChannelStreamingBlockEnabled(params.discordConfig, {
65+
previewAvailable,
66+
blockStreamingDefault: params.cfg.agents?.defaults?.blockStreamingDefault,
67+
});
68+
const canStreamDraft = previewAvailable && !accountBlockStreamingEnabled;
6869
const draftStream = canStreamDraft
6970
? createDiscordDraftStream({
7071
rest: params.deliveryRest,

‎extensions/discord/src/monitor/message-handler.process.draft-final.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,23 @@ describe("processDiscordMessage provider preview hook safety", () => {
9797
expect(createDiscordDraftStream).not.toHaveBeenCalled();
9898
});
9999

100+
it("uses an explicit partial preview despite inherited block delivery", async () => {
101+
dispatchInboundMessage.mockImplementationOnce(async (params?: DispatchInboundParams) => {
102+
expect(params?.replyOptions?.disableBlockStreaming).toBe(true);
103+
await params?.replyOptions?.onPartialReply?.({ text: "Hello" });
104+
await params?.dispatcher.sendFinalReply({ text: "Hello" });
105+
return { queuedFinal: true, counts: { final: 1, tool: 0, block: 0 } };
106+
});
107+
const ctx = await createAutomaticSourceDeliveryContext({
108+
cfg: { agents: { defaults: { blockStreamingDefault: "on" } } },
109+
discordConfig: { streaming: { mode: "partial" } },
110+
});
111+
112+
await runProcessDiscordMessage(ctx);
113+
114+
expect(createDiscordDraftStream).toHaveBeenCalledTimes(1);
115+
});
116+
100117
it("does not re-enter final delivery after message_sending cancellation", async () => {
101118
registerHooks("message_sending");
102119
deliverDiscordReply.mockResolvedValueOnce({ visibleReplySent: false });

‎extensions/telegram/src/bot-message-dispatch-draft.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,16 @@ export function createTelegramDraftController(params: {
8282
threadSpec: TelegramThreadSpec;
8383
}) {
8484
const streamDeliveryEnabled = !params.isRoomEvent && params.streamMode !== "off";
85-
const accountBlockStreamingEnabled =
86-
resolveChannelStreamingBlockEnabled(params.telegramCfg) ??
87-
params.cfg.agents?.defaults?.blockStreamingDefault === "on";
88-
const canStreamAnswerDraft =
85+
const previewAvailable =
8986
params.allowProviderPreview &&
9087
streamDeliveryEnabled &&
9188
!params.hasTelegramQuoteReply &&
92-
!accountBlockStreamingEnabled &&
9389
!params.forceBlockStreamingForReasoning;
90+
const accountBlockStreamingEnabled = resolveChannelStreamingBlockEnabled(params.telegramCfg, {
91+
previewAvailable,
92+
blockStreamingDefault: params.cfg.agents?.defaults?.blockStreamingDefault,
93+
});
94+
const canStreamAnswerDraft = previewAvailable && !accountBlockStreamingEnabled;
9495
const streamReasoningDraft = params.resolvedReasoningLevel === "stream";
9596
const streamReasoningInProgressDraft =
9697
streamReasoningDraft && params.streamMode === "progress" && canStreamAnswerDraft;

‎extensions/telegram/src/bot-message-dispatch.reply-targets.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,29 @@ describeTelegramDispatch("dispatchTelegramMessage reply-targets", () => {
165165
expect(deliveredPayload.channelData).toBeUndefined();
166166
});
167167

168+
it("uses an explicit partial preview despite inherited block delivery", async () => {
169+
const draftStream = createDraftStream();
170+
createTelegramDraftStream.mockReturnValue(draftStream);
171+
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(
172+
async ({ dispatcherOptions, replyOptions }) => {
173+
await replyOptions?.onPartialReply?.({ text: "Hello" });
174+
await dispatcherOptions.deliver({ text: "Hello" }, { kind: "final" });
175+
return { queuedFinal: true };
176+
},
177+
);
178+
deliverReplies.mockResolvedValue({ delivered: true });
179+
180+
await dispatchWithContext({
181+
context: createContext(),
182+
streamMode: "partial",
183+
cfg: { agents: { defaults: { blockStreamingDefault: "on" } } },
184+
telegramCfg: { streaming: { mode: "partial" } },
185+
});
186+
187+
expect(createTelegramDraftStream).toHaveBeenCalled();
188+
expect(draftStream.update).toHaveBeenCalledWith("Hello");
189+
});
190+
168191
it("uses 30-char stream debounce for legacy block stream mode", async () => {
169192
const draftStream = createDraftStream();
170193
createTelegramDraftStream.mockReturnValue(draftStream);

‎extensions/telegram/src/config-ui-hints.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ export const telegramChannelConfigUiHints = {
2525
},
2626
nativeCommands: true,
2727
streaming: {
28-
"": 'Unified Telegram stream preview mode: "off" | "partial" | "block" | "progress" (default: "partial"). "progress" keeps a single editable progress draft until final delivery. Legacy boolean/streamMode keys are detected; run doctor --fix to migrate.',
29-
mode: 'Canonical Telegram preview mode: "off" | "partial" | "block" | "progress" (default: "partial").',
28+
"": 'Unified Telegram stream preview mode: "off" | "partial" | "block" | "progress" (default: "progress"). "progress" keeps a single editable progress draft until final delivery. Legacy boolean/streamMode keys are detected; run doctor --fix to migrate.',
29+
mode: 'Canonical Telegram preview mode: "off" | "partial" | "block" | "progress" (default: "progress").',
3030
chunkMode:
3131
'Chunking mode for outbound Telegram text delivery: "length" (default) or "newline".',
3232
"block.enabled":
33-
'Enable chunked block-style Telegram preview delivery when channels.telegram.streaming.mode="block".',
33+
"Enable normal Telegram block replies. This takes precedence over editable preview delivery.",
3434
"block.coalesce": "Merge streamed Telegram block replies before sending final delivery.",
3535
"preview.chunk.minChars":
3636
'Minimum chars before emitting a Telegram block preview chunk when channels.telegram.streaming.mode="block".',

0 commit comments

Comments
 (0)