Skip to content

[PR] fix: preserve terminal content rejections and reported usage - #6835

Open
ZhaoJun233 wants to merge 8 commits into
ranxianglei:masterfrom
ZhaoJun233:2026-11-15_content-rejection
Open

ZhaoJun233 wants to merge 8 commits into
ranxianglei:masterfrom
ZhaoJun233:2026-11-15_content-rejection

Conversation

@ZhaoJun233

@ZhaoJun233 ZhaoJun233 commented Nov 15, 2026 •

Copy link
Copy Markdown

Summary

Closes #6832.

Explicit HTTP 400 content verdicts terminate compatibility recovery, preserve the latest response and reported usage, and do not teach a reasoning compatibility posture from quoted diagnostics.

HTTP 400
  explicit content verdict -> preserve error + usage; stop
  ordinary validation      -> existing compatibility recovery

Evidence

  • Before: Eight role/cache-key regressions failed on earlier master 1ee510c. On the current candidate, 12 direct/later-verdict proxy/plugin cases also reproduced incorrect reasoning posture learning; Anthropic EOF could lose already-reported output usage.
  • After: 212 targeted tests pass against base 2e3cfc9, including response status/body/headers/request IDs, exact retry counts, committed blocks, thinking and cumulative usage. Local typecheck, build and architecture guard pass. The architecture pages and diagrams describe this branch's behavior.
  • Fixtures use synthetic data and local HTTP upstreams. Full remote CI passed on ff934e8, including all 11 test shards: CI run. The originating provider's content policy and matched content remain unknown.

Merge Danger

Door: two-way

Blast Radius: transport

Changes terminal-error and usage handling across adapters. Ordinary compatibility errors retain their recovery paths. Kernel, schema and release version are unchanged. Human review is required before merge.

@ranxianglei ranxianglei changed the title fix: preserve terminal content rejections and reported usage [PR] fix: preserve terminal content rejections and reported usage Nov 15, 2026
@ZhaoJun233
ZhaoJun233 marked this pull request as ready for review November 15, 2026 14:51
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。检索 open+closed 的 issue/PR,无其他内容拦截判定(content-blocked / agent_router_content_blocked)修复在途;仅本 PR 与两条无关的已关闭项。

Review of PR #6835 (draft): I checked out the branch, ran typecheck (clean), the new test file (12/12 pass), the modified loop/adapter/wire-contract suites, and read the full diff. Remote CI is all green (30 checks, 0 failed, 0 pending — all test shards windows+ubuntu × node 22/24, static-gates, mysql-contract, unused-exports).

