Skip to content

fix: preserve model error message and status source - #4477

Merged
wbxl2000 merged 20 commits into
MoonshotAI:mainfrom
kimi-agent-bot:fix/model-error-presentation-minimal
Nov 3, 2026
Merged

wbxl2000 merged 20 commits into
MoonshotAI:mainfrom
kimi-agent-bot:fix/model-error-presentation-minimal

Conversation

@kimi-agent-bot

@kimi-agent-bot kimi-agent-bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

让模型错误展示后端返回的 error.message,并确保只有真实模型 HTTP 响应的状态才进入 statusCode;KAP 与 HTTP 200 后的流式业务码不再冒充模型 HTTP 状态。

Bug Reproduction Steps

  1. OpenAI、OpenAI Responses、Anthropic 或 Google GenAI 返回结构化错误,SDK 组合文本与后端 error.message 不同。
  2. 或在 HTTP 200 已建立的流式响应中返回业务 429 / 503。
  3. 旧链路可能展示 SDK 拼接文本、协议前缀,或并不存在的 HTTP 状态。

Root Cause

协议边界把 SDK 组合后的 message 当作后端原文,并把真实 HTTP、KAP 详情状态和流式业务码写入同一个 statusCode。这次在 #4352 后的新请求链上修复取值和来源,不引入统一错误对象,也不改变跨 attempt 的最终错误选择。

Code Changes

核心边界是“协议解码完整归一化,重试策略只消费归一化字段”。所有远程错误都在解码或旧错误构造时得到必填 retryable: boolean,不再让调度层从 statusCode、错误子类或 message 反推是否重试。

