Skip to content

fix(typesafe): shrink and retry a request Jev finds over its window, stop dropping decision answers - #5794

Merged
nicoloboschi merged 1 commit into
mainfrom
fix/typesafe-max-tokens-recovery
Oct 19, 2026
Merged

nicoloboschi merged 1 commit into
mainfrom
fix/typesafe-max-tokens-recovery

Conversation

@nicoloboschi

Copy link
Copy Markdown
Collaborator

Fixes #5715.

Problem

We size TypeSafe requests with our own tokenizer, but Jev counts mixed-script text (emoji, CJK, Arabic, accents) at about 2× ours. A request that fits our 26k budget can come back 400 {"detail":{"error_type":"max_tokens_exceeded"}}:

  • TypeSafe reranker → recall fails with HTTP 500 (the issue).
  • Decision model ask_all → the failure was logged and those answers silently left out; the decision reranker then ranked those candidates last.

Jev's tokenizer isn't published and there is no count endpoint, so we can't count exactly. Instead, recover when Jev refuses.

Fix

  • TypeSafe reranker (cross_encoder.py): rank, cut, evidence sufficiency and page impact rebuild an overflowing request at half the budget (26k → 13k → 6.5k → 3.25k), then raise.
  • Decision model (decision_model.py): ask() splits an overflowing request into halves until a single question is too long; ask_all() now raises instead of dropping answers.
  • Decision reranker: caps each memory at 4k tokens, so one long memory can't overflow its question and fail the whole rerank.

No long-context header and no new setting, unlike the patch proposed in the issue: that was opt-in, so the default would have stayed broken.

Verified

  • Against the live API with the issue's repro (7 mixed-script candidates, 19k tokens by our count): the rank and cut each overflowed once, retried at 13k, and returned scores.
  • Tests: the fake upstream refuses bodies over a window counted at 2× ours: reranker repack, evidence retry, give-up after the floor, decision-model halving, ask_all raising, memory cap.

…stop dropping decision answers

Jev counts mixed-script text at about twice our tokenizer, so a request sized to
fit by our count can come back 400 max_tokens_exceeded (#5715). In recall's
TypeSafe reranker that was an HTTP 500; in the decision-model client it was
logged and the answers silently left out, ranking those candidates last.

- TypeSafe reranker: rank, cut, evidence sufficiency and page impact rebuild an
  overflowing request at half the budget (26k -> 13k -> 6.5k -> 3.25k), then raise.
- Decision model: ask() splits an overflowing request in halves until one
  question alone is too long; ask_all() raises instead of dropping answers.
- Decision reranker: caps each memory at 4k tokens so one long memory cannot
  overflow its question and fail the whole rerank.

Fixes #5715
@nicoloboschi
nicoloboschi merged commit b463785 into main Oct 19, 2026
114 of 117 checks passed
@nicoloboschi
nicoloboschi deleted the fix/typesafe-max-tokens-recovery branch October 19, 2026 16:44
@nicoloboschi nicoloboschi mentioned this pull request Nov 3, 2026
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.

TypeSafe reranker can exceed Jev context within the local token budget

1 participant