What I verified locally:

  • parseContentRejection (src/util.ts:581) is a correctly-scoped narrow evidence-permitlist — only the two observed signatures (code==="content-blocked" OR type==="agent_router_content_blocked", status 400), safe JSON.parse in try/catch, request IDs appended only if not already present. It deliberately does NOT key off quoted words in the message.
  • Every compatibility-recovery path is gated on it: role-rejection ladder (relay.ts:1439-1448, hop preserves a repair's verdict at 1511-1524), PCK probe, overflow-cap, strip-thinking degraded retry (core.ts:1874), and strictReasoningEcho learning (core.ts:1932). A content verdict terminates recovery, preserves its error + usage, and does not teach a reasoning posture.
  • The Anthropic EOF usage preservation (adapter-anthropic.ts:784) is guarded by !usageYielded — no double-yield; it only fires when a round* value was reported.
  • No usage double-count: settleAttemptUsage() records the original attempt and the return/continue prevents reaching the round-level recordUsage for the same attempt.
  • The new test (tests/content-rejection-compat.test.ts) is a real 12-case matrix (3 repair types × 2 plugin modes × 2 duringRepair) with teeth: asserts no sends after the verdict, status 400, terminal verdict preserved over the earlier validation error, x-request-id preserved, strictReasoningEcho NOT learned, and the legitimate output-budget retry preserved. Not a tautology.

One note on local test failures (not a PR regression): running the modified loop suites against the shared on-disk session store produced 5 failures in tests/loop-compress.test.ts. I confirmed these are environment, not code: (1) the same 4 pre-existing tests fail identically on the base commit 2e3cfc9; (2) in a clean XDG_DATA_HOME the whole file passes 16/16 including the new test. Root cause is the fixed session id loop-compress-test colliding with stale state in the shared store (rejected stale snapshot + a stale index.db schema missing orphans_json). Remote CI runs hermetic and is green, which is the authoritative verdict.

Code cleanliness (external-contribution bar): naming is clear, no dead code, no duplication (single parseContentRejection reused at every site), comments explain the why, no new dependencies, no config surface added, wire-contract rule WC-026 added with provenance, architecture docs/diagrams updated. No issues found.

Verdict: mergeable once the draft is finalized. The fix is correctly scoped to the root cause (the recovery paths had no way to distinguish an explicit content verdict from an ordinary validation error), narrow enough to avoid false positives, well-tested, and CI-green.


结构化八问(中文):

  1. 是什么问题: 显式的 HTTP 400 内容拦截判定(content-blocked / agent_router_content_blocked)被当成普通兼容性错误处理——进入兼容性恢复(role/pck/overflow-cap 修复、strip-thinking 重试),丢失了终局判定和已报告的 usage,还会从被引用的诊断文本里错误地学习 reasoning 兼容性姿态。

  2. 什么原因导致的: 根本原因是各错误处理路径(role-rejection ladder、PCK probe、overflow-cap、strip-thinking 重试、strictReasoningEcho 学习)没有区分「显式内容拦截判定」与「普通校验错误」的机制——它们靠错误消息文本(可能引用 reasoning 字段)判断,而不是靠 provider 的显式身份(code/type)。于是判定里被引用的诊断文本被误读为「role 错 / cache-key 错 / context 超」的证据,触发恢复,结果:(a) 用早期校验错误替换了终局判定,(b) 丢失已报告 usage,(c) 错误学习 strictReasoningEcho。

  3. 影响范围与严重程度: 命中 GPT-6/agent_router 显式内容拦截(2 个已观测签名)的用户。p2——仍能用 bili,但看到误导性错误、丢失 usage(计费/统计不准)、并学到错误兼容性姿态(后续请求可能被错误改写,影响累积)。非完全不可用,但有明显问题。

  4. 怎么修复的: 新增 parseContentRejection(窄证据白名单,只匹配 2 个已观测签名),让所有兼容性恢复路径受它门控:不进入 role/pck/overflow-cap 修复、不触发 strip-thinking 重试、不学习 strictReasoningEcho、保留该响应的 error+usage(不被早期校验错误替换)、捕获并保留 x-request-id;adapter-anthropic.ts 的 EOF 保留 message_start 已报告 usage(!usageYielded 门控,不双重 yield)。

  5. 是否有回归问题: 无。parseContentRejection 对除 2 个签名外的一切返回 null,其他错误路径既有行为不变;usage 保留由 !usageYielded 门控;CI 全绿(30 项 0 失败)。本地 5 个 loop-compress 失败已验证为环境问题(固定 session id + 共享存储过期状态),base commit 同样失败、干净存储下 16/16 通过,非 PR 回归。

  6. 是否破坏缓存: 否。不涉及缓存/重试/去重逻辑;x-request-id 仅用于错误消息,不用于缓存。

  7. 是否改了设计方向: 否。现有错误处理架构内的定向修复,新增一个检测函数并让现有路径受其门控,无架构变更。

  8. 是否引入了新的配置: 否。无新配置/env/CLI 标志。

判定: 可合(draft 定稿后)。

@ZhaoJun233

Copy link
Copy Markdown
Author

回应这条评审,逐项补充当前状态:

  1. 识别范围与恢复边界。 仍只识别 HTTP 400 下已观测到的两种结构化身份:error.code=content-blocked 或 error.type=agent_router_content_blocked。消息中引用 role、cache-key、overflow、thinking 等诊断词不会扩大匹配范围;其他校验错误保留原恢复路径。合法兼容性重试后来收到内容拒绝时,以后来那份响应为终局,保留其状态、正文和响应头。12 项矩阵同时覆盖直接拒绝、恢复后拒绝及两种模式。
  2. usage 与 reasoning 姿态。 只结算上游已经报告的 usage;Anthropic EOF 分支受 !usageYielded 约束,避免重复产出。内容拒绝也不会触发 strictReasoningEcho 学习。这项修复不代表上游请求未收费,也不推算缺失的 usage。
  3. 本地共享存储失败。 你给出的 base 对照和独立存储结果支持将那批失败归入测试环境。这里没有据此放宽断言;合入证据采用当前提交的远端隔离 CI。
  4. 缓存与重试的表述。 更精确地说,本 PR 确实改变了这类终局错误的兼容性重试决策,包括跳过 pck 探测;没有改 prompt-cache key 的构造或存储格式。WC-026 的公开出处已指向 Explicit content rejections enter compatibility recovery and can lose verdict or usage #6832。
  5. 当前状态。 已转为 ready for review。提交 ff934e8c25667c4afca90f3f20fd0d257d7706b7 的完整 CI通过,11/11 个 test 分片成功;本地相关定向测试 212 项通过。以上是该提交的验证结果,合入仍由维护者审查决定。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

逐条确认,并采纳第 4 点对我八问 #6 的澄清。

  1. 识别范围与恢复边界 — 一致。窄证据白名单(仅 content-blocked / agent_router_content_blocked,HTTP 400)不靠消息里引用的诊断词扩大匹配;其他校验错误保留原恢复路径;合法重试后来收到内容拒绝时以后来那份为终局(保留状态/正文/响应头)。12 项矩阵覆盖直接拒绝、恢复后拒绝、两种模式,与我本地读到的行为一致。

  2. usage 与 reasoning 姿态 — 一致。只结算上游已报告的 usage;Anthropic EOF 分支受 !usageYielded 约束不重复产出;内容拒绝不触发 strictReasoningEcho 学习;不推算缺失 usage、不暗示未收费。

  3. 本地共享存储失败 — 一致。base 对照 + 独立存储结果支持归入测试环境;你们没有据此放宽断言,合入证据用远端隔离 CI,这是对的。

  4. 缓存与重试表述 — 采纳澄清,修正我八问 fix: post-merge review fixes + per-route context window + XDG config #6 的措辞。准确表述应为:本 PR 改变了这类终局错误的兼容性重试决策(内容拒绝跳过 pck 探测、role 阶梯、overflow-cap、strip-thinking 重试),但没有改 prompt-cache key 的构造或存储格式。原 fix: post-merge review fixes + per-route context window + XDG config #6「不涉及缓存/重试/去重逻辑」对「重试」的表述过宽,已纠正;「不破坏 prompt-cache key 构造/存储」的结论维持。

  5. 当前状态(已实时核实) — 我刚通过镜像缓存核对该提交 ff934e8c25:state=open,已转 ready for review(mergeable_state 由 blocked→behind,behind 仅表示 base 落后 master,非阻塞);CI 30 项 0 失败 0 待处理(15 success + 15 skipped,含全部 test 分片、static-gates、mysql-contract、unused-exports)。与你们所述一致。

判定维持:可合。 修复打在根因上(恢复路径无法区分显式内容判定与普通校验错误),范围窄、测试有牙、CI 全绿、外部贡献整洁度达标。合入由维护者决定。

ZhaoJun233 and others added 4 commits November 16, 2026 17:33
…lict)

