Skip to content

feat: salvageParseRanges — lenient compress-arg parser (5-layer ladder) - #109

Open
ranxianglei wants to merge 3 commits into
masterfrom
2026-08-22_compress-arg-salvage
Open

feat: salvageParseRanges — lenient compress-arg parser (5-layer ladder)#109
ranxianglei wants to merge 3 commits into
masterfrom
2026-08-22_compress-arg-salvage

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Why

Weak/local models (vLLM qwen etc.) emit compress tool arguments that fail strict JSON.parse ~50% of the time (see billion-context-omp#121): truncated output caps, raw newlines inside summary strings, trailing commas, or plain prose. Hosts currently swallow the parse failure with no evidence.

What

One shared parser for every billion-context host (src/salvage-parse.ts):

Layer Name Handles
1 json strict JSON.parse
2 json-fenced ```json fences stripped
3 json-repaired trailing commas + raw newlines in string literals repaired
4 array-prefix truncated content array — brace-stack scanner salvages complete prefix entries (works even inside an unclosed wrapper); also recurses into double-encoded content strings truncated mid-array
5 field-regex per-field regex extraction incl. from m00150 to m00220 prose shape

Never throws. Returns { ranges, layer, note } so hosts can log why parsing degraded. extractRanges() also normalizes JSON-string (double-encoded) content arrays.

Field-regex layer keeps a ≥50-char summary gate (anti-garbage) — matches the floor the hosts already enforce.

Tests

17 new cases (tests/salvage-parse.test.ts); full suite 408/408. Version bumped to 0.0.33.

Follow-up host PRs (proxy / omp / pi) will consume 0.0.33 and close omp#121.

…n/fenced/repaired/array-prefix/field-regex)

Weak/local models (vLLM qwen etc.) emit compress tool arguments that fail
strict JSON.parse ~50% of the time (see billion-context-omp#121): truncated
output caps, raw newlines inside summary strings, trailing commas, or plain
prose. Hosts currently swallow the parse failure as {} with no evidence.

This kernel module gives every billion-context host one shared parser:
  layer 1  strict JSON.parse
  layer 2  strip ```json fences, parse
  layer 3  repair trailing commas + raw newlines in string literals, parse
  layer 4  truncated content array: salvage complete prefix entries
           (brace-stack scanner that works even inside an unclosed wrapper)
  layer 5  field-regex extraction (startId/endId/summary/topic, plus
           'from m00150 to m00220' prose shape)

Never throws; returns ranges + deepest layer reached + log note so hosts can
surface WHY parsing degraded. extractRanges() also normalizes JSON-string
(double-encoded) content arrays.

tests: 15 new cases in tests/salvage-parse.test.ts; full suite 408/408.
Wrapper JSON parses fine but its content string is truncated — layers 1-3
succeeded as JSON yet produced 0 ranges, and the raw brace scanner can't
see through escaped quotes. Recurse salvageParseRanges into the inner
string (bounded: one encoding layer per level).

test: double-encoded content truncated mid-array
@ranxianglei
ranxianglei force-pushed the 2026-08-22_compress-arg-salvage branch from 6a2a4c9 to 5892169 Compare August 22, 2026 05:55
@ranxianglei

Copy link
Copy Markdown
Owner Author

CI green (409/409). @ranxianglei please merge — this unblocks the three host PRs (billion-context / billion-context-omp / billion-context-pi) that fix omp#121. Note: the 0.0.33 release publish failed with npm 404 (NPM_TOKEN likely expired); this PR re-bumps to 0.0.34. After merge, a *_release-v0.0.34 branch → master will publish (once the token is fixed).

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.

1 participant