Repository navigation
fix: forward-once-then-learn for image-dominated payloads (#496) - #500
Conversation
The default per-image estimate (base64/4, uncapped) matches byte-billing relays (#488) but overestimates pixel-tile upstreams (official Anthropic/OpenAI) by up to ~200x, so a session whose estimated image floor alone exceeded the window was hard-failed 502 preflight_compress_failed even though real cost was a few K tokens - a regression vs master for official-API multimodal users. When images are the sole over-window component (textEstimate < limit) and there is no upstream overflow evidence yet (lastInputTokens < limit and no learned limit for the model), forward once so the upstream arbitrates billing: tile upstreams accept (zero behavior change); byte relays reject once, self-heal learns the window, later requests fail-fast. Exactly one rejected forward - #488's 400 loop stays broken, no new knob.
📦 Built Package ArtifactBranch: Option A — Install from npm PR tag (recommended)npm install -g billion-context@pr-500Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pr500.tgz
npm install -g packageThis comment is automatically updated on each push. |
[bot] 🏷 Reviewed — verified independently. LGTM, ready for a human merge (I won't merge per policy). I checked out the head (
The single failure, Design — the mechanism actually holdsTraced
Scope note — now moot, but confirms the merge is safeYour note said the branch "carries #489's content into master." That's no longer accurate: #489 is already merged to master (current tip Minor, non-blocking
Nothing blocking. Recommend you merge when ready. |
|
Independent review (second session) — no functional bug found; LGTM. Verified on top of current master (post-#504/#505/#506, i.e. with weak-overflow learning now live):
From my side this is merge-ready as-is. |
…eady path (#1960) The steady request path (client echoes the round back) silently dropped redacted_thinking blocks because anthropicToCore had no case for them, so every later request rebuilt the latest assistant message without the block and Anthropic answered 400 "cannot be modified" forever — the half of #1960 that kept the session stuck after the compress turn. - acp-kernel pin 0.0.99 → 0.0.101 (exact), which carries kernel PR #500 (redacted_thinking sidecar round-trip). Also rides along from v0.0.100+: #483 ref capacity widened to 9,999,999, #484 case-insensitive protected tool matching, #478 nudge cadence re-anchor, #493 language-preservation behind an opt-in flag (default off), and #499 prune/recommend shared per-turn index (hundreds of ms saved on ordinary requests in large sessions — release-note material). - tests/issue1960-steady-redacted.test.ts: client-echoed [thinking(sig), redacted(data), tool_use] must survive prepare→outbound byte-identical in order. Verified failing on 0.0.99, passing on 0.0.101. Preflight: typecheck clean; targeted loop/thinking/reasoning suites 186/186 green incl. both new #1960 files; build OK.
What
Follow-up to #496 — fixes the residual design risk from PR #489's image-token accounting. The default per-image estimate (
base64/4, uncapped) matches byte-billing relays but overestimates pixel-tile upstreams (official Anthropic/OpenAI) by up to ~200x, so a session whose estimated image floor alone exceeded the window was hard-failed502 preflight_compress_failedeven though the real cost was a few K tokens — a regression vs master for official-API multimodal users (e.g.bili claudepasting screenshots).Fix — forward-once-then-learn (
src/server.ts)When images are the sole over-window component (
textEstimate < limit) and there is no upstream overflow evidence yet (session.stats.lastInputTokens < limitand no learned limit for this model), the fit gate forwards once instead of hard-failing, letting the upstream arbitrate billing:With either evidence signal present we trust the estimate and fall through to fold / fail-fast exactly as before.
Scope note — stacked on PR #489
This branch is based on
f7deccc(PR #489 tip), so it carries #489's content into master alongside this fix. The second commit also carries #489's doc gaps noted in #496 items 1 & 2 (BILI_IMAGE_TOKEN_CAPenv rows +[Unreleased]changelog entries for #488 and #496). If those were already added to #489, drop the doc commit.Pre-flight
npm run typecheck— cleannpm test— 986 pass / 1 fail / 987 total. The 1 failure (launcher.test.ts→resolveClientCommand: codex/claude resolve to themselves) is a pre-existing environmental failure, reproduced identically on pristine basef7deccc; unrelated to this change.tests/fix-488-multimodal.test.ts(多模态会话上下文控制失效 + preflight 救援 502(codex responses store:false) #488-A rewritten → tile upstream accepts the once-forwarded payload) + newtests/issue496-forward-once-learn.test.ts(byte relay: one rejected forward then fail-fast) — 8/8 pass.npm run build— successNot addressed here (tracked in #496, non-blocking)
tool_result.content[]embedded b64;type:"document"PDF blocks; responsesfile_id) — same as master, non-regression.