Single conflict: tests/issue2929-codex-fold-double-miss.test.ts. Master rewrote the ranxianglei#2929 fold probe to be schedule-independent (245ecb1, 7247410) after this PR's last master-sync; the PR's latest CI commit (86c0790) had pinned the same nudge cadence via NUDGE_GROWTH_TOKENS + kernelConfig nudge tuning on the old fixed-index structure. Resolved by taking master's schedule-independent probe verbatim — it subsumes the PR's determinism goal and is the tested CI-green baseline. The PR's content-rejection fix (parseContentRejection + recovery-path gating) is fully preserved in the cleanly-merged src files. Verified: typecheck clean; issue2929 probe passes; content-rejection-compat 12/12 pass.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI conflict resolved for PR #6835 — merge state dirty → blocked (mergeable, waiting on review/CI).

What I did this run

  1. Fetched live state: master tip 6a641f37, PR head 86c0790d (branch 2026-11-15_content-rejection), PR base 301e1a54 — master was 26 commits ahead.
  2. Merged origin/master into the PR head (merge, not rebase — no force-push needed).
  3. Resolved the single merge conflict (see below) and pushed the merge commit 241a861ec6 (fast-forward on the fork).
  4. Verified locally: typecheck clean; the resolved probe passes; the PR's content-rejection-compat suite passes 12/12; the parseContentRejection gating is intact across src/util.ts, src/fetch-util.ts, src/loop/core.ts, src/server/relay.ts.

