Repository navigation
fix(pipeline): preserve media/reply follow-ups and strict turn ordering - #11322
Open
JosephTian876 wants to merge 1 commit into
Open
JosephTian876 wants to merge 1 commit into
JosephTian876 wants to merge 1 commit into
Conversation
Contributor
|
Sorry @JosephTian876, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 5 days and 16 hours by commenting |
6 tasks done
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
JosephTian876
force-pushed
the
fix/follow-up-preserve-media-and-order
branch
from
November 27, 2026 02:29
d5fe9f8 to
a21bbcb
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
When a user sends a follow-up message while an agent turn is still running (thinking or executing tools),
try_capture_follow_up()offers the raw platform event toAgentTurn.steer(), whereNativeAgentSession.steer_turn()extracts text viainput.event.get_message_str() or input.event.get_message_outline().This causes three user-facing bugs:
Imagewith emptymessage_str) falls back toget_message_outline(), collapsing the image into the literal 4-character string"[图片]"and consuming the event before it can reach multimodal request preparation, image encoding, or image captioning. The model sees only"[图片]"and cannot inspect the image.Image,Recordwithout STT transcription,Video,File) keep onlymessage_strand silently drop the attached media components.Replycomponent either drops the quoted message entirely (when comment text is present,get_message_str()is non-empty soReplyis ignored) or degrades to a shallow outline without running async quoted-text/image extraction (extract_quoted_message_text/extract_quoted_message_images).provider_request, side-threadthread_selected_text, or structured wakeuptool_resultpayloads would likewise lose those fields if collapsed into text-only steering.Modifications
Shared plain-text steering predicate (
astrbot/core/agent_input.py):extract_plain_steering_text(event)returning the original message text (preserving whitespace) only when the event contains no non-plain input components (Image,File,Record,Video,Reply) and no structured extras (provider_request, non-emptythread_selected_text, or wakeuptool_result).At/Faceor voice messages already transcribed toPlainbyPreProcessStageSTT) continue to steer normally;get_message_outline()is never used to fabricate placeholder text for media/replies.Runtime steering defense-in-depth (
astrbot/core/astr_agent_runtime/session.py):NativeAgentSession.steer_turn()so raw-event steering (input.content is None) delegates toextract_plain_steering_text(input.event)and rejects non-plain events instead of falling back toget_message_outline().input.content is not None, used by SDKAgentRun.steer()and subagent delivery) keeps its documentedformat_input_content()contract unchanged.Strict arrival-order barrier and leak-free cleanup (
astrbot/core/pipeline/process_stage/follow_up.py,astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py):_FollowUpOrderSlotand_FollowUpOrderStatedataclasses, and allowedFollowUpCaptureto represent deferred (non-steered) captures (receipt=None,monitor_task=None).session.pending_turn_countis waiting),try_capture_follow_up()skipsturn.steer()and reserves a deferred order slot. Subsequent plain-text messages observe the barrier and queue strictly in arrival order instead of steering ahead of the deferred turn.finalize_follow_up_capture()withtry...finallyaround monitor-task cancellation so order slots are always released and downstream waiters woken on early returns, exceptions, or cancellations without leaking_FOLLOW_UP_ORDER_STATE.InternalAgentSubStage.process()so queued events stopped via/stopor/resetwhile waiting exit cleanly without emitting spurious typing indicators or starting new runs.Tests (
tests/unit/test_follow_up_media_and_order.py):Image,Record,Video,File,Reply(media, plain-text, and reply-id-only), structured extras,At/Face/STT plain-text preservation,NativeAgentSession.steer_turn()defense-in-depth, FIFO plain-text steering regression, image-then-text anti-reordering, barrier release when the deferred turn becomes active, transition-gap andpending_turn_countraces, mid-queue/out-of-order cancellations, monitor errors,/stopcleanup, and zero state leakage.This is NOT a breaking change. / 这不是一个破坏性变更。
Verification Steps & Test Results
ruff check .:All checks passed!ruff format --check .:599 files already formattedgit diff --check: cleanpytest:584 passed(including all 35 new unit/end-to-end tests intests/unit/test_follow_up_media_and_order.pyand all existing runtime, wakeup, webchat follow-up, tool-loop runner, subagent, process-stage image, and main-agent suites).Backport Compatibility Note (
v4.29.4)The same design maps directly onto
v4.29.4, where active runs are tracked via_ACTIVE_AGENT_RUNNERS[umo](runner.run_context.context.eventas the owner event) inastrbot/core/pipeline/process_stage/follow_up.py, follow-up text extraction lives in_event_follow_up_text(), andInternalAgentSubStagelives inastrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py.Suggested Merge Order
astrbot/core/agent_input.py,astrbot/core/astr_agent_runtime/session.py,astrbot/core/pipeline/process_stage/follow_up.py,astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py, and a new test filetests/unit/test_follow_up_media_and_order.py.astrbot/core/agent_input.pyrelative to KB-retrieval enhancements (feat(kb): add clean retrieval_query, score threshold gating, and hybrid retrieval mode #11319) (extract_plain_steering_text()vs.PreparedRequest/prepare_input_content()). Recommended merge order: merge this bug fix independently or first; any order merges cleanly without conflicts.Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
📚 I checked the affected WebUI instructions and screenshots in
docs/zhanddocs/enagainst the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog./ 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新
docs/zh和docs/en的相关操作说明与截图(或说明无需更新文档的原因)。No WebUI navigation, page structure, or user-facing labels were changed.🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Preserve rich follow-up inputs and enforce FIFO processing while maintaining plain-text steering for eligible messages.
Bug Fixes:
Enhancements:
Tests: