Skip to content

fix(agent-core-v2): validate Kimi media upload status - #4905

Merged
7Sageer merged 3 commits into
release/2026-11-13-2from
bug-358-11-12-kimi-image-extract-status
Nov 13, 2026
Merged

7Sageer merged 3 commits into
release/2026-11-13-2from
bug-358-11-12-kimi-image-extract-status

Conversation

@sailist

@sailist sailist commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Windows 会话中,ReadMediaFile 读取从 Word 提取的公式图片后,后续模型请求可能反复返回 HTTP 400。代码层面已确认:Kimi 文件上传适配只检查上传接口是否返回文件 ID,没有检查文件处理结果,导致处理失败或尚未就绪的文件仍可能变成并复用 ms:// 引用。

Kimi /v1/files 还存在两种响应形态:托管智能体格式使用 extract_status / extract_error,模型推理兼容格式使用 status / status_details。本 PR 在生成和缓存引用前统一校验两种形态;原始 Windows 案例是否由同一机制触发仍需其现场响应进一步核实,本 PR 不作超出代码证据的归因。

Bug Reproduction Steps

代码级复现:

  1. 让 Kimi POST /v1/files 返回 HTTP 2xx,响应包含文件 ID,以及 extract_status: "error" 或兼容格式的 status: "error"。
  2. 通过 uploadImage 调用真实 kimiFiles 上传一张图片。
  3. 修复前,上传适配仍返回 ms://<id>,媒体解析器随后会把它作为成功结果缓存并用于后续请求。
  4. 修复后,同一响应抛出包含文件 ID、状态和具体错误详情的上传错误;既有失败路径继续执行,且不会写入成功上传缓存。

回归测试还覆盖未就绪状态和空文件 ID,并让后续上传返回 extract_status: "ready" 与 status: "uploaded" 的桥接响应,验证合法响应仍生成相同的 ms:// 引用。

Root Cause

createKimiFiles 在 client.files.create 成功后直接返回文件引用,丢失了响应中的处理状态。上传请求成功与文件处理成功因此被错误地视为同一件事;而媒体解析器只会对适配器正常返回的结果写入内存与持久缓存,所以无效引用会跨后续请求复用。

这是针对根因的修复:在引用生成之前拒绝失败、未就绪或缺少有效文件 ID 的响应,而不是在模型请求返回 400 后清理会话或绕过错误。

Code Changes

  • packages/agent-core-v2/src/human/llm/builtin/provider/kimi/files.ts:新增统一的 parseUploadedKimiFile 校验,同时服务 Kimi OpenAI、Anthropic 与 Responses 上传能力。
    • extract_status 存在时必须为 ready。
    • 兼容格式的 status 接受 ready / ok / processed;桥接响应中的 status: "uploaded" 仅在 extract_status: "ready" 时接受。
    • 两种状态字段同时存在时分别校验,任一失败或未就绪都会抛错。
    • 保留仅含非空 id、不携带状态字段的精简兼容响应。
    • 非对象响应、缺失或空白文件 ID 直接抛错。
    • 错误信息包含文件 ID、状态字段和值,并依次保留 status_details、extract_error、字符串或嵌套 error.message、message 中的可用详情;非字符串 extract_error 继续经 JSON 序列化保留。
  • packages/agent-core-v2/test/llm-adapter/model/modelRequester.test.ts:等量扩展现有 uploadImage 用例,覆盖两种状态字段的失败与未就绪响应、错误详情、空 ID 和桥接成功响应,并保留原能力声明和凭证传递断言。测试声明数保持 14,未净增。
  • .changeset/kimi-image-extract-status.md:更新用户可见修复说明,覆盖失败或未就绪的 Kimi 媒体上传。
  • 既有媒体解析与缓存代码不需要改动:它们本来就只缓存正常返回的上传结果,并把普通上传异常交给既有失败降级路径。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
