Repository navigation
Conversation
Greptile SummaryFixes a silent data-loss bug in Confidence Score: 5/5Safe to merge — minimal, targeted fix with no side effects on well-covered downstream paths. Single-line behavioral change that fixes a clear data-loss bug. The downstream consumer already has the typeof string guard for this case, no other consumers of toolCall arguments blindly treat them as objects, and the regression test is present and correct. No files require special attention. Reviews (1): Last reviewed commit: "fix(agents): preserve malformed function..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
Fixes a silent data-loss bug in the OpenAI WS response → stored assistant-message conversion path by preserving malformed tool-call argument payloads (instead of replacing them with {}), enabling faithful replay/debugging of tool calls.
Changes:
- Preserve raw
function_call.argumentsstring whenJSON.parsefails inbuildAssistantMessageFromResponse(). - Add a regression unit test that asserts malformed JSON arguments are preserved.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/agents/openai-ws-message-conversion.ts | Preserve raw tool-call arguments on JSON parse failure to avoid silent {} replacement/data loss. |
| src/agents/openai-ws-stream.test.ts | Adds regression coverage for malformed tool-call argument preservation in parsed assistant messages. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a6c7818421
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f47f46b7a1
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Refreshed this branch on current I have not changed the broader cross-provider replay semantics here yet. Anthropic/Google still expect object-shaped args on replay, so if we want to harden malformed OpenAI history across providers too, that should land as a follow-up rather than getting mixed into this focused upstream bug fix. |
|
Merged via squash.
Thanks @100yenadmin! |
…lent {} replacement (openclaw#61956)
Merged via squash.
Prepared head SHA: 4185913
Co-authored-by: 100yenadmin <[email protected]>
Co-authored-by: jalehman <[email protected]>
Reviewed-by: @jalehman
…lent {} replacement (openclaw#61956)
Merged via squash.
Prepared head SHA: 4185913
Co-authored-by: 100yenadmin <[email protected]>
Co-authored-by: jalehman <[email protected]>
Reviewed-by: @jalehman
…lent {} replacement (openclaw#61956)
Merged via squash.
Prepared head SHA: 4185913
Co-authored-by: 100yenadmin <[email protected]>
Co-authored-by: jalehman <[email protected]>
Reviewed-by: @jalehman
…lent {} replacement (openclaw#61956)
Merged via squash.
Prepared head SHA: 4185913
Co-authored-by: 100yenadmin <[email protected]>
Co-authored-by: jalehman <[email protected]>
Reviewed-by: @jalehman
…lent {} replacement (openclaw#61956)
Merged via squash.
Prepared head SHA: 4185913
Co-authored-by: 100yenadmin <[email protected]>
Co-authored-by: jalehman <[email protected]>
Reviewed-by: @jalehman
…lent {} replacement (openclaw#61956)
Merged via squash.
Prepared head SHA: 4185913
Co-authored-by: 100yenadmin <[email protected]>
Co-authored-by: jalehman <[email protected]>
Reviewed-by: @jalehman
Fixes #61478.
Recreated from #61527 with single-concern scope (as requested by @steipete).
What this fixes (plain English)
When replaying OpenAI assistant history, if a tool call's arguments contain malformed JSON, the code silently replaced them with an empty object
{}. This caused irrecoverable data loss — the original arguments were permanently destroyed, making it impossible to debug or retry the tool call. The same data loss occurred through the HTTP/WS transport replay path, where preserved raw strings were double-encoded byJSON.stringify. The same coercion gap existed on the Anthropic and Google transport boundaries, where replayed string arguments would reach provider SDKs that expect a parsed object.Technical details
Root cause: In
buildAssistantMessageFromResponse(), theJSON.parse(item.arguments)catch block returned{} as Record<string, unknown>instead of preserving the raw string. Additionally,createOpenAIResponsesTransportStreamFnblindlyJSON.stringify'd tool-call arguments, double-encoding any preserved raw strings. The Anthropic and Google transport stream builders both passed raw tool-call arguments straight into provider SDK payloads, so a preserved string would reach those providers un-coerced.Fix:
item.arguments(the raw string) with a type assertion. DownstreamconvertMessagesToInputItemsalready handlestypeof block.arguments === "string"explicitly.typeofguard to avoid double-encoding.coerceTransportToolCallArgumentsinsrc/agents/transport-stream-shared.tsparses raw string arguments back into objects at the Anthropic and Google transport boundaries (the providers that need parsed JSON), falling back to{}only if parsing fails — preserving the debug path for OpenAI while keeping other providers working.Files changed
OpenAI path (commit 1)
src/agents/openai-ws-message-conversion.ts— catch block preserves raw argumentssrc/agents/openai-transport-stream.ts— typeof guard prevents double-encoding string argumentssrc/agents/openai-ws-stream.test.ts— regression tests for parse preservation + e2e replay round-tripsrc/agents/openai-transport-stream.test.ts— regression test for transport stream string argument serializationCross-provider replay coercion (commit 2)
src/agents/transport-stream-shared.ts— newcoerceTransportToolCallArgumentshelpersrc/agents/anthropic-transport-stream.ts— coerces replayed string arguments at the Anthropic boundarysrc/agents/anthropic-transport-stream.test.ts— regression tests covering string/object/malformed argument replaysrc/agents/google-transport-stream.ts— coerces replayed string arguments at the Google boundarysrc/agents/google-transport-stream.test.ts— regression tests covering string/object/malformed argument replayRelated
Test plan
🤖 Generated with Claude Code