Skip to content

fix: bili codex pins embedded mode via probed --no-daemon (#1867) - #2089

Merged
ranxianglei merged 2 commits into
masterfrom
2026-10-04_codex-no-daemon-probe
Oct 4, 2026
Merged

ranxianglei merged 2 commits into
masterfrom
2026-10-04_codex-no-daemon-probe

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What & why

bili codex auto-injects -c model_context_window=… -c model_auto_compact_token_limit=… (#321 budget alignment). On Codex ≥0.156 those command-line overrides exclude the TUI from its shared background server (config_exclusion() in codex-rs/tui/src/daemon_startup.rs — the two budget keys are not on the allowlist), so every launch prints Running without the shared background server: … requires embedded mode. and falls back to embedded.

The fallback itself exposes the real defect: without any -c injection (user self-set model_context_window, or an unresolvable model) the TUI silently attaches to an existing shared daemon whose env was frozen at daemon start — all model traffic then bypasses bili's per-session proxy and compression silently stops working. And if bili cold-starts the daemon first, the surviving daemon keeps pointing at a proxy port that died with the session. The launcher's proxy is session-scoped by design, so embedded is the only deterministic run mode for bili codex.

Per owner decision in #1867 (Phase 0, resident-proxy direction deferred): pin embedded explicitly instead of relying on the accidental exclusion.

Changes

  • src/launcher.ts
  • CLIENTS.md — Codex section: new "Run mode: bili codex pins embedded" note (why embedded, escape hatches, shared-server users run native codex).
  • tests/launcher.test.ts — 4 regression tests: pinned-args truth table; probe unit test (flag present/absent/dead binary/missing binary/cache); runLaunch integration (fresh launch gets budget args AND --no-daemon; self-aligned window and unresolvable-model variants still get --no-daemon — the silent-bypass guard; user --no-daemon not duplicated; --remote suppresses); old-binary launch unchanged (probe fail-safe).

Behavior change (intentional)

On Codex builds that support --no-daemon (~≥0.156): bili codex run mode changes from auto-selected (attach to / auto-start shared background server, with the per-launch fallback warning when budget args present) to explicitly embedded. The warning disappears; compression routing becomes deterministic in all cases. Older binaries are probed and launched unchanged. Users who pass --no-daemon or --remote themselves are never touched.

Config surface

None — no new config fields, env vars, or CLI flags. Capability detection is by probing the installed binary's own --help output; the only observable addition is one launcher log line (bili: codex pinned to embedded mode (--no-daemon) — …) when the flag is injected.

Pre-flight

  • npm run typecheck — clean
  • node --import tsx --test tests/launcher.test.ts — 259/259 pass (incl. 4 new; pre-existing codex budget test unchanged and green)
  • npm run build — success
  • Full suite + E2E: CI

Closes #1867

@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: 2026-10-04_codex-no-daemon-probe (2fe98fd)

Option A — Install this exact build (recommended)

npm install -g billion-context@0.0.2134-pr.2089.23f13ce

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

Option B — Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei
ranxianglei force-pushed the 2026-10-04_codex-no-daemon-probe branch from 10a4310 to a88cb34 Compare October 4, 2026 11:41
ework-agent added 2 commits October 4, 2026 20:15
…1867)

runClient plans the spawn via planClientSpawn BEFORE calling deps.spawnImpl —
on win32 a .cmd fake arrives wrapped as 'comspec /d /s /c "<line>"', so the
'cmd === fakeCodex' capture guard never matched: the client child was a plain
fake without the exit override and runClient's promise stayed pending forever,
draining the event loop ('Promise resolution is still pending...') and
cascading into every later test in the file.

Match the embedded path instead and unwrap the comspec line back to client
tokens with a quote-aware splitter (round-trips buildWindowsCommandLine),
pinned by a platform-neutral round-trip unit test.
@ranxianglei
ranxianglei force-pushed the 2026-10-04_codex-no-daemon-probe branch from a88cb34 to 2fe98fd Compare October 4, 2026 12:16
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

PR #2089 审查完成 — 结论:可合(等最后 4 个 test job 转绿)

先过方向关(①原 issue):#1867 triage 已定位根因是会话级 proxy 与 codex 共享后台守护进程的生命周期错配,警告只是表面现象;owner floor 9 批准 Phase 0(probe 注入 --no-daemon + 逃生舱,resident 暂缓)。本 PR 与批准规格逐项核对:probe(help-probe、按二进制缓存、fail-soft)、逃生舱(--no-daemon/--remote 跳过)、-c 预算注入不变、CLIENTS.md 说明、回归测试——全部落实,方向无偏。

结构化七问:

  1. 是什么问题:bili codex 的 proxy 随会话生灭,但 codex ≥0.156 的 TUI 默认 attach 长命共享 daemon——attach 到别人起的 daemon 时全部流量绕过 bili(压缩静默失效);若 daemon 由 bili 冷启,会话结束后残留 daemon 还指向死端口。-c 预算注入(REQ: codex 压缩预算协调 + 匿名代理模式拦截伪造(根本解决方案) #321)在 ≥0.156 上强制 embedded,把这个问题暴露成每次启动的警告。
  2. 什么原因导致的:生命周期错配(per-session proxy vs long-lived daemon),不是警告本身。auto 模式(attach/auto-start)让路由不确定:压缩是否生效取决于谁先起了 daemon、daemon env 冻结的是什么。
  3. 怎么修复的:显式钉住 embedded——探测安装二进制的 codex --help 是否有 --no-daemon(行首锚定精确匹配、按命令缓存、5 s 超时、任何失败→不注入→退回旧行为),命中则在启动参数前插。用户已传 --no-daemon 或 --remote 则跳过(codex 对两者组合 hard-error)。-c 预算注入保持不变(embedded 模式下等效)。
  4. 是否有回归问题:改动路径上的既有行为逐项清点——REQ: codex 压缩预算协调 + 匿名代理模式拦截伪造(根本解决方案) #321 预算注入(不变,既有 budget 测试绿);MCP 注入顺序(不变,仍在其后 prepend);direct-URL 模式(未触碰);旧二进制(<0.156 无该 flag)(probe 失败→启动参数与改动前逐字节一致,有端到端测试);Windows cmd.exe 包装一致性([bug] Windows: a space in the client or -e path truncates the launch (spawn shell:true, unquoted) — and silently kills compression when only the command is quoted #679,probe 与实际启动同走 planClientSpawn);用户自传 flag(永不动)。审查中发现一个真问题并已修复:新测试在 Windows 上挂死整个文件(CI windows-22 红)——根因:win32 下 .cmd 假二进制被 planClientSpawn 包成 comspec /d /s /c "<line>",spawnImpl 里 cmd === fakeCodex 永不匹配,假子进程永不退出,node:test 报 "Promise resolution is still pending" 并取消其后全部测试。已在 follow-up commit 2fe98fde 修复(quote-aware 拆行还原 + 平台无关的 round-trip 单测钉住 buildWindowsCommandLine 契约);我独立诊断出同一根因,交叉验证一致。有意行为变更(PR 正文已披露):≥0.156 上运行模式从 auto 变为显式 embedded,fallback 警告消失,全场景路由确定化。
  5. 是否破坏缓存:不涉及。未触碰任何缓存/重试/游标/去重策略;新增 Map 只是进程内能力记忆(key=命令+prefix,数量受进程内不同命令数约束)。
  6. 是否改了设计方向:没有——本 PR 就是 owner 批准的 Phase 0 本身;resident-proxy 方向按 owner 决定暂缓(非否决)。
  7. 是否引入新配置:没有。检测完全靠探测安装二进制自身的 --help 输出,不加 env/config/CLI flag;唯一可观测副作用是注入时一行 launcher 日志。

验证与历史(透明记录):

  • 原 head 10a43105 CI 红:分支 base 早于 master 的 Gate tests/ under CI typecheck — clear all pre-existing test type errors (#1970) #1990(typecheck 门禁从 src-only 扩到 src+tests),本地 pre-flight 跑的是旧脚本所以没暴露——典型 stale-base。现已 rebase 到 8ecb2549;其后 master 又进 3 个提交(fix(#2082): dsh 插件工具消失 — 注册卡死自愈 + 桌面副本 boot smoke 门 #2091 dsh-desktop、dsh中工具会突然消失 #2082×2,只碰 src/agent/dsh-native.ts、src/update.ts 及对应测试,与本 PR 文件零重叠)。
  • 残留风险注记:probe 依赖 clap 的次行式 help 渲染。已用真实 0.147 二进制管道捕获验证 + 0.159.3 源码确认(flag 扁平进顶层 parser、仓库内无 help template 覆盖)。若未来 codex 改渲染风格,probe 静默返回 false → 退回 PR 前行为(警告 + 意外 fallback),不会弄坏启动——fail-safe 设计。
  • CI(当前 head 2fe98fde):全部 e2e lane(含 real codex lane)、registry e2e、build-artifact、version-guard 已绿;4 个 test (os,node) job 仍在跑(windows 是本修复的关键验证面)。

判定:可合,待 4 个 test job 转绿(重点 windows)。合并由人执行:#2089

@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

CI 全绿,审查收工。 head 2fe98fde 全部 15 个 check run 通过(含此前红的 test (windows-latest, 22) 和 windows-24——Windows 测试修复有效),e2e lane、registry e2e、build-artifact、version-guard 全过。

最终判定:可合。合并由人执行:#2089

@ranxianglei
ranxianglei merged commit d47f468 into master Oct 4, 2026
14 checks passed
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

📦 Merged Build Published

This merge to master was published as 0.0.7-master.d47f468 (rolling master tag).

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Codex launcher] 预算参数 -c 注入导致 Codex 0.159.3 回退到 embedded mode 并显示 shared background server warning

1 participant