Repository navigation
fix(agent-core-v2): ensure tool_result content is never empty - #4300
kimi-agent-bot wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 15e0558 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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. |
A tool result that serialized to empty content (e.g. a persisted
tool.result wire record whose output was neither a string nor a part
array, folded back as an empty tool message) was re-lowered into every
subsequent request, and Anthropic-protocol endpoints reject it with
400 "tool_result.content: Field required" — permanently bricking the
session, with /compact and resume failing the same way.
Guard the serialization branches so an empty tool result lowers to a
non-empty placeholder ("Tool output is empty.") instead:
- agent-core-v2 anthropic lower: pad an empty tool_result block list
- kosong anthropic toolResultToBlock: same guard
- agent-core-v2 openai lower: placeholder for empty string/part list
- agent-core-v2 openai-responses lower: placeholder for empty output
Since every request re-lowers from the wire history, fixing the
serialization self-heals already-corrupted sessions with no migration.
Media-only tool results keep their media blocks unchanged.
The OpenAI legacy (chat-completions) lowering left an empty tool result as a dropped content key (no parts / think-only), an empty string (extract_text of nothing, or a single empty text part), or an empty / all-empty-text part array. Strict OpenAI-compatible validators (e.g. LiteLLM) reject tool messages without content, the same permanent-brick failure class as an empty tool_result on Anthropic endpoints. Normalize every empty shape to the same 'Tool output is empty.' placeholder used by the other lowering paths; non-empty tool results pass through byte-identical. Also rewrites the changeset to describe this PR's single purpose (empty tool results never serialize as empty content) instead of the media-recovery scenario, which belongs to a different PR of the split.
commit: |
e064d06 to
15e0558
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e064d062c9
ℹ️ 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".
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Fix sessions permanently failing with HTTP 400 (`tool_result.content: Field required`, or missing tool message content on strict OpenAI-compatible validators such as LiteLLM) when an empty persisted tool result is replayed. A tool result that serialized to empty content was re-lowered into every subsequent request and rejected, so `/compact` and resume kept failing the same way. Empty tool results now lower to a non-empty placeholder text (`Tool output is empty.`) across the Anthropic, OpenAI, OpenAI legacy, and OpenAI Responses request paths, so already-affected sessions self-heal without any migration. |
There was a problem hiding this comment.
Condense the changeset to one user-facing sentence
This entry is three implementation-heavy sentences naming status codes, validator implementations, protocol paths, and migration details. Changesets feeds this text to CLI release notes, but the repository requires one short user-facing sentence stating only the visible change; condense it to the session-recovery outcome.
AGENTS.md reference: AGENTS.md:L90-L90
Useful? React with 👍 / 👎.
| role: 'tool', | ||
| tool_call_id: message.toolCallId, | ||
| content: | ||
| content === undefined || content.length === 0 ? EMPTY_TOOL_CONTENT_PLACEHOLDER : content, |
There was a problem hiding this comment.
Pad all-empty output in every OpenAI lowerer
When toolMessageConversion: 'keep_parts' replays a tool result containing two or more empty text parts, content is a non-empty array, so this length-only guard forwards only empty strings instead of the placeholder (the new kosong legacy guard already treats that shape as empty). A repo-wide search also shows packages/kosong/src/providers/openai-responses.ts:528-548 still returns [] or '' for empty/think-only results. These inputs can therefore continue sending the validator-rejected payload and leave the session unrecoverable; detect usable content and apply the fallback in both lowerers.
AGENTS.md reference: AGENTS.md:L104-L104
Useful? React with 👍 / 👎.
|
关闭说明:同一问题在 main 上已通过重构后的架构修复,本 PR 不再需要合入。
|
Problem
A persisted
tool.resultwire record whose output folds to empty content (not a string, not a part array — e.g.{},[],null) is re-lowered into every subsequent request as an empty tool message. Anthropic-protocol endpoints reject it with HTTP 400tool_result.content: Field required, and strict OpenAI-compatible validators (e.g. LiteLLM) reject tool messages missingcontentwith 422. Since the bad record stays in the session history, every retry,/compact, and resume fails identically — the session is permanently bricked.Fix
Guard the serialization branches so an empty tool result lowers to the non-empty placeholder
Tool output is empty.instead, at five lowering sites:toolResultToBlock: same guardfunction_call_output(both extract-text and keep-parts modes)undefined(content key dropped at serialization),'', and all-empty-text part arraysMedia-only tool results keep their media blocks unchanged; non-empty results are byte-identical. Because every request re-lowers from the wire history, already-corrupted sessions self-heal with no migration.
Tests
anthropic-lower.test.tsreplays a persisted badtool.resultthroughfoldV2WireRecordsto prove the session self-heals.agent-core-v2+kosongtargeted suites green; typecheck clean.拆分自 #4269 的 layer 1(layer 2「媒体拒收恢复」拆到另一个 PR;原 PR 保持不动)。