Skip to content

[PR] fix(codex): keep marketplace Git repos inside CODEX_HOME (overlay owns .tmp) - #5586

Closed
ranxianglei wants to merge 1 commit into
masterfrom
wt-5585-ework-daemon
Closed

ranxianglei wants to merge 1 commit into
masterfrom
wt-5585-ework-daemon

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

What

Fixes the bili codex failure where Codex rejects every Git-backed plugin-marketplace update with:

Codex could not update marketplace `context-mode`: trusted Git repository root escapes Codex home

(affected marketplaces: context-mode, context7-marketplace, floorplan). Plain codex never shows this.

Root cause

bili codex runs Codex against an overlay home (~/.codex-bili, or a per-session slot ~/.codex-bili-sN). To share the user's existing Codex state, the launcher symlinks every entry of the real ~/.codex into the overlay — including .tmp. Codex keeps its marketplace/plugin Git checkouts under $CODEX_HOME/.tmp/marketplaces/<name>, so with CODEX_HOME=<overlay> those repo paths resolve back through the .tmp symlink into the real home — outside the active home. Codex's containment check ("trusted Git repository root escapes Codex home") then rejects each update. Plain codex uses ~/.codex directly, where .tmp is a real subdirectory, so nothing escapes.

Fix

The overlay now owns .tmp instead of sharing it. refreshOverlayHome and finalizeCodexHome take an opt-in localOnlyEntries exclusion set ({ ".tmp" } for the codex lane):

  • the startup fold never links the real home's .tmp into the overlay (and excludes it from the hollow-home accounting);
  • the exit fold never merges the overlay's .tmp back into the real home nor relinks it;
  • a stale escaping .tmp symlink left by a pre-fix launch is dropped at startup so Codex recreates it as a genuine per-overlay path.

The dsh shared-home fold is untouched (it does not pass the set, so its behavior is byte-for-byte unchanged).

Behavior change (disclosed)

  • Before: bili codex shared ~/.codex/.tmp into the overlay via a symlink, so its marketplace Git repos escaped the active home and every Git-backed marketplace update failed.
  • After: each overlay (the shared ~/.codex-bili home or a -sN slot) owns its own .tmp; Codex clones its marketplaces into it on first launch (one-time per overlay; the directory then persists). Marketplace/plugin data still works, and nothing in the real ~/.codex/.tmp is touched.

No new config fields, env vars, or CLI flags are introduced.

Tests

New hermetic suite tests/codex-overlay-tmp-containment.test.ts:

  • a fresh launch never links .tmp in (unrelated entries still link through);
  • a client-owned .tmp persists across re-launch refresh and exit finalize (no merge-back, no relink, no real-home pollution), with the containment invariant asserted (the repo's canonical path resolves inside the active home);
  • prepareCodexHome migrates away a stale escaping .tmp symlink;
  • a negative control proving the pre-fix path links .tmp in and escapes (so the suite has teeth).

Local: npm run typecheck clean; targeted suites green (66/66: the new suite plus launcher-sqlite-overlay, codex-concurrent-launch, launcher-codex-sqlite-home, codex-overlay-env). Full regression runs on CI.

Closes #5584

…5584)

bili codex shares the real codex home into its overlay via symlinks, which linked $CODEX_HOME/.tmp in from the real home. Codex stores git-backed marketplace/plugin checkouts under $CODEX_HOME/.tmp/marketplaces/<name>, so their canonical paths resolved back OUTSIDE the active overlay home and Codex rejected every such update with "trusted Git repository root escapes Codex home".

The overlay now owns .tmp itself: refreshOverlayHome/finalizeCodexHome take a localOnlyEntries exclusion set ({".tmp"}) so .tmp is never linked in from the real home, never merged back into it, and a stale escaping symlink left by a pre-fix launch is dropped at startup so codex recreates it as a genuine per-overlay path. dsh's shared-home fold is unaffected (opt-in param).

Regression suite: tests/codex-overlay-tmp-containment.test.ts (fresh, persistence across launch+exit, stale-symlink migration, plus a negative control proving the old behavior escapes).

Closes #5584
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

📦 Built Package Artifact

Branch: wt-5585-ework-daemon (3b35bee)

Latest build — install this exact version

npm install -g billion-context@0.0.7960-pr.5586.de9100d

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
3b35bee billion-context@0.0.7960-pr.5586.de9100d build

Download artifact

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

Install instructions are refreshed on each push.

@ranxianglei ranxianglei changed the title fix(codex): keep marketplace Git repos inside CODEX_HOME (overlay owns .tmp) [PR] fix(codex): keep marketplace Git repos inside CODEX_HOME (overlay owns .tmp) Nov 3, 2026
@ranxianglei

Copy link
Copy Markdown
Owner Author

🤖 Powered by ework · qwen3.8-27b

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

PR #5586 审核结论:代码正确、测试有牙、可合;当前 CI 红是继承性失败,与本 PR 无关。

先说 CI(最关键,已拉 job 日志逐一核对)

  • 三个失败 shard —— ubuntu-latest(24)/bin3、windows-latest(22)/bin3、windows-latest(22)/bin4 —— 每个都是 4 个失败,且全部集中在 tests/storage-engine-proofs.test.ts,同一签名:storage engine: full-mode restart is invisible on the {chat|anthropic|responses|google} wire 的 pre-migration body #0 digest drift vs committed goldens(sha256 actual≠expected,ERR_ASSERTION)。这是存储引擎 wire golden-digest 漂移,和本 PR 改的 launcher overlay .tmp 是两个不相干的子系统。
  • 新测试 codex-overlay-tmp-containment.test.ts 落在 windows N=5 的 bin5(通过);ubuntu 侧虽落进失败的 bin3,但该 shard 的 4 个失败全是 storage-engine-proofs,新测试 0 次出现在失败里。static-gates(ubuntu/windows)全绿。
  • ⇒ CI 红 = master 继承红(storage-engine-proofs golden 漂移),非本 PR 引入。跨平台一致复现(ubuntu+windows 同 4 条)说明是确定性 golden 漂移,不是抖动。处置:归 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/ci-fixes 修好后对本 PR 重跑即绿;不要把 golden 再生成塞进这个无关 PR。

