Repository navigation
fix(compress): repair missing closing brace on last content entry - #254
Conversation
When non-strict tool-call providers (Qwen-family) emit the compress
content array as a JSON string with the last entry's closing '}'
dropped, JSON.parse fails and the tool reported a misleading
'content must be an ARRAY' error.
- tailRepair/repairContentTail: deterministically re-append '}' before
the final ']' when the trimmed string ends with '"]' preceded by '"';
a no-op for well-formed input (no false positives).
- describeDiagnostics: for array/object-shaped-but-unparseable content,
surface the parser's own diagnostic ('the JSON failed to parse: ...')
instead of 'must be an ARRAY', giving the model a retryable signal.
Closes #253
📦 Built Extension ArtifactBranch: Option A — Install from npm PR tag (recommended)pi install npm:billion-context-pi@pr-254Each push to this PR publishes a new version under the Option B — Download artifact
tar xzf billion-context-pi-pr254.tgz
pi install ./packageThis comment is automatically updated on each push. |
[bot] Reviewed & verified — ready to merge (merge left to you, human-only). I didn't just trust the PR description — I re-ran everything on the branch ( Verification (all green, matches the claims)
Before/after (the part I added)Replayed the exact #253 payload (single entry, ~6 KB summary, dropped closing
So the e2e test genuinely reproduces the bug and the fix resolves it — not passing vacuously. Code review (traced the logic, no issues)
Notes
LGTM. Merging is yours. |
…ss-tail-repair-missing-brace fix(compress): repair missing closing brace on last content entry
Summary
Fixes #253.
With Qwen-family models in non-strict tool-call mode, the
compresstool'scontentargument arrives as a JSON-encoded array string whose last entry object is missing its closing}(the tail is\"+]instead of\"+}]).JSON.parserejects the whole string, and the tool surfaced a misleading error —content must be an ARRAY— even though the input is an array. This sent capable models into restructuring the payload instead of fixing the brace.Changes (
src/compress-tool.tsonly)tailRepair()/repairContentTail(): whenargs.contentis a string that fails to parse and its trimmed form ends with\"](preceded by\"), re-append}before the final]and retry. A no-op for well-formed input (a valid array never still parses after appending}), so there are no false positives. Wired intonormalizeRangesbeforeparseCompressArgs.describeDiagnostics()now detects array/object-shaped-but-unparseable content and reports the parser's own diagnostic (the JSON failed to parse: Expecting ',' delimiter near char N) instead ofmust be an ARRAY, giving the model a retryable signal. Themust be an ARRAYfallback is preserved for genuinely non-array-shaped garbage.Why here and not in acp-kernel
The issue suggested the repair in acp-kernel's
parseContentArray. I placed it in the adapter instead so this is a self-contained, single-repo fix — an acp-kernel change would require a cross-repo release (human PR merge + npm publish) before it could ship. The tail-repair could still be upstreamed to acp-kernel later so other hosts (opencode-acp) benefit; happy to open that as a follow-up if you want.Verification
tests/compress-tail-repair.test.ts(11 tests): single & multi-entry recovery, no-false-positive cases, trailing-whitespace tolerance, accurate error message, and an end-to-end tool test reproducing the compress tool: model emits array missing closing '}' before final ']' — misleading "must be an ARRAY" error, lenient parse doesn't repair one missing brace #253 payload (single ~6 KB entry with the dropped}) that previously rejected withno-valid-ranges … must be an ARRAYand now resolves successfully.npm run typecheckclean ·npm test439 pass, 0 fail (no regressions) ·npm run buildclean (dist 521.71 KB, repair present in bundle).Notes
versionbump (release-branch territory).