The conflict (semantic, one test file) — tests/issue2929-codex-fold-double-miss.test.ts

  • Master rewrote the codex 命中率问题分析 #2929 fold probe to be schedule-independent (commits 245ecb1a9e, 7247410976) after this PR's last master-sync: it arms the fold on "first nudge-carrying request with ≥11 refs" instead of fixed request indices, and pins messageTimestamps:false for a hermetic wire shape.
  • The PR's latest CI commit (86c0790d "pin cache probe cadence") had pinned the same nudge cadence via NUDGE_GROWTH_TOKENS + kernelConfig.nudge.minGrowthFloor/minGrowthRatio on the old fixed-index structure.
  • Both sides were fixing the same flakiness (nudge-schedule drift). Master's schedule-independent approach subsumes the PR's determinism goal and is the tested CI-green baseline.
  • Resolution: took master's probe verbatim. The PR's actual content-rejection fix (the parseContentRejection evidence-permitlist + recovery-path gating) lives entirely in the cleanly auto-merged src/ files and is untouched.

Current state

  • PR head: 241a861ec6 (merge of 86c0790d + master 6a641f37); fork head matches.
  • mergeable: true, mergeable_state: blocked (was dirty — conflict cleared; "blocked" = waiting on required review/CI, normal).
  • CI: 25 checks queued on the new head (final-head push, no [ework:ci-held] marker → the branch's one full CI pass).

No design decision needed, no new issue, no labels. Waiting on CI.


结构化八问

  1. 是什么问题:PR [PR] fix: preserve terminal content rejections and reported usage #6835 与 base 分支(master)产生合并冲突(merge state: dirty),无法合并。
  2. 什么原因导致的:冲突集中在单个测试文件 tests/issue2929-codex-fold-double-miss.test.ts。master 在本 PR 上次同步 master 之后,把 codex 命中率问题分析 #2929 fold 探针重写为「调度无关」(按「首个带 nudge 且 ≥11 refs 的请求」触发 fold,而非固定请求下标,并钉死 messageTimestamps:false);而本 PR 最新的 CI 提交 86c0790d 还在旧的固定下标结构上用 NUDGE_GROWTH_TOKENS + kernelConfig nudge 调参去钉同一个 nudge 节奏。两边修的是同一处测试抖动,结构对不上,git 无法自动合并。
  3. 影响范围与严重程度:仅该 PR 的合并被阻塞(dirty),不影响线上行为、不影响其他 PR。属流程性阻塞,非功能缺陷。
  4. 怎么修复的:用 merge(非 rebase,避免 force-push)把当前 master(6a641f37)并入 PR 头(86c0790d);冲突文件取 master 的调度无关探针版本(它涵盖了 PR 想要的确定性目标,且是 CI 已验证的基线)。PR 真正的内容拦截修复(parseContentRejection + 各恢复路径门控)全部在干净自动合并的 src/ 文件里,未受影响。本地验证:typecheck 通过、该探针通过、content-rejection-compat 12/12 通过。
  5. 是否有回归问题:无。冲突文件取的是 master 当前 CI 绿的版本;PR 的内容拦截逻辑逐处核对仍在(util / fetch-util / core / relay 各门控点);typecheck 全绿。
  6. 是否破坏缓存:否。未触碰 prompt-cache key 构造、存储格式、去重键或重试策略。
  7. 是否改了设计方向:否。纯合并冲突解决,未引入任何新方向。
  8. 是否引入了新的配置:否。无新 env / config / CLI 标志。

判定:冲突已解决并推送(241a861ec6),PR 由 dirty → blocked(可合并,待 review/CI)。等待 CI 结果。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

2 similar comments
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

ci-check added 2 commits November 18, 2026 14:20
…2nd conflict)

