Skip to content

fix: normalize stringified tool call arguments on resume#2814

Merged
tusharmath merged 4 commits intomainfrom
fix/tool-call-arg-normalization
Apr 3, 2026
Merged

fix: normalize stringified tool call arguments on resume#2814
tusharmath merged 4 commits intomainfrom
fix/tool-call-arg-normalization

Conversation

@amitksingh1490
Copy link
Copy Markdown
Contributor

@amitksingh1490 amitksingh1490 commented Apr 3, 2026

Summary

Normalize stringified tool call arguments before request serialization so resumed conversations can be sent back to providers without invalid tool-call payloads.

Context

Some providers can return assistant tool calls whose arguments are emitted as stringified JSON instead of structured objects. That becomes a problem when the conversation is resumed and replayed, because downstream request builders expect structured tool arguments and can otherwise send invalid payloads back upstream.

Changes

  • parse stringified JSON tool arguments during ToolCallArguments deserialization
  • add ToolCallArguments::normalize() to repair persisted Unparsed tool arguments and wrap unrecoverable values in a fallback object
  • introduce NormalizeToolCallArguments and run it in the orchestrator before provider-specific request conversion
  • export the new transformer from the domain transformer module
  • add regression coverage for both synthetic stringified tool calls and the real kimi-k2p5-turbo-error-dump.json resume scenario

Key Implementation Details

The fix is split into two layers:

  1. Deserialize-time repair converts valid stringified JSON into Parsed values immediately.
  2. Pre-request normalization handles older persisted conversations that still contain Unparsed arguments. If repair fails, the raw content is preserved in a fallback object so request builders always receive structured JSON.

This keeps the fix provider-agnostic while ensuring the outbound request pipeline works for resumed conversations.

Use Cases

  • resume a conversation dump created from a provider that emitted tool arguments as strings
  • replay assistant patch/read tool calls without sending string payloads back upstream
  • protect future providers that may return the same malformed or stringified tool-call shape

Testing

cargo test -p forge_domain --test test_kimi_dump_normalization --test test_stringified_tool_calls
cargo check -p forge_domain -p forge_app -p forge_repo -p forge_main

@github-actions github-actions bot added the type: fix Iterations on existing features or infrastructure. label Apr 3, 2026
@amitksingh1490 amitksingh1490 changed the title fix(domain): normalize stringified tool call arguments for API compatibility fix: normalize stringified tool call arguments on resume Apr 3, 2026
@tusharmath tusharmath merged commit 3253412 into main Apr 3, 2026
10 checks passed
@tusharmath tusharmath deleted the fix/tool-call-arg-normalization branch April 3, 2026 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: fix Iterations on existing features or infrastructure.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants