feat: add parseCompressArgs — lenient compress-arg parsing with diagnostics - #111
Open
ranxianglei wants to merge 3 commits into
Open
feat: add parseCompressArgs — lenient compress-arg parsing with diagnostics#111ranxianglei wants to merge 3 commits into
ranxianglei wants to merge 3 commits into
Conversation
…ostics Single shared parser for compress tool arguments, replacing the five divergent strict parsers across the stack (kernel rebuild, proxy, pi, omp). Accepts fenced / trailing-comma / raw-newline / double-stringified / stringified-content shapes, salvages complete entries from truncated JSON prefixes (partial entries dropped, never guessed), and returns structured diagnostics (kind, rawPrefix, keys, invalidItems) as data for adapters to emit. rebuildCompressionState now recovers vLLM stringified content and truncated tool-call text instead of silently dropping them. Refs #108
…ars fallbacks Downstream validation (proxy/omp/pi) surfaced three real shapes the parser did not cover: - a single range at the top level with no content array (proxy drift) - top-level topic fallback (omp/pi schemas) - top-level summaryMaxChars (omp/pi schemas) All are now owned by the kernel so adapters can converge on it.
This was referenced Aug 22, 2026
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.
背景
跟踪 issue: #108
compress 参数解析目前散落在 5 个实现里,各自 strict
JSON.parse、各自静默失败:rebuild.ts(fork-recovery)Array.isArray(content);vLLM stringified content 静默丢全部压缩块safeJsonParsecatch →{}→ 模型收到Compression FAILED: no valid ranges parsednull,无日志生产事故形状:流截断(truncated JSON prefix)、markdown 围栏、尾逗号、字符串内裸换行、gateway 把参数 / 嵌套数组 stringify(vLLM,billion-context#176)。
改动
src/parse-compress-input.ts(新)parseCompressArgs(input, opts?: { callId }) → { ranges, diagnostics }contentcontent数组中完整的条目;partial 条目丢弃,绝不发明startRef | startId | messageId、endRef | endIddiagnostics是数据不是日志:kind∈ok | empty-input | not-object | missing-content | content-not-array | malformed-json | truncated | no-valid-ranges,附rawPrefix(≤800 字符)/length/keys/invalidItems;adapter 决定落点(日志 / debug event / tool result)src/rebuild.ts删除第 5 个实现(strictCompressInputEntry+extractRanges),换用parseCompressArgs——顺带修掉 vLLM fork-recovery 静默丢块src/index.ts导出parseCompressArgs+CompressParseDiagnostics/CompressParseKind/ParsedCompressInputDESIGN.md职责表加行:compress argument parsing (lenient) = core边界(不在本 PR)
compressRejects+rejectionFeedback)共用 streak 机制,见 统一 compress 参数解析(salvage + diagnostics)— 4 个实现收敛到内核 #108验证
npm test:424 pass / 0 fail(新增 30 用例:全部生产形状 + salvage 边界 + rebuild 回归——strict object 不变量 / vLLM stringified 恢复 / 截断 salvage / garbage 不重建)npm run typecheck干净;npm run build成功