Skip to content

fix(yuanbao): resolve quoted message media refs via msg_id cache#27425

Closed
loongfay wants to merge 1 commit into
NousResearch:mainfrom
YuanbaoTeam:dev
Closed

fix(yuanbao): resolve quoted message media refs via msg_id cache#27425
loongfay wants to merge 1 commit into
NousResearch:mainfrom
YuanbaoTeam:dev

Conversation

@loongfay

Copy link
Copy Markdown
Contributor

QuoteContextMiddleware failed to populate quote_media_refs because quote.desc from the Yuanbao platform is often empty and never contains ybres: references.

This PR introduces a lightweight in-memory cache (msg_id → resids, cap 512) in ExtractContentMiddleware that records media resource IDs for every inbound message (including observed ones). QuoteContextMiddleware now resolves quoted media by looking up the cache instead of parsing quote.desc, fixing the issue.

Adds 17 unit tests covering cache mechanics, eviction, and end-to-end Extract → Quote integration. All 111 tests pass.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery labels May 17, 2026
teknium1 added a commit that referenced this pull request May 18, 2026
Yuanbao's QuoteContextMiddleware has a transcript-lookup fallback for
when quote.desc is empty: it scans the session transcript for the quoted
message_id and pulls ybres anchors out of its content. That fallback
works for observed (silent) group messages because the platform writer
attaches message_id (yuanbao.py:2091).

It silently fails for @bot agent-processed messages because gateway/run.py
wrote them as {role:user, content, timestamp} with no message_id, so
quoting an earlier @bot turn that contained an image/file couldn't be
resolved.

Fix: attach event.message_id to the user transcript entry at all three
write sites in gateway/run.py — the agent_failed_early branch, the
no-new-messages edge case, and the normal agent path (first user-role
entry in new_messages).

Surfaces gap reported in #27425 (loongfay) using the existing fallback
already on main; no new caches needed.

Co-authored-by: loongfay <loongfay@users.noreply.github.com>
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the detailed investigation @loongfay — you correctly identified the gap where the existing transcript-lookup fallback (added May 10 in fc2754d) couldn't resolve quotes against @bot-processed messages.

Went with a smaller fix at the root cause instead: gateway/run.py was writing @bot user messages to the transcript without message_id, while observed group messages (yuanbao.py:2091) already attached it. Symmetric writes mean the existing transcript fallback now covers @bot quotes too — no new caches needed.

Merged via #27866. You're co-authored on the commit. Thanks again for surfacing this.

Lillard01 pushed a commit to Lillard01/hermes-agent that referenced this pull request May 21, 2026
Yuanbao's QuoteContextMiddleware has a transcript-lookup fallback for
when quote.desc is empty: it scans the session transcript for the quoted
message_id and pulls ybres anchors out of its content. That fallback
works for observed (silent) group messages because the platform writer
attaches message_id (yuanbao.py:2091).

It silently fails for @bot agent-processed messages because gateway/run.py
wrote them as {role:user, content, timestamp} with no message_id, so
quoting an earlier @bot turn that contained an image/file couldn't be
resolved.

Fix: attach event.message_id to the user transcript entry at all three
write sites in gateway/run.py — the agent_failed_early branch, the
no-new-messages edge case, and the normal agent path (first user-role
entry in new_messages).

Surfaces gap reported in NousResearch#27425 (loongfay) using the existing fallback
already on main; no new caches needed.

Co-authored-by: loongfay <loongfay@users.noreply.github.com>
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
Yuanbao's QuoteContextMiddleware has a transcript-lookup fallback for
when quote.desc is empty: it scans the session transcript for the quoted
message_id and pulls ybres anchors out of its content. That fallback
works for observed (silent) group messages because the platform writer
attaches message_id (yuanbao.py:2091).

It silently fails for @bot agent-processed messages because gateway/run.py
wrote them as {role:user, content, timestamp} with no message_id, so
quoting an earlier @bot turn that contained an image/file couldn't be
resolved.

Fix: attach event.message_id to the user transcript entry at all three
write sites in gateway/run.py — the agent_failed_early branch, the
no-new-messages edge case, and the normal agent path (first user-role
entry in new_messages).

Surfaces gap reported in NousResearch#27425 (loongfay) using the existing fallback
already on main; no new caches needed.

Co-authored-by: loongfay <loongfay@users.noreply.github.com>
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 P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants