Repository navigation
feat(bot): support multimodal OpenViking resource reads - #4593
Conversation
Code Review — PR #4593: feat(bot): support multimodal OpenViking resource reads
Overall assessmentStrong PR. The architecture is clean and the safety story is unusually thorough for this kind of feature:
I verified the security-sensitive paths on the server side: Findings, ordered by severity. None of them block the PR in my view, but #1 and #2 deserve answers before merge. Findings1. [Medium] Root-key mode: image downloads bypass the per-user client scoping that
|
| kind | server | bot | delta |
|---|---|---|---|
| audio | .flac .m4a .mp3 .oga .ogg .wav |
.aac .ac3 .flac .m4a .mp3 .ogg .opus .wav |
bot misses .oga; adds .aac .ac3 .opus |
| video | .avi .m4v .mkv .mov .mp4 .webm |
.avi .flv .mkv .mov .mp4 .webm .wmv |
bot misses .m4v; adds .flv .wmv |
Concretely: an .m4v resource in the bot is classified as non-media and goes down the text-read path (level="read" over video bytes) instead of the intended overview path, while the server's MCP read correctly treats it as video. The extras in the bot are harmless (they route to overview). Since media_limits.py already exists as the shared constants module, hoisting the three extension sets there and importing on both sides would prevent future drift. Same for _uri_suffix/_mcp_uri_suffix, which are currently identical duplicates.
5. [Low] A/V overview errors are flattened by read_content's exception swallowing
VikingClient.read_content catches every exception and returns "". For the new audio/video branch, a 403 (permission denied), a 404, a server 500, and a legitimately empty overview all produce the same model-facing message: "No OpenViking textual overview is available for this audio resource." The model can't distinguish "retry" from "you're not allowed" from "there is nothing here."
Suggested fix: for the A/V branch, either call client.overview(uri) directly (letting the exception flow into the structured per-URI error path), or have read_content return/log the error type. Low priority — but it's the one place where the new error semantics are less informative than the rest of the PR.
6. [Low] Demotion is all-or-nothing, and user-message media is never demotable — recency preference inverts in that edge
_demote_historical_tool_media returns 0 and demotes nothing unless reclaimable history covers the full overflow, and it only ever considers role == "tool" messages. When the budget is mostly consumed by user-attached images (not demotable) and history tool media can't cover the overflow, the new image is dropped while older tool media stays inline — the opposite of the "prefer recent tool media" intent (this is the one commit-message/code mismatch I found).
Scenario: user attaches a 2 MiB photo; a later round's openviking_multi_read returns a 2.5 MiB image; overflow ≈ 0.75 MiB; no tool-message candidates exist → new image dropped with the generic "would exceed the inline media limit" note, which doesn't tell the model that user attachments consumed the budget.
Suggested fix (pick one): (a) allow partial demotion — reclaim what's available, then attach if under budget; (b) mention in the drop note that existing media (including user attachments) occupies most of the budget. (a) also fixes the general case where reclaimable < overflow for other reasons. Low severity since the failure mode is still safe and explained.
7. Nits
VikingMultiReadTool._MAX_INLINE_MEDIA_BYTES = MAX_INLINE_TOOL_RESULT_MEDIA_BYTESbinds at class-definition time. Runtime tuning ofmedia_limits.MAX_INLINE_TOOL_RESULT_MEDIA_BYTES(or monkeypatching the module, asloop.py's tests do) silently won't affect the tool. Reading the module constant at call time, or a one-line comment, would prevent surprises.- The constant name
MAX_INLINE_TOOL_RESULT_MEDIA_BYTESis now also used to budget user-attached images at the request level; slightly misleading, though the comment explains the intent. OpenVikingPostCallHook(skill-read branch) converts a multimodal result tostrwhen appending "Related Experiences". Correct today (SKILL.md reads are text), but if a skill read ever becomes multimodal, media is silently dropped there. A# text-only by designcomment would prevent a future foot-gun._is_tool_result_success(MultimodalToolResult)isTrueeven when every URI inside a multi-read failed (str()starts with "Multi-read results for ...", per-URI failures areERROR:lines mid-text). Pre-existing semantics for multi-read, unchanged by this PR — noting only for completeness.offset/limitare silently ignored for image URIs (the range note is correctly dropped viaitem_range_note); harmless, but the tool description could say so.- Good catch preserving legacy text serialization in
00364a2d(test_codex_preserves_legacy_text_tool_output_serializationasserts the"firstsecond"concatenation) — that's exactly the regression guard this adapter needed.
Test coverage gaps
The new tests are good quality and cover the core matrix: provider gating (both directions), parallel-tool-result budget, consecutive-round demotion, per-image attachment, TypeScript-stays-text, aggregate byte cap, A/V overview routing, sniff rejection, adapter text-serialization preservation, and adapter image conversion. Gaps I'd like to see closed (roughly in priority order):
- Permission-denied image read:
stat/download_bytesraising a 403 → structured"Error reading from Viking: ..."per-URI result (currently untested; this is also the path finding Bump actions/download-artifact from 4 to 7 #1 rides on). - Root-key cross-user URI (
viking://user/<uid>/resources/x.png) — see finding Bump actions/download-artifact from 4 to 7 #1. - Size-changed-after-check branch (
len(data) > size) — the "Image changed after its size was checked" message has no test. _MAX_INLINE_IMAGES = 4count cap — the ">4 images in one call" message has no test.- User-attached media + tool media overflow — verifies the non-demotable-history edge in finding fix: fix_build #6.
- Extension/MIME mismatch —
.pngfile whose bytes are actually JPEG: currently inlined asimage/jpeg(sniff wins over extension). Probably intended, but worth pinning in a test. - All-or-nothing demotion branch (
reclaimable_bytes < bytes_needed→ nothing demoted, new media dropped). - A/V overview empty/error — the "No OpenViking textual overview" path (ties to finding Bump github/codeql-action from 3 to 4 #5).
Verdict
Approve-with-questions. The design is right, the guardrails are layered, and the text-path regression risk is well contained (legacy serialization is explicitly tested; Tool.execute return type widening is backward compatible; hooks were audited — only OpenVikingPostCallHook touches results and it was fixed in this PR). Please address finding #1 (user-scoping for image downloads in root-key mode — at minimum confirm server-side enforcement) and finding #2 (live-backend verification for list-typed function_call_output.output) before merge; the rest can be follow-ups.
qin-ctx
left a comment
There was a problem hiding this comment.
整体方向没问题,但当前还有一个必须修复的问题:图片新路径没有复用文本读取的 user scoping,导致 root-key/trusted bot 下同一个工具对文本和图片的身份语义不同。先修这个再合;另外当前 CI 仍是 BLOCKED。
Description
让 VikingBot 的
openviking_multi_read能根据 OpenViking 资源类型返回适合模型使用的内容,同时保持现有文本读取行为不变。本次改动不新增 OpenViking SDK 或 API,也不通过 user message 注入媒体内容。
Human Involvement
Related Issue
无。
Type of Change
Changes Made
MultimodalToolResult,让工具结果可以同时包含模型可消费的多模态内容和用于日志、事件及执行记录的纯文本表示。openviking_multi_read识别图片资源后,通过 SDK 下载原始字节,校验大小和文件签名,并将 PNG、JPEG、GIF、WebP 作为 tool message 中的image_url内容返回给模型。read_content(level="overview")获取已有语义理解结果,不增加额外下载、转写或媒体理解链路。Testing
已通过:
完整运行三个受影响测试文件时结果为
178 passed, 4 failed。4 个失败分别涉及既有 Compile 提示词、token usage 额外字段和 commit hook 参数断言,与本次多模态读取改动无关。Checklist
Screenshots
不适用。
Additional Notes
overview,不是 VikingBot 新生成的逐字稿。diagrams/目录未包含在本 PR 中。