Skip to content

[PR] fix: use matched Codex windows for side request guards - #7206

Open
ReineLan wants to merge 1 commit into
ranxianglei:masterfrom
ReineLan:2026-11-19_guardian-model-window
Open

ReineLan wants to merge 1 commit into
ranxianglei:masterfrom
ReineLan:2026-11-19_guardian-model-window

Conversation

@ReineLan

Copy link
Copy Markdown
Contributor

Fixes #7205.

A Codex Guardian Responses request can resolve to bili's anonymous 200,000-token window even though the Codex model sources know codex-auto-review. The regular alignment can only clamp downward, so a matched window above the default never reaches the side guard.

Use model-specific Codex evidence for the Responses side guard when generic resolution has no native or operator window. Prefer the current live cache or catalog, with the bundled per-model entry as a fallback. These live sources already account for output headroom. An explicit headroom cap or a smaller upstream overflow arm retains the reservation. This is scoped to the existing side lane and keeps its raw passthrough and local oversize check.

Verification

  • Reproduced the local 413 on the unpatched branch using a Codex-shaped payload estimated at 244,108 tokens and a local fake upstream. The regression now forwards the original payload and checks that the parent session's state, usage, and snapshot are untouched.
  • The same regression checks both the bundled 272,000 and live 258,400 windows, oversize rejection before upstream, unknown model and non-Codex fallback, explicit operator limits and headroom, and a smaller learned overflow window.
  • 64 targeted tests passed across side-request-isolation.test.ts, codex-live-window.test.ts, and issue5243-codex-catalog-window.test.ts. npm run typecheck, npm run build, and git diff --check passed.
  • The real Codex plus provider suite was unavailable locally. The two production 413s were blocked before forwarding, so the mock upstream result cannot establish how the provider would have handled those calls.

This changes which evidence supersedes the anonymous fallback in one lane. Please give the window precedence and headroom behavior a maintainer review.

@ranxianglei ranxianglei changed the title fix: use matched Codex windows for side request guards [PR] fix: use matched Codex windows for side request guards Nov 18, 2026
@ranxianglei ranxianglei added bug Something isn't working codex p2 scope/wiring labels Nov 18, 2026
@ranxianglei

Copy link
Copy Markdown
Owner

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复 — 检索 open+closed issues/PRs("side request guard" / guardian 413 / codex window):相关项仅 closed #557、#1111(不同的 side-lane 主题),无其他 open PR 指向本线程;这是 #7205 的唯一修复 PR。

Maintainer review of the window precedence and headroom behavior (as requested):

Direction: the fix targets the root cause, not the symptom. The guard's effective window comes from the generic resolution result; when no native/operator window is found (nativeFromFallback), that result is the anonymous 200K default, and the regular Codex alignment can only clamp downward — so a matched window above the default never reaches the side guard. The PR feeds the guard the model-specific Codex evidence (live cache/catalog first, bundled per-model snapshot as fallback) exactly in that fallback case. It does not raise the 200K default or weaken the guard globally.

Precedence ladder (verified in code + tests, highest to lowest):

  1. Operator per-model pins (providers.<url>.models.<m>.context, compress.modelContextLimit) — still win; they clear the fallback flag so the new branch never fires (subtest: both 160K pins → 160K guard).
  2. Any generic/native window evidence (beta/suffix/plugin/runtime/launcher/configured/peek/table/registry) — unchanged; the branch requires nativeFromFallback && resolvedNativeWindow === undefined.
  3. (new) Matched Codex per-model evidence — live cache/catalog (258,400 = 272K × 95%) or bundled snapshot (272,000), only when it exceeds the anonymous default.
  4. Anonymous default 200K — unchanged for everything else.

Headroom behavior (verified):

  • Live evidence already nets Codex's own output headroom (effective_context_window_percent), so the bili-side output reservation is skipped — but only when the operator has not set an explicit outputHeadroomMaxPct (subtest: 0.25 → 258.4K − 50K = 208.4K guard, reservation kept) and the overflow arm does not constrain (subtest: arm 210K < 272K → arm governs, reservation kept, 160K guard).
  • Bundled snapshot is a raw window → reservation kept (subtest: maxOut=0 → no-op, 272K guard holds).
  • Non-Codex clients and unknown models stay at 200K (two subtests).

Regression review (existing behaviors on the touched path, each checked):

  • Side-request bypass of preflight/kernel state (标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388): preserved — guard still runs before passthrough; the test asserts parent session state/stats/snapshot are byte-identical and the body is forwarded verbatim.
  • Guard 413 response shape: unchanged.
  • Overflow arm (armedForGuard): preserved, explicitly retained when smaller than the new window.
  • Main pipeline window resolution (nudge bands, preflight wall): untouched — only the guard's inputs change.
  • Non-responses protocols, non-Codex UAs, models with generic evidence: byte-identical path (branch does not fire).
  • One intentional behavior change (disclosed): for responses-protocol side requests in the anonymous-fallback case, the guard's effective window goes from fixed 200K to the matched Codex window (up to 272K), and the block threshold moves from 230K (200K × 1.15) to 296.8K (258.4K × 1.15) for the incident shape. That is the fix itself.
  • Residual (pre-existing, out of scope, not a regression): a Codex deployment whose only window evidence is a large config.toml model_context_window with the model absent from the tables still gets the 200K guard — codex-config-window is deliberately excluded because it is not per-model evidence.

