Skip to content

fix: surface partial compress drops in the model-facing receipt (#1495) - #1499

Merged
ranxianglei merged 3 commits into
masterfrom
2026-09-27_fix-partial-compress-drop
Sep 27, 2026
Merged

ranxianglei merged 3 commits into
masterfrom
2026-09-27_fix-partial-compress-drop

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem (#1495)

A batched compress call with 3 entries silently folded only 2 — the 3rd entry vanished with no failure note. Root cause (verified against acp-kernel 0.0.95 + master b371bd0):

  1. The kernel's lenient parser is designed to salvage complete entries from damaged arguments — e.g. when a gateway JSON-stringifies AND truncates the content array (salvageContentEntries, dist/index.js:7827 only recovers complete top-level objects; an unterminated trailing entry is dropped with no diagnostic other than kind="truncated"). A corrupted single element instead yields kind="ok" + invalidItems>0 + invalidReasons.
  2. bili's applyRanges (src/stream.ts) only read those diagnostics on TOTAL failure (ranges.length === 0). On partial success it discarded invalidItems/invalidReasons/kind, so the model received a clean [Compressed X, Y → 2 block(s)] receipt for an entry that was requested but never folded. Apply-layer per-range errors (r.errors) had the same invisibility whenever some other range in the batch succeeded, and the server-side log was silent too.

This is mode-independent (proxy + plugin modes share this one execution path; all wire adapters route through applyRanges) — so default mode exhibits the same behavior as lean; lean just has a shorter tool description that omits the "some gateways stringify arrays" note, making the exposure slightly more likely.

Fix (at the decision point, not a symptom mask)

  • applyRanges now appends to every non-total receipt:
    • [PARTIAL: …] note when parse diagnostics report drops — per-entry rejection reasons (invalidItems/invalidReasons), or for kind="truncated": how many ranges were recovered and that any unlisted requested range was LOST, with acp_status guidance to re-issue;
    • Errors: … for apply-layer per-range errors (unknown refs, …) that previously vanished on partial success.
  • Wired into BOTH receipts: the [Compressed …] success line and the [Compression FAILED: …] 0-blocks line.
  • Server-side warn log in parseCompressInput for the partial-drop case (previously unlogged).

⚠️ Behavior change (old → new)

Previously, a compress call whose arguments arrived partially damaged returned a clean success receipt naming only the ranges that landed (and logged nothing). Now such calls additionally carry a [PARTIAL …] annotation (and apply-layer errors carry Errors: …), plus a server warn log. Clean calls are byte-identical (pinned by regression test #4).

Regression tests

New tests/issue1495-partial-compress-drop.test.ts (4 cases): valid+invalid mix names the rejected entry inline; truncated gateway-stringified array names the salvage loss and never lists the lost range as applied; unknown-ref apply-layer error surfaces on partial success; clean call stays unannotated.

Pre-flight

  • npm run typecheck ✅
  • npm test ✅ 2875 pass / 0 fail / 12 skipped (default-gated e2e)
  • npm run build ✅
  • e2e codex full run: local upstream unreachable from the agent sandbox — ci-e2e.yml auto-runs on this PR (src/stream.ts is a hot file)

Closes #1495

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-09-27_fix-partial-compress-drop (a36feb2)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.1455-pr.1499.9be1779

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-pr1499.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] 🏷 Reviewing now — pulling branch 2026-09-27_fix-partial-compress-drop, will verify against #1495's root cause analysis, run the full pre-flight locally, and walk the regression checklist (receipts in both compression modes, clean-call byte-identity). Full findings in a follow-up comment.

@ranxianglei

Copy link
Copy Markdown
Owner Author

Rebased onto master (head 235c74a) — master had absorbed #1497/#1494 in the meantime, which already shipped a parallel fix for the invalidItems>0 receipts (different wording, pinned by tests/issue1494-compress-params.test.ts). Conflict resolution keeps master's #1494 shapes as the baseline and layers this PR's two genuine deltas on top:

  1. kind="truncated" salvage loss — droppedEntriesNote (src/stream.ts) now opens with a truncated branch (invalidItems can be 0 when the gateway cut the stringified array); the server-side [acp-compress-input] partial: log (src/compress-tool.ts) extends its condition with || kind === "truncated"; the success-path [acp-proxy: compress PARTIAL] log now carries kind=….
  2. apply-layer per-range errors on partial success — new applyErrorNote(r) appended to BOTH the success line (Errors: …, capped 3×200c) and the FAILED line.

The branch's own partialDropNote wording was dropped in favor of master's already-pinned messages; the 4 regression tests were adapted to the merged semantics (clean-call test now asserts no REJECTED/TRUNCATED/Errors: markers). Local: typecheck 0, issue1495 4/4, issue1494+stream-compress+compress-tool 13/13, ccr-plugin+loop-core-compress 12/12, build OK.

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 收到 —— 你已经在处理 #1497/#1494 的合并协调了(和我 review 时的建议同向)。我现在拉取新 head 235c74a 做最终核验:确认 diff 只剩两个 delta(truncated salvage loss + apply-layer errors)、无旧 partialDropNote 残留、与 master 上 #1494 已钉住的措辞不冲突,并跑完整 pre-flight(typecheck + 全量测试 + build,你本地跑的是定向子集)+ 检查 CI。结果稍后贴回。

@ranxianglei
ranxianglei force-pushed the 2026-09-27_fix-partial-compress-drop branch from 4f67720 to dd1e4d6 Compare September 27, 2026 14:45
@ranxianglei
ranxianglei merged commit ce53d3b into master Sep 27, 2026
13 checks passed
@ranxianglei
ranxianglei deleted the 2026-09-27_fix-partial-compress-drop branch October 15, 2026 05:32
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.

lean模式批量压缩丢失

1 participant