代码本体(逐路径核对了 refreshOverlayHome / finalizeCodexHome / prepareCodexHome / migrateLegacyCodexOverlay / runLaunch)

结构化八问:

  1. 是什么问题:bili codex 用 overlay home(~/.codex-bili 或 -sN slot)跑 Codex,启动折叠把真实 ~/.codex 所有条目(含 .tmp)都 symlink 进 overlay;Codex 把 marketplace/plugin 的 git checkout 放在 $CODEX_HOME/.tmp/marketplaces/<name>,于是 repo 路径经 .tmp symlink 解析回真实 home——落在 active home 之外,被 Codex 的 containment check("trusted Git repository root escapes Codex home")拒绝,git-backed marketplace 更新全挂。
  2. 什么原因导致的:overlay 默认「共享」真实 home 全部条目,但 .tmp 是 Codex 放 git 仓库的容器目录,必须位于 active CODEX_HOME 之内、不能是穿透到真实 home 的链接。根因是「共享 .tmp」这条策略本身错了,不是某个检查漏判——所以修法是把策略改对,而不是在检查处打补丁(疏,非堵)。
  3. 影响范围与严重程度:仅 codex 车道 + 有 git-backed marketplace 的用户(context-mode/context7-marketplace/floorplan);症状是这些 marketplace 更新失败,但 codex 编码主功能不受影响、plain codex 不受影响。属「特定条件下某功能失效、有绕行」→ p2 合理([Bug][Codex Launcher] Marketplace Git repositories escape CODEX_HOME through Bili .tmp symlinks #5584 已标 p2/codex/scope/wiring)。
  4. 怎么修复的:让每个 overlay 自己拥有 .tmp 而非共享。refreshOverlayHome/finalizeCodexHome 加 opt-in 排除集 localOnlyEntries(codex 车道传 {".tmp"}):启动折叠不把真实 home 的 .tmp 链进来(也不计入 hollow 账)、退出折叠不把它 merge 回真实 home 也不 relink;pre-fix 遗留的逃逸 symlink 在启动时丢弃,让 Codex 重建为真·per-overlay 目录。dsh shared-home 折叠不传该集合 → 字节级不变。
  5. 是否有回归问题:审过的既有行为——① dsh 车道 refreshOverlayHome(dshHome, overlay, "settings.yaml")(src/launcher.ts:2842)不传 localOnlyEntries → 行为逐字不变;② codex 非 .tmp 条目仍正常 link-in / merge-back;③ hollow-home 记账只多排除了 .tmp 一项(合理,它现在是本地条目);④ 退出 finalize 对 .tmp 既不回并也不 relink,真实 ~/.codex/.tmp 全程不被触碰(测试 2 断言了 anti-pollution)。Windows junction 场景 lstat 同样报 isSymbolicLink()===true,drop 逻辑跨平台成立(测试用 dir/junction 双形态覆盖)。无无意回归。
  6. 是否破坏缓存:不涉及(无缓存/重试/游标/去重键变更)。
  7. 是否改了设计方向:小范围语义调整——codex overlay 对 .tmp 从「共享」改为「自有」。是根因修复,方向正确,未动架构边界。
  8. 是否引入了新的配置:无新 env/config/CLI flag(PR 声明属实,diff 亦确认)。

测试有效性:4 个 case 都有牙——尤其第 4 个是负向对照(不传 localOnlyEntries → .tmp 确实被链进来且 realpath 逃逸出 overlay = 复现原 bug),保证套件不会假绿;第 2 个断言了 containment 不变量 + re-launch 持久化 + 不污染真实 home。fresh / persist / migrate-stale / negative 四路径齐备,够兜底。

diff 整洁度 & 代码整洁:仅 2 文件(src/launcher.ts +39/-7、新增测试 +117),无 lockfile/version/kernel 变动、无空行噪音。命名达意(localOnlyEntries / CODEX_LOCAL_ONLY_HOME_ENTRIES),.tmp 集中在一个常量,注释讲 why(#5585 rationale),best-effort try{unlink}catch{} 沿用本文件既有 idiom(风格一致,非新增坏味道),无 as any/@ts-ignore、无新依赖。达标。

判定:✅ 代码与测试质量达标、方向正确、无无意回归,可合。唯一拦路的是继承性 CI 红(storage-engine-proofs golden 漂移,与本 PR 无关)——按 CI 协调纪律等 master/ci-fixes 收敛后重跑转绿即可,无需在本 PR 内处理。

@ranxianglei

Copy link
Copy Markdown
Owner Author

(ai: sglang-gpu0/qwen3.8-27b) 已合入 master: 本 PR 的改动经「codex 车道小修合集第三辑」#5971 送审合入。本 PR 关闭以免重复。

@ranxianglei ranxianglei closed this Nov 8, 2026
yanhuojiyusheng pushed a commit to yanhuojiyusheng/billion-context that referenced this pull request Nov 9, 2026
@github-actions github-actions Bot mentioned this pull request Nov 13, 2026
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.

[Bug][Codex Launcher] Marketplace Git repositories escape CODEX_HOME through Bili .tmp symlinks

1 participant