Skip to content

fix: budget new input without trimming the current turn - #301

Merged
Eigenwise merged 1 commit into
Eigenwise:mainfrom
liangzhechen655:fix/preserve-current-turn-on-context-overflow
Oct 10, 2026
Merged

Eigenwise merged 1 commit into
Eigenwise:mainfrom
liangzhechen655:fix/preserve-current-turn-on-context-overflow

Conversation

@liangzhechen655

Copy link
Copy Markdown
Contributor

max_context_tokens currently measures history before adding the new user input. A request that was within budget can therefore exceed the configured limit as soon as that input is appended, across all four completion APIs.

Count the complete pending request after adding the input, and trim only older turns. Preserve the current turn: if the newest input plus the fixed context cannot fit, raise the existing ValueError before calling the provider. This also preserves the current turn for continuations without a new input.

Public API regressions cover run, run_stream, run_async, and run_async_stream, with both a request that fits after removing an older turn and an input that cannot fit. Token counting and provider completions are deterministic test doubles; no live provider call is required.

Validation (Windows / Python 3.13): all 8 new regression cases fail on the original code; full suite after the fix: 391 passed, 3 credential-gated tests skipped. Repository-wide Black and Flake8 checks pass.

AI assistance: Codex assisted with reproduction, implementation, and verification. This changes the behavior of max_context_tokens: oversized new inputs are now rejected locally rather than sent to the provider.

@Eigenwise Eigenwise left a comment •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated review of a0bb9b862b86688d719e8ec9c706b3e7264cd386: the earlier complexity-only rework request is withdrawn.

I checked the normal repository CI log for run 38017830710: 391 tests passed, 3 MiniMax integration tests skipped, with repository-wide Black and Flake8 passing. The source review preserves the four completion modes and current-turn continuations. The new regression intentionally retains rejected input; additional history/retry cases can follow up. No blocking correctness finding remains from this review. These are CI results, not a local or live-provider run.

@Eigenwise Eigenwise left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked a0bb9b862b86688d719e8ec9c706b3e7264cd386. The pending-input fix has regressions across all four completion modes and preserves current-turn continuations. Normal repository CI passed: 391 tests, with 3 MiniMax integration skips, plus Black and Flake8. The earlier complexity-only rework request is withdrawn.

@Eigenwise
Eigenwise merged commit f064071 into Eigenwise:main Oct 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants