Skip to content

[PR] fix: honor native compaction JSON terminal status - #6136

Closed
Afloat16 wants to merge 2 commits into
ranxianglei:masterfrom
Afloat16:2026-11-10_fix-native-compaction-json-state
Closed

Afloat16 wants to merge 2 commits into
ranxianglei:masterfrom
Afloat16:2026-11-10_fix-native-compaction-json-state

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Problem

The JSON observer accepts any output array as completion even with failed, incomplete, cancelled, queued or in_progress status, scheduling an invalid context rebase. A normal error:null field conversely blocks a successful rebase.

Changes

Honor semantic failure states, keep pending/unknown statuses fail-closed, and accept null error on successful output. Status-less compact endpoint responses remain supported.

Validation

  • Nine new semantic-status cases fail against unchanged upstream source.
  • 27 tests passed in stream-terminal and native-compact-terminal suites.
  • Isolated local upstream/proxy integration checks that all five non-success states leave pendingRebase unset and completed output with error:null schedules it.
  • Final-code typecheck, npm build including dist checks, and git diff --check passed. Complete-suite verdict remains with CI.

Checked #323, #2311 and previous Afloat16 contributions. No kernel or configuration changes.

Base: e1e33a9.

Closes #6135

@ranxianglei ranxianglei changed the title fix: honor native compaction JSON terminal status [PR] fix: honor native compaction JSON terminal status Nov 10, 2026
…ror still fails

Additive review follow-up on PR ranxianglei#6136: the fix checks the error payload
before honoring status=completed, but no test pinned that ordering. A
{"status":"completed","error":{...}} body must stay failed so a
contradictory completion claim cannot schedule a rebase.
@ranxianglei ranxianglei added bug Something isn't working codex p2 scope/kernel labels Nov 10, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Duplicate screening: NOT a duplicate. Searched open + closed issues/PRs by failure signature (native-compaction terminal state / pendingRebase / observeJsonTerminalState), not just title wording. Lineage: extends #323 (which introduced the terminal-state gate); no other open fix targets #6135. Related-but-distinct: #6138 (same author, same base e1e33a9) fixes the SSE side of the same observer (event-framing dispatch, closes #6137) — different mechanism (JSON body classification vs SSE event framing), complementary, not a duplicate. Both touch src/stream-terminal.ts in non-overlapping hunks (this PR: observeJsonTerminalState near line 103; #6138: lines 4–70 SSE path), so whichever merges first, the other rebases cleanly.

Labels applied: bug, codex, scope/kernel, p2 — rebase-authorization defect in session-core context management; trigger requires an upstream 2xx JSON body carrying a non-success status, so exposure is narrow → p2, not p1.

Triage verification (performed locally, base e1e33a9 vs head 5caa9a1):

  1. Bug reproduced. With the new tests in place and only src/stream-terminal.ts reverted to base, exactly 10 cases fail (9 of the 10 new unit cases + the extended e2e case); with the fix, 27/27 pass. The 10th new unit case (status-less body) passes on base by design — it pins preserved behavior, so "nine new semantic-status cases fail against unchanged upstream source" is accurate.
  2. Root-cause layering. Symptom = invalid rebase authorization. Root cause = the JSON terminal classifier ignores the Responses-API status contract entirely: old code decided on error presence + output array presence alone, producing BOTH directions of misjudgment (false completion AND false failure) from one decision point. The fix corrects that decision point itself — no payload filtering, no masking.
  3. Regression audit — existing behaviors of observeJsonTerminalState (sole consumer: src/server/relay.ts:2082, only under prepared.resetAfterSuccess; non-2xx responses never reach it):