extract_status: "ready",或兼容状态 status: "ready" / "ok" / "processed" 返回并可缓存 ms:// 引用 保持不变 现有 Kimi 端点 无需
extract_status: "ready" 同时携带 status: "uploaded" 返回 ms:// 引用 保持不变 桥接两种响应格式的端点 无需
仅返回非空 id,省略两种状态字段 返回 ms:// 引用 保持不变 返回精简 OpenAI 兼容响应的代理端点 无需
extract_status 为 error、processing 或其他非 ready 值 仍生成并可缓存引用 抛出含状态与详情的错误,不写成功缓存 无合理依赖;旧行为会复用失败或未就绪引用 无;修复缺陷
status 为 error、processing、单独 uploaded 或其他非就绪值,包括与 ready 提取状态冲突 仍生成并可缓存引用 抛出含状态与详情的错误,不写成功缓存 无合理依赖;旧行为会复用失败或未就绪引用 无;修复缺陷
非对象响应或文件 ID 缺失、空白 可能生成 ms://undefined 或空白引用 立即抛出上传响应错误 无合理依赖 无;修复缺陷
响应携带 status_details、extract_error、error 或 message 错误详情被忽略,或仅保留 extract_error 在上传错误中保留可用详情 需要定位媒体处理失败原因的用户与开发者 无需

受影响模块与覆盖:

  • Kimi 文件上传适配:修改后的 modelRequester.test.ts 直接覆盖状态校验、错误原因保留、成功响应及原能力声明/凭证行为。
  • 媒体解析、降级与缓存:mediaResolver.test.ts 全文件回归,包含未携带 extract_status 的真实 Kimi 上传成功场景和普通上传失败后的 inline 降级。
  • 未修改公开 wire、配置、SDK、CLI 或 transcript 契约,也未修改提示词。
验证结果与环境边界
  • 本地:modelRequester.test.ts 14/14 通过。
  • m0-dev:modelRequester.test.ts 14/14,mediaResolver.test.ts 58/58,合计 72/72 通过。
  • m0-dev:agent-core-v2 typecheck 通过。
  • m0-dev:两个 TypeScript 改动文件 oxlint 0 errors;9 个 warnings 均位于测试文件未修改行的既有 no-confusing-void-expression。
  • 提交前安全扫描:3 个改动文件,未发现敏感信息、二进制或大文件问题。
  • coding-win 环境因 SSH banner 超时未能创建,未运行 Windows 测试;本次没有平台特定分支,相关回归已在 m0-dev 完成。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve). 本次为内部维护反馈,无单独 issue;问题背景与代码级复现已完整列出。
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update. 本次为局部错误处理修复,不需要文档更新。

@changeset-bot

changeset-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4800cf4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T04:34:24.049677Z 4800cf4 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@4800cf4
npx https://pkg.pr.new/@moonshot-ai/kimi-code@4800cf4

commit: 4800cf4

