Skip to content

Conversation

@ammar-agent
Copy link
Collaborator

Fixes workspace errors when chat history contains corrupted tool inputs (e.g., string instead of object).

Problem

The httpjail-coder workspace produced this error:

messages.1.content.3.tool_use.input: Input should be a valid dictionary

Root cause: A message in history had a malformed tool input where the AI generated invalid JSON:

{
  "type": "dynamic-tool",
  "input": "{\"script\" timeout_secs=\"10\": \"ls\"}"  // String instead of object
}

When loaded from history and sent to the API, this was rejected.

Solution

Created sanitizeToolInputs() that runs before sending messages to the API:

  • Scans all assistant messages for tool parts
  • Replaces invalid inputs (string/null/array) with empty objects {}
  • Preserves valid object inputs unchanged
  • Original history remains untouched

Testing

  • 10 tests including reproduction with the actual problematic message
  • All edge cases covered (string, null, array, valid objects)
  • No existing tests broken

Generated with cmux

Fixes workspace errors when chat history contains corrupted tool inputs.

The httpjail-coder workspace had a message where the AI generated malformed
JSON that was stored as a string in the tool input field:
  input: '{"script" timeout_secs="10": "ls"}'

This caused API errors: 'Input should be a valid dictionary'

Solution:
- Created sanitizeToolInputs() to replace invalid inputs (strings, null,
  arrays) with empty objects before sending to API
- Integrated into AIService message processing pipeline
- Original history remains unchanged, only API request is sanitized
- Comprehensive test coverage including the actual problematic message

Generated with `cmux`
@ammario ammario added this pull request to the merge queue Oct 27, 2025
Merged via the queue into main with commit 5c24be2 Oct 27, 2025
13 checks passed
@ammario ammario deleted the tool-use-error branch October 27, 2025 02:02
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