Tests: the new e2e is real — real proxy + fake upstream, exact window values asserted in the 413 message, upstream-hit counting, parent-session isolation, verbatim forwarding; 8 subtests cover the full precedence matrix. 64/64 targeted tests pass locally (side-request-isolation, codex-live-window, issue5243-codex-catalog-window); typecheck + build clean.

CI: 52 runs — 37 success, 14 skipped, 1 failure: test (ubuntu-latest, 22, 3), failing on #4982 e2e: draining same-lane predecessor + squatter (tests/issue4982-draining-twin-ladder.test.ts:384, "P1 must have registered itself"). That is a process-spawn lane-registration timing e2e, unrelated to this diff: it passes 7/7 locally on the PR branch, and the recent master merge 548e396 (PR #7083) shows the same one-red-test-lane pattern on a different e2e timing test (#5631 restart survival). Fleet-level e2e timing flake, not a regression from this PR. A re-run of the failed job should clear it.

Verdict: code correct, scoped to the side lane, well-tested; precedence and headroom semantics verified as described. Ready to merge once the flaky job re-run is green. Merge is owner-only.


中文八问

  1. 是什么问题:Codex Guardian 的 side request(responses 协议、codex-auto-review)被本地 413 误杀——guard 用匿名 200K 兜底窗口衡量,235K/242K token 的负载被拦,而该模型实际匹配窗口是 272K(内置快照)/ 258.4K(在线表 95%)。
  2. 什么原因导致的:side guard 的窗口取自通用解析结果;当没有任何 native/operator 窗口证据时(nativeFromFallback),该结果就是匿名 200K 默认值;常规 Codex 对齐只能向下钳制,匹配到的更大窗口永远到不了 guard。
  3. 影响范围与严重程度:仅 Codex responses 协议 side request 车道(Guardian review 等),且仅当模型只能靠 Codex 专属表/快照解析时触发;主会话车道不受影响。p2:车道可用但大负载被误拦,可绕行(缩短会话)。
  4. 怎么修复的:在通用解析落到匿名兜底的条件下,guard 改读模型专属 Codex 证据(在线缓存/目录优先,内置 per-model 快照兜底),窗口抬到匹配值;输出预留仅在"在线证据已含 net headroom + 运营未显式设上限 + 溢出 arm 不构成约束"三者同时成立时跳过。运营 per-model 钉死、显式 headroom 上限、更小的溢出 arm 全部保持优先。
  5. 是否有回归问题:已审既有行为——side request 绕过 preflight/kernel 状态(标题生成等侧请求污染主会话状态:prepareAnthropic 缺 isTitleGen 守卫、快照无条件覆盖、survivedCount 每请求空转 #388)保持;413 响应形状不变;溢出 arm 保留(210K arm → 160K 子测试);运营 per-model 钉死仍优先(160K 子测试);非 responses/非 Codex/有通用证据的路径字节级不变(分支不触发);主管道窗口解析未动。无 fail-fast 变吞错、无阈值漂移、无输出格式变化。有意变更一处(已披露):匿名兜底场景下 guard 有效窗口从固定 200K 变为匹配 Codex 窗口(最高 272K),拦截阈值 230K → 296.8K(258.4K×1.15)——即修复本身。残留(既有、非回归):仅有 config.toml 大窗口且模型不在表中的部署仍走 200K(config-window 源按设计排除,非 per-model 证据)。
  6. 是否破坏缓存:不涉及——未触碰缓存/重试/增量游标逻辑,改动仅限 guard 的窗口与预留输入。
  7. 是否改了设计方向:没有——复用既有证据阶梯(codexAlignedWindow)与文档化窗口层级(顶层 modelContextLimit 是 last-resort,见 docs/configuration.md),无架构/数据流转向。
  8. 是否引入新配置:无新 env/config/默认值。

标签:PR #7206 与源 issue #7205 已打 bug / p2 / codex / scope/wiring(Codex side-lane 守卫的窗口取值缺陷,可用但有误拦,按本 PR diff 独立判定)。

收工判定:代码正确、范围收敛、测试充分(本地 64/64 定向测试 + typecheck + build 全绿);CI 唯一红为无关 e2e 时序 flake(本地 7/7 通过,master 同期另一 e2e 同样红)。flaky job 重跑转绿后即可合并;合并由 owner 执行。

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.

Codex Guardian reviews can hit a false local 413 despite a known model window

2 participants