Repository navigation
perf(control_plane): scope request_amendment & lifecycle_recovery RPCs and cut CLI test subprocess tax - #9599
loopx-agent wants to merge 1 commit into
Conversation
…PCs and speed up CLI recovery tests Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Gemini · Google · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
本次在干净独立的 worktree 上对 PR #9599 确切提交 9599@d3a2f2f01ec2281a5da34f33128b8b9d7b514045(基线 main@811c1a1f66652d3fc3b9830d467e14b45b7423c1)完成 Goal-bound 独立审查(wait_for_ci=false)。逐一审计 6 个文件的完整 diff、request_amendment.py(含 control_request -> recover_request_amendment 嵌套和 execute_request_amendment 事务链)与 lifecycle_recovery.py(receipt_bound_lifecycle_candidate 7 跳投影/推导链)、test_canonical_claim_execution_proof.py 与 test_task_lease_argument_recovery.py 的 _invoke_loopx_cli 与 _teardown_sqlite_runtime、对照探针、6 套件 -n 4 并行测试、隔离 --basetemp 串行与外部工作目录泄漏盘点、静态检查和标准预合并金丝雀门禁,未发现阻断或非阻断缺陷,结论为 APPROVE。
动机 / Motivation
受影响方与触发条件:触发请求修订执行、恢复与控制操作的多跳调用方(execute_request_amendment、recover_request_amendment、control_request)、按回执推导生命周期候选项的调用方(receipt_bound_lifecycle_candidate),以及高频本地运行 tests/control_plane/test_canonical_claim_execution_proof.py 与 tests/control_plane/test_task_lease_argument_recovery.py 的维护者与验证流水线。
修改前后场景对照:改动前,execute_request_amendment、recover_request_amendment 与 control_request 在 snapshot/reserve/commit/readback 多跳 RPC 中各自重复计算 _runtime_fingerprint();receipt_bound_lifecycle_candidate 在 lifecycle_source、derive、lifecycle_obligation 与 replan_successor_transition_ack 多跳链中每跳各自重算指纹;同时 test_canonical_claim_execution_proof.py 与 test_task_lease_argument_recovery.py 对每条测试 cli 命令均冷启动子进程,并对 file 和 sqlite 一并隔离和用子进程关闭运行时。改动后,上述 4 个多跳同步入口直接由既有的 @effect_runtime_request_scope() 装饰(无转发层),单次请求仅解析 1 次源码指纹且在 control_request -> recover_request_amendment 嵌套调用下通过 try_join/leave 安全复用;两个测试文件新增 spy 多 RPC 与异常退栈回归测试;两个恢复 CLI 测试模块将夹具与本地运行器改为默认调用进程内 loopx_cli_main(保留 via_subprocess=True、node -e 写入脚本与 --cli-bin PATH 生成命令行真实子进程验证),仅对 sqlite 隔离 TMPDIR 并在结束时以 _teardown_sqlite_runtime(restart_effect_runtime(wait_for_exit=True) + close_stale_cleanup_sweeps)等待进程退出。
可观测交付结果:独立对照探针实测:REQ_AMEND_CF_OK 在嵌套外层作用域下 cancel -> recover_request_amendment 共 4 次 RPC 仅计算 1 次指纹(去掉装饰器对照 revise 为 2/2);LIFECYCLE_CF_OK 在嵌套外层作用域下 receipt_bound_lifecycle_candidate 共 7 次 RPC 仅计算 1 次指纹(去掉装饰器对照为 7/7),异常退栈均归零;6 个关联 pytest 套件 -n 4 下 167 passed in 41.49s,4 个变更测试文件在隔离 --basetemp 下串行 122 passed in 72.68s,两个端到端恢复 CLI 模块在外部临时工作目录运行 76 passed in 33.96s,工作目录还原不变且两者均测得 locators=0 live_lines=0。
明确非目标:不改变请求修订与中止恢复的状态机、锁顺序或 receipt 校验语义;不改动生命周期候选项与后继 ACK 推导规则;不抽改跨文件公共夹具;不取消生成命令行 --cli-bin 解析、node -e 脚本与 via_subprocess=True 的真实子进程覆盖。
改动思路 / Approach
生产侧遵循仓库一致惯例:在 execute_request_amendment、recover_request_amendment、control_request(request_amendment.py)以及 receipt_bound_lifecycle_candidate(lifecycle_recovery.py)上直接添加 @effect_runtime_request_scope()。由于 control_request 内部在 recover 或 cancel 路径会调用 recover_request_amendment(request_amendment.py),而装饰器通过 try_join()/leave() 支持同线程重入,两处均加装饰器既能让直接调用方获得作用域保护,又保证内部嵌套调用仅解析 1 次源码指纹并在最外层退出时复位 _REQUEST_RUNTIME_REVISION。测试侧仅对 sqlite 隔离 TMPDIR 与执行 _teardown_sqlite_runtime,并在顺序 CLI 辅助函数保留生成命令与代表性 todo list 的真实子进程覆盖。
flowchart LR
subgraph Prod["生产多跳入口 @effect_runtime_request_scope()"]
RA["execute_request_amendment / recover_request_amendment / control_request"] -->|"snapshot -> reserve/commit/cancel -> recover"| R1["4+ RPC 共用 1 次指纹;nested try_join 不提前关"]
LR["receipt_bound_lifecycle_candidate"] -->|"lifecycle_source -> derive -> obligation -> ack (7 RPC)"| L1["共用 1 次指纹;异常复位 ContextVar"]
end
subgraph Tests["CLI 测试加速与隔离清理"]
SQ["仅 sqlite 调用 isolate_sqlite_runtime"] --> CLI["_invoke_loopx_cli 默认 loopx_cli_main"]
CLI -->|"via_subprocess=True / node -e / --cli-bin"| Sub["保留真实 subprocess.run"]
SQ -->|"finally"| TD["_teardown_sqlite_runtime (wait_for_exit=True)"]
end
(说明性控制流图,对应提交 d3a2f2f01ec2281a5da34f33128b8b9d7b514045;基于源码审计与本地探针整理,不代表监控截屏。)
架构评估结论(仅在确实存在多跳 RPC 链的 4 个同步入口函数上直接复用 @effect_runtime_request_scope() 装饰器,签名与函数体零改动;control_request 与 recover_request_amendment 同时加装饰器可在直调与内部重入两条入口均保证 1 次指纹;测试夹具仅对 sqlite 做隔离与 wait_for_exit=True 回收,并在各自模块收敛 _invoke_loopx_cli 与 _teardown_sqlite_runtime。),当前 PR 边界:共 6 个文件(+290/-36):request_amendment.py(+4/-1)与 lifecycle_recovery.py(+2/-0)合计仅 +6/-1 行生产改动;test_request_amendment_recovery.py(+89/-0)与 test_replan_semantics_transport.py(+69/-0)覆盖作用域/退栈验证;test_canonical_claim_execution_proof.py(+73/-19)与 test_task_lease_argument_recovery.py(+53/-16)收敛进程内 CLI 驱动与仅 sqlite 清理;无新接口或参数。
具体改动 / Changes
- 规范依据检查:
no_spec。docs/architecture/rfcs/typescript-control-plane-migration-v0.md约定 TS 侧拥有决策、Python 负责适配器编排,未限定请求作用域或测试进程驱动细节,按既有effect_runtime_request_scope契约与测试质量准则核验。验收条目标注如下:request-amendment-scope-reuse: implemented:execute_request_amendment、recover_request_amendment 与 control_request 共享请求修订并支持重入和异常退栈,由 test_request_amendment_entrypoints_share_one_effect_runtime_scope 与REQ_AMEND_CF_OK验证。lifecycle-recovery-scope-reuse: implemented:receipt_bound_lifecycle_candidate 跨越7跳投影与衍生调用共用 1 次指纹且衍生抛错后归零,由 test_receipt_bound_lifecycle_candidate_shares_one_effect_runtime_scope 与LIFECYCLE_CF_OK验证。claim-and-lease-harness-isolation: implemented:test_canonical_claim_execution_proof.py 与 test_task_lease_argument_recovery.py 默认走进程内 CLI、保留真实子进程检查,并仅对sqlite隔离与等待退出清理。
共改动 6 个文件(+290/-36):
- request_amendment.py & request_amendment.py(
+4/-1):导入并用@effect_runtime_request_scope()装饰execute_request_amendment、recover_request_amendment与control_request。 - lifecycle_recovery.py(
+2/-0):导入并用@effect_runtime_request_scope()装饰receipt_bound_lifecycle_candidate。 - test_request_amendment_recovery.py(
+89/-0):验证control_request(revise/cancel)、recover_request_amendment及第 2 次 RPC 注入异常后的 1 次指纹与退栈复位。 - test_replan_semantics_transport.py(
+69/-0):验证receipt_bound_lifecycle_candidate多 RPC 共享 1 次指纹与failing_derive异常退栈复位。 - test_canonical_claim_execution_proof.py(
+73/-19):抽出_invoke_loopx_cli与_teardown_sqlite_runtime,仅sqlite隔离与停止清理,保留node -e与todo listvia_subprocess=True子进程验证。 - test_task_lease_argument_recovery.py & test_task_lease_argument_recovery.py(
+53/-16):抽出_invoke_loopx_cli与_teardown_sqlite_runtime,保留--cli-bin生成命令子进程测试,仅sqlite隔离与等待退出清理。
对主干的风险 / Risks
- 无新增阻断或非阻断缺陷:
test_canonical_claim_execution_proof.py与test_task_lease_argument_recovery.py中夹具 teardown 的finally块严格先于函数参数monkeypatch退栈执行,因此_teardown_sqlite_runtime()(restart_effect_runtime(wait_for_exit=True)+close_stale_cleanup_sweeps())始终作用于sqlite隔离的临时目录并等待进程退出,之后才由monkeypatch.undo()恢复TMPDIR/NODE_OPTIONS并删除tmp_path;外部临时工作目录运行 76 例实测locators=0 live_lines=0。_invoke_loopx_cli中os.chdir(REPO)/os.chdir(ROOT)切换的均为仓库根路径自身,且在finally内恢复previous_cwd,实测外部工作目录跑完准确还原为原目录。
- 独立验证结果(全部实测于精确提交
d3a2f2f01ec2281a5da34f33128b8b9d7b514045):- 对照探针(
REQ_AMEND_CF_OK&LIFECYCLE_CF_OK):外层作用域嵌套下control_request(..., "cancel")2 例(file/sqlite)实测nested_fp=1, nested_rpc=4,去掉装饰器对照__wrapped__revise实测unwrapped_revise_fp=2, unwrapped_revise_rpc=2(2 passed in 1.06s);receipt_bound_lifecycle_candidate外层嵌套实测nested_fp=1, nested_rpc=7,去掉装饰器对照__wrapped__实测unwrapped_fp=7, unwrapped_rpc=7。 - 关联套件并行回归(
-n 4):test_request_amendment_recovery.py、test_replan_semantics_transport.py、test_canonical_claim_execution_proof.py、test_task_lease_argument_recovery.py、test_goal_amendment_authority.py、test_effect_runtime_request_scope.py共167 passed in 41.49s。 - 串行与外部工作目录泄漏盘点(隔离
--basetemp):4 个改动测试文件串行122 passed in 72.68s(LEAK_CENSUS_BT locators=0 live_lines=0);外部临时工作目录运行test_canonical_claim_execution_proof.py与test_task_lease_argument_recovery.py共76 passed in 33.96s(工作目录不变、LEAK_CENSUS_EXT locators=0 live_lines=0)。 - 静态与边界检查:
ruff check6 文件通过;git diff --check与git merge-tree --write-tree干净无冲突;mypy --follow-imports=silent request_amendment.py lifecycle_recovery.py0 错误(Success: no issues found in 2 source files);loopx check --scan-path(6 文件)errors=0, warnings=0。 - 标准预合并金丝雀(
loopx canary premerge --tier standard --from-git-diff):direct_checks 6/6、catalog_canaries 8/8、risk_profile_smokes 8/8全部通过(failures=0);退出码为 1 仅因本地 Goal 当前尚未写入本头作者侧change_quality回执(status=receipt_missing,quality_receipt_failure_count=1)。按 Goal 策略未等待远程 CI(wait_for_ci=false)。
- 对照探针(
我的整体评价 / Verdict
- 长程与用户体验影响:
long_horizon为 improved:request_amendment系列与receipt_bound_lifecycle_candidate(实测达 7 跳 RPC)单次调用仅解析 1 次源码指纹,且两个 CLI 恢复测试收敛子进程启动并零泄漏回收。user_experience为 preserved:请求修订/中止语义、生命周期候选项、生成命令--cli-bin解析与via_subprocess=True子进程校验均与基线完全一致。视觉核查(visual_review):本次改动仅涉及 Python 控制面请求修订/生命周期恢复作用域与后端恢复测试驱动,不涉及任何前端页面或浏览器渲染界面。未验证范围:不适用;无前端界面渲染改动。 - 架构与工作量定性:
code_volume为necessary,compatibility_assessment为retain;change_proportionality为proportionate;架构结论 retain(仅在确实存在多跳 RPC 链的 4 个同步入口函数上直接复用@effect_runtime_request_scope()装饰器,签名与函数体零改动;control_request与recover_request_amendment同时加装饰器可在直调与内部重入两条入口均保证 1 次指纹;测试夹具仅对sqlite做隔离与wait_for_exit=True回收,并在各自模块收敛_invoke_loopx_cli与_teardown_sqlite_runtime。)。共 6 个文件(+290/-36):request_amendment.py(+4/-1)与lifecycle_recovery.py(+2/-0)合计仅+6/-1行生产改动;test_request_amendment_recovery.py(+89/-0)与test_replan_semantics_transport.py(+69/-0)覆盖作用域/退栈验证;test_canonical_claim_execution_proof.py(+73/-19)与test_task_lease_argument_recovery.py(+53/-16)收敛进程内 CLI 驱动与仅sqlite清理;无新接口或参数。 - 语义词汇与最终结论:未引入新状态、协议字段或语义词汇,完全复用现有
@effect_runtime_request_scope()与清理原语。所有验证通过,可以批准。
English verdict: APPROVE at d3a2f2f. @effect_runtime_request_scope() cleanly pins one runtime fingerprint per call across multi-RPC execute_request_amendment, recover_request_amendment, control_request, and receipt_bound_lifecycle_candidate (7 -> 1 fp in probe) with safe nesting and error unwind, while test_canonical_claim_execution_proof.py and test_task_lease_argument_recovery.py run cli in-process with preserved subprocess coverage, sqlite-only isolation, wait_for_exit=True teardown, and zero leaked runtime workers.
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
动机 / Motivation
受影响的是提交或恢复请求关联修订的操作者,以及维护过期租约恢复的开发者。 一次修订或恢复会调用多个运行时 RPC。基线的过期租约测试从诊断取出认领命令,并启动独立 CLI 进程。 候选在逻辑调用内复用指纹,常规 CLI 回归改为进程内运行。 范围是请求修订、原回执生命周期投影以及两组本地恢复测试。
改动思路 / Approach
Effect runtime 的现有作用域负责选择运行时版本。请求保留、目标修订和租约仍由原有领域 owner 决定。 请求关联失败后重新读原效果并补齐原关联。生命周期投影从同一义务的完成行推导候选,随后由现有读回验证。真实 File 和 SQLite CLI 在已提交但丢失请求关联的路径上保留 18 次 RPC,在同操作重放时保留 15 次 RPC。两条路径的指纹分别从 18、15 次降到 1 次。公开 manager-inbox 的 revise、cancel 和 recover 两版均为 1 次。直接生命周期候选保持 7 次 RPC,指纹由 7 降到 1。 运行时作用域 请求修订 CLI
具体改动 / Changes
- 请求修订、recover 和 control 复用调用作用域。合成链接失败后,按原请求成功关联既有目标回执。两版执行 File 和 SQLite 都只创建一个 Todo,重新执行同操作时读回相同结果且不改变 provider revision。 请求修订 恢复入口
- 生命周期候选复用来源投影、派生和后继确认的作用域。无可用来源仍退出,派生异常能清理 scope。 生命周期入口 原调用方
- 恢复测试的常规调用转为进程内。两组过期租约用例把 recovery.claim.cli_args 交给默认进程内 driver。use_fixture_route=False 只去掉 fixture 路由参数,仍由 cli_main 在同一进程执行。 本提交中的 todo list 子进程覆盖读回,另一组 --cli-bin 用例覆盖显式启动器和参数修复。 过期回执路径 CAS 路径
request-amendment-parity 在基线和候选通过。 expired-claim-process-boundary 仍有缺口。 真实路径验收
对主干的风险 / Risks
[P2] 过期租约恢复测试漏掉生成 claim 的启动失败。 只注入生成的 claim 启动故障,File 和 SQLite 的 12 项基线用例失败,候选 12 项全过。仅把生成的 claim 恢复为子进程后,正常 12 项通过,同一启动故障重新使 12 项失败。 在这两组用例执行生成的 claim 时传入已有 via_subprocess=True,保留原 argv、退出码与租约读回。 四组测试主干 119 项、候选 122 项通过。Ruff、两个生产模块的 mypy、公开内容扫描和 16 项选中及 6 项直接 premerge 检查通过。 本地模拟的是生成命令的解释器不可用和已提交效果的关联响应故障。实际安装包、生产延迟、Windows 和远端 CI 未在本轮运行。 生成命令调用
我的整体评价 / Verdict
REQUEST_CHANGES。 已验证请求修订及生命周期候选的指纹收益和原回执行为。恢复过期租约场景中生成 claim 的子进程覆盖后再复评,保留常规测试的进程内优化。
English verdict: REQUEST_CHANGES at d3a2f2f. Runtime fingerprint savings and receipt replay are verified. The two expired-lease recovery tests no longer launch the generated claim in a separate process and miss an injected launch failure in all twelve cases.
Summary
Reduce control-plane request-scope RPC/source-fingerprint overhead on request-amendment and lifecycle-recovery orchestration, and cut verification latency across two CLI-heavy control-plane test suites without altering production semantics or leaking runtime workers:
@effect_runtime_request_scope):loopx/control_plane/collaboration/request_amendment.py: decorateexecute_request_amendment,recover_request_amendment, andcontrol_requestso multi-RPC request amendment and recovery flows pin one runtime source fingerprint per logical request instead of re-hashing on every RPC.loopx/control_plane/work_items/lifecycle_recovery.py: decoratereceipt_bound_lifecycle_candidateso multi-RPC lifecycle projection/replan flows share one runtime source fingerprint per invocation.tests/control_plane/test_request_amendment_recovery.py: verifycontrol_request(revise,cancel) andrecover_request_amendmentcall_runtime_fingerprintonce across multi-RPC flows and clean_REQUEST_RUNTIME_REVISIONon both normal completion and injected RPC failures.tests/control_plane/test_replan_semantics_transport.py: verifyreceipt_bound_lifecycle_candidatepins one_runtime_fingerprintacross multi-RPC projection/derivation calls and resets_REQUEST_RUNTIME_REVISIONon normal return and injected derivation failure.tests/control_plane/test_canonical_claim_execution_proof.py&tests/control_plane/test_task_lease_argument_recovery.py: route standard fixtureloopx.cliinvocations in-process via shared_invoke_loopx_cli/_teardown_sqlite_runtimehelpers, limitisolate_sqlite_runtime/ daemon teardown tosqliteprovider runs (reusing pytest's session-scoped worker Effect runtime onfileruns), and preserve real subprocess coverage for emitted--cli-binPATH resolution,node -eauthoring scripts, and a representativevia_subprocess=Truetodo listreadback.Local Verification & Paired Benchmarks
ruff checkon all 6 touched files: passed (0 errors)mypy --follow-imports=silenton both production modules: passed (no issues found in 2 source files)pytest -n autoon all 4 touched suites:122 passed in 28.52s/tmpcwdpyteston both optimized CLI suites:76 passed in 37.65s--basetemp /tmp/w69-leak-basetemp):76 passed in 34.72s,info_files=0 live_pids=0origin/main@811c1a1f6665(3xalternating-n auto+1xserial):tests/control_plane/test_canonical_claim_execution_proof.py:-n auto: base[14.17, 12.56, 12.81]median12.81s-> head[9.61, 9.84, 10.42]median9.84s(+23.2% faster)serial: base50.35s-> head23.05s(+54.2% faster)tests/control_plane/test_task_lease_argument_recovery.py:-n auto: base[7.26, 7.36, 7.44]median7.36s-> head[7.08, 7.34, 7.0]median7.08s(+3.8% faster)serial: base25.27s-> head12.66s(+49.9% faster)loopx check --scan-pathon all 6 files:ok=True,errors=0, warnings=0loopx canary premerge --from-git-diff --git-diff-base origin/main:passed(8/8catalog canaries,8/8risk profile smokes,4/4direct checks,manual_holds=0)