Skip to content

fix: preserve fitting history when the token count fails - #97

Merged
crizCraig merged 6 commits into
mainfrom
fix/count-failure-no-compress
Nov 21, 2026
Merged

crizCraig merged 6 commits into
mainfrom
fix/count-failure-no-compress

Conversation

@crizCraig

@crizCraig crizCraig commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

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/main and out of scope for this PR (tracked separately).

crizCraig and others added 6 commits November 20, 2026 21:22
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>
…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>
@crizCraig
crizCraig merged commit d3f2f87 into main Nov 21, 2026
11 of 12 checks 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.

1 participant