fix(agent): recover from provider context overflows - #1838
Merged
Conversation
- preserve recent exact context across automatic compression - retry overflow recovery within the same logical model round - propagate structured provider errors through adapters and stream processing - distinguish round attempts from transport retries in traces
wsp1911
marked this pull request as ready for review
July 28, 2026 16:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Improve context overflow handling with structured provider error detection, bounded recovery compression, and recent-context preservation.
Overflow recovery now remains within the same logical model round while exposing each recovery attempt through lifecycle events and traces.
Type and Areas
Type:
Bug fix
Areas:
Rust core, AI adapters, agent stream, core contracts
Motivation / Impact
Some providers omit token usage, making pre-request context estimates unreliable. An underestimated request could exceed the provider context window and fail without recovery.
This change:
Recovery is bounded to avoid unbounded retry loops. Plain HTTP 400 responses without overflow evidence remain classified as invalid requests, and output-token limit errors are excluded from context overflow recovery.
Verification
Passed:
pnpm run fmt:rscargo test -p bitfun-core-typescargo test -p bitfun-ai-adapterscargo test -p bitfun-agent-streamcargo test -p bitfun-core round_executor::testscargo test -p bitfun-core execution_engine::testscargo check --workspacenode scripts/check-core-boundaries.mjsgit diff HEAD --checkcargo check --workspacereported only pre-existing CLI unused-import and dead-code warnings.Reviewer Notes
The main behavioral changes are:
No persistence migration is required.
Checklist