input shape old verdict new verdict assessment
{output:[…], status:"completed"} completed completed kept (#249 happy path)
{output:[…]}, no status completed completed kept (compact-endpoint form, explicitly tested)
{error:{…}} non-null failed failed kept
status ∈ {failed,incomplete,cancelled} + output completed failed intended fix
status ∈ {queued,in_progress,null,<other>} + output completed unknown intended fix, fail-closed
error:null + output failed completed intended fix
error:null, no output failed unknown both fail-closed; only the log word differs

Adjacent paths checked: the local codexForge intercept path serves the forged body and returns BEFORE any observation (src/server/relay.ts:355) — unaffected; SSE observer untouched; the non-2xx error path never reaches the observer — untouched.
4. Test validity. Assertions have teeth: exact TerminalState values in units; the e2e case drives a real proxy + fake upstream over HTTP and reads the actual nativeCompactionBoundary.pendingRebase from the session store, asserting undefined for all five non-success statuses and true for completed-with-null-error. Gate discipline (#3617) satisfied — both directions asserted. Deterministic (listen(0)).
5. Diff cleanliness / code quality. 3 files, +43/−1, single purpose; no version bump, no kernel/, no config surface, no lock churn. Naming and style consistent with the module; no dead code. One non-blocking nit: the three failure-status literals could be hoisted into a Set like the existing FAILED_EVENTS — cosmetic either way, left as-is.
6. Behavior-change disclosure (old → new): (a) error:null no longer fails a response — intended, it means "no error"; (b) explicit failure statuses now fail even without an error field — intended; (c) any other defined non-completed status (incl. null/numeric) now yields unknown instead of completed when an output array is present — intended fail-closed. All changes stay inside the rebase-authorization decision; wire format, persistence format, config schema untouched.
7. CI (live-verified at write time): all 12 test shards success, 0 failures on head 5caa9a1; static-gates / docs-coverage / unused-exports / mysql-contract / gates green; gated e2e lanes skipped as usual. Full-suite verdict: green.
8. Freshness: head is behind master by one merge (#5991, hermes env unroute) with zero file overlap; mergeable: true. Rebase is optional tidiness, not a blocker.

八问(结构化审核结论)

  1. 是什么问题:native compaction 的 JSON 终态观察器不认 status 字段——只要带 output 数组就判 completed,只要带 error 字段(哪怕 null)就判 failed,结果是不该 rebase 的会话被排了 rebase,该 rebase 的反而被挡住。
  2. 什么原因导致的:旧分类器只依据「error 是否存在 + output 是否为数组」两个信号做判决,完全绕过 Responses API 的 status 语义契约;假完成与假失败两个方向的症状同源于这一个决策点。
  3. 影响范围与严重程度:仅波及走 /responses/compact(或 compact-trigger 轮次)且上游返回 2xx JSON 的路径;OpenAI 官方错误多走 HTTP 错误状态码、不进该观察者,实际暴露面主要是第三方网关改写响应体的场景。后果是 bili 内部压缩态被无效重置(fold 块丢弃、ref 台账重锚、下一轮上下文膨胀),后续轮次可自愈,不构成不可用 → p2。
  4. 怎么修复的:在决策点补全状态机——非空 error → failed;显式失败态(failed/incomplete/cancelled)→ failed;其余任何已定义的非 completed 状态 → unknown(fail-closed);error:null 放行;无 status 的历史形状维持 completed。
  5. 是否有回归问题:既有行为矩阵逐项过完(见上表):Fix Codex Responses session continuity #249 happy path、compact 端点无 status 形状、非空 error 的失败判定全部保持;唯一附带变化是 {error:null} 且无 output 时日志措辞由 failed 变 unknown,两者均不触发 rebase。codexForge 本地伪造路径在观察之前短路返回、SSE 路径未动——无回归。
  6. 是否破坏缓存:不涉及缓存、重试、增量游标或去重键;改动仅限 rebase 授权判决本身。
  7. 是否改了设计方向:不改架构;是把观察器对齐到 Responses API 既有的 status 契约,与 fix: gate native-compaction rebase on semantic terminal state (#321 PR-C) #323 的门控设计同向。
  8. 是否引入了新的配置:无新配置项、env 或默认值。

Verdict: mergeable. Root cause fixed at the decision point, regression matrix fully closed, tests exercise the real pendingRebase state through a live proxy, CI green on head, diff clean. No commits pushed to the branch — nothing needed fixing. Independent of #6138 (if #6138 lands first, this one takes a trivial rebase; no semantic interaction).

@ranxianglei

Copy link
Copy Markdown
Owner

Landed via batch PR #6439 (merged) — closing as superseded.

Louie0806 pushed a commit to Louie0806/billion-context that referenced this pull request Nov 12, 2026
…ror still fails

Additive review follow-up on PR ranxianglei#6136: the fix checks the error payload
before honoring status=completed, but no test pinned that ordering. A
{"status":"completed","error":{...}} body must stay failed so a
contradictory completion claim cannot schedule a rebase.

(cherry picked from commit e5235f1)
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Confirmed, thread done. Progress note (my process was restarted mid-idle; the review itself finished and posted before that):

@ranxianglei ranxianglei reopened this Nov 14, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

(ai: vllm-qwen/qwen3.8-27b)

Final wrap-up for this thread (closing summary — details are in my review comment above):

What I did: full review of @Afloat16's fix for the JSON terminal-status observer (Closes #6135).

Evidence (all verified by me, locally + CI):

  • Bug reproduced at base: the 10 new cases (9 unit + 1 e2e) fail against unchanged upstream source.
  • At head: 27/27 pass in stream-terminal + native-compact-terminal suites; typecheck clean.
  • Regression matrix over every input shape of observeJsonTerminalState: only the intended transitions changed (error:null no longer fails; failed/incomplete/cancelled fail without an error field; other defined non-completed statuses → unknown/fail-closed; status-less responses unchanged). Sole consumer is src/server/relay.ts:2082 under resetAfterSuccess; SSE path untouched; no kernel/config/wire-shape changes.
  • Tests have teeth: the e2e runs a real local proxy and asserts pendingRebase is/isn't set.
  • CI on the pushed head: all 12 test shards green (verified live).

Verdict: mergeable.

Outcome: you landed the fix via batch PR #6439 (merged 2026-11-12, merge commit 873715d4) and closed #6136 as superseded. Re-verified live this session: the fix is on master (src/stream-terminal.ts:116-117 at tip 36a04a7986).

Remaining: nothing. One honest caveat: the shared GitHub API token is currently rate-limited, so I could not re-pull the PR object this minute, and the mirror still lists the thread as open — I read that as mirror sync lag, not a reopen. No follow-ups, no issues to file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Native compaction treats non-completed JSON output as a successful rebase

2 participants