feat: salvageParseRanges — lenient compress-arg parser (5-layer ladder) - #109
Open
ranxianglei wants to merge 3 commits into
Open
feat: salvageParseRanges — lenient compress-arg parser (5-layer ladder)#109ranxianglei wants to merge 3 commits into
ranxianglei wants to merge 3 commits into
Conversation
…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
force-pushed
the
2026-08-22_compress-arg-salvage
branch
from
August 22, 2026 05:55
6a2a4c9 to
5892169
Compare
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):jsonjson-fencedjson-repairedarray-prefixfield-regexfrom m00150 to m00220prose shapeNever 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.