fix: improve context budget and streaming#1605
Conversation
📝 WalkthroughWalkthroughThis PR adds two independent features: (1) retry overflow hardening with context-budget diagnostics for requests that exceed the model window, redirecting unfittable preflight results through recovery before provider calls and formatting actionable error messages; and (2) markdown smooth-streaming control via a new ChangesRetry Overflow Hardening
Markdown Smooth Streaming Control
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 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)
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.
🧹 Nitpick comments (1)
src/main/presenter/agentRuntimePresenter/contextBudget.ts (1)
35-43: ⚡ Quick winConsider deriving
RequestContextBudgetDiagnosticsfromRequestContextPreflightResultviaPick<>.The new type is structurally a strict subset of
RequestContextPreflightResult. UsingPick<>keeps the two in sync if preflight result fields are renamed or retyped later, and tightensbuildRequestContextBudgetDiagnosticsso the compiler enforces the mapping.♻️ Proposed refactor
-export type RequestContextBudgetDiagnostics = { - usableContextLength: number - inputTokens: number - toolReserveTokens: number - requestedMaxTokens: number - effectiveMaxTokens: number - remainingOutputTokens: number - totalRequestTokens: number -} +export type RequestContextBudgetDiagnostics = Pick< + RequestContextPreflightResult, + | 'usableContextLength' + | 'inputTokens' + | 'toolReserveTokens' + | 'requestedMaxTokens' + | 'effectiveMaxTokens' + | 'remainingOutputTokens' + | 'totalRequestTokens' +>export function buildRequestContextBudgetDiagnostics( preflight: RequestContextPreflightResult ): RequestContextBudgetDiagnostics { - return { - usableContextLength: preflight.usableContextLength, - inputTokens: preflight.inputTokens, - toolReserveTokens: preflight.toolReserveTokens, - requestedMaxTokens: preflight.requestedMaxTokens, - effectiveMaxTokens: preflight.effectiveMaxTokens, - remainingOutputTokens: preflight.remainingOutputTokens, - totalRequestTokens: preflight.totalRequestTokens - } + const { + usableContextLength, + inputTokens, + toolReserveTokens, + requestedMaxTokens, + effectiveMaxTokens, + remainingOutputTokens, + totalRequestTokens + } = preflight + return { + usableContextLength, + inputTokens, + toolReserveTokens, + requestedMaxTokens, + effectiveMaxTokens, + remainingOutputTokens, + totalRequestTokens + } }Also applies to: 208-220
🤖 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/main/presenter/agentRuntimePresenter/contextBudget.ts` around lines 35 - 43, The RequestContextBudgetDiagnostics type should be derived from RequestContextPreflightResult using TypeScript's Pick<> so it stays in sync and the compiler enforces field mapping; replace the explicit object type for RequestContextBudgetDiagnostics with a type alias like Pick<RequestContextPreflightResult, 'usableContextLength' | 'inputTokens' | 'toolReserveTokens' | 'requestedMaxTokens' | 'effectiveMaxTokens' | 'remainingOutputTokens' | 'totalRequestTokens'> and update the corresponding buildRequestContextBudgetDiagnostics mapping to reflect the new type; do the same refactor for the similar type declared around lines 208-220 so both are defined via Pick<> from RequestContextPreflightResult.
🤖 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 `@src/main/presenter/agentRuntimePresenter/contextBudget.ts`:
- Around line 35-43: The RequestContextBudgetDiagnostics type should be derived
from RequestContextPreflightResult using TypeScript's Pick<> so it stays in sync
and the compiler enforces field mapping; replace the explicit object type for
RequestContextBudgetDiagnostics with a type alias like
Pick<RequestContextPreflightResult, 'usableContextLength' | 'inputTokens' |
'toolReserveTokens' | 'requestedMaxTokens' | 'effectiveMaxTokens' |
'remainingOutputTokens' | 'totalRequestTokens'> and update the corresponding
buildRequestContextBudgetDiagnostics mapping to reflect the new type; do the
same refactor for the similar type declared around lines 208-220 so both are
defined via Pick<> from RequestContextPreflightResult.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fdad6ea8-1e3b-4a1f-9b2a-53f93332a44b
📒 Files selected for processing (14)
docs/issues/agent-tool-context-budget/plan.mddocs/issues/agent-tool-context-budget/spec.mddocs/issues/agent-tool-context-budget/tasks.mddocs/issues/markdown-smooth-streaming-control/plan.mddocs/issues/markdown-smooth-streaming-control/spec.mddocs/issues/markdown-smooth-streaming-control/tasks.mdsrc/main/presenter/agentRuntimePresenter/contextBudget.tssrc/main/presenter/agentRuntimePresenter/index.tssrc/renderer/src/components/markdown/MarkdownRenderer.vuesrc/renderer/src/components/message/MessageBlockContent.vuetest/main/presenter/agentRuntimePresenter/agentRuntimePresenter.test.tstest/main/presenter/agentRuntimePresenter/contextBudget.test.tstest/renderer/components/MarkdownRenderer.test.tstest/renderer/components/message/MessageBlockContent.test.ts
Summary
UI Structure
BEFORE
AFTER
Tests
Summary by CodeRabbit