fix(context): recover from provider overflow#87
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughRoutes completions through a recovery flow that detects provider context-window errors, compacts session context, rebuilds the completion request, optionally validates rebuilt budget, emits compaction/usage events, and retries once; adds IsContextWindowError and comprehensive tests. ChangesProvider Context Window Overflow Recovery
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #87 +/- ##
==========================================
+ Coverage 69.11% 69.24% +0.12%
==========================================
Files 214 215 +1
Lines 18998 19104 +106
==========================================
+ Hits 13131 13229 +98
- Misses 4717 4722 +5
- Partials 1150 1153 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/assistant/context_overflow_compaction.go`:
- Around line 62-85: Change the compaction event flow so the pre-compaction
event is clearly an attempt and the post-compaction event is emitted from the
rebuilt context state: update the first runtime.emitContextCompaction call
(before runtime.CompactSessionFrom) to use wording like "attempting compaction
before retry" so it doesn't promise success, call runtime.CompactSessionFrom as
now, then on success emit the post-compaction event using compactionMessage with
the recovered session/build budget from the rebuilt state (use the budget value
on recoveredEntry rather than input.build.Budget) and only emit that
post-success event after err == nil; leave the
isCompactNothingToDoError(providerErr) early-return behavior unchanged but
ensure it does not cause a misleading pre-compaction success message.
In `@internal/assistant/retry.go`:
- Around line 258-266: The current contextWindowProviderMessage function is too
permissive because the "token limit" substring matches quota/billing or
plan-limit errors; narrow this by replacing the generic "token limit" pattern
with more specific context-window phrases (e.g., "token limit exceeded for
request", "token limit for this request", or "context token limit") and add
explicit negative/regression checks to ignore billing/quota messages such as
"daily token limit exceeded", "quota exceeded", "billing", or "plan limit" so
IsContextWindowError/nonRetryableProviderMessage won't misclassify those errors;
update the patterns slice in contextWindowProviderMessage accordingly and add
unit tests covering a regression case like "daily token limit exceeded".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 265f782a-a101-424f-a442-7ddb0b4938d4
📒 Files selected for processing (4)
internal/assistant/context_overflow_compaction.gointernal/assistant/context_overflow_compaction_test.gointernal/assistant/retry.gointernal/assistant/runtime_model.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/assistant/context_overflow_compaction_test.go`:
- Around line 129-139: The test expectations assert the inner error codes
instead of the runtime wrapper codes returned by recoverProviderContextOverflow;
update the failing cases that use providerOverflowFailingSummaryClient and
providerOverflowLargeSummaryClient to expect the wrapped codes: replace wantCode
"compact_summarize" with "context_overflow_compact" for the
providerOverflowFailingSummaryClient case, and replace the inner provider code
(testContextWindowExceededOopsCode) with
"context_budget_after_provider_overflow_compact" for the
providerOverflowLargeSummaryClient case — also update the identical expectation
in the other occurrence noted (the second test block around the same clients) so
all tests reflect the wrapper error codes from recoverProviderContextOverflow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 54d15641-70d6-4a50-baa1-c43d5e2b5cfc
📒 Files selected for processing (7)
internal/assistant/context_auto_compaction_internal_extra_test.gointernal/assistant/context_auto_compaction_test.gointernal/assistant/context_overflow_compaction.gointernal/assistant/context_overflow_compaction_test.gointernal/assistant/export_test.gointernal/assistant/retry.gointernal/assistant/retry_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/assistant/retry.go
- internal/assistant/context_overflow_compaction.go
|



No description provided.