provider SDK / stream event
  → builtin/protocol/*/decodeError
    → kind(结构化 type/code 与真实来源)
    → retryable(必填 boolean)
    → retryAfterMs(服务端要求的等待)
    → statusCode(仅真实 HTTP,供展示和诊断)
    → message(后端原文,缺失时为空)
  → generate / settle / llm-requester / 旧错误转换
    → 保留 kind、retryable、requestId、trace、diagnostics
  → retry policy
    → 只按 retryable 决定是否重试
    → 按 retryAfterMs、退避、jitter、最大次数决定何时重试

已合并 main(9ce252a37),保留主线新增的 diagnoseError / diagnostics 机制,同时延续本 PR 的 source: 'stream' 和真实状态边界。当前工作树相对该基线为 42 个文件、+1858 / -465。未改 UI、turn 状态机或重试次数/退避,未新增统一 LlmError 或错误对象全链路直通。

已按后端错误码表 revision 1306 复核:个人与企业的 5 小时、7 天、月度、余额及组织额度场景统一使用 exceeded_current_quota_error;rate_limit_reached_error 与 engine_overloaded_error 分别走限流与过载分支。新增场景复用结构化分类,不读取业务 reason 或 message 决定配额,也不把普通 403 改为限流。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
后端结构化错误的 message 可能包含 SDK 组合文本、协议名、code/param 或兜底说明 只使用后端 error.message,缺失时为空,不清洗或追加文案 使用 OpenAI、OpenAI Responses、Anthropic、Google GenAI 的 TUI、print、desktop、web、VS Code 与 ACP 用户 无
Kimi 配额分类 可由余额等 message 文案推断 只按结构化 type/code;文案不再作为配额依据 Kimi 官方模型用户 无
Responses 流式事件 可能拼接协议前缀并由业务码合成 400/429 只展示后端 message;配额、限流、过载按结构化 code 分类 使用 OpenAI Responses 与 Kimi Responses 的客户端 无
HTTP 200 后的流式业务错误 可能展示为真实 HTTP 状态 statusCode 缺失;保留业务分类与应有的重试语义,不重复发送终止事件 使用流式模型请求的客户端 无
流式数值业务码的分类与重试 可能一律按 provider 重试,或把数值当成真实 HTTP 状态 数值只作分类输入:429 限流、529 过载、413 请求过大;其他确定性 4xx 不原样重试,5xx 按既有规则重试 使用流式请求与自动重试的用户 无
重试判断 普通 status 会回退到 HTTP 状态集合,空响应看 finishReason,旧错误还会按子类或图片文案判断 所有远程错误必填 retryable;策略只读该字段,statusCode 仅诊断;退避、jitter、次数与 retryAfterMs 调度不变 所有自动重试场景及自定义 Protocol 自定义 decodeError 必须返回明确 boolean
Error2 与 SDK 错误载荷 Provider 错误的 retryable 由静态错误码元数据决定,可能覆盖显式值,反序列化后也会丢失 优先透传并在往返转换中保留显式 retryable;无该字段的旧内部错误仍用静态元数据 使用最终 turn/SDK 错误载荷决定后续重试的调用方 无
旧通用 Provider 图片错误 ChatProviderError 可凭图片文案禁止重试 不再读取 message;内置图片/视频上传错误类显式 false,普通 generic provider 默认 true 直接构造旧通用错误类的自定义 Provider 构造时显式传 retryable: false
Google 400 + INVALID_ARGUMENT 旧版可能凭 SDK 组合 message 正则识别为 context_overflow 没有结构化证据时按普通确定性 400,不再从 message 推断上下文溢出 Google GenAI 流式请求用户 无;恢复该细分类需后端提供明确结构化 code
无真实 HTTP 状态的结构/图片恢复 可能按 message 触发严格投影或媒体剥离 不再按 message 触发;真实 HTTP 400/422 的既有兼容判断不变 使用流式请求与自定义 Provider 的用户 无
真实模型 HTTP 错误 message 与状态可能同时失真 保留真实状态、后端 message、requestId、trace、diagnostics 与 Retry-After 所有模型 HTTP 错误场景 不需要
KAP 接入层详情状态 可能进入模型 HTTP 展示路径 KAP-only 或不匹配的 details.statusCode 不进入模型状态;其他诊断保留 排查 KAP 与模型请求错误的用户 无
跨 attempt 重试后的最终错误 展示最后一次错误 不变,仍展示最后一次错误 所有自动重试场景 不需要
错误卡片结构与恢复入口 现有卡片与【继续】 不变 desktop 与 web 用户 不需要

文案配额分类的移除没有配置退路,需维护者在 PR 中明确批准;在批准前,下方行为变更检查项保持未勾选。

受影响模块与覆盖:

  • 四条 Provider 解码、Kimi 分类钩子、Google 建流/迭代边界:src/human/test/llm/errors.test.ts。
  • core 与 V2 兼容错误契约、双向转换、诊断保留和重试:test/llm-adapter/contract/errors.test.ts、test/agent/loop/loop.test.ts。
  • 注册表流来源透传与分类钩子边界:test/llm-adapter/protocol/protocolAdapterRegistry.test.ts。
  • KAP 详情序列化:test/_base/errors/serialize.test.ts。
  • subagent 错误重建:test/session/subagent/runAgentTurn.test.ts。
  • 协议错误兼容:test/app/protocol/errors.test.ts。
  • SDK 的限流与原文序列化:packages/node-sdk/test/sdk-rpc-client-v2.test.ts。
验证环境与结果(macOS,Node 24,pnpm 10.33.0)
  • 相关错误、Turn、Loop 与 Node SDK 测试:25 个文件、557 个测试通过。覆盖真实 HTTP 429/503、无状态流式业务码、quota、structure/image、filtered empty、abort/unknown,以及 400 显式可重试和 503 显式不可重试。
  • Error2 与 SDK 序列化增量回归:2 个文件、115 个测试通过,验证显式 retryable 不被静态错误码元数据覆盖,并在往返转换中保留。
  • pnpm -C packages/agent-core-v2 test:390/394 个测试文件通过,7838 个测试通过、2 个跳过。6 个失败包括 3 个 30 秒超时、1 个临时目录 ENOTEMPTY、2 个 XState 5 秒超时。
  • 隔离重跑上述失败相关文件及新增 fixture 文件:5/6 个文件通过,331 个测试通过。仅剩 tool.test.ts 中 returns the spawned agent id when a foreground subagent times out 的已知 30 秒超时;其余失败均未复现。
  • pnpm typecheck:通过,包括 packages 构建、全部 package、CLI、VS Code 与 vis 类型检查。
  • pnpm -C packages/agent-core-v2 build、pnpm -C packages/node-sdk build:通过。
  • pnpm lint:0 errors;仓库既有 2744 个 warnings。
  • git diff --check:通过。
  • GitHub CI(HEAD 312a31f):全部检查通过,test-windows 按预期 skipped;增量评审完成,未解决线程为 0。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • 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 Oct 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 312a31f

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 Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T12:31:52.469895Z 312a31f Manual request
ℹ️ 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 Oct 27, 2026 •

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

commit: 312a31f

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 193e3ba542

ℹ️ 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".

@kimi-agent-bot

Copy link
Copy Markdown
Collaborator Author

@codex review
已 resolve 的主题代表我们的判断取舍与当前代码现状,请勿重复提出(其余约定同首轮)。

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: c28c81a028

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b13dc2502f

ℹ️ 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".

@wbxl2000

Copy link
Copy Markdown
Collaborator

@codex review
增量评审:请只审自上次评审以来的新增 commit;未变更代码请勿重复提出;已 resolve 的主题仅当核实现状代码确已修复或不再成立时才抑制(其余约定同首轮)。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9ff1633b3c

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0909f0fc1

ℹ️ 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".

@wbxl2000

Copy link
Copy Markdown
Collaborator

@codex review
增量评审:请只审自上次评审以来的新增 commit;未变更代码请勿重复提出;已 resolve 的主题仅当核实现状代码确已修复或不再成立时才抑制(其余约定同首轮)。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6a8fd7e6f5

ℹ️ 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".

@wbxl2000

Copy link
Copy Markdown
Collaborator

@codex review
增量评审:请只审自上次评审以来的新增 commit;未变更代码请勿重复提出;已 resolve 的主题仅当核实现状代码确已修复或不再成立时才抑制(其余约定同首轮)。

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 1528cb8333

ℹ️ 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".

@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@codex review
增量评审:请只审自上次评审以来的新增 commit;未变更代码请勿重复提出;已 resolve 的主题仅当核实现状代码确已修复或不再成立时才抑制(其余约定同首轮)。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5a69fb1028

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 5a69fb1028

ℹ️ 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".

@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@codex review
已 resolve 的主题代表我们的判断取舍与当前代码现状,请勿重复提出(其余约定同首轮)。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ceda7776d

ℹ️ 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".

@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@codex review
已 resolve 的主题代表我们的判断取舍与当前代码现状,请勿重复提出(其余约定同首轮)。

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 1720cb54ad

ℹ️ 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".

@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@codex review
增量评审:请只审自上次评审以来的新增 commit;未变更代码请勿重复提出;已 resolve 的主题仅当核实现状代码确已修复或不再成立时才抑制(其余约定同首轮)。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48964a0fa9

ℹ️ 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".

@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@codex review
增量评审:请只审自上次评审以来的新增 commit;未变更代码请勿重复提出;已 resolve 的主题仅当核实现状代码确已修复或不再成立时才抑制(其余约定同首轮)。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f47674eb1a

ℹ️ 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".

Comment thread packages/node-sdk/src/errors.ts Resolved
@wbxl2000

wbxl2000 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@codex review
增量评审:请只审自上次评审以来的新增 commit;未变更代码请勿重复提出;已 resolve 的主题仅当核实现状代码确已修复或不再成立时才抑制(其余约定同首轮)。

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 312a31fcc8

ℹ️ 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".

@wbxl2000
wbxl2000 merged commit 02d2e8f into MoonshotAI:main Nov 3, 2026
18 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 3, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Port of upstream MoonshotAI/kimi-code 02d2e8f (MoonshotAI#4477), translated onto this
fork's single llm tree.

Retryability is now a property of the error instead of a kind/status lookup
per consumer:
- LlmStatusErrorInfo carries statusCode?: number and retryable; every
  LlmRemoteErrorMessage variant carries retryable.
- toLlmStatusErrorMessage computes it from the HTTP status set, and no longer
  sanitizes or appends the thinking-effort hint: both belong to the display
  layer (llm-adapter's contract), which already applied them, so the old
  placement appended the hint twice on that path.
- toLlmErrorMessage / toLlmTransportErrorMessage / toLlmStreamErrorMessage
  assign retryability per class (abort and unknown false; timeout, connection
  and provider true).
- isRetryableError is now 'syntax? false : error.retryable'; no caller keeps
  its own copy of the status-code table.
- ChatProviderError and its subclasses carry retryable with per-class
  defaults; APIStatusError takes an optional statusCode and a retryable
  override. errorFromLlmMessage/llmMessageFromError round-trip the flag and
  pass the status code through without synthesizing 429.
- Serialization preserves an explicit retryability (registry default only as
  fallback) and strips a details.statusCode that the direct model error does
  not confirm; fromErrorPayload restores it for the API* class names.
- The Kimi quota classifier no longer guesses from message wording: only a
  structured quota code counts, a missing status is accepted, and the message
  comes from the nested error body.
- node-sdk keeps a backend message verbatim, recognizes a rate-limit class
  without a synthesized 429, and prefers an error's own retryability over the
  code registry when the class exposes one.
- The OpenAI decoder reads code/type/message from the SDK's error body and
  classifies quota/overloaded/context-overflow by structured code before the
  status, so a nested body is not re-stringified into the user message.

Local adaptation: upstream splits this code across human/llm-requester,
human/llm/protocol/{errors,rules/status,kit/http} and human/llm/response;
this fork keeps one human/llm/errors.ts plus requester/bases/*, so those
pieces are folded there. The stream-source distinction in upstream's decoder
has no counterpart: the fork's parsers surface mid-stream errors through the
same requester catch, so the branch stops at the HTTP-status path. The other
three decoders gained the retryability flags but keep their existing message
parsing.

Carried fixup: kap-server's workspace route reached into
agent-core-v2/_base/utils/workdir-slug (introduced with 718a3ae and missed
by check:boundaries); workspaceRootKey is exported from the engine root and
the route imports the public surface.

Verified: 852 tests across 59 affected files (human/llm, human/test/agent,
_base/errors, llm-adapter, app protocol, runAgentTurn), node-sdk 307,
agent-core-v2/kap-server/apps-kimi-code typechecks clean, engine build and
check:boundaries clean, oxlint 0 errors, check:no-comments green. Reverse
checks: forcing isRetryableError false reddens the turn retry case, and
dropping the explicit retryability from serialization reddens the round-trip
case. The 'executes multiple tool calls concurrently' case was red until its
500 fixture gained retryable: true - the same fixture change the port needs
wherever an error literal crosses the retry policy.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Continues the MoonshotAI#4477 port with the stream-source distinction this fork lacked.

A mid-stream failure carries the provider's business code in the SDK error's
status field, not an HTTP status. convertOpenAIError now takes an optional
source: 'stream', and the requester passes it from the stream loop: the HTTP
status is dropped from the classification, a structured business code decides
the kind (rate limit, overloaded, quota exhausted, context overflow, request
too large), and anything left over goes through the new
toLlmStreamErrorMessage, which maps 429/529/413 and derives retryability from
the business code. The request-path classification is unchanged.

toLlmStreamErrorMessage lives beside toLlmStatusErrorMessage in
human/llm/errors.ts (upstream keeps it in human/llm/protocol/rules/status).

Verified: 7 new cases (status 429/529/413 and code rate_limit_exceeded /
engine_overloaded_error / insufficient_quota / context_length_exceeded, each
asserting kind, retryable and the absence of an HTTP status); 847 pass across
the affected trees, engine typecheck clean, oxlint 0 errors, check:no-comments
green. The anthropic, openai-responses and google-genai requesters still
classify stream failures on the legacy path.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…rotocols

Completes the stream-source half of MoonshotAI#4477.

- anthropic: convertAnthropicError takes source: 'stream'; a mid-stream failure
  drops the HTTP status and classifies by the body error type (quota,
  overloaded, rate limit, context overflow), falling back to
  toLlmStreamErrorMessage. The body message wins over the SDK-composed one.
- openai-responses: the requester passes source: 'stream' to the shared OpenAI
  converter, so a responses stream failure is classified the same way as chat.
- google-genai: convertGoogleGenAIError parses the JSON error body once
  (parseGoogleGenAIErrorBody) and reads code/message/status from it;
  RESOURCE_EXHAUSTED and 429, plus OVERLOADED and 529, are classified
  explicitly, and the retry-after detail is read from the parsed body. The
  stream path drops the HTTP status and uses the business code.

All three requesters wrap their stream loop and report the failure with the
stream source, so an SDK throw mid-stream no longer surfaces as an HTTP status
error with the wrong kind.

Verified: two new unit cases (anthropic body type, google business code), 855
tests across the affected trees, engine typecheck clean, import boundaries,
oxlint 0 errors and check:no-comments green.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…r cases

Coverage only — the source side of MoonshotAI#4477 landed earlier (d843689,
1cc9d0f, f5d3834, 2c3ed68); these cases pin behavior that had no
local twin.

`test/llm-adapter/contract/errors.test.ts` gains a `model error HTTP status
source` block: explicit retryability beats the HTTP status class in both
directions, a real model status survives `errorFromLlmMessage` and the
reverse mapping, a provider error code rides the code slot with its status
and trace id, and message-recovery patterns stay off when there is no real
HTTP status.

`src/human/test/llm/errors.test.ts` gains three stream-source cases: an
initial Google HTTP 429 keeps its status while the same business 429 on the
stream path drops it, a structured context code outranks the 400 HTTP
fallback, and an unknown OpenAI stream business code still classifies by the
numeric code, drops the status and keeps its headers.

Local-form notes:
- Upstream pins the registry boundary through
  `registry.request(...).protocol.base.decodeError(...)`. The fork's registry
  only exposes `resolve(model)`; the boundary lives in each base's
  `convert*Error(error, hook?, source)` instead, so the assertions target
  those.
- Upstream's four-protocol stream matrix is expressed here as a seven-case
  requester-level `it.each` (already present) plus the three converter-level
  cases above, rather than the end-to-end `generateEvents` variants.
- `APIStatusError` takes `traceId` and `code` in its fifth and sixth
  positional slots locally; upstream's fifth slot is a diagnostics object
  that has no local counterpart, so the provider-code case asserts the code,
  status and trace id only.
- `ChatProviderError`'s retryability is the fourth positional argument
  locally, not the fifth, so the existing deterministic-validation cases keep
  their shape.

Verified: agent-core-v2 typecheck clean; 59 pass across the two error files
and 106 pass in the `app/llmProtocol` error suite.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…limit

`providerRateLimitErrorFromPayload` rebuilt a rate-limit failure from its
KimiErrorPayload but passed only `requestId`, so
`APIProviderRateLimitError` fell back to its default status of 429. A
status-less mid-stream rate limit — the shape every protocol produces once
the HTTP status is dropped on the stream path — came back to the parent
agent wearing an HTTP 429 that never existed, which changes how the turn
reports and retries it.

The rebuild now carries `details.statusCode` through, so a stream failure
stays status-less and a real HTTP 429 keeps its status. A real
`APIProviderRateLimitError` already passes through unchanged via
`isProviderRateLimitError`, and an `Error2` carrying `statusCode: 429` is
recognized there too; both are pinned now.

Local-form note: the fork has two `APIProviderRateLimitError` classes —
`packages/kosong/src/errors.ts` (four parameters, status hard-coded to 429)
and `packages/agent-core-v2/src/llm-adapter/contract/errors.ts` (five
parameters, status overridable). The engine throws the latter. `toKimiErrorPayload`
in node-sdk branches on `instanceof` against the former, so an engine error
handed to it directly reports `internal`; that duplicate is out of scope
here and stays on the MoonshotAI#4477 gap list.

Verified: agent-core-v2 typecheck clean; subagent suites 141 pass. Reverting
the status pass-through reddens `does not invent HTTP 429 when rebuilding a
stream rate-limit failure`; restoring it is green.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Source side is complete after d221dbc, and every upstream test file now
has a local counterpart except three recorded gaps: the two duplicated
APIProviderRateLimitError classes leave node-sdk's toKimiErrorPayload unable
to read an engine error (needs a public-export decision), the loop-level
"keeps the terminal real 503 after an earlier real 429" case is not ported,
and the registry-boundary case is pinned at each base's convert*Error
instead of a registry.decodeError the fork does not have.

Stays in_progress until those are decided.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 5, 2026
The row still said in_progress, pointing at a follow-up that landed as
1cc9d0f, f5d3834, 2c3ed68 and d221dbc. Checked rather than
assumed: the three error suites and the human llm tree pass (106 + 39 + 248),
and the source side carries every piece the row described — retryability as an
error property, the status code carried through serialization, mid-stream
failures classified by business code with the HTTP status dropped, and no
synthesized 429 on a rebuilt stream rate limit.

Ledger: closed 73 -> 74, remaining 26 -> 25.
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.

3 participants