Commit 05d9c48
fix(anthropic): validate streamed tool arguments the same way as non-stream
The review of the batch caught a real inconsistency I introduced. Making
`toolUseArguments` degrade an unparseable string to `{}` fixed the
non-stream path only: the streaming path forwarded every `partial_json`
fragment verbatim, so one malformed relay payload became `arguments:"not
json"` through `parseStream` and `"{}"` through `parseResponse`. Two
answers to the same defect, and the streaming one is what a live client
actually hits.
Fragments are now buffered per tool block and validated once at
`content_block_stop`, through the same helper. A tool call cannot execute
before its arguments are complete, so buffering costs nothing.
Three tests, each verified by ablation rather than assumed:
- malformed streamed fragments degrade to `{}` (reverting the buffering
fails it)
- valid fragments split mid-token reassemble intact, so buffering does
not corrupt the normal case (also fails when reverted)
- EOF carrying `message_delta.stop_reason` but no `message_stop` settles
with that stop reason instead of erroring
That third one closes the second review finding: the two existing EOF
tests assert the pre-existing error behavior and never send a stop
reason, so they stayed green with the new fallback reverted -- they were
not testing the change they shipped with. Disabling the fallback now
fails this test (14 pass / 1 fail) and restoring it returns 15/15.
Suites: anthropic-stream-hardening, anthropic-adapter, anthropic-hardening,
anthropic-compatible-stream, anthropic-tail-guard, anthropic-empty-content,
anthropic-thinking-signature, anthropic-reasoning, anthropic-tool-schema,
claude-messages-endpoint, anthropic-tool-reorder -- 115 pass, 0 fail.
Co-authored-by: Wibias <37517432+Wibias@users.noreply.github.com>1 parent decb08b commit 05d9c48
2 files changed
Lines changed: 71 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
765 | 765 | | |
766 | 766 | | |
767 | 767 | | |
| 768 | + | |
768 | 769 | | |
769 | 770 | | |
770 | 771 | | |
| |||
808 | 809 | | |
809 | 810 | | |
810 | 811 | | |
| 812 | + | |
811 | 813 | | |
812 | 814 | | |
813 | 815 | | |
| |||
833 | 835 | | |
834 | 836 | | |
835 | 837 | | |
836 | | - | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
837 | 844 | | |
838 | 845 | | |
839 | 846 | | |
840 | 847 | | |
841 | 848 | | |
| 849 | + | |
842 | 850 | | |
843 | 851 | | |
| 852 | + | |
844 | 853 | | |
845 | 854 | | |
846 | 855 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
106 | 167 | | |
0 commit comments