Skip to content

[PR] fix(#5243): honor codex's model_catalog_json when aligning windows - #5305

Merged
ranxianglei merged 1 commit into
masterfrom
2026-10-31_codex-catalog-window
Oct 31, 2026
Merged

ranxianglei merged 1 commit into
masterfrom
2026-10-31_codex-catalog-window

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Fixes #5243

What was wrong

The codex-cli catalog install stores its model table ONLY in the file named by config.toml's model_catalog_json — there is no models_cache.json at all. bili only ever read models_cache.json, so for those installs every request fell through to the flat 272K unknown-model fallback: windows clamped 1050000 -> 272000, nudge bands sized against 272K, emergency compression firing at ~35% of real usage.

What this does

  1. Honors model_catalog_json — parsed from codex config.toml (base file, profile overlay, and -c CLI overrides all carry the key through the effective view). Relative paths resolve against $CODEX_HOME. Candidate order: catalog file first, then models_cache.json; a readable table stays authority even when a lookup misses (no cross-file fall-through).
  2. config.toml fallback instead of blind 272K — when NO table file is readable but model_context_window is set, size from the operator's own number and log one warn per model naming what happened.
  3. Honest clamp log — the [codex] clamp line now names the actual winning source (client-metadata / codex-catalog / codex-models-cache / codex-config-window / bundled-snapshot / codex-fallback) via an additive source field on the alignment result, replacing the old static 'current client metadata preferred' text that lied when no client metadata existed.

No wire changes, no kernel changes, no config-surface additions (reading a key from CODEx's OWN config.toml is discovery, not bili configuration).

Verification

  • New regression suite tests/issue5243-codex-catalog-window.test.ts: the exact issue repro (catalog-only install -> 828400 instead of 272000), legacy models_cache path unchanged, config-window fallback shape, unreadable-catalog fall-through, readable-catalog authority, relative path resolution, client-metadata precedence, non-codex control (no source field, no clamp), effective-view merge plumbing.
  • Existing codex window suites updated for the additive source field only.
  • Local: typecheck clean; 106/106 pass across issue5243 + codex-models + codex-live-window + codex-window-align + codex-overlay-env + codex-profile-effective + model-windows + launcher-max-outputs + codex-catalog-cache.

The codex-cli catalog install writes ONLY the file named by config.toml's
model_catalog_json — models_cache.json may be absent entirely — so bili
clamped the window to the flat 272K unknown-model fallback and nudge bands
fired EMERGENCY at ~35% real usage.

- client-config: parse model_catalog_json (base/profile TOML, -c overrides,
  effective-view merge carries the key)
- codex-models: candidate order model_catalog.json -> models_cache.json
  (relative path vs $CODEX_HOME); a readable table is authority even on a
  lookup miss; no readable table + config.toml model_context_window set ->
  size from the operator's own number instead of 272K
- codexAlignedWindow reports which surface produced the window (additive
  source field); the [codex] clamp log names that source instead of claiming
  "current client metadata preferred" when none existed; warn once per model
  on the config-window fallback
@ranxianglei ranxianglei changed the title fix(#5243): honor codex's model_catalog_json when aligning windows [PR] fix(#5243): honor codex's model_catalog_json when aligning windows Oct 31, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

查重: 不重复。 检索 open+closed issue/PR,无其它针对「codex model_catalog_json 窗口对齐 / 272K 回退」的在途条目。本 PR(GitHub #5305,镜像 #5309)是 GitHub issue #5243 的修复;机制独立于既有的 #2600(models_cache 读取)、#1953(live-table 缓存)。

标签: bug / codex / scope/kernel / p2(缺陷;涉及 codex 车道;窗口对齐属压缩预算决策面;过度压缩=体验退化,非数据丢失/完全不可用 → p2)。


方向关(原 issue 是否真问题、层次判断)

  • 复现核实:Codex model_catalog_json installs still fall back to the 272K window — #2600 fix only reads models_cache.json #5243 报 codex catalog 安装(model_catalog_json 指向文件、无 models_cache.json)被 clamp 到 272K,而真实窗口 828400(max_context_window 872000 × 95%)。我按源码核对:旧 readCodexModelWindow 只读 models_cache.json,catalog 安装该文件不存在 → 落 unknown-model 272K 回退。根因成立。
  • 层次:作者修的是根因(对齐时到底读哪个模型表文件),不是在日志层抹掉症状 —— 符合「疏不堵」。
  • 方案评估:候选顺序 catalog→cache→config-window→bundled,且「可读表即权威、不跨文件穿透」= 忠实镜像 codex 自身的模型解析(codex 用哪个文件,bili 就用哪个),方向正确。

回归审查(既有行为清点)

diff 触碰 3 个 src(client-config / codex-models / server/handle)+ 3 个测试。逐项:

  • 旧 models_cache 路径:保留;legacy 安装(未设 model_catalog_json)行为不变,有专门回归行钉住(source="codex-models-cache")。✅ 保持
  • 命中表时的 min(configured, max_context_window)×percent 语义:逐字保留(旧代码同一表达式)。✅ 保持
  • client 元数据优先级:仍最高(cw 存在直接返回)。✅ 保持
  • 有意变更(均已披露):① 新增 catalog 为第一来源;② 新增 config-window 回退层(旧代码从不把 model_context_window 当尺寸源,只在命中表后当 cap);③ clamp 日志从静态谎称「current client metadata preferred」改为如实报 source。三者皆为本 PR 目的,正文已声明。
  • 非 codex 客户端:仍返回无 source、不 clamp(negative control 钉住)。✅ 保持
  • 未见 fail-fast 变吞错 / 阈值漂移 / 时序漂移 / 输出格式破坏。

代码审查(主关)

  • parseModelTable 抽出旧 inline 校验,行为等价;liveTableCandidates 相对路径对 $CODEX_HOME resolve、绝对路径原样;单例 liveTable 的 key 含全路径+ino+mtime/ctime+size,两文件间正确失效。
  • 边界:可读但空/畸形 JSON 的 catalog 判为权威并阻断 cache 穿透 —— 文档化的设计选择,边缘场景(正常 catalog 安装本就没有 cache),可接受。
  • 无 as any/@ts-ignore;命名达意(CodexWindowSource/alignedResult/readCodexLiveModelWindow);注释讲 why;向后兼容 accessor readCodexModelWindow 保留。整洁度达标。

测试有效性

新套件 8 条断言全部有牙(deepEqual 精确值),覆盖:issue 原始复现(828400 vs 272000)、legacy 不变、config-window 形状、不可读 catalog 穿透、可读 catalog 权威(不穿透)、相对路径、client 元数据优先、非 codex 负控、effective-view 合并。手工核算 828400 = min(1050000, 872000)×95% 正确。既有两套测试仅加 source 字段、断言仍在。判定:真测试、能兜底。

两点观察(均不拦合,披露如下)

  1. 性能(轻微):readCodexLiveModelWindow 现在无条件 readCodexConfig(磁盘读+TOML 解析),旧代码仅在命中表后才读。小文件、大概率 OS 页缓存命中,边际成本小;若现有 config mtime 缓存([enhancement] opencode/omp 显式声明的 provider baseURL 从未被 extractHttpsHosts 自动发现(与 #1405 前提不符) #1411)意在覆盖 codex config,此处绕过了它。建议并入未来配置缓存工作,不单开碎片 issue。
  2. 行为变更披露(Deliverables#4):catalog 安装窗口从「272K 平铺回退」→「catalog 派生值」;无可读表但设了 model_context_window 时,从「bundled/272K」→「该值(warn 一次/每模型)」——均为修复目的,正文已声明。

结构化八问

  1. 是什么问题:codex 用 model_catalog_json 装模型表的,codex 只认这个文件、根本没有 models_cache.json;bili 只读 models_cache.json,于是这类安装全部落到 272K 未知模型回退,nudge 分母被压到 204K、紧急压缩在真实用量 ~35% 就连发。
  2. 什么原因导致的:对齐窗口的读取器硬编码了唯一来源文件 models_cache.json,不认识 config.toml 里 codex 自己声明的 model_catalog_json —— 读错来源,而非阈值/日志错。
  3. 影响范围与严重程度:所有走 catalog 安装的 codex 用户(自定义大窗口模型尤甚);症状=压缩过早触发、用量读数虚高、体验退化(非数据丢失/非完全不可用)→ p2。
  4. 怎么修复的:让对齐器按 codex 真实解析顺序取模型表(catalog→cache→config-window→bundled),可读表即权威、不跨文件穿透;并让 clamp 日志如实报来源面。
  5. 是否有回归问题:旧 cache 路径、min() 语义、client 元数据优先、非 codex 不受影响 —— 逐项核过均保持;三处有意变更已披露。高危模式(吞错/阈值/时序/输出格式)未见。
  6. 是否破坏缓存:不涉及(纯窗口记账+日志文案,不动压缩块/前缀缓存/重试游标)。
  7. 是否改了设计方向:没有;反而让 bili 的窗口对齐更忠实镜像 codex 自身模型解析。
  8. 是否引入新配置:无 —— 读的是 codex 自己 config.toml 里的键(发现,非 bili 配置面),无新 env/config/默认值。

CI

23 项 check 当前全部 queued(仓库 run 积压),尚无绿/红判。本地未跑全量(共享资源纪律);新回归套件的断言我已逐条对照源码手工验证。最终绿以 head 062948078 的 CI 为准;若冒出继承性 master 红,按 #4599 哨兵处理(合 ci-fixes)。

收工判定:可合(pending CI 转绿)。分支侧无需我再改 —— 无缺陷需直修、无新 issue 需立;两点观察已在上方披露供 owner 知悉。合并权在人(GitHub PR #5305)。

@ranxianglei ranxianglei added bug Something isn't working codex p2 scope/kernel labels Oct 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-31_codex-catalog-window (0629480)

Latest build — install this exact version

npm install -g billion-context@0.0.7418-pr.5305.b6f64cf

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
0629480 billion-context@0.0.7418-pr.5305.b6f64cf build

Download artifact

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

Install instructions are refreshed on each push.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.946-master.afdf889 (rolling master tag).

npm install -g billion-context@0.0.946-master.afdf889  # 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.

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/kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codex model_catalog_json installs still fall back to the 272K window — #2600 fix only reads models_cache.json

1 participant