Skip to content

fix(gateway): preserve reply anchors across queued turns - #64752

Open
hansnow wants to merge 3 commits into
NousResearch:mainfrom
hansnow:fix/feishu-queued-reply-anchor
Open

fix(gateway): preserve reply anchors across queued turns#64752
hansnow wants to merge 3 commits into
NousResearch:mainfrom
hansnow:fix/feishu-queued-reply-anchor

Conversation

@hansnow

@hansnow hansnow commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix reply anchoring when multiple messages are queued into the same shared group session.

When two group members mention the agent while a turn is already running, the queued turn's final response could be delivered using the original event. This caused the later answer to quote the earlier member's message instead of the message that produced that answer.

Root cause

_run_agent() recursively processed queued follow-ups but returned only the final response text to the outer delivery layer. The outer layer therefore still held the first event's chat and message context.

Intermediate queued replies also did not explicitly bind delivery to the message ID for the turn being completed.

Solution

  • Carry the deepest queued turn's MessageEvent and reply anchor back to the delivery layer with AnchoredReply.
  • Bind intermediate queued responses to their own event message IDs.
  • Route final text, images, files, voice/TTS, streaming media, and footer content through the final queued event.
  • Preserve native multi-image batching while forwarding the correct reply anchor.
  • Keep compatibility with third-party adapters that implement the older batch-image signature.
  • Consume reply_to_mode=first only after the first successful visible delivery, while preserving reply_to_mode=all for every delivered part.
  • Add regression coverage for queued delivery context, failed delivery attempts, multipart output, streaming ancillary media, and adapter batch paths.

Validation

  • Focused gateway/platform regression suite: 383 passed, 22 skipped, 4 deselected.
  • New queued-reply regression tests: 9 passed.
  • Ruff checks passed.
  • git diff --check passed.
  • Independent codex -m gpt-5.6-sol review --uncommitted completed with no actionable findings.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jul 15, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for tracing this through the queued recursive path. The reported defect is present on current main: gateway/run.py:20405-20477 derives the pending event's source and anchor for the recursive turn but returns that result without delivery context; _handle_message_with_agent then returns a plain response at gateway/run.py:12406. gateway/platforms/base.py:5072-5077 consequently anchors outbound text to the original event.

The AnchoredReply and recursive delivery-context propagation in this PR address that boundary, including the base adapter's attachment paths. This is an automated hermes-sweeper review.

@teknium1 teknium1 added sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants