Skip to content

[PR] fix: raise a fallback-sized codex session to bili's own model window (#7205) - #7517

Merged
ranxianglei merged 5 commits into
masterfrom
fix/codex-window-raise
Nov 23, 2026
Merged

ranxianglei merged 5 commits into
masterfrom
fix/codex-window-raise

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

这是啥问题?

宿主的 codex 会话如果一开始落在 bili 的 fallback 窗口(比如 272K 以下),之后永远不会变大:即使 bili 自己的模型窗口是 1M,这个会话也只能在旧的小窗口里压缩,白白损失上下文长度。(#7205)

根本原因

src/codex-models.ts 的窗口对齐逻辑只做"向小收"(bili 窗口 < 宿主窗口时收窄),没有"向大抬":会话在 fallback 窗口建立后,对齐函数拿到 bili 的更大窗口也不会把会话抬上去。

怎么修的

  • codexAlignedWindow(limit, model, headers, clientWindow?, canRaise = false) 新增 canRaise 参数。
  • src/server/handle.ts 只在bili 因 fallback 拿到了小于模型真实窗口的值时传 canRaise = true(nativeFromFallback),即"bili 自己降级过,才允许把会话抬回 bili 的模型窗口"。
  • 抬升直接采用对齐后的 limit,不走 windowShrinkReason(窗口变大不是 shrink,不给客户端发缩小提示);client-metadata 路径(宿主自己报的窗口)永远不抬。

影响面

  • 只有 codex 车道、且 bili 走过 fallback 的会话:窗口从 fallback 值抬到 bili 模型窗口。
  • 其他一切行为不变(默认参数 canRaise=false,老调用点原样)。

测试

  • 新增 tests/issue7205-codex-window-raise.test.ts(8 用例:fallback 抬升、不抬 client-metadata、抬升不发 shrink 提示、isCodexClient 判定等)。
  • 回归 codex-models.test.ts 10/10、tsc --noEmit 0。

风险

低。抬升只发生在 bili 自己降级过的场景,且是向大不是向小(客户端看到的可用窗口变多,不会因"窗口变小"触发重发/截断类连锁)。

Refs #7205

…7205)

An anonymous alias (e.g. codex-auto-review) matched no window source in the
native ladder, so bili kept its generic 200K anonymous default while bili's
own codex-fallback path knew the model accepts 272K — every payload between
the two died on bili's LOCAL 413 wall below the point the model actually
accepts.

