Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci-e2e-fake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ jobs:
if: failure()
run: |
mkdir -p tmp/e2e-artifacts
for d in tmp/e2e-codex-fake-*; do [ -d "$d" ] && cp -r "$d" tmp/e2e-artifacts/ || true; done
# Every hermetic workdir this suite creates (#1802 env / #1965 / #2195 /
# #2222 / #3203 lanes use their own prefixes, not e2e-codex-fake-).
for d in tmp/e2e-codex-fake-* tmp/e2e-codex-env-* tmp/e2e-codex-1965-* tmp/e2e-codex-2195-* tmp/e2e-codex-2222-* tmp/e2e-codex-3203-*; do [ -d "$d" ] && cp -r "$d" tmp/e2e-artifacts/ || true; done

- uses: actions/upload-artifact@v4
if: failure()
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/ci-windows-codex.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,24 @@ jobs:
# mtime and a WAL-only commit leaves the main db's bytes AND mtime untouched,
# so the stale-generation-wins failure is reproducible HERE but not on POSIX
# (the deterministic unit twin lives in tests/launcher-sqlite-overlay.test.ts).
# Zero tokens: every model call goes to the local fake upstream.
# #2222 adds the shared-state lane (CODEX_SQLITE_HOME): the overlay must hold
# no sqlite files at all and native runs see every thread immediately.
# #3203 adds the CONCURRENT lane: two bili codex sessions on one CODEX_HOME
# both run, each in its own -s<N> slot, threads land in one live db.
# Zero tokens: every model call goes to the local fake upstream.
windows-codex-sequential-home:
needs: [gate]
if: needs.gate.outputs.run == 'true'
name: sequential bili codex launches keep all threads in the real home (#2195)
runs-on: windows-latest
timeout-minutes: 20
# 30 (not 20): the #2222 shared-state lane and the #3203 concurrent lane
# add real-launch steps to this job.
# Transient runner↔registry blips (ECONNRESET) must not red a PR (#2611):
# raise npm's built-in fetch retry (default 2) so a ~10s jitter rides out
# instead of aborting setup. Job-level → covers every registry op here
# (global CLI install AND `npm ci`). Bounded: worst case ~+2 min before a
# genuine sustained outage still fails fast.
timeout-minutes: 30
env:
npm_config_fetch_retries: '5'
npm_config_fetch_retry_mintimeout: '5000'
Expand All @@ -150,16 +156,18 @@ jobs:
- name: Build
shell: pwsh
run: npm run build
- name: Run the #2195 + #1965 real-launch lanes
- name: Run the #2195 + #1965 + #2222 + #3203 real-launch lanes
shell: pwsh
run: $env:ACP_TEST_E2E_FAKE = "1"; node --import tsx --test --test-name-pattern "#2195|#1965" tests/e2e/e2e-codex-fake.test.ts
run: $env:ACP_TEST_E2E_FAKE = "1"; node --import tsx --test --test-name-pattern "#2195|#1965|#2222|#3203" tests/e2e/e2e-codex-fake.test.ts
- name: Collect E2E artifacts
if: failure()
shell: pwsh
run: |
New-Item -ItemType Directory -Force tmp/e2e-artifacts | Out-Null
Get-ChildItem -Directory tmp/e2e-codex-2195-* -ErrorAction SilentlyContinue | Copy-Item -Recurse -Force -Destination tmp/e2e-artifacts
Get-ChildItem -Directory tmp/e2e-codex-1965-* -ErrorAction SilentlyContinue | Copy-Item -Recurse -Force -Destination tmp/e2e-artifacts
Get-ChildItem -Directory tmp/e2e-codex-2222-* -ErrorAction SilentlyContinue | Copy-Item -Recurse -Force -Destination tmp/e2e-artifacts
Get-ChildItem -Directory tmp/e2e-codex-3203-* -ErrorAction SilentlyContinue | Copy-Item -Recurse -Force -Destination tmp/e2e-artifacts
- uses: actions/upload-artifact@v4
if: failure()
with:
Expand Down
2 changes: 2 additions & 0 deletions CLIENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,8 @@ so the plugin can never route codex's own traffic. Three postures:
| `bili plugin install codex` + a running bili + self-exported `HTTPS_PROXY` | Tools + compression for power users who manage their own env |
| `bili plugin install codex` alone | The four tools appear in codex but no conversation is proxied, so there is nothing for them to act on; `tools/list` fails with -32003 (`bili proxy unreachable … — start bili or set BILI_MCP_PROXY`) when nothing is reachable |

**Concurrent sessions (#3203).** Several `bili codex` launches may run at once in the same project directory with the same `CODEX_HOME`: each launch takes its own per-session overlay slot (`<CODEX_HOME>-bili-s<N>`, pool of 16) and its own lane proxy, so routing, MCP conversation binding, and compression state never cross between sessions. With the shared-state default (codex ≥ 0.147.0) both sessions' history lands in the ONE live state db in the real home and survives any exit order — see `BILI_CODEX_STATE_MODE` in CONFIGURATION.md. Older binaries, or `BILI_CODEX_STATE_MODE=legacy`, keep one exclusive overlay per home: the second concurrent launch is refused with `BILI_OVERLAY_BUSY`.

The install writes a single `[mcp_servers.bili]` block into `~/.codex/config.toml`
(command = node, args = dist/mcp.js). #1660 removed the install-time origin bake
(#403: a baked URL went stale after drift/reboot and left the tools pointing at
Expand Down
3 changes: 3 additions & 0 deletions CLIENTS.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ Codex 是唯一一个插件安装无法自给自足的客户端。接缝矩阵
| `bili plugin install codex` + 在跑的 bili + 自行导出 `HTTPS_PROXY` | 自己管 env 的 power user:工具 + 压缩 |
| 只装 `bili plugin install codex` | codex 里出现四个工具但没有对话被代理、无话可操作;全不可达时 `tools/list` 报 -32003(`bili proxy unreachable … — start bili or set BILI_MCP_PROXY`) |

**并发会话(#3203)。** 同一项目目录、同一 `CODEX_HOME` 下可以同时跑多个 `bili codex`:每次启动各取一个独立的每会话 overlay 槽位(`<CODEX_HOME>-bili-s<N>`,池上限 16)和各自的 lane 代理,路由、MCP 会话绑定、压缩状态互不串线。共享状态默认(codex ≥ 0.147.0)下,两个会话的历史都落在真实 home 的同一个活库上,退出顺序不影响保留 —— 见 CONFIGURATION.md 的 `BILI_CODEX_STATE_MODE`。旧版二进制或 `BILI_CODEX_STATE_MODE=legacy` 保持每 home 一个独占 overlay:第二个并发启动会被 `BILI_OVERLAY_BUSY` 拒绝。


安装写入 `~/.codex/config.toml` 单个 `[mcp_servers.bili]` 块(command = node,args = dist/mcp.js)。#1660 去掉了安装时烘焙 origin(#403:烘焙的 URL 在漂移/重启后变成死端口,工具永远指向它);shell 在会话启动时解析代理 —— env `BILI_MCP_PROXY` > 活实例登记(任一 lane 的代理,或 `bili start` 守护)> 8787 用户区默认 —— 漂移或重启后绝不残留死 URL,shell 直接附着到活着的那个。会话绑定是 headless 的:启动器在 spawn 时传 `BILI_CONVERSATION_ID`,插件 shell 否则绑定下一个新会话;逐调用的 `conversation_id` 覆盖与其他客户端一致(#760)。Codex ≥0.160 还在每次 `tools/call` 的 `_meta.threadId` 里盖上真实 thread id;shell 按调用消费(严格校验、绝不写回 spawn 时的全局绑定),优先级高于过期的 `BILI_CONVERSATION_ID` 残留与模型抄写的 `conversation_id`(#2024)。

**Responses 原生链式(一个坑)。** bili 靠重放完整 `input` 来压缩,因此无法跟随 OpenAI 原生的 `previous_response_id` 链式续传:只带增量的续传请求会在上游丢失之前的轮次,却仍返回 200。对 codex 而言今天这不是问题 —— 观察到的构建都发 `store:false` 且从不设置 `previous_response_id`(是观察不是证明;E2E 未覆盖该形态)。若你把走原生链式的 Responses 客户端指向 bili,要么重发完整 input/output 历史,要么设 `ACP_KEEP_RESPONSE_ID=1`;bili 剥掉非空 `previous_response_id` 时现在会记一条 `warn`(#1954)。完整链式支持跟踪在 #1973。见[官方迁移指南](https://developers.openai.com/api/docs/guides/migrate-to-responses)。
Expand Down
2 changes: 2 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ This index is generated from `website/config-reference/*.yaml` — edit the seed
| `BILI_ZCODE_PORT` | number | unset | — | Port pin for the zcode lane. |
| `BILI_ZCODE_SIGNING_FIXED` | boolean-ish | off | — | Fixed-signing mode for the zcode credential lane. |
| `BILI_CLAUDE_UPSTREAM` | string | unset | — | Upstream pin for the claude lane. |
| `BILI_CODEX_STATE_MODE` | string | auto | — | codex state handling: auto (shared db via CODEX_SQLITE_HOME on modern codex, legacy overlay copies otherwise), shared, or legacy. Shared mode runs up to 16 concurrent sessions, one per-session overlay slot each; legacy keeps one exclusive overlay at a time. |
| `BILI_ATTACH_HEALTH_DEADLINE_MS` | number | (built-in) | — | Deadline for attach health checks when joining an external daemon. |
| `BILI_ATTACH_EVIDENCE_GRACE_MS` | number | (built-in) | — | Grace period for attach ownership evidence. |
| `BILI_PROVIDER_REWRITES` | string | unset | — | Provider URL rewrite rules applied before routing. |
Expand Down Expand Up @@ -1804,6 +1805,7 @@ File keys resolve only when the matching env var is unset. Defaults in parenthes
| `BILI_CLAUDE_UPSTREAM` | claude direct mode: your relay endpoint, when `ANTHROPIC_BASE_URL` already points at a relay the launcher would otherwise bypass. |
| `BILI_CLAUDE_NATIVE_PORT` | Pin an **exact** port for the claude native lane's hook-spawned proxy (#964/#1660): strict-port semantics — a squatter on the port is refused loudly instead of hopping — and the baked managed `ANTHROPIC_BASE_URL` points at it. Without it the hook rides the self-managed zone (`BILI_ZONE_PORT` base + per-lane sticky) and re-pins the managed URL to the live origin each session, so port drift self-heals (#1660). |
| `BILI_CODEX_COMPACT` | Codex native-compaction handling. Default `intercept`: bili intercepts codex's compaction requests and forges a local handoff to the ACP state when the safety gate passes (transform ok + steady-state usage < 90% of the window + at least one active compressed block) — trigger form forges a 2-frame SSE, endpoint form forges `{output}` — and never contacts upstream. Scope (#3008): covers the explicit forms (compaction_trigger + /responses/compact) and the inline auto-compact that transits as an ordinary turn, detected by its SUMMARIZATION_PROMPT template — a user-overridden compact_prompt falls out of detection and transits verbatim; a compaction bili only observed (pass/gate) is rebased post-hoc (#2372). Forged ACP summaries are re-injected as a history-borne handoff message (developer-message fallback) so compressed content stays visible after codex truncates its history. Set `pass` to opt out and forward codex's compaction requests upstream (native compaction backstops). On any gate failure the request passes through untouched. Codex client detection (which traffic this applies to, also used for window clamping and session-identity fingerprinting): the User-Agent must either start with a registered prefix (`codex_cli_rs/`, `codex_exec/`, `codex desktop/` — matched case-insensitively, since variants like Codex Desktop send an initial capital, #1169) or contain a whitespace-delimited component starting with lowercase `codex` (unknown variants such as `codex_sdk_ts/…`, #645 — narrowed from a bare substring to a token-level prefix in #1641 so non-codex clients whose UAs merely mention "codex" mid-token or in parens are no longer misclassified; the fallback stays case-sensitive on purpose so "Codex"-shaped relays are excluded, #1106). |
| `BILI_CODEX_STATE_MODE` | codex state handling (#2222, #3203). Default `auto`: when the codex binary honors `CODEX_SQLITE_HOME` (codex-cli ≥ 0.147.0, probed via a cached `--version` call), bili points it at the REAL `$CODEX_HOME` — codex keeps its WAL-mode state db on the SINGLE physical path in the real home, shared live across bili and native runs. Each launch takes its own per-session overlay slot from a bounded pool (`<CODEX_HOME>-bili-s1..s16`): the generated files (.env, config.toml) and the proxy binding are per-slot, so up to 16 independent sessions run concurrently on one `$CODEX_HOME`, each routing through its own proxy running on its own lane (`codex-s<N>` — two same-build launches sharing one lane would refuse each other at the port layer, #3044). Slots persist and are reused — never auto-deleted, because cold-start thread records resolve through them (#43bf59fc9) — so a crashed session's slot is simply reclaimed by the next launch. With no per-launch db copy there is no exit-time merge-back and no `.bili-conflict` generations (the #381/#1917/#1918/#1919/#1951/#1965/#2195 patch family retires in this mode). The pre-#3203 fixed-name `<CODEX_HOME>-bili` overlay migrates back into the real home exactly once, on the first shared-mode launch, under the same provenance adjudication; a launch is refused while a live legacy-era launch still holds it. `shared` forces this mode (degrades loudly to legacy when the binary is too old); `legacy` forces the old per-launch copy / merge-back mechanism with its single exclusive overlay (one launch at a time). Env-only escape hatch — there is **no** file equivalent. A user-set `CODEX_SQLITE_HOME` is honored as-is (native and bili runs must share one logical db); a managed requirements.toml `sqlite_home` wins over both. |

---

Expand Down
2 changes: 2 additions & 0 deletions CONFIGURATION.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
| `BILI_ZCODE_PORT` | number | unset | — | zcode 车道的端口钉死。 |
| `BILI_ZCODE_SIGNING_FIXED` | boolean-ish | off | — | zcode 凭据车道的固定签名模式。 |
| `BILI_CLAUDE_UPSTREAM` | string | unset | — | claude 车道的上游钉死。 |
| `BILI_CODEX_STATE_MODE` | string | auto | — | codex 状态处理方式:auto(新版 codex 走 CODEX_SQLITE_HOME 共享库,旧版回退 overlay 副本)、shared、legacy。shared 模式最多 16 个并发会话,每会话一个独立 overlay 槽位;legacy 保持一次仅一个独占 overlay。 |
| `BILI_ATTACH_HEALTH_DEADLINE_MS` | number | (built-in) | — | 挂接外部守护进程时健康检查的截止时间。 |
| `BILI_ATTACH_EVIDENCE_GRACE_MS` | number | (built-in) | — | 挂接归属证据的宽限期。 |
| `BILI_PROVIDER_REWRITES` | string | unset | — | 路由前应用的 provider URL 重写规则。 |
Expand Down Expand Up @@ -1799,6 +1800,7 @@ ACP 原生 agent(当前为 `pi` 扩展)会在每个进程内向代理上报
| `BILI_CLAUDE_UPSTREAM` | claude 直连模式:当 `ANTHROPIC_BASE_URL` 已指向某个 relay 时,用它指定你的 relay 端点(否则会被旁路)。 |
| `BILI_CLAUDE_NATIVE_PORT` | 为 claude 原生通道 hook 拉起的代理钉死**确切端口**(#964/#1660):严格端口语义——口上的占用者被大声拒绝而不是跳口——烘进受管 `ANTHROPIC_BASE_URL`。不设则 hook 骑自管区(`BILI_ZONE_PORT` 基准 + 每 lane 粘性),且每次会话把受管 URL 重钉到存活 origin,端口漂移自愈(#1660)。 |
| `BILI_CODEX_COMPACT` | codex 原生压缩处理。默认 `intercept`:安全门通过时(transform 成功 + 稳态用量 < 窗口 90% + 至少一个活跃压缩块)拦截 codex 的压缩请求,在本地伪造向 ACP 状态的交接——trigger 形态伪造 2 帧 SSE,endpoint 形态伪造 `{output}`——且不接触上游。作用范围(#3008):覆盖显式形态(compaction_trigger + /responses/compact)与以普通请求形态过线的内联自动压缩(按 SUMMARIZATION_PROMPT 模板检测)——用户自定义 compact_prompt 后锚点失配、按原样转发;bili 仅旁路观察到的压缩(pass/安全阀放行)走事后 rebase(#2372)。伪造的 ACP 摘要经历史承载交接消息注入(缺席时 developer 消息兜底),保证 codex 截断历史后压缩内容仍可见。设为 `pass` 可退出,把 codex 的压缩请求转发给上游(原生压缩兜底)。任一安全门失败则原样透传。codex 客户端判定(本项生效范围,同时用于窗口 clamp 与会话身份指纹):User-Agent 须以已注册前缀开头(`codex_cli_rs/`、`codex_exec/`、`codex desktop/`——大小写不敏感,因 Codex Desktop 等变体首字母大写,#1169),或含某个以**小写** `codex` 开头的空白分隔组件(未知变体如 `codex_sdk_ts/…`,#645——#1641 起从裸子串收窄为 token 级前缀,UA 中仅在括号内/路径段提及 "codex" 的非 codex 客户端不再被误判;兜底有意保持大小写敏感,排除 "Codex"-形中继,#1106)。 |
| `BILI_CODEX_STATE_MODE` | codex 状态处理(#2222、#3203)。默认 `auto`:当 codex 二进制支持 `CODEX_SQLITE_HOME`(codex-cli ≥ 0.147.0,经缓存的 `--version` 探测判定)时,bili 将其指向**真实** `$CODEX_HOME` —— codex 的 WAL 模式状态库留在真实 home 内的单一物理路径上,bili 与原生运行共享同一个活库。每次启动从有界池(`<CODEX_HOME>-bili-s1..s16`)取一个独立的每会话 overlay 槽位:生成文件(.env、config.toml)与代理绑定都按槽位隔离,因此同一个 `$CODEX_HOME` 下最多可有 16 个独立会话并发运行,各自走自己的代理(代理各跑在独立 lane `codex-s<N>` 上 —— 同构建的两次启动若共享一个 lane,会在端口层互相拒绝,#3044)。槽位持久保留并复用 —— 绝不自动删除,因为冷启动的线程记录要经由槽位解析(#43bf59fc9)—— 崩溃会话的槽位会被下一次启动直接回收。没有逐次启动的数据库拷贝,就没有退出时的合并回写、也没有 `.bili-conflict` 隔离代(#381/#1917/#1918/#1919/#1951/#1965/#2195 补丁族在此模式下退役)。#3203 之前的固定名 `<CODEX_HOME>-bili` overlay 在首次 shared 模式启动时按同一套溯源仲裁一次性迁回真实 home;若仍有存活的旧版 launch 持有它,本次启动会被拒绝。`shared` 强制此模式(二进制过旧时大声降级为 legacy);`legacy` 强制旧的逐次拷贝 / 合并回写机制及其单一独占 overlay(一次只能一个会话)。仅环境变量的逃生舱 —— **没有**文件等效项。用户自设的 `CODEX_SQLITE_HOME` 原样尊重(原生与 bili 运行必须共享同一逻辑库);managed requirements.toml 的 `sqlite_home` 压过两者。 |

---

Expand Down
1 change: 1 addition & 0 deletions scripts/live-files.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const LIVE_FILES = [
"tests/build-info.test.ts",
"tests/cache-theorem.test.ts",
"tests/claude-native.test.ts",
"tests/codex-concurrent-launch.test.ts",
"tests/e2e-plugin-tool-routing.test.ts",
"tests/graceful-close.test.ts",
"tests/hermes-native.test.ts",
Expand Down
Loading
Loading