Master advanced 6a641f3..4b77eab (~40 commits, incl. Pi Anthropic full-request compat, preflight egress-fuse fold, cache-mark pinning) after the prior conflict resolution. Re-merged the new master.

Conflicts (2, both auto-generated architecture docs, module-ledger hunk):
- docs/architecture.md + docs/architecture.zh-CN.md: the pipeline row one-liner (PR: 'terminal content rejection / usage' vs master: 'handle / prepare-* / relay / inject') and the lanes row (master added 'Pi Anthropic full-request compatibility'). Resolved by union: kept master's structural pipeline description + the PR's behavior note, and took master's lanes row (superset).

All src/loop/* (adapter-anthropic/google/openai/responses, core.ts) and tests/loop-compress.test.ts auto-merged cleanly; the PR's content-rejection fix (parseContentRejection + recovery-path gating) is fully preserved.

Verified locally: typecheck clean. The 7 loop-compress.test.ts failures are environmental (Node v22.23.2 sandbox) — they fail identically on master alone (6) and on the PR head (5, incl. the PR-added content-rejection test); both CIs are/were green on GitHub. The merge's failure set is exactly the union of those; zero new failures introduced. PR's content-rejection-compat suite passes 12/12; issue2929 probe passes.
Master advanced 4b77eab..548e396 (3 commits: wire-client sidecars ranxianglei#7083, Windows-portable shutdown-signal test) while resolving the prior conflict. Clean auto-merge — the 3 commits touch src/server/handle.ts + side-lane/shutdown tests, none of which the PR modifies. typecheck clean.
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

CI conflict re-resolved for PR #6835 — the conflict had re-appeared because master advanced ~40 commits after my previous resolution. Merge state dirty → blocked (mergeable, waiting on review/CI) again.

What I did this run

  1. Verified live state: my previous merge (241a861ec6) was still the PR head, but master had moved 6a641f37 → 4b77eab409 → 548e396022 (batch merges landing continuously).
  2. Merged the new master into the PR head. Because master kept moving mid-run, I did two merges: 4b77eab409 (the conflict source) then 548e396022 (to track the moving master before pushing).
  3. Resolved the 2 conflicts (both auto-generated architecture docs) and pushed the final head 161d0c5392 (fast-forward, no force-push).
  4. Verified locally: typecheck clean (run twice); the PR's content-rejection-compat suite passes 12/12; the parseContentRejection gating is intact.

The conflict (2 auto-generated doc files, one module-ledger hunk each)

  • docs/architecture.md + docs/architecture.zh-CN.md: the pipeline row one-liner (PR: "terminal content rejection / usage" vs master: "handle / prepare-* / relay / inject") and the lanes row (master added "Pi Anthropic full-request compatibility").
  • Resolution: union of intent — kept master's structural pipeline description + the PR's behavior note, and took master's lanes row (superset).
  • All src/loop/* (adapter-anthropic/google/openai/responses, core.ts) and tests/loop-compress.test.ts auto-merged cleanly; the PR's content-rejection fix is fully preserved.

On the 7 loop-compress.test.ts failures (not caused by this merge)
I confirmed these are environmental (this sandbox, Node v22.23.2), not merge-induced:

  • 6 of the 7 fail on master alone in this sandbox (yet master's CI is green on GitHub).
  • The 7th (the PR-added "content rejection after committed compression") fails on the PR's own head in this sandbox (yet the PR's CI was green on GitHub).
  • The merge's failure set is exactly the union of those two sets → zero new failures introduced by the merge. CI on GitHub runs in the proper environment and will be the authoritative verdict.

Current state

  • PR head: 161d0c5392 (includes master up to 548e396022); fork head matches.
  • mergeable: true, mergeable_state: blocked (was dirty — conflict cleared; "blocked" = waiting on required review/CI, normal).
  • CI: 28 checks running on the new head (final-head push, no [ework:ci-held] marker → the branch's full CI pass).

No design decision, no new issue, no labels. Waiting on CI.


结构化八问

  1. 是什么问题:PR [PR] fix: preserve terminal content rejections and reported usage #6835 再次与 master 产生合并冲突(merge state: dirty)——上一次解决冲突后,master 又前进了约 40 个提交。
  2. 什么原因导致的:master 在我上次合并(基于 6a641f37)之后持续前进(4b77eab409 → 548e396022,多为 batch 合并)。冲突集中在两个自动生成文档 docs/architecture.md / .zh-CN.md 的模块总表同一处:PR 把 pipeline 行一句话改成了「终止性内容拒绝/用量结算」,而 master 把 lanes 行加了「Pi Anthropic 全量请求兼容」,两边对同一表格行做了不同修改,git 无法自动合并。(src/loop/* 代码两边虽都改但区域不重叠,全部自动合并干净。)
  3. 影响范围与严重程度:仅该 PR 的合并被阻塞(dirty),不影响线上行为、不影响其他 PR。属流程性阻塞,非功能缺陷。
  4. 怎么修复的:merge(非 rebase,避免 force-push)把新 master 并入 PR 头;因 master 在运行中持续前进,做了两次合并(4b77eab409 解决冲突源 + 548e396022 推送前追踪最新 master)。两个文档冲突按「意图并集」解决:保留 master 的结构性 pipeline 描述 + PR 的行为注记,lanes 行取 master 超集。PR 的内容拦截修复(parseContentRejection + 各恢复路径门控)全部在干净自动合并的 src/ 里,未受影响。
  5. 是否有回归问题:无。typecheck 两次全绿;PR 的 content-rejection-compat 12/12 通过;loop-compress.test.ts 的 7 个失败经三向对照(master 单独 / PR 头 / 合并后)确认全部为沙箱环境问题(Node v22.23.2,压缩标记断言),master 单独跑就挂 6 个、PR 头单独跑就挂 5 个(含 PR 新增的那个),合并后的失败集合恰好是两者之并——本次合并未引入任何新失败。GitHub CI 会在正确环境跑,是最终判据。
  6. 是否破坏缓存:否。未触碰 prompt-cache key 构造、存储格式、去重键或重试策略。
  7. 是否改了设计方向:否。纯合并冲突解决,未引入任何新方向。
  8. 是否引入了新的配置:否。无新 env / config / CLI 标志。

判定:冲突已解决并推送(161d0c5392,已含最新 master 548e396022),PR 由 dirty → blocked(可合并,待 review/CI)。等待 CI 结果。

@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

[ework] CI fix verified green ✓

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit content rejections enter compatibility recovery and can lose verdict or usage

2 participants