Skip to content

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

Closed

Description

@Afloat16

Reproduction

At e1e33a9, observeResponsesTerminalState returns completed for {"status":"incomplete","output":[]}. Failed, cancelled, queued and in_progress statuses also complete when an output array exists. Conversely, {"status":"completed","error":null,"output":[]} fails.

Impact

The relay uses this verdict to authorize native-compaction rebase. A false completion can clear context state on the next turn even when compaction did not complete; null error also suppresses a legitimate rebase.

Expected behavior

Explicit failure states should fail, pending or unknown statuses should remain unknown, and null error should allow successful output. Status-less compact endpoint objects should keep their existing behavior.

Verified patch

Nine regressions fail on unchanged source. The fix passes 27 targeted tests, including a local upstream/proxy checking actual pendingRebase state for five non-success statuses and successful null-error output. Typecheck and build pass. This extends #323's native-compaction gate; #2311 addresses preflight summaries.

Activity

  1. added a commit that references this issue on Nov 10, 2026
  2. ranxianglei commented on Nov 10, 2026

    @ranxianglei
    Owner

    🤖 Powered by ework · qwen3.8-27b

    (ai: opencode/qwen3.8-27b)

    查重: 不重复 — but before touching code I listed open [PR] rows: this thread already has a fix PR #6136 (opened by the reporter). Per the one-fix-PR-per-thread rule I did not open a second PR; I independently verified #6136 against the report instead.

    Triage — verified live on current master:

    • Reproduced all six misjudged shapes through observeResponsesTerminalState: incomplete, failed, cancelled, queued, in_progress with an output array all return "completed"; {"status":"completed","error":null,"output":[]} returns "failed".
    • Root cause (src/stream-terminal.ts:104-108): the JSON path never reads status at all, and tests field presence (error !== undefined) rather than value — so OpenAI's standard success payload (error: null) fails while every non-success status completes.
    • Impact confirmed in code: src/server/relay.ts:2117 schedules the context rebase (markNativeCompactionBoundary) on any "completed" verdict — a false completion rebases onto a compaction that never happened and discards valid blocks (Fix Codex Responses session continuity #249 class); the null-error false-fail silently suppresses legitimate rebases.

    Verification of PR #6136 (head 5caa9a1d):

    • Diff: a 3-line semantics change in observeJsonTerminalState only; the SSE branch is byte-identical; no config/wire/kernel/persistence changes. Status-less compact-endpoint objects stay supported (new test pins {object:"response.compaction", output:[…]} → completed).
    • Regression sweep over pre-existing behaviors: non-null error → failed (kept); no-error + output array → completed (kept); no output / unparseable / empty / oversized body → unknown (kept). Every new delta is either the intended fix or fail-closed.
    • Targeted suites on the PR head: 27/27 pass (unit + relay-level e2e asserting real pendingRebase state for all five non-success statuses and the null-error success case). Against unfixed source, exactly the 9 new semantic cases fail — the regressions have teeth.
    • Typecheck clean, build clean on the PR head. CI on 5caa9a1d: 27 success / 1 skipped / 0 failed. Base e1e33a97 is an ancestor of master with zero churn on the three touched files since.

    Two small corrections I made directly (labeled commits / ops):

    1. No test pinned that {"status":"completed","error":{…}} still fails (the error payload must outrank the completion claim). Added one unit row as additive commit e5235f1ef8 on the PR branch — tests only, no source change. CI re-runs on the new head.
    2. The PR carried p2; per the severity policy, data-loss-class defects are p1 without downgrade — swapped to bug · p1 · codex · scope/kernel (issue side labeled the same).

    Behavior changes (old → new, all intentional):

    JSON body old verdict new verdict
    status: failed / incomplete / cancelled (+ output) completed failed
    status: queued / in_progress / unrecognized / non-string completed unknown
    status: completed, error: null, output: […] failed completed
    no status, error: null, output: […] failed completed ⚠️

    ⚠️ The last row is the one delta beyond the issue's letter ("status-less objects keep existing behavior"): the PR applies "explicit error: null = no error" uniformly rather than only on the completed path. No known provider emits error: null without a status field, so it is unobservable in current traffic — flagging it anyway so the owner can veto if they want the carve-out strict.

    Sibling facet tracked separately: #6137/#6138 (truncated SSE terminal header) is a different mechanism (SSE branch, line splitting) and stays out of this fix — untouched here.

    标签: bug · codex · scope/kernel · p1 —— 误判会让未完成的压缩触发上下文重基、丢弃有效块,属数据丢失类,按 2026-10-19 口径定 p1。

    八问:

    1. 是什么问题:原生压缩的 JSON 终态判定完全不看 status——任何带 output 数组的响应(哪怕 failed/cancelled/queued)都判成"完成",而真正的成功载荷(error:null)反而判成失败。
    2. 什么原因导致的:JSON 分支只查字段存在性(error !== undefined、output 数组在不在),从未读取 status;error: null 被当成"有错误"。
    3. 影响范围与严重程度:所有走 Responses 车道原生压缩的会话(codex 系 compact 端点/触发器)。假完成会在下一轮把上下文重基到一次从未发生的压缩上并丢弃有效块(Fix Codex Responses session continuity #249 同类,数据丢失);假失败静默压制合法重基。p1。
    4. 怎么修复的:JSON 判定先按语义读 status——显式失败态(failed/incomplete/cancelled)→ failed;待定/未知/非字符串状态 → unknown(fail-closed);仅 completed 放行到原有 error/output 检查,且 error:null 不再算错误。SSE 分支不动。
    5. 是否有回归问题:既有行为逐项审过——非空 error→failed 保持;无 error+output 数组→completed 保持(无 status 端点形态有测试钉住);无 output/不可解析/空体/超限→unknown 保持。唯一额外漂移:无 status 且 error:null 的对象从 failed 变 completed(已在上表披露),已知流量中不可观测。未发现其他回归。
    6. 是否破坏缓存:不涉及——纯出站终态观测,不触碰缓存键/前缀/重试/游标。
    7. 是否改了设计方向:不涉及——仍在 REQ: codex 压缩预算协调 + 匿名代理模式拦截伪造(根本解决方案) #321 PR-C 既有门内收紧判定,数据流不变。
    8. 是否引入了新的配置:不涉及。

    Verdict: #6136 is verified correct and complete for this issue — ready for your merge once CI goes green on e5235f1ef8. I can't merge PRs (system rules forbid it) — please merge yourself: #6136

  3. ranxianglei commented on Nov 12, 2026

    @ranxianglei
    Owner

    Fixed in batch PR #6439 (merged).

  4. added a commit that references this issue on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions