Skip to content

fix(qqbot): streaming improvements — idle flush, remove splitText, replyMsgId TTL, markdown pipe - #5902

Closed
Eric-GoodBoy-Tech wants to merge 134 commits into
QwenLM:mainfrom
Eric-GoodBoy-Tech:feat/qqbot-streaming-improvements
Closed

Eric-GoodBoy-Tech wants to merge 134 commits into
QwenLM:mainfrom
Eric-GoodBoy-Tech:feat/qqbot-streaming-improvements

Conversation

@Eric-GoodBoy-Tech

@Eric-GoodBoy-Tech Eric-GoodBoy-Tech commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

Refactors QQ Bot streaming behavior: replaces BlockStreamer coalescing with a 2-second idle flush, removes a self-imposed 2000-character limit, adds 5-minute TTL to passive reply tracking, and fixes markdown table detection.

Adds P1 group features: full-message handling with groupAllPolicy, slash command unification across all message paths, noreply mechanism for non-@ messages, and @mention support with default Markdown replies.

Why it's needed

  1. BlockStreamer incompatible with QQ Bot. BlockStreamer coalesces text by paragraph boundary (\n\n at minChars=400). QQ Bot cannot edit sent messages, so coalesced chunks arrive as a single undecipherable message — e.g., 15 short tool-call progress updates get merged into one.

  2. Self-imposed character limit. splitText() capped messages at 2000 characters with no API basis. QQ Bot Open Platform imposes no content length limit on text or markdown messages.

  3. Expired replyMsgId. Passive replies require msg_id within a 5-minute window. Old code never removed expired entries, causing API rejections.

  4. Tables sent as plain text. hasMarkdownSyntax did not detect pipe tables, so pure tables (no other markdown markers) were sent as msg_type=0 and rendered as raw text in QQ.

  5. No group full-message support. QQ Bot API v2 supports GROUP_MESSAGE_CREATE events (since 2025-06-22) when the group owner enables full-message permission. Previously all non-@ messages were silently dropped.

  6. Slash commands only worked in one path. C2C and full-message paths lacked slash command detection, causing /help, /new, /clear to be treated as plain text.

Changes

Streaming & Reply Infrastructure

  • Replace BlockStreamer + splitText with onResponseChunk idle-flush (2-second timer)
  • Add replyMsgIdCleanupTimer (5-minute TTL) to prevent stale passive replies
  • Remove hasMarkdownSyntax — all replies default to markdown (msg_type=2), API rejection triggers plain-text fallback
  • Remove splitText (no API character limit exists)

P1 Group Features

  • Add handleGroupAll() with groupAllPolicy (log|keyword|all) and keywordTriggers
  • Handle group management events: GROUP_ADD_ROBOT, GROUP_DEL_ROBOT, GROUP_MSG_REJECT, GROUP_MSG_RECEIVE
  • Track groupActiveMsgEnabled per-group with state persistence
  • Unify slash command detection across handleGroup, handleGroupAll, and handleC2C
  • Default all replies to Markdown (msg_type=2) for @mention support
  • Inject sender openid/member_openid into message context prefix
  • Preserve raw @mention tags in non-slash group messages
  • Add @mention format instructions and botOpenId to model context
  • Add noreply mechanism: [可选回复] prefix for non-@ messages, model outputs {{skip}} to skip

Security hardening

  • api.ts: validate gateway URL protocol (wss: only) via new URL() parsing
  • QQChannel.ts: use sanitizeSenderName() and sanitizeLogText() from @qwen-code/channel-base for all user-controlled input in prompts and audit logs
  • QQChannel.ts: sanitizePromptText() applied to user message content in all three handlers to prevent prompt injection via invisible characters
  • QQChannel.ts: bot messages tagged with [bot] prefix for model judgment instead of hard block

Reviewer Test Plan

How to verify

  1. Run existing tests: cd packages/channels/qqbot && npx vitest run — all 158 tests pass.
  2. Configure a QQ Bot channel in settings.json with blockStreaming: "off".
  3. Send a message that triggers a multi-step tool call (e.g. "search for weather in three cities and compare").
  4. Verify each progress update appears as a separate message within ~2 seconds of the model pausing.
  5. Test full-message monitoring: enable group full-message permission, set groupAllPolicy: "all", and send /new in a group (with and without @mention).

Evidence (Before & After)

Before: Model outputs 10 lines of tool-call progress → BlockStreamer merges them → one massive message.
After: Each status line appears as a separate message. The 2-second idle timer ensures complete sentences are sent as units.

Before (slash commands): /new in C2C or full-message paths → treated as plain text → sent to LLM.
After: /new correctly intercepted by parseCommand() in all three paths.

Tested on

OS Status
🍏 macOS ✅ tested

Risk & Scope

  • Main risk: The 2-second idle timer may occasionally split a single thought into two messages if the model pauses mid-sentence (rare with modern inference speeds).
  • Not validated: Group chat markdown content field (documented as required for groups but API appears to tolerate its absence).
  • Breaking changes: blockStreaming config for QQ Bot should be set to "off" — existing users with "on" will see no change unless they update their config. The splitText function is removed.
  • New config keys: groupAllPolicy, keywordTriggers, groups.*.requireMention, allowMention, chatTypes — all backward-compatible with sensible defaults.
  • New config key: cron-msg-experimental (replaces experimental from earlier draft) — gates all cron/non-prompt textChunk handling; false by default
  • Non-cron code paths verified identical to pre-cron baseline via git diff

Linked Issues

Closes #5901
Refs #6094 — cron/blockStreaming interaction resolved, cron-msg-experimental config replaces experimental

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qqbot: streaming improvements and deprecated approaches

4 participants