Repository navigation
fix: route unparseable compress tool args to the lenient parser instead of degrading to {} (#1502) - #1508
Conversation
…ad of degrading to {} (#1502)
When a model's compress arguments failed strict JSON.parse, three call sites (loop/core.ts streaming, compress-loop-responses.ts x2) discarded the raw string and executed against {}, bypassing the kernel's lenient salvage ladder (trailing comma / single quotes / fence / truncated prefix) and mislabeling corrupt calls as empty ones in the client-facing receipt. Retain the raw string on parse failure and feed it to parseCompressInput; give unsalvageable string input its own corruption receipt (safe length-only label, no payload echo) instead of the #1384 empty-call verdict; log head+tail to separate truncation from mid-string corruption.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.1439-pr.1508.b019125This exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr1508.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #1508 review 完成(修 #1502)。结论:可以合并。 按规范逐项报告: ① 原 issue 方向关 ✅#1502 的层次判断正确且已在 floor 3 固化:根因是调用点的前置降级(raw string 进 lenient 层之前被换成 ② 回归审查(既有行为清点)✅ 无回归diff 触碰路径逐项判定:
审查中发现的一处跨路径效应(判定为有意统一,非回归): ③ 代码审查 ✅
④ 测试有效性 ✅ 断言有牙7 个测试:前提钉住( ⑤ diff 整洁度 ✅单一线性 commit,4 文件(3 源 + 1 新测试),每行都与本 PR 目的相关;无 package.json/version 触碰、无锁文件连带、无空行重排。 验证证据
本 PR 引入回归:0 处。 三处有意行为变更均已在 PR 描述披露旧值→新值+原因;审查中新发现的跨路径回执统一(非流式 OpenAI/Responses 也获得新损坏回执)属同一设计意图的自然延伸,守卫键不变,一并在此披露。 🇨🇳 中文摘要:修复了 proxy 侧三处「compress 工具参数 JSON.parse 失败即丢原始字符串、降级为 |
What changed
Issue #1502: when a model's
compresstool-call arguments failed strictJSON.parse, three call sites degraded the args to{}before they reached the kernel's lenient parser — discarding the raw string entirely:src/loop/core.tsstreaming loop (the site from the issue's field logs)src/compress-loop-responses.ts— BOTH Responses-API sites (surfaceProxyJson+ the non-streaming re-request branch). Same root cause, found during triage; one issue per root cause, fixed together.Consequences:
parseCompressArgssalvage ladder exists to recover, never reached it; the call executed as{}and compressed nothing.kind=missing-contentwith the fix: stop empty-compress-call retry loops — targeted no-content receipt (#1366) #1384 empty-call verdict ("Do NOT re-issue an empty call") — wrong advice for a corrupt-but-retryable call, and indistinguishable from a genuinely empty companion call.head=(first 200 chars); the tail is the decisive discriminator between truncation and mid-string corruption.Fix (at the discard sites, not a downstream mask)
src/loop/core.ts: onJSON.parsefailure the raw argument string is retained (rawArgs) and passed as a new optionalrawArgumentsparameter ofexecuteProxyTool; the compress branch feeds it toparseCompressInput→ kernel lenientparseCompressArgsinstead of the degraded{}. Non-compress tools keep the{}fallback (their handlers take objects).src/compress-loop-responses.ts: same retention at both sites; both now also loglen/head/tail(the non-streaming site previously logged nothing useful about the shape).src/stream.tsapplyRanges: a string input the lenient parser could NOT salvage (malformed-json/truncated;diagnostics.lengthis set only for string inputs) gets its own single-line receipt naming syntax corruption with a safe length-only label (no payload echo, fix: replay connect-phase transport failures and report committed compression when the re-request dies (#1453) #1454 pattern) instead of inheriting the empty-call verdict; the 出现持续压缩失败,无法自动恢复 #847 degenerate-retry guard advice is now class-specific.tail=(last 200 chars) alongsidehead=.Behavior changes (old → new) — flagged per policy
{}→ nothing compressed; receipt said the call "carried no content at all" and advised NOT to re-issueno valid ranges parsed (kind=missing-content)+ empty-call advice "Do NOT re-issue an empty call" (wrong: fixing the syntax IS retryable)the call's arguments (N chars) were not parseable JSON (+ looks truncated)+ "re-issue as well-formed JSON"; #847 guard bucket movesparse:missing-content:0:→parse:malformed-json|truncated:0:so corrupt and empty calls are distinct failure classes…not parseable JSON (len=N, head=…) — executing with {}(Responses non-streaming site logged nothing)tail=added everywhere; Responses sites loglen/head/tail{}/ no args)Wire fidelity: tool-call arguments remain byte-exact on the wire (#1039) — this only changes how bili parses its own proxy-tool invocations server-side. Both compression modes considered: plugin mode suppresses injection and the agent owns execution (unaffected); proxy mode is where this executes.
Triage notes (per Issue Triage rules)
len=28543,keys=[],kind=missing-content) matches the degraded-{}path exactly; feeding the same-shaped string raw yieldskind=okthrough the salvage ladder. The two field hits were fully-delivered (un-truncated) strings whose strict-parse failure made them take the discard path.src/stream-google.ts:28(Gemini structuredfc.args, never a string),src/plugin.ts:926(MCP JSON-RPC object), and the non-streaming OpenAI/Responses/Anthropic paths which already pass raw strings to the lenient parser.Pre-flight
npm run typecheck— cleannpm test— 2941 pass / 0 fail / 12 skipped (e2e-gated)tests/issue1502-raw-args-salvage.test.ts(7 tests): unit-level salvage viarawArguments(trailing comma / fenced / single-quote / truncated prefix), fix: stop empty-compress-call retry loops — targeted no-content receipt (#1366) #1384 empty receipt pinned unchanged, corruption receipts for unbalanced vs balanced garbage with distinct 出现持续压缩失败,无法自动恢复 #847 guard keys, plus two loop-level end-to-end tests throughrunCompressLoop(salvaged range compresses; garbage yields head+tail log + corruption marker instead of the empty verdict)npm run build— successe2e-codex(diff touchessrc/loop/**hot files)Fixes #1502