Repository navigation
Commit 799330b
committed
fix(claude): keep mid-conversation system messages in the timeline
Claude Code sends role:"system" entries inside `messages`, and every one of
them was folded into `instructions`. The parser pushes `data.instructions`
onto the system prompt before anything else, so each injected reminder rewrote
the head of the prompt and invalidated the upstream KV cache prefix. Where no
metadata.user_id is present, the Desktop prompt_cache_key fallback hashes the
same system parts, so the cache key rotated along with it.
Emit each non-empty in-messages system message as a chronological
{ type: "message", role: "developer", content: [{ type: "input_text", text }] }
input item instead. Top-level Anthropic `system` keeps flowing through
systemToInstructions into body.instructions unchanged, so `instructions` now
has exactly one source and stops moving mid-conversation.
Not role:"system" in `input`. The schema allows it, but ChatGPT Codex rejects
it, parseRequest re-hoists it onto the system prompt, and the canonical
Responses forward folds text-only system items back into instructions - so it
would land back where it started. `developer` is first-class in the schema and
keeps timeline order.
The fold was deliberate in origin (cee918c) so native ChatGPT would not 400
on a system input item. That constraint is real and still respected; the
2026-07-11 note that folding is "the only shape that works on every route" is
what turned out to be stale.
systemParts keeps its array shape in the cache-key hash on purpose. Joining it
to a string would rotate every existing cohort key for a reason unrelated to
this bug.
Closes #4148.1 parent 4498fb9 commit 799330b
2 files changed
Lines changed: 94 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
157 | 164 | | |
158 | 165 | | |
159 | 166 | | |
| |||
333 | 340 | | |
334 | 341 | | |
335 | 342 | | |
336 | | - | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
337 | 349 | | |
338 | 350 | | |
339 | 351 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
12 | 29 | | |
13 | 30 | | |
14 | 31 | | |
| |||
310 | 327 | | |
311 | 328 | | |
312 | 329 | | |
313 | | - | |
314 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
315 | 337 | | |
316 | 338 | | |
317 | 339 | | |
318 | 340 | | |
319 | 341 | | |
320 | 342 | | |
321 | 343 | | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
328 | 352 | | |
329 | 353 | | |
330 | 354 | | |
331 | 355 | | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
332 | 401 | | |
333 | 402 | | |
334 | 403 | | |
| |||
0 commit comments