(MOT-4014) fix: guarantee context assembly stays within budget - #495
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (15)
📝 WalkthroughWalkthrough
ChangesContext budgeting and fail-closed generation
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant TurnLoop
participant ContextClient
participant ContextManager
participant LLMRouter
TurnLoop->>ContextClient: assemble messages, tools, and request overhead
ContextClient->>ContextManager: context::assemble
ContextManager->>ContextManager: prune, compact, and emergency-reduce function results
ContextManager-->>ContextClient: bounded context or context/overflow
ContextClient-->>TurnLoop: assembled context and usable budget
TurnLoop->>ContextClient: count final messages and tools after hooks
ContextClient->>ContextManager: context::count-tokens
ContextManager-->>TurnLoop: final token count
TurnLoop->>LLMRouter: router::chat only when final request fits
Possibly related PRs
Suggested reviewers: Poem
✨ 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 |
skill-check — worker0 verified, 42 skipped (no docs/).
Four for four. Nicely done. |
Problem
Context assembly could compact repeatedly and still return a successful response whose estimated token count exceeded the model's usable input budget. A multi-megabyte function result in the latest turn was protected by normal pruning and tail-selection rules, so it survived every compaction attempt.
The harness also added tool schemas, system aids, hook messages, response formats, and provider options after assembly. When context-manager was unavailable or returned an unusable result, the harness could fall back to raw history and call the provider without a complete final preflight.
Solution
token_count <= usableas a hard postcondition for every successfulcontext::assembleresponse.context/overflowandharness/context_overflowfailures when a safe request cannot be produced.router::chat.applied.tokens_beforecompaction metric.Impact
A 4.98 MB latest function result now becomes a bounded reference and the turn can continue without breaking call/result pairing. Irreducible requests fail locally with a structured context-overflow action and never reach the provider.
Validation
context-manager: fullcargo test, including 84 BDD scenarios and 749 steps.harness: fullcargo test, including 220 unit tests plus manifest and schema coverage.cargo clippy --all-targets -- -D warningsfor both packages.context::assemblewire-schema golden.git diff --check.Fixes MOT-4014
Summary by CodeRabbit
New Features
Bug Fixes
context/overflowandharness/context_overflowerrors when requests cannot safely fit.