Skip to content

parseCompressArgs: content given as a single entry object is rejected (content-not-array) while the same drift at the top level is tolerated — asymmetric salvage wall #470

Closed

Description

@ranxianglei

Observed (via billion-context #1494/#1495, PR ranxianglei/billion-context#1497)

A model that batch-compresses successfully for thousands of refs occasionally re-issues a lost range with content as the single entry object instead of a one-element array:

{"content": {"startId": "m04083", "endId": "m04092", "summary": "..."}}

parseCompressArgs answers kind=content-not-array (dist parseCompressArgs ~:7232/7239) — a hard failure with no salvage.

Meanwhile the SAME drift at the top level is already tolerated by the salvage ladder: a bare top-level entry object {"startId":..., "endId":..., "summary":...} parses fine. So the ladder's policy ("an entry-shaped object in the wrong slot is recovered") is applied asymmetrically: top-level yes, inside content no. Stringified/fenced variants recovered elsewhere also exist.

Why this matters beyond proxy hosts

billion-context shipped a wrapper-side normalization (normalizeCompressInput in PR #1497) for the proxy lane — but plugin-mode agents execute their own bundled acp-kernel, so those agents keep hitting the wall, and the two worlds now have divergent parse semantics for the same input. Root-cause home per our convention is the kernel ladder.

Suggested fix

In parseCompressArgs, after the Array.isArray(content) check fails, if the value isPlainObject(content) and it looks entry-shaped (has any of startRef/startId/endRef/endId/summary/ranges), wrap it into a one-element array — mirroring the existing top-level bare-object recovery. Diagnostics should record the recovery (e.g. an invalidReasons note or a dedicated kind upgrade) so hosts can observe the drift rate.

Not security-bearing: wrapped entries still pass validateEntry (bounds + summary gates) unchanged.

Context

  • Original accident: 3-entry batch → 1 entry dropped at parse → silent partial success (proxy receipt side fixed in bili PR #1497) → model retried the lost range with the single-object shape → hard failure.
  • Kernel pin in bili at the time: 0.0.95.

Activity

  1. ranxianglei commented on Sep 27, 2026

    @ranxianglei
    OwnerAuthor

    🤖 Powered by ework · qwen3.8-27b

    [bot] 🏷 Fixed — PR: #471 (branch 2026-09-27_content-object-salvage, commit afa1c54, based on master head 6915978).

    Triage verification

    Reproduced. Against the pre-fix kernel, the exact shape from the issue:

    • {content: {startId: "m04083", endId: "m04092", summary: ...}} → {ok:false, kind:"content-not-array"}, 0 ranges — hard wall, no salvage
    • same entry at top level (no content key) → ok, 1 range — tolerated
    • stringified variant of the object shape → also content-not-array

    So the asymmetry is real: the ladder's own policy ("an entry-shaped value in the wrong slot is recovered") was applied at the top level but hard-rejected inside content. Root cause is the final else branch of parseObjectValue in src/parse-compress-input.ts — a gap in the salvage ladder itself, not a host or proxy problem. That confirms your layer judgment: the home for this is the kernel, which is exactly why plugin-mode agents kept hitting the wall while the bili proxy lane got wrapper-side relief (#1497).

    What the fix does

    In parseObjectValue, when content is neither an array nor a string but is a plain object, it's wrapped into a one-element array and flows through the shared validateEntry pipeline unchanged; if the object instead carries a nested ranges array, that array is unwrapped (you listed ranges among the entry markers, and wrapping it would have failed validation). Two deliberate choices:

    1. Unconditional wrap, not field-gated shape detection. Your suggested fix gated on "looks entry-shaped"; I adopted the unconditional variant because it is byte-for-byte what normalizeCompressInput in billion-context#1497 already does (isPlainObject(c) → content: [c]). Convergence matters more than precision here: with gating, the two lanes could still diverge on e.g. an entry-shaped object with unexpected extra keys. False-positive risk is zero either way, since bounds + summary gates apply unchanged downstream — garbage degrades to per-entry reasons, never to a phantom range.
    2. New additive diagnostic diagnostics.contentSalvage === true marks every recovered input (object wrap and ranges unwrap), so hosts can observe the drift rate exactly as you asked. Canonical array inputs leave it undefined.

    String-encoded and fenced double-stringified variants recover automatically (they funnel into the same branch), and rebuildCompressionState benefits without changes. The schema layer (COMPRESS_PARAMETERS) is untouched — it still structurally rejects object-under-content, and its contract test now pins both layers' roles explicitly.

    Behavior change (old → new) — required disclosure

    Input shape Before After
    {content: {startId,endId,summary}} well-formed kind=content-not-array, 0 ranges kind=ok, 1 range, contentSalvage=true
    {content: {foo: 1}} garbage content-not-array no-valid-ranges + per-entry reason ("missing range bounds"), still 0 ranges
    {content: {ranges: [...]}} hard fail unwrapped, parsed normally
    {content: 42/null/true} content-not-array unchanged
    truncated string, single-object content truncated, 0 ranges unchanged (partial entries dropped, never guessed)
    canonical {content: [...]} ok unchanged, no new flag set

    Why this is safe: only inputs that previously died with zero ranges are affected, and they can now at best recover entries that pass the identical validation the canonical path uses. Nothing security-bearing shifts.

    Tests & pre-flight

    Note for the #1497 side: once this ships, the proxy-lane normalizeCompressInput becomes belt-and-braces rather than load-bearing — you may keep it (defense in depth against older bundled kernels) but the semantics now agree by construction.

  2. added a commit that references this issue on Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions