Skip to content

fix(sessions): auto-compact on context overflow instead of failing the turn#340

Merged
Aaronontheweb merged 2 commits into
devfrom
fix/auto-compact-on-overflow
Mar 20, 2026
Merged

fix(sessions): auto-compact on context overflow instead of failing the turn#340
Aaronontheweb merged 2 commits into
devfrom
fix/auto-compact-on-overflow

Conversation

@Aaronontheweb

Copy link
Copy Markdown
Collaborator

Summary

When the LLM provider rejects a request with a context overflow error (e.g., "request (66540 tokens) exceeds the available context size (65536 tokens)"), the session now triggers emergency compaction instead of failing the turn.

Before: LlmCallFailedFailCurrentTurn() → user sees error, session stuck
After: LlmCallFailed → detect overflow → notify user → CompactionTriggered → compact → Ready

Uses the existing compaction pipeline (extractive reducer + observation summary). The user sees a message asking them to resend their last message after compaction completes.

Closes #314

Test plan

  • dotnet build — clean
  • All 1,140 tests pass
  • Test with a model that has a small context window to trigger overflow
  • Verify compaction runs and session becomes usable again after overflow

@Aaronontheweb Aaronontheweb enabled auto-merge (squash) March 20, 2026 22:11
…e turn (#314)

When the LLM provider rejects a request with a context overflow error,
the session now triggers emergency compaction instead of failing the turn.

Also hardens IsContextOverflowError detection:
- Uses ProviderException.StatusCode (400) when available
- Broader keyword matching for Anthropic ("prompt is too long") and
  vLLM ("token...exceed") in addition to Ollama/OpenAI patterns
- 16 new tests covering detection across provider error formats

The keyword matching is inherently brittle — there is no standard error
format for context overflow across LLM providers. Tests document the
known formats and catch regressions.
@Aaronontheweb Aaronontheweb force-pushed the fix/auto-compact-on-overflow branch from 9d2f1f4 to b1c1a12 Compare March 20, 2026 22:18
@Aaronontheweb Aaronontheweb merged commit b81ecbb into dev Mar 20, 2026
3 checks passed
@Aaronontheweb Aaronontheweb deleted the fix/auto-compact-on-overflow branch March 20, 2026 23:24
Aaronontheweb added a commit that referenced this pull request Mar 20, 2026
…y, and frontmatter stripping

Update version to 0.7.4 and add release notes for context overflow
auto-compaction (#314, #340), skill preservation across compaction,
and YAML frontmatter stripping from injected skills (#324, #339).
Aaronontheweb added a commit that referenced this pull request Mar 20, 2026
…y, and frontmatter stripping (#341)

Update version to 0.7.4 and add release notes for context overflow
auto-compaction (#314, #340), skill preservation across compaction,
and YAML frontmatter stripping from injected skills (#324, #339).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: no auto-compaction on context overflow — session fails instead of recovering

1 participant