Skip to content

Commit 79a41e1

Browse files
TheArchitectitclaude
authored andcommitted
fix: bounds check in compact boundary loop
When preserve_recent_messages == 0, raw_keep_from equals messages.len(), causing index out of bounds when accessing session.messages[k]. Added k >= session.messages.len() check to prevent panic. Reason: Compaction with preserve_recent_messages=0 triggered OOB access when checking for tool-use/tool-result pair preservation at boundary. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 155293f commit 79a41e1

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

rust/crates/runtime/src/compact.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub fn compact_session(session: &Session, config: CompactionConfig) -> Compactio
128128
// is NOT an assistant message that contains a ToolUse block (i.e. the
129129
// pair is actually broken at the boundary).
130130
loop {
131-
if k == 0 || k <= compacted_prefix_len {
131+
if k == 0 || k <= compacted_prefix_len || k >= session.messages.len() {
132132
break;
133133
}
134134
let first_preserved = &session.messages[k];

0 commit comments

Comments
 (0)