Commit 299cd2f
fix(anthropic): keep tool argument deltas incremental and fail malformed ones
The previous commit fixed the stream/non-stream inconsistency by buffering
`input_json_delta` fragments until block close. That was the wrong repair
and the review caught it: `src/bridge.ts:628` maps every adapter delta to
a client-visible `response.function_call_arguments.delta` frame, and
`tests/responses-stream-tool-events.test.ts:30` pins that split fragments
stay split. Withholding them left a started function call showing empty
arguments until the block ended -- a protocol regression traded for a
consistency fix.
Fragments flow again as they arrive. The assembled copy is still kept, but
only to check at `content_block_stop` whether the payload parses. When it
does not, the turn errors instead of emitting `tool_call_end`: the
fragments are already downstream and cannot be repaired the way
`toolUseArguments` repairs the non-stream path, and a client that received
`not json` must not then be told the call completed normally.
`streamedToolArgumentsParse` treats an empty buffer as valid, because a
no-argument tool call sends no `input_json_delta` at all -- checking for
`"{}"` instead would have failed those and also swallowed a legitimate
empty-object argument.
Four tests, each checked by ablation rather than assumed:
- malformed fragments error the turn and emit no `tool_call_end` or `done`
(disabling the guard: 16 pass / 1 fail)
- valid fragments arrive as two separate deltas, not one joined string --
this is the contract the previous commit broke (removing incremental
forwarding: 15 pass / 2 fail)
- two `tool_use` blocks in one message keep separate buffers, so the
second cannot inherit the first's JSON
- a block with no fragments is not treated as malformed
Suites: anthropic-stream-hardening, responses-stream-tool-events,
anthropic-adapter, anthropic-compatible-stream, anthropic-hardening,
anthropic-tail-guard, claude-messages-endpoint -- 64 pass, 0 fail.
Co-authored-by: Wibias <37517432+Wibias@users.noreply.github.com>1 parent 05d9c48 commit 299cd2f
2 files changed
Lines changed: 93 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
287 | 304 | | |
288 | 305 | | |
289 | 306 | | |
| |||
835 | 852 | | |
836 | 853 | | |
837 | 854 | | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
842 | | - | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
843 | 859 | | |
| 860 | + | |
844 | 861 | | |
845 | 862 | | |
846 | 863 | | |
847 | 864 | | |
848 | 865 | | |
849 | | - | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
850 | 877 | | |
851 | 878 | | |
852 | 879 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | | - | |
127 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | | - | |
131 | | - | |
132 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | | - | |
| 148 | + | |
| 149 | + | |
148 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
149 | 197 | | |
150 | 198 | | |
151 | 199 | | |
| |||
0 commit comments