@sailist sailist changed the title fix(agent-core-v2): reject failed Kimi image extraction fix(agent-core-v2): validate Kimi media upload status Nov 13, 2026
@sailist
sailist changed the base branch from release/2026-11-13 to release/2026-11-13-2 November 13, 2026 08:55
@7Sageer
7Sageer merged commit 90d8e31 into release/2026-11-13-2 Nov 13, 2026
16 checks passed
@7Sageer
7Sageer deleted the bug-358-11-12-kimi-image-extract-status branch November 13, 2026 09:57
@github-actions github-actions Bot mentioned this pull request Nov 13, 2026
wbxl2000 pushed a commit that referenced this pull request Nov 16, 2026
* fix(agent-core-v2): avoid quadratic cloning during session replay (#4885)

* fix(agent-core-v2): avoid quadratic cloning during session replay

* fix(agent-core-v2): isolate replay assignments and preserve rollback order

* refactor(agent-core-v2): make participant mutable replay explicit opt-in

---------

Co-authored-by: kimi-agent-bot <[email protected]>

* fix(agent-core-v2): validate Kimi media upload status (#4905)

* fix(agent-core-v2): reject failed Kimi image extraction

* chore: add Kimi image extraction changeset

* fix(agent-core-v2): validate Kimi media upload status

* fix(kap-server): forward swarm member task events (#4922)

* test(agent-core-v2): make zero-timeout task wait deterministic (#4925)

Co-authored-by: kimi-agent-bot <[email protected]>

* feat(registry): support search_url and feedback_url on custom registry providers (#4875)

* feat(registry): support search_url and feedback_url on custom registry providers

* fix(sdk): honor provider.env credentials and custom_headers for feedback_url

* refactor(core): submit feedback through the engine

Web and desktop reach this machine through kap-server, so feedback submission resolves the active model's provider in the engine and is exposed on the same route and klient method. The SDK facade keeps the managed OAuth path and no longer re-derives provider credentials.

* refactor(sdk): drop the unused feedback facade

Product clients submit feedback through the engine. The SDK facade and oauth toolkit no longer keep a second managed-only submission path.

* refactor(feedback): share engine schemas across route and klient

The HTTP body uses the engine field names, so the route forwards it and the klient contract imports the same schemas.

* refactor(feedback): drop unused kap and klient surfaces

TUI reaches IFeedbackService through the harness. The HTTP routes, klient facade, and the schemas that only served them have no caller.

* refactor(feedback): package and upload feedback attachments in the engine

* refactor(feedback): keep FeedbackService internal to agent-core-v2

* test(cli): provide execFile in node:child_process mocks

The feedback codebase scanner added in this branch calls
promisify(execFile) at module scope and is now reachable from the
agent-core-v2 index, so partial child_process mocks in these suites
failed module evaluation.

* feat(feedback): disclose submitted files, attach request_id, and drop text-only option (#4876)

* feat(registry): support search_url and feedback_url on custom registry providers

* fix(sdk): honor provider.env credentials and custom_headers for feedback_url

* refactor(core): submit feedback through the engine

Web and desktop reach this machine through kap-server, so feedback submission resolves the active model's provider in the engine and is exposed on the same route and klient method. The SDK facade keeps the managed OAuth path and no longer re-derives provider credentials.

* refactor(sdk): drop the unused feedback facade

Product clients submit feedback through the engine. The SDK facade and oauth toolkit no longer keep a second managed-only submission path.

* refactor(feedback): share engine schemas across route and klient

The HTTP body uses the engine field names, so the route forwards it and the klient contract imports the same schemas.

* refactor(feedback): drop unused kap and klient surfaces

TUI reaches IFeedbackService through the harness. The HTTP routes, klient facade, and the schemas that only served them have no caller.

* refactor(feedback): package and upload feedback attachments in the engine

* refactor(feedback): keep FeedbackService internal to agent-core-v2

* test(cli): provide execFile in node:child_process mocks

The feedback codebase scanner added in this branch calls
promisify(execFile) at module scope and is now reachable from the
agent-core-v2 index, so partial child_process mocks in these suites
failed module evaluation.

* feat(feedback): disclose submitted files, attach request_id, and drop text-only option

* fix(session-export): keep SESSION_NOT_FOUND for missing non-empty session ids

The global-log-only fallback exists for feedback submissions without an
active session (empty id). Scoping it to empty ids restores the 40401
envelope that kap-server's export route promises for unknown sessions.

* test(agent-core-v2): pin retained request id semantics in llmRequester assertions

* chore: sync web dist from code-app

code-app: 11563df26b92f0035659083327976a2e9b8e6727

code-app-release: b0b6d9c7a45c96ca48039ff05789c6e90f76ef20

code-app-local-build: 005d2b437493b7ab04d01f70542f3b6356699f4d

* ci: release packages (#4918)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix(agent-core-v2): align request id back-sync with main

---------

Co-authored-by: kimi-agent-bot <[email protected]>
Co-authored-by: Haozhe <[email protected]>
Co-authored-by: 7Sageer <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants