Repository navigation
feat(agent-core-v2): replace hidden media tool results with omission notices - #4601
Conversation
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4409496d75
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| `use a model with ${tag.kind} input capability to view it]`; | ||
| return { | ||
| role: 'system', | ||
| content: [{ type: 'text', text: `${hint}\n${buildMediaPathTag(tag.kind, tag.path)}` }], |
There was a problem hiding this comment.
Keep untrusted paths out of system-role notices
When a workspace or attachment filename contains instruction-like text (POSIX filenames can include newlines), tag.path is derived from the tool result and inserted into a real system message. buildMediaPathTag escapes XML delimiters but not semantic prompt content, and the OpenAI Responses adapter preserves this as system or promotes it to developer, so a repository-controlled filename gains higher authority than its original tool output. Keep the dynamic path at user/tool authority rather than embedding it in a system-role notice.
Useful? React with 👍 / 👎.
| if (tag === undefined) { | ||
| return { | ||
| role: 'system', | ||
| content: [{ | ||
| type: 'text', | ||
| text: '[media omitted: a ReadMediaFile tool result was hidden because the current model does not support image or video input]', |
There was a problem hiding this comment.
Distinguish failed reads from omitted media
When an older session contains a failed ReadMediaFile call—such as an empty, missing, oversized, text, or unsupported file—the result has no media tag and now becomes this notice claiming media was omitted because the model lacks image/video support. That replaces a failed operation with a false successful-media implication, so a text-only model can reason as though a file was read; inspect the result's error state and emit a failure-specific notice instead.
AGENTS.md reference: AGENTS.md:L111-L113
Useful? React with 👍 / 👎.
| if (message.toolCallId === undefined || !hiddenCallIds.has(message.toolCallId)) { | ||
| out.push(message); | ||
| } else { | ||
| out.push(omittedReadMediaResult(message)); |
There was a problem hiding this comment.
Add a changeset for the visible behavior
This commit intentionally changes user-visible model behavior for every text-only session with ReadMediaFile history, but its file list contains no .changeset entry. Add a patch changeset for @moonshot-ai/kimi-code describing the new omission notices so the behavior change appears in the CLI release notes.
AGENTS.md reference: AGENTS.md:L90-L91
Useful? React with 👍 / 👎.
Requirement or Bug
纯文本模型(
image_in/video_in均不成立)的会话中,历史里 ReadMediaFile 的 tool result 在每次请求的投影阶段被整条删除,模型完全感知不到"这里曾经读过某个媒体文件",连文件路径等纯文本上下文也一并丢失。本 PR 把含媒体内容的 result 从删除改为在原位置替换为一条 user 占位提醒,让模型知道此处省略了一段媒体内容、来源文件路径、以及当前模型看不到它的原因。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路:
agent-media-toolsresolver(mediaPolicy.ts)在纯文本模型请求中本来就要过滤 ReadMediaFile 的广告面和历史调用;本 PR 只改变含媒体标签的 result 的处理方式——从"整条丢弃"改为"原位替换为 user 消息",其余逻辑不变。assistant 侧所有 ReadMediaFile tool call 仍被过滤(tools 列表中该工具已被剔除,其调用痕迹保持一致过滤;且 result 变为非 tool 角色后保留 call 会产生悬挂调用)。文案风格对齐仓库既有写法(
mediaResolverService.ts的unsupportedMedia:omit 说明 + capability 提示 +buildMediaPathTag路径标签)。占位消息只影响发给模型的请求投影,持久化历史不动,切回视觉模型后历史调用与结果原样恢复。关键决策:占位采用 user 而非 system 角色——文件路径来自工具结果,属于不可信内容(文件名可包含换行与指令性文本),放入 system 消息会使注入内容获得更高指令优先级(部分 adapter 还会提升为 developer);user 角色保持提醒语义的同时避免这一提权。
阅读指南:只需看
packages/agent-core-v2/src/agent/loop/mediaPolicy.ts的mediaTagOf/omittedReadMediaResult/hideReadMediaFile;测试改动在llmRequesterService.test.ts的既有 media 用例内,可略读。Behavior Changes and Affected Users
受影响模块与测试覆盖:
packages/agent-core-v2/src/agent/loop/mediaPolicy.ts:test/agent/llmRequester/llmRequesterService.test.ts的 media 用例覆盖带路径标签(变 user 占位)与无标签(仍删除)两种 result,并双向钉住纯文本与视觉模型(消息原样)行为;原有 tools/toolCalls 过滤断言保留。验证结论:改动测试文件 61/61 通过;
tsc --noEmit通过;oxlint 与注释检查无新增告警。m0-dev 全量套件 18248/18276 通过,唯一失败为sessionExport时间戳 zip 用例(与本改动无交集,单文件重跑 22/22 通过,环境性失败)。本地验证命令
corepack pnpm vitest run test/agent/llmRequester/llmRequesterService.test.ts:61/61 通过corepack pnpm exec tsc --noEmit:通过node scripts/check-no-comments.mjs:OKoxlint(两个改动文件):0 warnings / 0 errorsChecklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.