Skip to content

fix(yuanbao): resolve quoted file/image media via transcript lookup - #26216

Merged
teknium1 merged 5 commits into
mainfrom
salvage-22742
May 15, 2026
Merged

teknium1 merged 5 commits into
mainfrom
salvage-22742

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

Salvage of #22742 by @libo1106 onto current main.

Summary

Yuanbao bot can now read quoted file/image messages in group chats. Previously, quoting a file/image and @-mentioning the bot returned "file not found" because the quote's cloud_custom_data doesn't carry the resourceId needed for download (especially for file quotes, type=3).

Mechanism

  • _extract_text + new _parse_resource_id store [file:name|ybres:rid] / [image|ybres:rid] anchors on TIMFileElem / TIMImageElem / TIMSoundElem / TIMVideoFileElem observation so the resourceId is recoverable later.
  • QuoteContextMiddleware._extract_quote_context now returns a 3-tuple including quote_media_refs extracted from the quote desc via _YB_RES_REF_RE.
  • DispatchMiddleware._dispatch_inbound_event falls back to a reversed transcript lookup by message_id when the quote desc lacks ybres anchors (file quotes only carry filename in desc), resolves quote refs exclusively (skipping unrelated history backfill), and overrides message_typeDOCUMENT when resolved media includes application/* or text/* so gateway/run.py's file injection feeds content to the agent.
  • New _RESOLVABLE_MEDIA_KINDS = frozenset({"image", "file"}) replaces 4 duplicated inline set literals.

Salvage

Validation

  • py_compile gateway/platforms/yuanbao.py — OK
  • scripts/run_tests.sh tests/test_yuanbao_*.py — 215/215 pass

Closes #22742.

libo1106 added 5 commits May 15, 2026 01:09
…ote desc lacks ybres

When a user quotes a file message (type=3) and @bot, the quote's desc field
only contains the filename without a ybres:// resource reference. The existing
QuoteContextMiddleware only extracted media refs from desc using the ybres regex,
which always returned empty for file quotes.

Fix: add a transcript lookup fallback in QuoteContextMiddleware.handle() —
when quote_media_refs is empty but reply_to_message_id is set, search the
session transcript for the quoted message_id and extract ybres anchors from
its content.

Also fix message_type classification: when quote media resolves non-image files,
override message_type to DOCUMENT so gateway/run.py's document injection logic
properly prepends the file path and content for the agent.
@teknium1
teknium1 merged commit 0086cda into main May 15, 2026
13 of 15 checks passed
@teknium1
teknium1 deleted the salvage-22742 branch May 15, 2026 08:17
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage-22742 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8251 on HEAD, 8251 on base (➖ 0)

🆕 New issues (1):

Rule Count
invalid-argument-type 1
First entries
gateway/platforms/yuanbao.py:2621: [invalid-argument-type] invalid-argument-type: Argument is incorrect: Expected `MessageType`, found `Literal[MessageType.DOCUMENT] | Any | None`

✅ Fixed issues (1):

Rule Count
invalid-argument-type 1
First entries
gateway/platforms/yuanbao.py:2509: [invalid-argument-type] invalid-argument-type: Argument is incorrect: Expected `MessageType`, found `Any | None`

Unchanged: 4310 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels May 15, 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 P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants