fix(coderd/x/chatd): reject double-encoded tool arguments with actionable errors - #28044
Draft
ibetitsmike wants to merge 2 commits into
Draft
fix(coderd/x/chatd): reject double-encoded tool arguments with actionable errors#28044ibetitsmike wants to merge 2 commits into
ibetitsmike wants to merge 2 commits into
Conversation
…able errors
Some models occasionally send a structured tool argument as a
JSON-encoded string, for example {"files": "[...]"} instead of
{"files": [...]}. The Go decoder rejects that with an unmarshal error
naming internal Go types, which models struggle to act on.
Reject such input during the existing pre-hook schema walk instead:
when a property whose advertised schema declares an array or object
carries a string, return a retryable tool error telling the model to
send the value as JSON directly. Every builtin tool decodes those
properties into slices, structs, or maps, so nothing that would have
executed is rejected.
Collaborator
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some models occasionally double-encode a structured tool argument as a JSON string, for example
{"files": "[...]"}instead of{"files": [...]}foredit_files. Today the Go decoder rejects that withcannot unmarshal string into Go struct field EditFilesArgs.files of type []chattool.editFileEdits, an error that names internal Go types and gives the model nothing actionable, so retries often repeat the same mistake.Changes
toolschema(renamedValidateUnambiguoustoValidate): during the existing pre-hook schema walk, report a typedStringifiedErrorwhen a property whose advertised schema declares an array or object carries a string value.toolinput: for that error, the synthetic retryable tool result now says the propertyis a string, but the schema declares an arrayand tells the model toRetry with the value provided as JSON directly, not wrapped in a string, instead of the ambiguous-key advice.Non-goals
No input coercion. Silently re-parsing the string would let a
pre_tool_usehook consumer authorize different bytes than the tool executes, which the admission layer exists to prevent. Every input rejected here would fail the tool's Go decoder anyway, so nothing that would have executed is now rejected.Testing
toolschema_test.gofor top-level, nested, and object-property double-encoding, plus a non-string scalar mismatch that stays with the decoder.TestPartitionStringifiedToolCallInputpins the model-facing retry message.