Skip to content

fix: route unparseable compress tool args to the lenient parser instead of degrading to {} (#1502) - #1508

Merged
ranxianglei merged 1 commit into
masterfrom
wt-1502-ework-daemon
Sep 27, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
wt-1502-ework-daemon

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What changed

Issue #1502: when a model's compress tool-call arguments failed strict JSON.parse, three call sites degraded the args to {} before they reached the kernel's lenient parser — discarding the raw string entirely:

  • src/loop/core.ts streaming 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:

  1. Salvageable inputs — trailing commas, single quotes, fenced JSON, truncated prefixes with complete entries — exactly what acp-kernel's parseCompressArgs salvage ladder exists to recover, never reached it; the call executed as {} and compressed nothing.
  2. The client-facing receipt reported kind=missing-content with 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.
  3. The diagnostic log printed only 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: on JSON.parse failure the raw argument string is retained (rawArgs) and passed as a new optional rawArguments parameter of executeProxyTool; the compress branch feeds it to parseCompressInput → kernel lenient parseCompressArgs instead 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 log len/head/tail (the non-streaming site previously logged nothing useful about the shape).
  • src/stream.ts applyRanges: a string input the lenient parser could NOT salvage (malformed-json/truncated; diagnostics.length is 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.
  • Diagnostic logs gain tail= (last 200 chars) alongside head=.

Behavior changes (old → new) — flagged per policy

Case Old New
Salvageable but strict-unparseable compress args Executed as {} → nothing compressed; receipt said the call "carried no content at all" and advised NOT to re-issue Kernel salvage ladder recovers the ranges → compression succeeds (the designed #362 / quote-drift path)
Truly unparseable compress args Receipt no valid ranges parsed (kind=missing-content) + empty-call advice "Do NOT re-issue an empty call" (wrong: fixing the syntax IS retryable) Receipt the call's arguments (N chars) were not parseable JSON (+ looks truncated) + "re-issue as well-formed JSON"; #847 guard bucket moves parse:missing-content:0: → parse:malformed-json|truncated:0: so corrupt and empty calls are distinct failure classes
Logs …not parseable JSON (len=N, head=…) — executing with {} (Responses non-streaming site logged nothing) Tool-aware tail: compress says "routing the raw string to the lenient parser"; tail= added everywhere; Responses sites log len/head/tail
Genuinely empty calls ({} / no args) #1384 targeted empty-call receipt Unchanged (pinned by test)

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)

  • Reproduced against acp-kernel 0.0.95 directly: the issue's field-log signature (len=28543, keys=[], kind=missing-content) matches the degraded-{} path exactly; feeding the same-shaped string raw yields kind=ok through the salvage ladder. The two field hits were fully-delivered (un-truncated) strings whose strict-parse failure made them take the discard path.
  • Layer judgment: root cause is the pre-parse degradation at the call sites (symptom = misleading receipt + lost salvage); the fix removes that mechanism rather than filtering downstream. The sibling Responses sites share the root cause and are fixed in this PR.
  • Out of scope, verified not affected: src/stream-google.ts:28 (Gemini structured fc.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 — clean
  • npm test — 2941 pass / 0 fail / 12 skipped (e2e-gated)
  • New regression suite tests/issue1502-raw-args-salvage.test.ts (7 tests): unit-level salvage via rawArguments (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 through runCompressLoop (salvaged range compresses; garbage yields head+tail log + corruption marker instead of the empty verdict)
  • npm run build — success
  • CI will auto-run e2e-codex (diff touches src/loop/** hot files)

Fixes #1502

…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.
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: wt-1502-ework-daemon (d013ea4)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1439-pr.1508.b019125

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr1508.tgz
npm install -g package

Install instructions are refreshed on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,开始审查 PR #1508(修 #1502:proxy 工具参数 JSON.parse 失败被降级为 {}、绕过 lenient salvage 层)。流程:拉分支核对代码 → 回归审查(既有行为清点)→ 本地验证(typecheck/test/build)→ 查 CI(e2e-codex 会自动跑)→ 出结论。稍后回。

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 PR #1508 review 完成(修 #1502)。结论:可以合并。 按规范逐项报告:

① 原 issue 方向关 ✅

#1502 的层次判断正确且已在 floor 3 固化:根因是调用点的前置降级(raw string 进 lenient 层之前被换成 {}),不是 receipt 文案。本 PR 打在源头(三个 discard 点保留原始字符串并路由给已接好的 parseCompressArgs 字符串入口),不是下游过滤——符合「疏不堵」原则。issue 三条建议(路由/区分回执/补 tail 日志)全部落地。查重:triage 时已检索 #1306/#1384/#362/#847 族,无重复立项。

② 回归审查(既有行为清点)✅ 无回归

diff 触碰路径逐项判定:

既有行为 结论
严格可解析的参数(所有工具、所有 wire) 保持——rawArgs 为 undefined 时 input=args,字节级同路径
解析失败 + 非 compress 工具(decompress/acp_status/…) 保持 {} fallback(rawArguments 只在 compress 分支消费)
真空调用 {}/空串参数 → #1384 empty-call receipt 保持,测试逐字钉住(carried no content at all + Do NOT re-issue an empty call)
#362 shape-drift({ranges:…} 对象输入)→ 格式课 receipt 保持——对象输入无 diag.length,argCorruption=false,走原 generic 分支
#1366 单行失败契约(failure 保持一行,#1029) 保持——新 corruption receipt 也是单行
可救回但严格失败的 compress 参数 有意变更(已披露):旧「按 {} 执行+空调用劝退」→ 新 salvage 成功
真正不可解析的参数 有意变更(已披露):新独立损坏 receipt;#847 守卫桶 parse:missing-content:0: → parse:malformed-json|truncated:0:(损坏≠真空成为不同失败类)
诊断日志 有意变更(已披露):head= 旁加 tail=(后 200 字符);Responses 非流式站点从「只打 error」到完整 len/head/tail

审查中发现的一处跨路径效应(判定为有意统一,非回归):src/stream-openai.ts:25 和 src/stream-responses.ts:39(非流式路径)本来就直传原始字符串给同一个宽松 parseCompressInput——所以新的 corruption receipt 也会在这两条路径生效(垃圾字符串的回执从旧的 no valid ranges parsed (kind=malformed-json…) 变为 (N chars) were not parseable JSON…)。这两条路径的 #847 守卫键本来就用 diagnostics.kind(桶不变),变的只是回执措辞——四种 wire 形态同一故障同一诚实回执,正是 issue 要的「可区分」。全套测试(含 wire-contract golden)通过,无快照钉住旧措辞。核过不受影响的:stream-google.ts:29(Gemini 结构化 args)、plugin.ts:942(MCP 对象)、stream.ts:32 Anthropic dispatch(对象入参)、preflight.ts:1131(对象入参)——四个 executeProxyTool/applyRanges 调用面全清点完毕,无第四个降级点遗漏。

③ 代码审查 ✅

④ 测试有效性 ✅ 断言有牙

7 个测试:前提钉住(assert.throws(() => JSON.parse(raw)) 证明确是严格解析失败)、四种 salvage 变体断言真实建块、#1384 空调用回执逐字钉住、corruption receipt 断言长度标签+截断注记+不得含空调用措辞、#847 守卫键前缀正则区分(/^parse:truncated:0:/ vs /^parse:malformed-json:0:/)、两个 runCompressLoop 端到端(mock fetch,断言流内回执、refetch 次数、日志 head+tail 正则)。小缺口(不拦):Responses 两个站点本身无专属 e2e,但共享逻辑(executeProxyTool+applyRanges)已被单测钉死,站点只是 2 行的 rawArgs 透传。

⑤ diff 整洁度 ✅

单一线性 commit,4 文件(3 源 + 1 新测试),每行都与本 PR 目的相关;无 package.json/version 触碰、无锁文件连带、无空行重排。

验证证据

本 PR 引入回归:0 处。 三处有意行为变更均已在 PR 描述披露旧值→新值+原因;审查中新发现的跨路径回执统一(非流式 OpenAI/Responses 也获得新损坏回执)属同一设计意图的自然延伸,守卫键不变,一并在此披露。

🇨🇳 中文摘要:修复了 proxy 侧三处「compress 工具参数 JSON.parse 失败即丢原始字符串、降级为 {} 执行并误报空调用」的根因——改为把原始字符串路由给内核既有的宽松 salvage 层(可救回的尾逗号/单引号/fence/截断前缀现在能压成块),救不回时给出独立的「参数损坏」回执与 #847 守卫桶,并与刚合入 master 的 #1494/#1497 核对无语义冲突、rebased head 本地全绿、CI 13/13 全绿,可以合并。

@ranxianglei
ranxianglei merged commit d2282ae into master Sep 27, 2026
13 checks passed
@ranxianglei
ranxianglei deleted the wt-1502-ework-daemon branch October 15, 2026 05:33
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.

proxy 工具参数 JSON 解析失败被降级为空对象执行,原始字符串被丢弃、lenient 容错层被绕过

1 participant