Commit c2c3375
committed
fix(strip-content): preserve thinking parts with no thinking or text fields
Defense-in-depth layer on top of PR #9 (Tom's fix that removed
redacted_thinking from CLEARED_REASONING_TYPES).
The predicate inside stripClearedReasoning treated any thinking/reasoning
part where both `thinking` and `text` fields were undefined as a cleared
shell and dropped it. That's correct for legitimate cleared shells (which
have both fields explicitly set to "[cleared]"), but wrong for edge-case
shapes where a provider emits a thinking-type part carrying only
non-standard fields like `data` or `signature`. Dropping such parts from
the latest assistant message causes Anthropic to reject the request with
'thinking or redacted_thinking blocks in the latest assistant message
cannot be modified'.
This adds a 2-line guard: if neither `thinking` nor `text` key is
present on the part, we cannot prove it is cleared, so we preserve it.
Drop-callback-cleared parts are not affected because they set existing
fields to "[cleared]" (keys remain present). No call sites change, no
new state, no watermark, no cache-bust risk.
Refs: #8, #91 parent f8dea45 commit c2c3375
2 files changed
Lines changed: 36 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
216 | 243 | | |
217 | 244 | | |
218 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
293 | 302 | | |
294 | 303 | | |
295 | 304 | | |
| |||
0 commit comments