fix(agent): auto-handoff context overflow - #1829
Conversation
📝 WalkthroughWalkthroughAdds shared context-window error classification, refactors provider streaming to retry once on early overflow, migrates process finalization to the shared predicate, updates auto-compaction copy across locales, and adds specs plus tests for the new overflow flow. ChangesContext Overflow Auto-Handoff
Sequence Diagram(s)sequenceDiagram
participant Client
participant runStreamForMessage
participant CompactionService
participant coreStream
Client->>runStreamForMessage: send message
runStreamForMessage->>CompactionService: preflight recovery check
CompactionService-->>runStreamForMessage: recovery intent
runStreamForMessage->>coreStream: stream provider attempt 1
coreStream-->>runStreamForMessage: context-overflow event before output
runStreamForMessage->>CompactionService: prepareForContextPressureRecovery
runStreamForMessage->>coreStream: stream provider attempt 2
coreStream-->>runStreamForMessage: stream events or overflow failure
runStreamForMessage-->>Client: output or recovery-failure error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
docs/issues/context-overflow-auto-handoff/spec.md (1)
15-16: 📐 Maintainability & Code Quality | 🔵 TrivialExternal reference clarity.
The reference to "Bub
auto_handoff/context_overflowpattern" assumes reader familiarity with an external system. Consider adding a brief parenthetical explaining Bub is an internal/external reference, or link to documentation if available. This is optional polish for future readers.🤖 Prompt for 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. In `@docs/issues/context-overflow-auto-handoff/spec.md` around lines 15 - 16, The spec text uses the external “Bub auto_handoff/context_overflow” reference without enough context, so update the wording in the affected documentation section to briefly explain what Bub refers to or point to a local doc reference. Keep the existing intent in place, but make the mention self-contained and easy for future readers to understand when editing the context-overflow auto-handoff flow.src/renderer/src/i18n/es-ES/settings.json (1)
24-24: 🧹 Nitpick | 🔵 Trivial | 💤 Low valueConsider smoother Spanish phrasing for "raw context-window errors."
Current: "errores context-window sin procesar del proveedor" — the adjective placement after the compound noun is slightly unnatural. Consider "errores sin procesar de context-window del proveedor" or "errores raw de context-window del proveedor" for more idiomatic Spanish.
🤖 Prompt for 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. In `@src/renderer/src/i18n/es-ES/settings.json` at line 24, The Spanish text in the settings translation uses an unnatural phrase for “raw context-window errors” in the description string. Update the string in the i18n entry for the settings description to use smoother Spanish wording, keeping the meaning intact, and specifically adjust the part around “errores context-window sin procesar del proveedor” to a more idiomatic form.
🤖 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 `@src/main/presenter/agentRuntimePresenter/contextWindowError.ts`:
- Around line 6-12: The strong context-window detection in
STRONG_CONTEXT_WINDOW_ERROR_PATTERNS is too broad because “input exceeds” can
match unrelated failures and trigger the wrong recovery path. Update the
matching logic in contextWindowError.ts to either remove “input exceeds” from
the strong list or guard it behind clearer token/context cues, keeping the real
provider error from being replaced by overflow guidance. Use
STRONG_CONTEXT_WINDOW_ERROR_PATTERNS and any helper that consumes it to make the
change consistently.
In `@src/main/presenter/agentRuntimePresenter/index.ts`:
- Around line 3294-3299: The overflow handling in the presenter flow is
short-circuiting too early: in the `recoverProviderContextOverflow()` path, a
second provider overflow reaches the `buildProviderOverflowRetryFailure` check
before the reduced-token strict retry can run. Update the overflow handling
around `providerOverflowRecoveryAttempted`,
`strictProviderOverflowRetryUsedForRun`, and the retry scheduling logic so the
strict retry is enqueued/executed before throwing, and apply the same fix in the
corresponding overflow branch near the later retry path as well.
---
Nitpick comments:
In `@docs/issues/context-overflow-auto-handoff/spec.md`:
- Around line 15-16: The spec text uses the external “Bub
auto_handoff/context_overflow” reference without enough context, so update the
wording in the affected documentation section to briefly explain what Bub refers
to or point to a local doc reference. Keep the existing intent in place, but
make the mention self-contained and easy for future readers to understand when
editing the context-overflow auto-handoff flow.
In `@src/renderer/src/i18n/es-ES/settings.json`:
- Line 24: The Spanish text in the settings translation uses an unnatural phrase
for “raw context-window errors” in the description string. Update the string in
the i18n entry for the settings description to use smoother Spanish wording,
keeping the meaning intact, and specifically adjust the part around “errores
context-window sin procesar del proveedor” to a more idiomatic form.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: af597ab4-c282-4b79-96b3-24be349bf708
📒 Files selected for processing (29)
docs/issues/context-overflow-auto-handoff/plan.mddocs/issues/context-overflow-auto-handoff/spec.mddocs/issues/context-overflow-auto-handoff/tasks.mdsrc/main/presenter/agentRuntimePresenter/contextWindowError.tssrc/main/presenter/agentRuntimePresenter/index.tssrc/main/presenter/agentRuntimePresenter/process.tssrc/renderer/src/i18n/da-DK/settings.jsonsrc/renderer/src/i18n/de-DE/settings.jsonsrc/renderer/src/i18n/en-US/settings.jsonsrc/renderer/src/i18n/es-ES/settings.jsonsrc/renderer/src/i18n/fa-IR/settings.jsonsrc/renderer/src/i18n/fr-FR/settings.jsonsrc/renderer/src/i18n/he-IL/settings.jsonsrc/renderer/src/i18n/id-ID/settings.jsonsrc/renderer/src/i18n/it-IT/settings.jsonsrc/renderer/src/i18n/ja-JP/settings.jsonsrc/renderer/src/i18n/ko-KR/settings.jsonsrc/renderer/src/i18n/ms-MY/settings.jsonsrc/renderer/src/i18n/pl-PL/settings.jsonsrc/renderer/src/i18n/pt-BR/settings.jsonsrc/renderer/src/i18n/ru-RU/settings.jsonsrc/renderer/src/i18n/tr-TR/settings.jsonsrc/renderer/src/i18n/vi-VN/settings.jsonsrc/renderer/src/i18n/zh-CN/settings.jsonsrc/renderer/src/i18n/zh-HK/settings.jsonsrc/renderer/src/i18n/zh-TW/settings.jsontest/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.tstest/main/presenter/agentRuntimePresenter/compactionService.test.tstest/main/presenter/agentRuntimePresenter/contextWindowError.test.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/issues/context-overflow-auto-handoff/plan.md (1)
76-79: 📐 Maintainability & Code Quality | 🔵 TrivialVary sentence structure in test list items.
Lines 76–79 each begin with "- Add classifier coverage..." creating repetitive prose. Reword one or two items for readability, e.g., "Verify generic
input exceeds..." or "Include manifest coverage...".🤖 Prompt for 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. In `@docs/issues/context-overflow-auto-handoff/plan.md` around lines 76 - 79, The test plan bullets under the classifier coverage section are too repetitive, so rephrase one or two items to vary the sentence structure while keeping the same coverage intent. Update the list items in the plan content near the classifier coverage entries so they don’t all start with the same “Add classifier coverage...” pattern, using the existing phrasing around SDK Error objects, bounded errors[]/issues[] payloads, and generic input exceeds failures as anchors.Source: Linters/SAST tools
🤖 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.
Nitpick comments:
In `@docs/issues/context-overflow-auto-handoff/plan.md`:
- Around line 76-79: The test plan bullets under the classifier coverage section
are too repetitive, so rephrase one or two items to vary the sentence structure
while keeping the same coverage intent. Update the list items in the plan
content near the classifier coverage entries so they don’t all start with the
same “Add classifier coverage...” pattern, using the existing phrasing around
SDK Error objects, bounded errors[]/issues[] payloads, and generic input exceeds
failures as anchors.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 876dccf7-0c6a-46b4-95ee-c8c835d385e6
📒 Files selected for processing (6)
docs/issues/context-overflow-auto-handoff/plan.mddocs/issues/context-overflow-auto-handoff/spec.mddocs/issues/context-overflow-auto-handoff/tasks.mdsrc/main/presenter/agentRuntimePresenter/contextWindowError.tssrc/renderer/src/i18n/es-ES/settings.jsontest/main/presenter/agentRuntimePresenter/contextWindowError.test.ts
✅ Files skipped from review due to trivial changes (3)
- src/renderer/src/i18n/es-ES/settings.json
- docs/issues/context-overflow-auto-handoff/spec.md
- docs/issues/context-overflow-auto-handoff/tasks.md
🚧 Files skipped from review as they are similar to previous changes (2)
- test/main/presenter/agentRuntimePresenter/contextWindowError.test.ts
- src/main/presenter/agentRuntimePresenter/contextWindowError.ts
Summary by CodeRabbit
New Features
Bug Fixes
Documentation