Add a fallback phase before automatic context rollover (#33255)

## Why

Token-budget sessions need a final opportunity to preserve important state before the current context is compacted.

## What changed

- When `auto_compact_fallback_prompt` is configured, reserve `auto_compact_fallback_buffer_tokens` beyond the base auto-compaction limit.
- At the base limit, inject the fallback prompt once as a developer message while keeping the normal tool surface available. Continue reporting zero base-window tokens during this reserve.
- Roll over when the reserve or full model context is exhausted, and skip the fallback when a new context was already requested.

## Testing

Added coverage for using the fallback reserve, rolling over after it is exhausted, and bypassing the fallback for an explicit `new_context` request.

GitOrigin-RevId: 32983ecadc5cb4927e15ecd7b1e896cb52a9ad3b
This commit is contained in:
rka-oai authored and copyberry committed 2026-07-15 05:45:43 +00:00
1 parent 3afbd8dd45
commit 768330dd6c
10 files changed
+303 -53

No files matched your search

@@ -82,7 +82,7 @@ impl ToolExecutor<ToolInvocation> for GetContextRemainingHandler {
.await;
Ok(boxed_tool_output(GetContextRemainingOutput::new(
token_status.tokens_until_compaction,
token_status.base_window_tokens_remaining,
)))
})
}