Skip to content

fix(cron): keep tool preambles out of IM delivery - #2389

Closed
henryZhouLikeStudy wants to merge 3 commits into
TencentCloud:mainfrom
henryZhouLikeStudy:codex/cron-preamble-pr
Closed

henryZhouLikeStudy wants to merge 3 commits into
TencentCloud:mainfrom
henryZhouLikeStudy:codex/cron-preamble-pr

Conversation

@henryZhouLikeStudy

Copy link
Copy Markdown

Closes #2384

Problem

CronDeliveryService._deliver_agent() currently concatenates every token / delta in the turn. When a cron Agent emits a plan before calling a regular tool, that model-authored process text is prepended to the final answer and delivered to IM. The same stream also reaches TurnHistoryTracker, which can create an extra anonymous AI history row containing “plan + final answer”.

Regular Weixin streaming and invoke-mode delivery already discard lead-in text before non-ask_agent tools, but cron Agent delivery bypasses both paths.

Fix

  • Add withhold_pretool_stream_chunks() as a raw-chunk state machine.
  • Buffer text until the next tool result or final-answer boundary.
  • Discard text before ordinary tools, including parallel, fragmented-name, and repeated tool batches.
  • Keep team-host narration before ask_agent.
  • Preserve final text from no-tool turns and literal task_type=text output.
  • Clear buffered text and close the stream on error or HITL, so a partial process message is never pushed.
  • Feed the filtered stream to history and usage tracking so no synthetic “plan + final answer” row is added.

The filter is based on tool-call boundaries rather than language- or phrase-matching.

Validation

  • Targeted tests: 64 passed
  • Cron, Gateway, and history tests: 722 passed, 2 skipped
  • Full non-live suite: 4880 passed, 226 skipped, 12 failed
    • All 12 failures are from a Windows test machine without WSL: C:\Windows\System32\bash.EXE cannot execute. They are unrelated to this patch.
  • Ruff: passed
  • Ruff format: 1240 files already formatted
  • mypy: 597 source files passed
  • Dashboard build: passed

Cloud staging directly loaded the two production files from this commit:

cloud staging passed: no_tools, ordinary_tool, ask_agent, delivery import, #2351 module import

Real cron / IM acceptance

A one-shot Agent cron was scheduled on the production cloud instance against an existing Weixin/iLink session with fresh_thread=true. It was instructed to emit a plan, call current_time and ls, then return only CRON_PREAMBLE_ACCEPTANCE_PASS.

  • last_status=ok
  • one-shot job auto-disabled after execution
  • 5 thread messages total
  • AI checkpoint retained the original plan and tool calls
  • final AI message was exactly 29 characters
  • no anonymous AI row with a combined plan and final answer
  • Weixin send log reported chars=29 part=1/1

The current production instance also retains #2351. Its four generated-media-related file hashes were unchanged during this deployment. This PR itself contains only the cron text-delivery fix and does not include #2351.

All acceptance evidence is sanitized: no memory or chat content, account/channel/thread/message IDs, server addresses, API keys, JWTs, or channel tokens.

@TrueFurina

Copy link
Copy Markdown

Hi @jubaoliang ??

This PR has been open for over 3 days without movement - just wanted to gently bump it to the top of your review queue. I'm happy to rebase, adjust scope, or split it if that helps.

Let me know if there's anything I can do to move this along!

@jubaoliang

Copy link
Copy Markdown
Collaborator

请把这个变更重新提交到 develop。功能修改和问题修复都要指向 develop,不要直接指向 main。

Please open this change against develop instead of main.

@henryZhouLikeStudy

Copy link
Copy Markdown
Author

Superseded by #2684, which retargets this fix onto \develop\ as requested (filters ordinary-tool preambles from cron delivery and history while preserving ask_agent narration and text tasks). This PR is now closed in favor of the new one.

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.

[bug] cron Agent 会向 IM 推送工具调用前的过程文本

3 participants