codexAlignedWindow gains an opt-in canRaise (off by default, byte-identical
behavior): handle.ts passes nativeFromFallback so the raise only fires when
bili's number came from the generic fallback. Client-declared windows are
never raised; clamping still wins; source is preserved so the #5243
headroom accounting is untouched. New 8-case pin
tests/issue7205-codex-window-raise.test.ts.
@ranxianglei ranxianglei changed the title fix: raise a fallback-sized codex session to bili's own model window (#7205) [PR] fix: raise a fallback-sized codex session to bili's own model window (#7205) Nov 22, 2026
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: fix/codex-window-raise (a3e586b)

Latest build — install this exact version

npm install -g billion-context@0.0.11572-pr.7517.b849664

This exact version is immutable and reproducible. The rolling pr tag tracks the newest test build across all PRs.

Recent builds (commit → version)

commit version build
a3e586b billion-context@0.0.11572-pr.7517.b849664 build
a77ed0e billion-context@0.0.11534-pr.7517.b6edd4b build
2335489 billion-context@0.0.11533-pr.7517.957c4e5 build
7e0c878 billion-context@0.0.11451-pr.7517.c5c6e9e build
108c45b billion-context@0.0.11342-pr.7517.8ed1093 build
a1d7e6d billion-context@0.0.11332-pr.7517.af6b819 build

Download artifact

  1. Download the artifact from the Actions run
  2. Extract the tarball and install:
tar xzf billion-context-pr7517.tgz
npm install -g package

Install instructions are refreshed on each push.

codexAlignedWindow (codex-models.js) and FALLBACK_EFFECTIVE_WINDOW_FLOOR
(config.js) were imported in src/server.ts but never referenced there —
the real codexAlignedWindow usage is src/server/handle.ts:17, and both
modules stay loaded through other imports, so module init order is
unchanged. Pre-existing on master; found while reviewing #7517.
@ranxianglei ranxianglei added bug Something isn't working codex p2 scope/wiring labels Nov 22, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

[bot] 🏷 (ai: vllm-qwen/qwen3.8-27b)

查重: 不重复(机制不同),但与 open PR #7206 同修 #7205 —— 见下方「与 #7206 的关系」,这是本轮 review 最重要的发现。

标签: 已打 bug / codex / scope/wiring / p2(Codex 车道窗口对齐缺陷,可用但上下文长度被浪费,非数据丢失/缓存泄露,故 p2 不升 p1)。


Review 结论:代码正确、范围收敛、测试充分,可合(合并由 owner 执行)

方向(① 原 issue): 打到根因,不是治标。#7205 的本质是 codexAlignedWindow 只会「向小收」(clamp),不会「向大抬」——会话在 fallback 窗口(200K)建立后,bili 自己知道模型真实窗口是 272K 也不抬。本 PR 给对齐函数加 canRaise,且只在 bili 自己走过 fallback(nativeFromFallback)时才允许抬——即「bili 自己降级过,才把会话抬回 bili 的模型窗口」。这是根因修复,不是在某一层过滤症状。

回归审查(② 逐项过既有行为):

  • 默认 canRaise=false,所有老调用点字节级不变。
  • 抬升只在 nativeFromFallback 为真时发生——operator 调优 / configured / registry / plugin 上报的窗口永不抬(这些是权威源,不是 bili 的猜测)。
  • client-metadata 路径(宿主自己报的窗口)永不抬,只 clamp——宿主的自我声明对它自己是权威的(它可能故意压到模型最大值以下)。
  • 抬升不发 windowShrinkReason(窗口变大不是 shrink,不给客户端发缩小提示)——正确,避免触发「窗口变小」类的重发/截断连锁。
  • 下游清点:side-request guard(handle.ts:2854 读 reqConfig.modelContextLimit)→ 抬升后 guard 用 272K,事故负载解阻;WorkBuddy tier aliases (fast-model / balanced-model) are absent from bili's built-in window table, so the window silently falls back to 200000 and the effective wall collapses to 152000 — mid-session, after a model switch #5490 first-sight warn(handle.ts:1911)抬升后 nativeFromFallback=false 被抑制(一致:不再是匿名兜底);FALLBACK_EFFECTIVE_WINDOW_FLOOR(handle.ts:3084)抬升后不再适用(与 clamp 分支同等待遇)。
  • 一处表面瑕疵(非行为 bug):抬升后 wsSourceForLog 仍是 "default"(在 alignment 之前赋值),所以 [window-change] 行会记 model/default/272000——source 标签略 stale。但 landsOnAnonymousDefault = curRes.s==="default" && nativeFromFallback 因 nativeFromFallback=false 正确判 false(无误报),且抬升行本身记了真实 source;clamp 分支存在同样的 stale(已被接受)。可接受,不拦。

代码审查(③): 机制干净——alignedResult 仅当 canRaise && w>limit 返回 raised:true;clamp(limit>w)优先;handle.ts 新分支正确更新 reqConfig、清 nativeFromFallback、设 codexWindowNetsOutput、打日志。所有被重新赋值的变量都是 let。

测试有效性(④): 新增 8 用例,正负双向(gate 纪律 #3617):非 codex 不抬、默认关 pin(不抬,钉住 PR 前行为)、bundled-snapshot 抬 200K→272K、未知 slug 抬到 flat 272K(codex-fallback)、clamp 优先(400K→272K)、client-declared 永不抬(×2)、shipped-snapshot sentinel 200K→372K(证明用真实快照值而非硬编码 272K)、isCodexClient 前缀。deepEqual 断言完整形状(含 raised 标志)——有牙。CODEX_HOME 用临时目录隔离 live table(确定性)。与既有覆盖层级一致(clamp 分支也没有 handle 级测试)。本地 18/18 通过 + tsc --noEmit 0。

diff 整洁度(⑤): 干净——3 文件(codex-models.ts / handle.ts / 新测试),无无关改动、无空行重排。


与 #7206 的关系(重要)

open PR #7206(ReineLan,2026-11-18,#7205 的报告者)也写 "Fixes #7205",但机制不同:

#7206(ReineLan) #7517(本 PR,owner)
改哪 只喂 side-request guard 模型专属 Codex 证据 抬升整个会话窗口 reqConfig.modelContextLimit
范围 窄——只影响 guard 广——nudge/preflight/guard 全读 reqConfig.modelContextLimit,一致抬到 272K
触发 nativeFromFallback && resolvedNativeWindow===undefined nativeFromFallback && w>limit(且 codex 客户端)

关键:guard 的 limit 派生自 reqConfig.modelContextLimit(side-request.ts:1036,blocked = estimate >= limit×1.15)。本 PR 把它从 200K 抬到 272K → guard 阈值从 230K(200K×1.15,正是事故 413 的那道墙)抬到 ~312.8K(272K×1.15)→ 事故被修。且本 PR 抬升后清 nativeFromFallback(handle.ts:1088)→ #7206 的分支(要求 nativeFromFallback)不再触发 → #7206 在本 PR 之后冗余。两者改不同代码段、不冲突;本 PR 是更完整、更一致的修复(避免 #7206 单独合入后「nudge/preflight 用 200K、guard 用 272K」的不一致状态)。

建议:合 #7517(更完整的修复);#7206 可标 superseded 由 owner 决定关不关(我按政策不关单)。若 owner 更想要 #7206 的窄范围方案,则 #7517 的抬升是超集、仍建议保留。


顺手修(drive-by,独立 commit)

review 中发现 src/server.ts 有两个 pre-existing 死导入(master 上就有,不在本 PR diff 内):codexAlignedWindow(:18,真实用法在 handle.ts:17)和 FALLBACK_EFFECTIVE_WINDOW_FLOOR(:16)。两者在 server.ts 里各只出现 1 次(即导入行本身),删除安全(两模块经其他导入仍会加载,模块初始化顺序不变)。已按「小问题直接修 / ⑤b 无死代码」在 PR 分支补一个独立标注 commit:

  • 108c45b6ed1 refactor: drop two dead imports in server.ts (drive-by)

本地 tsc --noEmit 0 + 18/18 定向测试通过。该 commit 已 push 到 fix/codex-window-raise(PR head 现为 108c45b6ed1),会触发新一轮 CI。


CI 状态

  • 原 PR head(a1d7e6da1e2):30 checks,0 failed;static-gates / mysql-contract / lock-sync / docs-coverage / plan 全绿;全部 hermetic e2e(real codex vs fake upstream、persona/continuity、OpenCode V2 WS、dsh/pi 各车道、hermetic registry)全绿;7 个 test shard 在查时 in_progress。
  • real-codex e2e(ci-e2e.yml)按设计 skip:三层 CI,该车道只在 ci:full label / dispatch 或 master 30 分钟 cron 时跑;本 PR 无 ci:full label,master 的 nightly cron 兜底。非本 PR 的缺口。
  • 我 push 的 drive-by commit 会触发新一轮 CI(最终绿/红以新 head 的 CI 为准)。

中文八问

  1. 是什么问题:宿主的 codex 会话若一开始落在 bili 的 fallback 窗口(如 200K),之后永远不变大——即使 bili 自己知道模型真实窗口是 272K,会话也只能在旧的小窗口里压缩/判断,白白损失上下文长度;大 side request(~235K)还会被本地 413 误杀。
  2. 什么原因导致的:src/codex-models.ts 的窗口对齐逻辑只做「向小收」(bili 窗口 < 宿主窗口时 clamp 收窄),没有「向大抬」——会话在 fallback 窗口建立后,对齐函数拿到 bili 的更大窗口也不会把会话抬上去。
  3. 影响范围与严重程度:仅 codex 车道、且 bili 走过 fallback(nativeFromFallback)的会话;窗口从 fallback 值抬到 bili 模型窗口。p2:可用但上下文长度被浪费 + 大 side request 被误拦,可绕行(缩短会话),非数据丢失/缓存泄露。
  4. 怎么修复的:给 codexAlignedWindow 加 canRaise 参数;handle.ts 只在 bili 自己走过 fallback 时传 canRaise=true,抬升直接采用对齐后的 limit(不走 windowShrinkReason,因为变大不是 shrink);client-metadata 路径(宿主自报窗口)永不抬。
  5. 是否有回归问题:无。默认 canRaise=false 老调用点不变;抬升只在 bili 自己降级过时发生;operator/configured/registry/plugin 窗口与宿主自报窗口永不抬;不发 shrink 提示。唯一表面瑕疵(抬升后 [window-change] 行的 source 标签 stale 为 "default")无误报、与 clamp 分支同等、不拦。
  6. 是否破坏缓存:不涉及——未触碰缓存/重试/增量游标/去重键。
  7. 是否改了设计方向:没有——是既有对齐机制的扩展(加一条抬升路径),非架构/数据流转向。
  8. 是否引入新配置:无新 env/config/默认值。

收工判定:代码正确、范围收敛、测试充分(本地 18/18 + typecheck 0),CI 0 failed(7 shard 在跑 + drive-by commit 触发新一轮)。可合;合并由 owner 执行。建议同时处理与 #7206 的冗余关系(合 #7517,#7206 标 superseded 由 owner 定)。

…sized 200K now adopted)

The untouched-below-perception expectation predates #7205: a codex session
whose base window is bili's generic fallback (200K), below codex's own
knowledge (272K), is now raised to 272K instead of min-kept. In-table and
operator-tuned windows are untouched, as before. (#7205)
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

结论:3 条红 lane = 继承性 master 红(post-#7546 born-red),非本 PR 代码问题。本 PR 分支未做任何改动;待 #7558 合入后 re-merge master 即转绿。

本次运行做了什么(全部实时核实,非凭记忆):

  1. 重验 live check 状态:head 7e0c878cca 仍 3 红(ubuntu-24/1、ubuntu-22/1、windows-22/1,均 shard 1),同一测试 e2e #6069(tests/issue6069-epoch-pause-over-window.test.ts:231,preflight summarized the new history);无更新的绿 run——前序 wake 未修(也无从修,见下)。
  2. 逐条拉 3 个 job 日志:每个 shard 恰好 1 个失败、同一签名,无其它隐藏失败。
  3. 本地验证:PR head 上 Context limit exceeded. | 上下文超了 #6069 5/5 过 + PR 自身测试(issue7205-codex-window-raise + codex-window-align)16/16 全绿;PR base 上 Context limit exceeded. | 上下文超了 #6069 3/3 过。
  4. 机制钉死:CI 跑的是 merge-ref(PR head + master 9ad612e),merge-ref 含 [PR] Add a one-time gate to preflight collapse-before-forwarding: only triggers on first use for new conversations / old sess | preflight 转发前折叠加一次性门槛:只对新对话/未用过 bili 的老会话首次触发,掐断死循环从机制上不可能 (#7545) #7546(preflight one-shot gate);而 PR head 本身在 [PR] Add a one-time gate to preflight collapse-before-forwarding: only triggers on first use for new conversations / old sess | preflight 转发前折叠加一次性门槛:只对新对话/未用过 bili 的老会话首次触发,掐断死循环从机制上不可能 (#7545) #7546 之前(故本地绿)。[PR] Add a one-time gate to preflight collapse-before-forwarding: only triggers on first use for new conversations / old sess | preflight 转发前折叠加一次性门槛:只对新对话/未用过 bili 的老会话首次触发,掐断死循环从机制上不可能 (#7545) #7546 的 one-shot gate 未读 Snapshot as session reconstruction: identity claim order takes priority, message hash demoted to reference signal (root- | 快照即会话重构:身份认领顺序优先,消息哈希降级为参考信号(根治 #3588/#3640 一类误判) #3641 epoch-confirm latch——被整体替换历史的新纪元首轮超窗折叠被旧纪元已提交折叠计数挡住 → preflight 不发 summary 请求 → 断言失败。
  5. CI Control Center: Centralized CI Failure Handling & Status Sync (Comment all CI issues here; do not open new issues) | CI 总控: CI 失败集中处理与状态同步(所有 CI 问题在此评论, 勿开新 issue) #4599 台账确认:master 于 2026-11-22 14:46Z([PR] Add a one-time gate to preflight collapse-before-forwarding: only triggers on first use for new conversations / old sess | preflight 转发前折叠加一次性门槛:只对新对话/未用过 bili 的老会话首次触发,掐断死循环从机制上不可能 (#7545) #7546 合入 9ad612e)起 born-red,10+ 个 PR 同签名;修复 [PR] fix: preflight one-shot gate must not block a replaced epoch's first fold (#7545) #7558(434bf68843b,CI 全绿)在途、待 owner 合并;ci-fixes 是 master 祖先(0 unique commits,merge 为 no-op)。
  6. 零交集:本 PR diff(codex window raise,src/codex-models.ts + src/server/handle.ts)在 codex 车道;失败测试走 anthropic wire(/v1/messages),codexAlignedWindow 对非 codex 客户端直接 early-return——本 PR 不可能致此红。

为何不动本 PR 分支:按 CI 失败协调政策(owner policy 2026-10-24),master 红 = 继承性失败,禁止在自己分支重复修 master 级失败;修复已收敛在 #7558,本分支再修一遍是重复且会与 #7558 冲突。ci-fixes 是 no-op 祖先,无可合内容。

下一步:#7558 合入 master 后,re-merge master 进本分支触发 CI 即转绿,后续 wake 跟进。状态已一行报到 #4599。

结构化八问:

  1. 是什么问题:本 PR 的 3 条 test lane 红,全是同一个 e2e 测试 Context limit exceeded. | 上下文超了 #6069(同一 session id 下历史被替换、再长超窗时,该轮应被折叠并转发)。
  2. 什么原因导致的:不是本 PR。master 合入 [PR] Add a one-time gate to preflight collapse-before-forwarding: only triggers on first use for new conversations / old sess | preflight 转发前折叠加一次性门槛:只对新对话/未用过 bili 的老会话首次触发,掐断死循环从机制上不可能 (#7545) #7546(preflight one-shot gate,9ad612e)后,该 gate 不读 Snapshot as session reconstruction: identity claim order takes priority, message hash demoted to reference signal (root- | 快照即会话重构:身份认领顺序优先,消息哈希降级为参考信号(根治 #3588/#3640 一类误判) #3641 epoch-confirm latch,被整体替换历史的新纪元首轮超窗折叠被旧纪元已提交折叠计数挡住,preflight 不发 summary 请求。CI 跑 merge-ref(PR+master),故命中这个 master 级回归。
  3. 影响范围与严重程度:所有 merge-ref 含 9ad612e 的在途 PR(即当前全部 open PR)的 shard-1 test lane 红;master 上 Context limit exceeded. | 上下文超了 #6069 契约(epoch-confirm pending 期间超窗仍折叠)被破坏,替换历史后长超窗的会话会被拒(preflight_compress_failed,latch 只能转发后清除 → 会话卡死)。属 master 级可用性缺陷(p1 类),非本 PR 引入。
  4. 怎么修复的:修复已在 [PR] fix: preflight one-shot gate must not block a replaced epoch's first fold (#7545) #7558(434bf68843b,CI 全绿,待 owner 合并)——让 one-shot gate 读取 epoch-confirm latch。合入后 re-merge master 进本分支即绿;本分支零代码改动。
  5. 是否有回归问题:本 PR 自身行为无回归(PR head 本地全绿、PR 自身测试 16/16 过)。红是 [PR] Add a one-time gate to preflight collapse-before-forwarding: only triggers on first use for new conversations / old sess | preflight 转发前折叠加一次性门槛:只对新对话/未用过 bili 的老会话首次触发,掐断死循环从机制上不可能 (#7545) #7546 引入的 master 级回归,与本 PR diff 无关。
  6. 是否破坏缓存:不涉及。
  7. 是否改了设计方向:不涉及。
  8. 是否引入了新的配置:不涉及。

收工判定:本次确认为继承红,本 PR 分支无需改动,状态已报 #4599;等 #7558 合并后 re-merge master 转绿。

@ranxianglei
ranxianglei merged commit a9a322d into master Nov 23, 2026
56 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.1296-master.a9a322d (rolling master tag).

npm install -g billion-context@0.0.1296-master.a9a322d  # this exact build
npm install -g billion-context@master  # always the newest merged build

npm view billion-context@master prints the current version at any time.

ranxianglei pushed a commit that referenced this pull request Nov 23, 2026
…lict at 0.0.208

Master advanced 325 commits past the PR base (compress length-rejection
direction #6730/#6751 -> kernel 0.0.207, codex window raise #7517, #7583
review followups, #4410 plugin-carrier judge, #7574 id-list fixes, and
more). Content hunks auto-merged (kernel/src/compress.ts — the PR's
frontier/cloneState hunks vs master's #6730 length-remediation in disjoint
regions — tests/storage-state-fields.test.ts — the PR's
pendingOrphanSweepMaxRef round-trip lines vs master's new 3-arg
loadLegacyView call in the same test, and all four storage-render
goldens); the only conflicts were the three kernel version lines, resolved
at 0.0.208 = master's 0.0.207 + this PR's kernel/src change, per the
CI-enforced kernel version discipline.

Targeted local verification: tests/golden-storage-render.test.ts +
tests/storage-state-fields.test.ts 7/7, kernel issue6116/issue3769/
hide-consumed suites 27/27.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working codex p2 scope/wiring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant