Skip to content

test(control-plane): isolate cached temporary runtime roots - #5155

Merged
huangruiteng merged 1 commit into
mainfrom
codex/canonical-test-runtime-isolation-20260927
Sep 27, 2026
Merged

huangruiteng merged 1 commit into
mainfrom
codex/canonical-test-runtime-isolation-20260927

Conversation

@huangruiteng

Copy link
Copy Markdown
Collaborator

Motivation / 动机

Canonical CLI qualification can accidentally reuse a warmed host Effect runtime: the existing isolation helper changes temporary-directory environment variables, but Python may already have cached tempfile.tempdir. Parent-process calls and CLI subprocesses then resolve different runtime roots.

现有隔离 helper 只修改环境变量,Python 的临时目录缓存可能仍指向宿主运行时,导致父进程与 CLI 子进程不在同一隔离边界内。

Change / 改动

  • Patch the cached temporary directory through the existing scoped monkeypatch, alongside the environment variables; restore both at teardown.
  • Add three focused regression cases for cold/warmed caches, parent/child agreement, and teardown restoration.
  • Keep the existing Python test-transport helper. No new decision owner, production runtime, provider, timeout, lease proof, or transaction behavior changes.

Validation / 验证

  • Independent red baseline: 2 failed, 1 passed before the helper fix.
  • Focused regression plus real File/SQLite/CLI and canonical lease suites: 42 passed.
  • Original monitor follow-through and Goal handoff validation workload, in an isolated test-process root: 34 passed.
  • Premerge: all 4 direct checks and 3 selected canaries passed; Ruff and compilation passed.
  • Preserved the earlier host-runtime timeout failures. Test isolation does not resolve or qualify production coordination latency; that remains separate work. No timeout budget was increased and no failing test was removed.

User entry points / 用户入口

Test-only change: no shipped frontend, Lark, CLI schema, settings, or capability projection changes. The affected user path is repository qualification; real public CLI paths are exercised by the regression suites. No product UI companion is required.

Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com>

@huangruiteng huangruiteng left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

结论:APPROVE。已阅读完整 base-to-head diff;未发现阻塞项。评审固定于 80183cd07002730daff7dd565eca8ecdce95cb7a。这里批准的是测试隔离边界修复,不是生产协调服务性能已恢复。

动机

真实验收遇到的一个独立问题是:同一测试中,父进程可能缓存了宿主临时目录,CLI 子进程则读取新环境变量,二者误用不同 Effect runtime。反复重跑不能修复这个边界;新的负例在原 helper 上确实得到两失败、一通过。此次改动能消除测试对宿主运行时的意外依赖,让后续 File/SQLite 的真实验收更可信。生产 event-loop 卡顿是另一条因果路径,仍需独立修复和资格验证。

改动思路

复用 isolate_sqlite_runtime 的现有隔离所有者,在同一个 monkeypatch 生命周期内同时设置环境变量和 Python 缓存,退出时恢复。没有增加第二套 runtime 目录协议、超时策略或 provider 权威。只在每个子命令上临时补环境变量仍无法保护父进程;重写生产 runtime 或把已有 Python 测试 helper 迁移到 TS 又超出了这次已证实的缺陷。保留 Python 是测试 transport 的局部选择,不是新增 Python 决策源。

具体改动

关键代码讲解

  • tests/control_plane/canonical_authority_fixture.py:isolate_sqlite_runtime 新增 tempfile 导入并用 monkeypatch.setattr 设置 tempfile.tempdir。已有三个临时目录变量和 SQLite Node 选项不变;原来的 teardown 统一恢复环境和缓存。
  • test_runtime_isolation_covers_process_and_cli_temp_directories 分别从未缓存和已缓存状态进入 helper,检查当前进程的 gettempdir、真实 _runtime_dir 及一个实际 Python 子进程读取的目录一致。没有用 mock 返回所需目录。
  • test_runtime_isolation_restores_the_process_cache 在嵌套 patch 作用域结束后验证旧缓存和 runtime 根恢复,防止只证明当前测试通过却污染下一测试。

全 PR 只有两处测试路径,44 增、1 删。已扫描现有消费者和同作者最近八个 PR:现有 lease/monitor/CLI 测试使用这个 helper,但未覆盖缓存预热和恢复;新用例不是另加一个产品 walkthrough,也没有重复同形状 smoke 批次。

对主干的风险

最强回归风险是修改进程全局缓存后不恢复,导致后续测试串线;嵌套作用域负例直接约束这一点。真实 File/SQLite/CLI、租约生命周期和 monitor 套件共 42 项通过;原 monitor follow-through/Goal handoff 的同一 34 项工作负载在独立测试根通过;4 个直接检查和 3 个 canary、Ruff 与编译通过。没有提高 10 秒 RPC 预算、删除失败用例或把生产服务切换到测试根。

此前宿主运行时的超时保留为生产基础设施问题:独立纯 RPC 也失败,另一路真实 File 快照/CPU 复现已由运行时维护工作接手。本 PR 不改那条生产路径,不能拿隔离后通过冒充其性能资格验证。前端、Lark 和发布 CLI 的配置、schema、投影完全未改,因此没有 UI companion;受影响的是仓库测试入口,实际 public CLI 由上述套件覆盖。

我的整体评价

长程影响:改善持续验收的隔离与失败归因,且通过 teardown 验证保留后续测试的宿主状态。用户体验影响:发布用户路径保持原样,开发者无需反复干预宿主服务来运行这些隔离测试。改动是已证实缺陷在现有 owner 内的最小修复,没有兼容版本或持久格式负担。所有必需证据已核对,未查询或等待远端 CI。剩余风险是生产协调服务的累积历史/并发性能,这不属于本测试 PR 的完成宣称;合并仍留给维护者。

English verdict: APPROVE - 80183cd. No blocking finding: scoped cache/environment isolation and teardown are independently covered. Red baseline 2 failed/1 passed; 42 real backend/CLI regressions, the original 34-case workload, and all selected canaries passed. Production runtime latency remains separate, unqualified work.

@huangruiteng
huangruiteng merged commit 0b4ad3c into main Sep 27, 2026
23 of 28 checks passed
@huangruiteng
huangruiteng deleted the codex/canonical-test-runtime-isolation-20260927 branch September 27, 2026 03:14
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.

1 participant