Repository navigation
Commit 132ddb0
committed
frontend: "system_reminders": "tail" moves a client's system-reminder block out of a past turn onto the last user turn
Clients inject a system-reminder block into a past turn (a mode change, an environment note) and drop it
again on the next turn. The tokens a batch slot holds for that conversation's next turn are its prompt plus
every token the engine generated, so they stop matching at the block, the restore fails and the whole
conversation is read again: measured here on a 211990-token prompt, the shared prefix ended 155306 tokens in
and 211990 were read from nothing (~88 s of prefill for a turn that changed one line).
Known and unfixed upstream: anomalyco/opencode#23595 ("system-reminder keeps moving, causing unnecessary
prompt processing in llama.cpp") and #21518 (queued messages serialized inconsistently), with the proposed
fixes PR#27845 (anchor the reminder in place) and PR#24343 (drop stale plan reminders) both closed
unmerged. Claude Code has the same effect: anthropics/claude-code#48734 (a trailing newline in a historical
reminder drops cache_read to the tools block) and anthropics/claude-agent-sdk-typescript#269 (reminders
stripped when the message is replayed).
This is the same class of fix as pin_billing_stamp above, for the same reason: one change inside the
history costs the whole conversation. The block moves to the end of the prompt, where it is the newest
thing the model sees and where every turn has new tokens anyway, so the shared prefix of every later turn
stays intact. Blocks already in the last user turn are left alone (no duplication); a block that is
identical in a past turn and in the last turn stays where it is.
Opt-in: the config's "system_reminders" is "keep" (default: render the history exactly as the client sent
it) or "tail". Tests: SystemRemindersTail (moved to the last turn, flag off renders as before, no
duplication).1 parent 156b6f3 commit 132ddb0
3 files changed
Lines changed: 77 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
| 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 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
372 | 406 | | |
373 | 407 | | |
374 | 408 | | |
| |||
399 | 433 | | |
400 | 434 | | |
401 | 435 | | |
402 | | - | |
| 436 | + | |
| 437 | + | |
403 | 438 | | |
404 | 439 | | |
405 | 440 | | |
| |||
431 | 466 | | |
432 | 467 | | |
433 | 468 | | |
434 | | - | |
| 469 | + | |
435 | 470 | | |
436 | 471 | | |
437 | 472 | | |
| |||
493 | 528 | | |
494 | 529 | | |
495 | 530 | | |
496 | | - | |
| 531 | + | |
| 532 | + | |
497 | 533 | | |
498 | 534 | | |
499 | 535 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2446 | 2446 | | |
2447 | 2447 | | |
2448 | 2448 | | |
| 2449 | + | |
2449 | 2450 | | |
2450 | 2451 | | |
2451 | 2452 | | |
| |||
4689 | 4690 | | |
4690 | 4691 | | |
4691 | 4692 | | |
4692 | | - | |
| 4693 | + | |
4693 | 4694 | | |
4694 | 4695 | | |
4695 | 4696 | | |
| |||
4911 | 4912 | | |
4912 | 4913 | | |
4913 | 4914 | | |
4914 | | - | |
| 4915 | + | |
4915 | 4916 | | |
4916 | 4917 | | |
4917 | 4918 | | |
4918 | 4919 | | |
4919 | 4920 | | |
4920 | 4921 | | |
4921 | | - | |
| 4922 | + | |
4922 | 4923 | | |
4923 | 4924 | | |
4924 | 4925 | | |
| |||
5510 | 5511 | | |
5511 | 5512 | | |
5512 | 5513 | | |
| 5514 | + | |
| 5515 | + | |
| 5516 | + | |
| 5517 | + | |
5513 | 5518 | | |
5514 | 5519 | | |
5515 | 5520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4709 | 4709 | | |
4710 | 4710 | | |
4711 | 4711 | | |
| 4712 | + | |
| 4713 | + | |
| 4714 | + | |
| 4715 | + | |
| 4716 | + | |
| 4717 | + | |
| 4718 | + | |
| 4719 | + | |
| 4720 | + | |
| 4721 | + | |
| 4722 | + | |
| 4723 | + | |
| 4724 | + | |
| 4725 | + | |
| 4726 | + | |
| 4727 | + | |
| 4728 | + | |
| 4729 | + | |
| 4730 | + | |
| 4731 | + | |
| 4732 | + | |
| 4733 | + | |
| 4734 | + | |
| 4735 | + | |
| 4736 | + | |
| 4737 | + | |
| 4738 | + | |
| 4739 | + | |
| 4740 | + | |
4712 | 4741 | | |
4713 | 4742 | | |
4714 | 4743 | | |
| |||
0 commit comments