fix(translator): sanitize Read tool args from non-Anthropic models - #4451
Merged
diegosouzapw merged 1 commit intoJun 20, 2026
Merged
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Non-Anthropic models (GPT-5.5, DeepSeek …) sometimes emit absurd values for Claude Code's Read-tool args — most notably `limit: 25999999999999999`, negative offsets, stringified numbers, and stray `pages` on non-PDF files. Claude Code rejects those params and retries, wasting tokens and producing noisy output. The OmniRoute tool-call shim already buffers and re-emits Read args at finish-time (groundwork laid in #1257 for `pages: ""`); this commit extends the Read shim's `sanitizeReadArgs` rules: - clamp `limit` to 2000 (Claude Code's hard cap), drop if non-positive - clamp negative `offset` to 0 - coerce numeric-string `limit`/`offset` to numbers - keep `pages` only for `.pdf` files matching `\d+(-\d+)?` Pure inside-the-shim change — buffering/suppression/single-corrective-delta flow already in place. Other tools and the rest of the translator are untouched. Tests (TDD, all 7 added cases RED → GREEN): - limit clamp at 2000 (the original report's value) - non-positive limit dropped - negative offset clamped to 0 - numeric-string coercion for limit/offset - pages stripped on non-PDF - pages stripped on PDF when format is malformed - single-page form `"7"` preserved on PDF (case-insensitive `.PDF`) - combined absurd args (mirrors upstream's integration test) Inspired-by: decolua/9router#1144 Co-authored-by: GodrezJr2 <168538340+GodrezJr2@users.noreply.github.com>
diegosouzapw
force-pushed
the
feat/port-pr-1144-sanitize-read-tool-args
branch
from
June 20, 2026 23:24
dbf884f to
4a52479
Compare
tkgo11
pushed a commit
to tkgo11/OmniRoute
that referenced
this pull request
Sep 23, 2026
…iegosouzapw#4451) Integrated into release/v3.8.32
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
Port of
decolua/9router#1144by @GodrezJr2 — when non-Anthropic models (GPT-5.5, DeepSeek …) are used as Claude Code CLI proxies, they sometimes emit absurd Read-tool args (most notablylimit: 25999999999999999). Claude Code rejects bad params and retries — wasting tokens and producing noisy output.OmniRoute already has the buffering / single-corrective-delta machinery (
hasToolCallShim/applyToolCallShimToBufferinopen-sse/translator/helpers/toolCallShim.ts, groundwork laid forpages: ""stripping). This PR extends theReadshim's sanitization rules:limitto 2000 (Claude Code's hard cap); drop the field if non-positiveoffsetto0limit/offsetto numberspagesonly for.pdffiles matching\d+(-\d+)?All other tools and the rest of the translator pipeline are untouched.
Differences from upstream
.js; OmniRoute is.ts— sanitization helper carries explicit types.openai-to-claude.js. OmniRoute already had it viatoolCallShim.ts(used forsubmit_pr_reviewand the originalReadpagesstrip), so this PR is a pure shim extension — no changes toopenai-to-claude.ts.pagesrule (strip when empty-string or empty-array) is subsumed by the new PDF-only rule (also stripspageson non-PDF paths and malformed PDF ranges). Existingpagestests still pass..pdf/.PDF).Test plan
node --import tsx/esm --test tests/unit/translator-tool-call-shim.test.ts— 30/30 pass (22 baseline + 8 new, including a combined-absurd-args case mirroring upstream's integration test).openai-to-claude-strip-empty,translator-resp-openai-to-claude,translator-openai-to-claude— 24/24 pass.npm run typecheck:core— exit 0.npx eslint open-sse/translator/helpers/toolCallShim.ts tests/unit/translator-tool-call-shim.test.ts— 0 errors (4 pre-existinganywarnings in the test file).Inspired-by: decolua/9router#1144