fix(tool): tolerate stringified nested-union tool arguments - #298
Merged
Conversation
This was referenced Aug 16, 2026
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.
Closes #297
Summary
qwen-family models string-encode tool-argument containers whose schema is a nested union (
{"params": "{\"action\": \"list\"}"}), making theworkflowtool completely unusable on those models. Verified end-to-end: opencode's schema generation and parse pipeline are innocent; the wire capture shows the model emitting the double-encoded string; controlled A/B proves only the union shape on qwen triggers it.Change
tool.ts: strict decode first; on failure only, a lenient retry re-parses string values that sit where a container is expected (repairStringifiedContainers), then lets the normal decode judge the result. Legitimate strings are never touched because the retry only runs after strict decoding failed.Verification
test/tool/tool-define.test.ts(repair round-trip, unrepairable still rejects, JSON-looking plain strings untouched); suite 9/9.bun typecheckclean frompackages/opencode.Merge note
Precondition for the DAG dogfood path (issues #293/#294/#296 follow-ups): the running binary needs rebuild + restart before the workflow tool works on qwen-family models. Suggest merging this first among the harness batch.