Repository navigation
fix: preserve fitting history when the token count fails - #97
Merged
Merged
Conversation
Use a verified usage sample and a measured margin when counting fails. Share the guarded size between compaction planning and delivery, and retry a fast disconnect within the original deadline. Co-Authored-By: Codex <noreply@openai.com>
Apply the margin after sizing verified history and new content. Treat explicit upstream size rejections as over-window, preserve the delivery retry, and compress at budget equality. Co-Authored-By: Codex <noreply@openai.com>
…flow once Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Codex <noreply@openai.com>
…ing retries Co-Authored-By: Gemini <noreply@google.com>
Keeps delivery's retry and fallback exactly as on main after any non-success retry (review: claude_r1 P2 / codex r5 P2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
A dropped Count Tokens connection on round-3 request 17 triggered compression of a history that still fit the 960,000-token budget. This change removes the PR’s estimate-based fallback and retries the exact count for the same request body.
Network errors, timeouts and HTTP 5xx responses can trigger up to two retries, with 100 ms and 200 ms backoffs inside a shared five-second counting window. HTTP 4xx responses stop immediately. The first upload keeps its existing size-based timeout. A successful count goes through the existing sizing logic. Exhausted attempts return the failure to the same compression and delivery paths as main. Delivery keeps its independent retry.
The overflow-response retry depended on a body admitted by the removed fallback. Reverting it also removes the SSE inspector that hung on corrupt gzip. A loopback replay confirmed the client receives the decoding error promptly on both main and this branch.
Replaying the reconstructed round-3 request with a dropped connection followed by an exact count of 798,362 forwarded all 511 messages unchanged. Regression tests cover that replay, compression after three disconnects, a single attempt on HTTP 400, and successful delivery after planning exhausts its retries. The committed dist matches a build from an empty output directory.
Both local npm test colour modes finished with 1,741 passes and 21 skips. Their only failure was the statusline grandchild-cleanup assertion, also present on main in both modes. All 12 push and pull-request CI jobs passed on Linux, macOS and Windows.
Note: byte-based delivery fallback forwarding an oversized file/PDF request when Count Tokens fails (e.g., HTTP 400) is pre-existing behavior on
origin/mainand out of scope for this PR (tracked separately).