Repository navigation
feat(codex): reuse session processes - #1189
Merged
Merged
Conversation
tiantt
force-pushed
the
feat/codex-session-process-reuse
branch
from
October 27, 2026 10:19
987e6f1 to
0b9a3b5
Compare
tiantt
force-pushed
the
feat/codex-session-process-reuse
branch
3 times, most recently
from
October 27, 2026 11:07
cab1de4 to
5eaf216
Compare
Reuse Codex session processes with private runtime directories, crash recovery coverage, and process-pool lifecycle tests. Remove repo-local prd-spec/specs records and update repository guidance so public-change evidence is checked before committing. Co-authored-by: TRAE CLI <traecli@bytedance.com>
tiantt
force-pushed
the
feat/codex-session-process-reuse
branch
from
October 28, 2026 04:34
5eaf216 to
abaa8c8
Compare
yaozheng-fang
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Codex
direct+thread_mode="resume"场景下,旧路径每轮都会重新启动codex app-server、导入 rollout 并恢复 thread。短回合、多轮 session 里这些固定开销会快速压过实际模型/工具执行成本,同时 rollout 和请求体持续膨胀。本 PR 将 session 级 Codex process reuse 做成默认开启的 runtime 优化,并补上 MCP/ADK 工具回合的 guarded reuse:工具 manifest 固定在进程凭据上,每轮重新绑定 executor/callback/workspace/budget,并用 SDK 确认的 thread/turn 身份与进程级 request id 防止旧轮次或重连请求误执行。
主要变更
VEADK_CODEX_PROCESS_POOL_SIZE=0可关闭;idle TTL 默认 600s,单进程最多复用 100 轮。mcp_process_reuse=True,让稳定 ADK/MCP 工具回合也能复用进程;VEADK_CODEX_MCP_PROCESS_REUSE=0可仅关闭 MCP process reuse。pool_namespace以及(thread_id, version)身份校验修复跨 store/session ABA 复用风险;取消 identity check 时会关闭已取出的 warm process,避免泄漏子进程和CODEX_HOME。McpBridge:新增 guarded process credential、turn activation、request-id 去重、finish/drain/revoke lifecycle,idle process 不接受工具执行。VEADK_CODEX_DENY_READ_PATHS沙箱隔离增强,并修正已有空 workspace 被误报 reset 的行为。scripts/benchmark_codex_tools.py和 tool workload smoke,覆盖 single/parallel/serial/batch 工具场景与 warm hit 清理。性能收益
本地 macOS、
codex-cli 0.159.2、真实 Codex binary + loopback stub Responses backend 的 20 轮同 session benchmark:理想连续同 session 下 warm 命中率从 0% 提升为
(N-1)/N;20 轮场景为 95%,第 2 轮以后为 100%。线上实际命中率取决于 session 粘性、idle TTL、pool size、配置/fingerprint 稳定性和 store 是否被其它实例推进。合约与兼容性
direct+resume下的无工具和稳定工具回合进程复用;不改变shim或ephemeral路径。mcp_process_reuse、VEADK_CODEX_MCP_PROCESS_REUSE、VEADK_CODEX_PROCESS_POOL_SIZE、VEADK_CODEX_PROCESS_IDLE_TTL_SECONDS、VEADK_CODEX_DENY_READ_PATHS。codex app-server,以常驻内存换后续轮延迟和上下文膨胀下降。验证
git fetch origin && git rebase origin/main-> branch already up to dateuv run --extra dev pre-commit run --all-filesgit diff --checkCODEX_RUN_SMOKE=1 uv run --extra dev pytest tests/runtime/codex/test_codex_tool_workloads.py -m codex_smoke -p no:xdist -rs -q-> 8 passed, 3 deselecteduv run --extra dev pytest tests/runtime/codex/test_codex_mcp_bridge.py tests/runtime/codex/test_codex_process_pool.py tests/runtime/codex/test_codex_runtime_sdk.py tests/runtime/codex/test_codex_thread_store.py tests/runtime/codex/test_codex_turn_contract.py tests/runtime/codex/test_codex_tool_workloads.py -q-> 181 passed, 38 skippeduv run --extra dev --extra extensions pytest -n 8 -m "not codex_smoke and not piagent_smoke"-> 1 failed, 7942 passed, 55 skipped, 4 xfailed. Failure istests/frontend/server/runtime_artifacts/test_writer.py::test_success_uses_trusted_scope_and_hashes_utf8_bytes, where.mdcontent type wasapplication/octet-streaminstead of expectedtext/markdown; neither the test nor artifact writer files are touched by this PR.npm --prefix docs run types:checkpreviously failed in the generated docs scaffold atdocs/lib/source.ts(3,22): docs/.source/server.ts is not a module.npm --prefix docs run lintpreviously failed on existing Biome schema/format/import-order diagnostics outside the edited MDX content.风险