Commit 9eb1c77
committed
fix(security): memMsgIdx stale after trimContext drops the memory message (M5)
trimContext starts dropping messages from index 2 onward (keeps
messages[0] system + messages[1] task). The memory message is
initially at index 1, but when trimContext injects a trim-warning
at index 1, the memory shifts to index 2 — right into the droppable
zone. The existing fix-up code handles the trim-warning shift
(incrementing memMsgIdx), but if trimContext later drops the memory
message itself, memMsgIdx becomes stale: it points to whatever
message shifted into that slot (user task, assistant response, etc.),
and the next memory update overwrites that wrong message with memory
content.
Fix: after the trim-warning fix-up, verify that the message at
memMsgIdx still has Role="system". If not, the memory was dropped
— reset memMsgIdx to -1 so the memory update code re-inserts it
at the correct position (index 1) instead of overwriting a user
or assistant message.
Fixes M5 from security audit.1 parent 26a3a0b commit 9eb1c77
1 file changed
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
426 | 441 | | |
427 | 442 | | |
428 | 443 | | |
| |||
0 commit comments