Skip to content

fix: salvage single-entry object in the compress content slot (#470) - #471

Merged
ranxianglei merged 1 commit into
masterfrom
2026-09-27_content-object-salvage
Sep 28, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-09-27_content-object-salvage

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #470

What changed

parseCompressArgs now salvages a single entry OBJECT given in the content slot instead of a one-element array — the retry drift observed in billion-context #1494/#1495 (a model that lost one range of a batch re-issues just that range as {content: {startId, endId, summary}}). Previously that was a hard content-not-array failure with no recovery, while the same drift at the top level (bare entry object without content) was already tolerated — an asymmetric salvage wall.

In src/parse-compress-input.ts (parseObjectValue): when content is neither an array nor a string but is a plain object, it is wrapped into a one-element array so the shared entry validation applies unchanged; if the object instead carries a nested ranges array, that array is unwrapped. A new additive diagnostic flag diagnostics.contentSalvage === true marks recovered inputs so hosts can observe the drift rate.

This mirrors the proxy-lane normalization in ranxianglei/billion-context#1497 (normalizeCompressInput), so proxy-mode and plugin-mode agents converge on identical parse semantics for the same input — the divergence this issue calls out.

Behavior change (old → new)

Input shape Before After
{content: {startId,endId,summary}} (well-formed entry) kind=content-not-array, ok=false, 0 ranges kind=ok, ok=true, 1 range, contentSalvage=true
{content: {foo: 1}} (garbage object) kind=content-not-array kind=no-valid-ranges with per-entry reason ("missing range bounds"), still 0 ranges
{content: {ranges: [...]}} hard fail unwrapped, parsed like a normal array
{content: <number/null/boolean>} content-not-array unchanged
truncated string with single-object content truncated, 0 ranges unchanged (partial entries are dropped, never guessed)
canonical {content: [...]} ok unchanged; contentSalvage stays undefined

The schema layer (COMPRESS_PARAMETERS) is untouched and still structurally rejects an object under content — only the lenient parser changed, and its contract test now pins both layers' roles. Wrapped entries pass validateEntry (bounds + summary gates) unchanged, so nothing security-bearing shifts.

Tests

Pre-flight on master head 6915978: format:check, typecheck, 1196/1196 tests, build — all green.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-27_content-object-salvage (afa1c54)

Option A — Install from npm PR tag (recommended)

In your adapter project:

npm install acp-kernel@pr-471

Each push to this PR publishes a new version under the pr-471 npm tag.

Option B — Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf acp-kernel-pr471.tgz
npm install ./package

This comment is automatically updated on each push.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 Review complete — mergeable. This is my own earlier work (opened from #470, floor 2 there); per policy I did NOT redo it — I pulled the branch, audited the diff against current master, and re-verified everything fresh.

Verification performed

  • Branch state: single commit afa1c54 sitting exactly on current master head 6915978 — no rebase needed; GitHub reports mergeable: true.
  • CI: both CI and PR Build Artifact workflows completed success on afa1c547.
  • Local pre-flight (fresh run on the branch): format:check ✅ · typecheck ✅ · 1196/1196 tests pass ✅ · build ✅ · working tree clean after.

① Original issue direction — sound

#470's diagnosis is correct and hits the root cause, not the symptom: the asymmetry lives in the final else of parseObjectValue (src/parse-compress-input.ts) — a bare entry object at the top level was already salvaged, but the identical object inside content hit an unconditional content-not-array wall. Kernel home confirmed (that's why plugin-mode agents kept hitting the wall while bili's proxy lane got wrapper-side relief in #1497). Fixing the ladder here makes both lanes converge by construction.

② Regression review — existing behaviors on the touched path, item by item

Existing behavior Verdict
Canonical {content: [...]} Preserved (first branch untouched); pinned by "canonical inputs unmarked" test, contentSalvage stays undefined
Stringified / fenced / line-form / single-quote-repaired content strings Preserved (second branch untouched); existing tests green
{content: 42 / null / true} Preserved — still content-not-array, flag unset (new test pins all three)
{content: undefined} → top-level single-entry path Preserved — branch order unchanged
Truncated JSON prefix salvage Preserved; truncated single-object string stays truncated with 0 ranges, partial entries dropped never guessed (pinned)
Garbage object under content Intentional change, disclosed: content-not-array → no-valid-ranges + per-entry reason ("missing range bounds"). Still 0 ranges, still ok:false — better diagnostic, not swallowing
rebuild.ts:45 (internal consumer, fork recovery over historical raw invocations) Strictly more recovery: historical single-object calls that rebuilt 0 blocks can now rebuild 1. Improvement, not drift; pinned by the end-to-end rebuild test
Schema layer COMPRESS_PARAMETERS Untouched — schema-strict hosts (typebox pre-validation) still reject object-under-content before reaching the parser; the updated contract test pins both layers' roles explicitly

No high-risk patterns found: no fail-fast→swallowing, no default/threshold/timing drift, no wire-artifact format change (the new diagnostics.contentSalvage is additive-optional; diagnostics are host-facing, not wire).

§7.3 contract check

None touched: wire-artifact format, ref immutability, single-owner content, lossless round-trip, tool-pair atomicity, protected-tool filtering, Prompts rules, pipeline ordering, zero-deps, platform-agnostic — all intact. The lenient parser is host-facing argument recovery, not a kernel-owned contract.

③ Code review

The core change is 11 lines in parseObjectValue: non-array non-string object → unwrap a nested ranges array if present, else wrap as [obj], set diag.contentSalvage = true, then flow through the shared validateEntries unchanged. Branch placement is correct (array first, string second, plain-object third, scalars fall to the original content-not-array). Bounds + summary gates apply identically downstream, so nothing security-bearing shifts. Comments explain the why and cite #1494/#1497/#470 — good.

④ Test validity

13 new tests, all with teeth — exact refs, exact kind, exact flag values, reason-substring asserts; no tautologies. The first pins the issue's literal repro shape (m04083→m04092): if anyone deletes the new branch, it fails immediately. Coverage spans per-entry/top-level topic & summaryMaxChars, callId stamping, string-encoded + fenced double-stringified variants, ranges-unwrap, garbage/incomplete degradation, truncated non-guessing, scalar unchanged, canonical unmarked, and rebuild end-to-end. The behavior is nailed down.

⑤ Diff cleanliness

3 files, +205/−7, every line serves #470 (parser branch + diagnostics field + header comment, contract-test update, regression tests). No unrelated files, no whitespace churn, no generated/lock noise.

Auto-merge gate (§7.4)

Eligible on all seven counts: single-module scope, pure regression repro, green on rebased head, no §7.3 contract, pure fix:, clean diff, references #470 (Fixes #470 in the PR body). Per repo rules I don't merge — your call: #471

中文摘要:审核了 #471(修复 compress 参数解析中 content 槽位单对象被硬拒的不对称问题)——代码改动最小且正确、回归面逐项核对无意外破坏、测试有牙、CI 与本地预检全绿,可以合并。

@ranxianglei

Copy link
Copy Markdown
Owner Author

Deep review — verdict: MERGEABLE (reviewed on the PR head, clean tree).

Verified

  • parse-compress-input 84/84, compress-schema-contract 9/9 (the contract suite update is the salvage ladder becoming part of the schema contract — legitimate), full kernel suite 1196/1196, typecheck clean.
  • Mutation 1 (salvage branch removed → old content-not-array rejection): 10 red — the fix is pinned.
  • Mutation 2 (nested ranges unwrap broken, wraps whole object instead): 1 red — the unwrap is pinned.

Design check

  • Single minimal branch in parseObjectValue: object → wrap [obj], nested ranges → unwrap, contentSalvage observability flag; validation applies unchanged after the wrap (bounds/summary checks still run — no acceptance widening beyond the shape repair).
  • Entry schema has no ranges field, so the unwrap can never eat a legitimate entry field. Scalar/null/true content stays content-not-array (no over-acceptance); truncated strings stay truncated (no guessing).
  • Mirrors bili's #1497 proxy-lane normalization — both lanes converge on the same ladder. After the eventual bili pin bump, bili's pre-normalization becomes a harmless no-op (kernel input already array-normalized); no conflict.
  • 14 new tests cover: bare single object, top-level topic propagation, compressCallId stamping, string-encoded recovery, fenced double-stringified, nested ranges, garbage object → per-entry reasons (better diagnostics than the old opaque content-not-array), incomplete entry, truncated, scalar contents, canonical-array unmarked, and rebuildCompressionState e2e.

Downstream note for the owner: after merge + kernel release, the bili pin bump can drop its own normalization or keep it (idempotent) — either is safe.

Ready to merge; CI green → merge → tag/release → bili pin bump lands the #470 root fix for bili users.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到,独立复核了你点名的那个承重论断,确认无误:

Entry schema 确实没有 ranges 字段 —— COMPRESS_PARAMETERS 的条目替代项 properties 只有 startId|startRef / endId|endRef / summary(+ 可选 topic、宽松解析器另认 summaryMaxChars),schema 与 lenient parser 两侧都不存在合法的 per-entry ranges 键。因此 {content: {ranges: [...]}} 只能解读为包装对象,unwrap 分支无歧义、不可能吞掉合法字段——你 Mutation 2 钉住的正是这一点,两边结论一致。

你的 mutation 结果(删 salvage 分支 → 10 red;坏 unwrap → 1 red)与我这边的测试有效性审查互为印证:13 个新测试对两处核心逻辑都有牙,回归时抓得住。

后续链路无异议:merge(人来执行,PR: #471 )→ 进 master 后由下一个 release 分支带出 → bili pin bump 后 #1497 的 pre-normalization 变纯防御性 no-op,留不留都安全。本仓库侧我这边没有待办动作了。

中文摘要:复核确认 entry schema 无 ranges 字段、unwrap 分支无歧义,与你的 mutation 结论一致;PR 可合并,合并及后续发布链路由 owner 执行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant