Repository navigation
fix: reject incomplete/failed Responses JSON summaries in preflight (#2309) - #2311
Conversation
…2309) The SSE path already treats response.incomplete / response.failed as unusable summary terminals (#780/#784); the JSON path had no terminal check, so an HTTP-200 application/json body declaring status=incomplete with incomplete_details.reason=max_output_tokens sailed through requestSummary whenever its partial text cleared MIN_SUMMARY_CHARS (50) and entered a compression block plus the forwarded history. - extractSummaryText: explicit status=incomplete/failed now rejects the body whatever its text length, across both the flat output_text shortcut and the output[] walk. Omitted status stays accepted (compat gateways). - diagnoseEmptySummary: new responsesTerminalDiagnosis names the terminal precisely with the raw reason/error embedded verbatim, running before extractStreamError so a failed response is not claimed by the weaker bare-error framing. - emptySummaryIsSizeDriven: reason=max_output_tokens classifies as size-driven (halving recovery, #726 semantics); other reasons keep the transient bounded re-draw path. - Regression tests: extractor/diagnosis/classifier units plus proxy AND plugin-mode integration (first answer incomplete JSON, later answers complete): partial text never reaches the wire; persistent-incomplete fails fast carrying the diagnosis and arms the dead-end cooldown. - Updated the #987 pinned assertion whose input (status=incomplete JSON) now routes to the precise terminal diagnosis instead of 'plain-JSON completion with empty content' (that string is false when partial text rides the body).
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.2444-pr.2311.d89e8ccThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr2311.tgz
npm install -g packageInstall instructions are refreshed on each push. |
[bot] 🏷 PR #2311 审查结论(fix: reject incomplete/failed Responses JSON summaries in preflight,Closes #2309) 已拉取分支核对代码、rebase 到当前 master ① 是什么问题:Responses 摘要以 HTTP-200 JSON 返回且声明 ② 什么原因导致的: ③ 怎么修复的:三处协同——(a) 抽取前拒收显式 ④ 是否有回归问题:无。逐项过过的既有行为:
⑤ 是否破坏缓存:不涉及。不触碰前缀缓存、重试预算、dead-end 冷却键或去重逻辑;冷却机制原样复用并有测试钉住(marker 置位、cooldown 期零上游调用)。 ⑥ 是否改了设计方向:不涉及。这是既有终态校验合同在 JSON 路径上的补齐,机制/数据流/架构均未转向。 ⑦ 是否引入新配置:不涉及。无新 env/config/默认值/CLI flag。 行为变更披露(旧→新):
验证证据(我在 rebase 后的当前 master 上独立复跑,非沿用作者自述):
判定:从代码 / 回归 / 测试有效性看,本 PR 正确、完整、可合并。合并前两项前置卫生:(1) 作者 rebase 到最新 master(现落后 132 commit, |
📦 Merged Build PublishedThis merge to master was published as npm install -g billion-context@0.0.104-master.bc30d58 # this exact build
npm install -g billion-context@master # always the newest merged build
|
Closes #2309
What
The SSE path already treats
response.incomplete/response.failedas unusable summary terminals (#780/#784); the JSON path had no terminal check. An HTTP-200application/jsonResponses body declaringstatus: "incomplete"(incomplete_details.reason: "max_output_tokens") sailed throughrequestSummary()whenever its partial text clearedMIN_SUMMARY_CHARS(50) — the fragment then entered a compression block and the history forwarded to the business model. Observed in production with an 824-char partial.How
extractSummaryText(Responses section): explicitstatus === "incomplete" | "failed"now returns empty whatever the text length, across both the flatoutput_textshortcut and theoutput[]walk. Omitted status stays accepted — compat gateways that never send it are untouched (context window problem continues #987 class).diagnoseEmptySummary: newresponsesTerminalDiagnosisnames the terminal precisely with the raw reason/error embedded verbatim (the upstream returned an incomplete Responses summary (status=incomplete, reason=max_output_tokens)), running BEFOREextractStreamErrorso a failed response is not claimed by the weaker bare-error framing. Shape guard: bad status without a recognizable Responses output shape keeps the generic diagnosis.emptySummaryIsSizeDriven:reason=max_output_tokensnow classifies as size-driven → halving recovery ([Bug] Codex 额度中断后恢复长会话,preflight SSE 摘要为空并持续 502 #726 semantics; the production case was exactly this reason). Other reasons keep the transient bounded same-span re-draw path.Scope is deliberately Responses-only: openai/anthropic JSON paths accepting
finish_reason=length/stop_reason=max_tokenspartials is consistent with their SSE leniency (#764/#780 design — those wires do not require terminals); only Responses was asymmetric (SSE strict vs JSON lenient).Behavior changes (old → new)
status=incomplete|failedused to be accepted when its text ≥ 50 chars; it now enters the existing unusable-summary chain (same-span re-draw for transient reasons, halving for size-driven, fail-fast + dead-end cooldown when nothing recovers). Completed and status-omitted bodies behave exactly as before.status=incompleteJSON body the operator-facing string changes fromthe upstream returned a plain-JSON completion with empty content (status=incomplete)tothe upstream returned an incomplete Responses summary (status=incomplete[, reason=<raw>]). The old wording was factually wrong whenever partial text rode the body. This string appears in proxy logs and the 502 fail-fast message; one context window problem continues #987 pinned test assertion updated accordingly (openai/anthropic empty-completion strings unchanged).billion-context.json, no new env vars, no CLI flags).Evidence
New suite
tests/preflight-incomplete-json.test.ts(unit + integration through the real proxy):preflight_compress_failedcarrying the new diagnosis, bounded summary calls, zero forwards, dead-end marker armed, cooldown spends zero upstream calls.Pre-patch run of this suite on unpatched behavior: 6/6 fail (three on exactly
the rejected partial text must NOT reach the forwarded history, one onsystemic incomplete summaries must fail-fast, got 200). Post-patch: 6/6 pass, plus all pre-existing preflight suites green (104 tests across the 15 files importingsrc/preflight.ts) and typecheck + build clean.