Repository navigation
perf(control-plane): scope inventory/amendment RPCs and run research/lease CLI tests in-process - #9598
perf(control-plane): scope inventory/amendment RPCs and run research/lease CLI tests in-process#9598loopx-agent wants to merge 1 commit into
Conversation
…lease CLI tests in-process 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 #9598 确切提交 9598@62df2f7cbf217f30e6bcba7cd3c47fcc726560fd(基线 main@811c1a1f66652d3fc3b9830d467e14b45b7423c1)执行了 Goal-bound 独立审查(wait_for_ci=false)。逐一审计 6 个文件的完整 diff、read_delegation_inventory(2 + N RPC 及与 Delegations.operations 的嵌套兼容)与 admit_goal_amendment_proposal(推导、对齐投影与 goal.amendment_proposal.admit 6 RPC)、test_research_composition_gate.py 与 test_todo_update_lease_recovery.py 的局部共享辅助函数与仅 sqlite 退出等待清理、对照探针、6 套件 -n 4 并行回归、隔离 --basetemp 串行及外部工作目录泄漏盘点、静态检查和标准预合并金丝雀门禁,确认无阻断或非阻断缺陷,结论为 APPROVE。
动机 / Motivation
受影响方与触发条件:直接分页读取委派台账的调用方(read_delegation_inventory)、提交阶段二目标修订提案的调用方(admit_goal_amendment_proposal),以及高频本地运行 tests/capabilities/test_research_composition_gate.py 与 tests/control_plane/test_todo_update_lease_recovery.py 的维护者与验证流水线。
修改前后场景对照:改动前,直接调用 read_delegation_inventory 时跨 inventory_query、逐项 service.read 与 inventory_page(2 + N 次 RPC)每跳各自重算 _runtime_fingerprint();admit_goal_amendment_proposal 在推导开放重规划义务、对齐投影与 goal.amendment_proposal.admit 多跳链中每跳各自重算指纹;同时 test_research_composition_gate.py 与 test_todo_update_lease_recovery.py 的 cli() 均冷启动子进程,并对 file 与 sqlite 一并隔离临时目录或无条件重启动运行时。改动后,两个生产入口直接用既有的 @effect_runtime_request_scope() 装饰(无转发层),单次请求仅解析 1 次源码指纹且与 Delegations.operations 外层作用域安全重入;test_delegation_inventory.py 与 test_goal_amendment_proposal.py 补充共享指纹与合成异常退栈测试;test_research_composition_gate.py 与 test_todo_update_lease_recovery.py 默认将 cli() 改为进程内 cli_main(保留 via_subprocess=True、read_stage 与 _run_generated_cli 子进程验收),仅对 sqlite 隔离环境并通过 restart_effect_runtime(wait_for_exit=True) 与 close_stale_cleanup_sweeps 在 finally/addfinalizer 内清理进程。
可观测交付结果:独立对照探针实测:INVENTORY_CF_OK 在嵌套外层作用域下 6 次 RPC 仅计算 1 次指纹(去掉装饰器对照为 6/6);AMENDMENT_CF_OK 在嵌套外层作用域下 6 次 RPC 仅计算 1 次指纹(去掉装饰器对照为 6/6);两者合成异常退出均将 _REQUEST_RUNTIME_REVISION 干净复位为 None;6 个关联 pytest 套件 -n 4 下 132 passed in 32.70s,4 个变更测试文件在隔离 --basetemp 下串行 87 passed in 49.22s,两个端到端 CLI 测试模块在外部临时工作目录运行 39 passed in 36.97s,工作目录还原不变且两者均为 locators=0 live_lines=0。
明确非目标:不改变委派记录读取容错、目标修订提案因果成员校验证据或 journal 写入语义;不修改 delegation_inventory.py 既有类型注解;不取消研究组合门禁的 read_stage/_run_generated_cli 真实子进程检查或租约恢复的 via_subprocess=True 覆盖。
改动思路 / Approach
生产侧直接给 read_delegation_inventory(delegation_inventory.py)与 admit_goal_amendment_proposal(goal_amendment_proposal.py)添加 @effect_runtime_request_scope()。注意 Delegations.operations(collaboration_mcp.py)外层已包有 with effect_runtime_request_scope():,因此对 read_delegation_inventory 加装饰器后:当经由 Delegations.operations 调用时内层通过 try_join() 加入外层并在外层离开前保持修订活跃;当被直接调用时则独立创建作用域并在 finally 复位,兼顾两类调用方。测试侧仅对 sqlite 执行临时目录隔离和 restart_effect_runtime(wait_for_exit=True) + close_stale_cleanup_sweeps 回收,且保持真实生成子进程命令验收不被进程内驱动替代。
flowchart LR
subgraph Prod["生产多跳入口 @effect_runtime_request_scope()"]
DI["read_delegation_inventory"] -->|"query + N*observe + page (6 RPC)"| D1["共用 1 次指纹;支持 Delegations.operations 嵌套"]
GA["admit_goal_amendment_proposal"] -->|"derive + align + admit (6 RPC)"| G1["共用 1 次指纹;异常复位 ContextVar"]
end
subgraph Tests["端到端 CLI 与回收收敛"]
SQ["仅 sqlite 调用 isolate_sqlite_runtime"] --> CL["cli() 默认 cli_main"]
CL -->|"via_subprocess=True / read_stage / _run_generated_cli"| Sub["保留真实 subprocess.run"]
SQ -->|"finally / addfinalizer"| Clean["restart_effect_runtime(wait_for_exit=True) + close_stale_cleanup_sweeps"]
end
(说明性控制流图,对应提交 62df2f7cbf217f30e6bcba7cd3c47fcc726560fd;基于源码审计与本地探针整理,不代表监控截屏。)
架构评估结论(只在确实拥有多跳 RPC 的两个同步入口函数上直接复用 @effect_runtime_request_scope() 装饰器,既消除直接调用指纹重复又保留 Delegations.operations 的 try_join 嵌套行为;测试夹具仅对 sqlite 做隔离与 wait_for_exit=True 回收,且将公共恢复断言收敛到局部共享辅助函数 _isolate_provider_runtime / _invoke_todo_cli。),当前 PR 边界:共 6 个文件(+236/-48):delegation_inventory.py(+6/-1)与 goal_amendment_proposal.py(+6/-1)合计仅 +12/-2 行生产改动;其余为 2 个作用域/退栈单测(+44/-0, +49/-0)以及 2 个端到端 CLI 套件的进程内驱动与仅 sqlite 清理收敛(+49/-10, +82/-36);无新接口、状态或参数。
具体改动 / Changes
- 规范依据检查:
no_spec。docs/architecture/rfcs/typescript-control-plane-migration-v0.md规定 TS 决策边界而未限定 Python 适配器指纹作用域或测试加速实现,按既有作用域原语与测试隔离准则审查。验收条目标注如下:delegation-inventory-scope-reuse: implemented:read_delegation_inventory 在直接与嵌套调用中跨多跳共享 1 次指纹并退栈复位,由 test_read_delegation_inventory_shares_effect_runtime_request_scope_and_unwind 与INVENTORY_CF_OK覆盖。goal-amendment-proposal-scope-reuse: implemented:admit_goal_amendment_proposal 在6次内部 RPC 中仅解析 1 次指纹且合成失败复位回None,由 test_admit_goal_amendment_proposal_shares_effect_runtime_request_scope_and_unwind 与AMENDMENT_CF_OK覆盖。research-and-lease-harness-isolation: implemented:test_research_composition_gate.py 与 test_todo_update_lease_recovery.py 将cli()默认迁至cli_main、保留via_subprocess=True/read_stage/_run_generated_cli子进程验收,仅隔离并等待sqlite运行时停止。
共改动 6 个文件(+236/-48):
- delegation_inventory.py & delegation_inventory.py(
+6/-1):导入并用@effect_runtime_request_scope()装饰read_delegation_inventory。 - goal_amendment_proposal.py & goal_amendment_proposal.py(
+6/-1):导入并用@effect_runtime_request_scope()装饰admit_goal_amendment_proposal。 - test_delegation_inventory.py(
+44/-0):新增多 RPC(>=3,实测6)共享指纹与错误退栈单元测试。 - test_goal_amendment_proposal.py(
+49/-0):新增多 RPC(>=2,实测6)共享指纹与错误退栈单元测试。 - test_research_composition_gate.py(
+49/-10):fixture仅sqlite隔离并在finally等待运行进程停止;cli()默认cli_main(os.chdir(REPO)位于try/finally内),显式保留via_subprocess=True、read_stage与_run_generated_cli子进程验证。 - test_todo_update_lease_recovery.py(
+82/-36):抽取出局部辅助函数_isolate_provider_runtime(经request.addfinalizer在monkeypatch.undo()前停掉sqlite运行时)与_invoke_todo_cli(保留第 157/168 行via_subprocess=True子进程校验)。
对主干的风险 / Risks
- 无新增阻断或非阻断缺陷:
test_todo_update_lease_recovery.py中的request.addfinalizer(_cleanup)在monkeypatch之后注册(因为monkeypatch为函数前置参数 fixture,在进入测试体时已创建,而request.addfinalizer在测试体内部通过_isolate_provider_runtime注册),因此在 pytest 后进先出 teardown 顺序下_cleanup()严格先于monkeypatch.undo()和tmp_path清理执行,从隔离scoped_dir停止并等待进程退出,串行与外部工作目录泄漏盘点实测locators=0 live_lines=0。test_research_composition_gate.py中os.chdir(REPO)在try块内执行,异常或完成均经finally还原prev_cwd,外部临时工作目录运行 39 例后工作目录准确不变。
- 独立验证结果(全部实测于精确提交
62df2f7cbf217f30e6bcba7cd3c47fcc726560fd):- 对照探针(
INVENTORY_CF_OK&AMENDMENT_CF_OK):外层作用域嵌套下read_delegation_inventory(2 例)实测nested_fp=1, nested_rpc=6,去掉装饰器__wrapped__对照实测unwrapped_fp=6, unwrapped_rpc=6(2 passed in 1.64s);admit_goal_amendment_proposal外层嵌套实测nested_fp=1, nested_rpc=6,对照unwrapped_fp=6, unwrapped_rpc=6。 - 关联套件并行回归(
-n 4):test_delegation_inventory.py、test_goal_amendment_proposal.py、test_research_composition_gate.py、test_todo_update_lease_recovery.py、test_goal_amendment_authority.py、test_effect_runtime_request_scope.py共132 passed in 32.70s。 - 串行与外部工作目录泄漏盘点(隔离
--basetemp):4 个改动测试文件串行87 passed in 49.22s(LEAK_CENSUS_BT locators=0 live_lines=0);外部临时工作目录运行test_research_composition_gate.py与test_todo_update_lease_recovery.py共39 passed in 36.97s(工作目录不变、LEAK_CENSUS_EXT locators=0 live_lines=0)。 - 静态与边界检查:
ruff check6 文件通过;git diff --check与git merge-tree --write-tree干净无冲突;mypy --follow-imports=silent goal_amendment_proposal.py0 错误;mypy --follow-imports=silent delegation_inventory.py报 5 个错误且与基线811c1a1f6665错误消息集合逐条一致(MYPY_INV_NEW_ERRORS_VS_BASE: 0, IDENTICAL_MSG_SET: True);loopx check --scan-path(6 文件)errors=0, warnings=0。 - 标准预合并金丝雀(
loopx canary premerge --tier standard --from-git-diff):direct_checks 6/6、catalog_canaries 10/10、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:read_delegation_inventory与admit_goal_amendment_proposal(各实测 6 跳 RPC)单次请求仅计算 1 次运行时指纹,且两端到端测试收敛进程启动与等待退出回收、零残留。user_experience为 preserved:台账读取容错、修订提案因果成员校验、租约恢复与研究组合门禁及子进程 CLI 检查完全等价。视觉核查(visual_review):本次改动仅涉及 Python 控制面台账读取/修订提案作用域及后端测试辅助,未改动任何前端界面或浏览器渲染内容。未验证范围:不适用;无前端界面渲染改动。 - 架构与工作量定性:
code_volume为necessary,compatibility_assessment为retain;change_proportionality为proportionate;架构结论 retain(只在确实拥有多跳 RPC 的两个同步入口函数上直接复用@effect_runtime_request_scope()装饰器,既消除直接调用指纹重复又保留Delegations.operations的try_join嵌套行为;测试夹具仅对sqlite做隔离与wait_for_exit=True回收,且将公共恢复断言收敛到局部共享辅助函数_isolate_provider_runtime/_invoke_todo_cli。)。共 6 个文件(+236/-48):delegation_inventory.py(+6/-1)与goal_amendment_proposal.py(+6/-1)合计仅+12/-2行生产改动;其余为 2 个作用域/退栈单测(+44/-0,+49/-0)以及 2 个端到端 CLI 套件的进程内驱动与仅sqlite清理收敛(+49/-10,+82/-36);无新接口、状态或参数。 - 语义词汇与最终结论:未引入新状态、协议字段或语义词汇,完全复用现有
@effect_runtime_request_scope()与清理原语。所有验证通过,可以批准。
English verdict: APPROVE at 62df2f7. @effect_runtime_request_scope() collapses multi-RPC fingerprinting from 6 -> 1 on both read_delegation_inventory (safely re-entering Delegations.operations) and admit_goal_amendment_proposal with clean error unwind, while test_research_composition_gate.py and test_todo_update_lease_recovery.py run cli() in-process with preserved subprocess checks, sqlite-only isolation, wait_for_exit=True cleanup, 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
读取委派清单、提交修订提案的调用方,以及按诊断命令恢复已认领 Todo 的维护者。 多次调用运行时会重复计算同一份源码指纹;频繁的固定参数测试也各自启动解释器。 基线在直接清单和提案入口逐跳解析。在租约恢复用例中,生成的认领命令以单独的 Python 进程执行。 在 File 和 SQLite 让租约恢复生成 todo claim,分别运行正常对照和仅让这条生成命令启动失败的反例。 正常对照三组各 4 项通过。只使生成的 todo claim 启动失败时,基线 4 项失败,当前默认仍 4 项通过;将这一步恢复到子进程后,4 项重新检出。 验证覆盖本地 File、SQLite、合成状态和真实 CLI 进程。发布包、生产时延和远端 CI 未验证。
改动思路 / Approach
减少重复指纹准备,同时保留已生成恢复命令的跨进程验收。 运行时版本固定在单次作用域内,原授权和提案留存仍由现有领域 owner 处理。 复用现有作用域,保留真实恢复命令独立执行,固定参数调用可继续由进程内 helper 加速。 清单按现有地址与来源收集状态,提案按原义务、目标与 Agent 验证并只追加到提案日志。 直接清单以及修订提案重试的指纹均从 6 降到 1。公开清单入口通过外层作用域在两版均为 1。 清单入口 提案入口
具体改动 / Changes
精确提交 62df2f7cbf217f30e6bcba7cd3c47fcc726560fd,基线 811c1a1f66652d3fc3b9830d467e14b45b7423c1。6 个净路径 +236/-48,生产只增加 import 和两个装饰器;其余都是测试夹具、清理和验证。 对照「委派和提案原语义保持」「请求内指纹检查减少」和「生成认领命令的启动失败可被检出」。损坏一条清单记录仍返回不完整告警且不启动工作;丢失提案验证响应后原操作只追加一条提案,冲突重放拒绝,任何读回均不提交规范状态。 研究测试中的生成命令读取仍经子进程,租约恢复中保留的 inspect 子进程只覆盖自己的调用。 真实路径规范 提案与收据 研究读取
对主干的风险 / Risks
[P2] 生成的 Todo 认领恢复命令失去真实子进程覆盖。 租约恢复用例把诊断返回的真实认领 argv 交给默认进程内 helper;其他用例的保留子进程只验证租约检查。 将启动错误只注入带新操作键的生成 claim,没有改判定与存储。正常对照三组各 4 项通过。只使生成的 todo claim 启动失败时,基线 4 项失败,当前默认仍 4 项通过;将这一步恢复到子进程后,4 项重新检出。 从正常对照看,当前产品的命令仍可运行,缺口是默认测试检不出启动失效。基线 84 项、候选 87 项通过,18 项预合并选检和 6 项直接检查通过。额外配对故障探针验证诊断恢复路径。 生成认领调用
我的整体评价 / Verdict
REQUEST_CHANGES。 保留两处已实测的指纹优化,并补回生成认领命令的进程验收。让生成的 claim argv 走已有 via_subprocess 路径,并保留其退出码、认领收据和启动失败反例。 File 和 SQLite 两种初始租约状态均可用同一反例复验。
English verdict: REQUEST_CHANGES at 62df2f7. The runtime scope savings are verified. The generated Todo claim recovery no longer crosses the CLI subprocess boundary, and its four default cases miss an injected launch failure.
Delivery Brief
codex/s1-wave68-control-tax-20261129, based onorigin/main@811c1a1f6665).loopx/control_plane/collaboration/delegation_inventory.py: decoratedread_delegation_inventory(2 + NRPCs:inventory_query, per-itemservice.read,inventory_page) with@effect_runtime_request_scope(), collapsing runtime fingerprint hashing to1per call and unwinding cleanly on failure.loopx/control_plane/goals/goal_amendment_proposal.py: decoratedadmit_goal_amendment_proposal(3–4RPCs: obligation derivation, alignment projection, obligation inventory,goal.amendment_proposal.admit) with@effect_runtime_request_scope(), collapsing runtime fingerprinting to1per call with clean exception unwind.tests/test_delegation_inventory.py&tests/control_plane/test_goal_amendment_proposal.py: added focused multi-RPC fingerprint/unwind assertions (test_read_delegation_inventory_shares_effect_runtime_request_scope_and_unwind,test_admit_goal_amendment_proposal_shares_effect_runtime_request_scope_and_unwind).tests/capabilities/test_research_composition_gate.py&tests/control_plane/test_todo_update_lease_recovery.py: converted test-harnesscli()calls to runloopx.cli.mainin-process by default (with shared_isolate_provider_runtime+_invoke_todo_clihelpers, preservingvia_subprocess=True,read_stage, and_run_generated_clisubprocess checks), isolated SQLite TMPDIR only forsqlitecases, and cleaned up infinallyviarestart_effect_runtime(wait_for_exit=True)+close_stale_cleanup_sweeps.Verification (Local-First,
wait_for_ci=false)ruff checkon all 6 changed files: passed.mypy --follow-imports=silent: 0 errors ingoal_amendment_proposal.py;delegation_inventory.pyhas the exact same 5 pre-existing errors asorigin/main@811c1a1f6665(0 new errors).pytest -n auto -q tests/test_delegation_inventory.py tests/control_plane/test_goal_amendment_proposal.py tests/capabilities/test_research_composition_gate.py tests/control_plane/test_todo_update_lease_recovery.py: 87 passed in20.22s./tmpcwdpytest -n auto -q tests/capabilities/test_research_composition_gate.py tests/control_plane/test_todo_update_lease_recovery.py: 39 passed in18.42s.--basetemp /tmp/w68-leak-basetempworker leak census (21 passedin25.13s+18 passedin25.96s):info_files=0, live_pids=0.loopx check --scan-path ...(6 files): errors=0, warnings=0, public boundary scan clean.loopx canary premerge --from-git-diff --git-diff-base origin/main: passed (18/18selected checks passed: 10 catalog canaries + 8 risk-profile smokes,failures=0,manual_holds=0,merge_gate_passed=true).Paired Benchmarks (vs detached
origin/main@811c1a1f6665, HEAD62df2f7cbf21)origin/maintest_research_composition_gate.py-n auto(3x med)13.45s([25.05, 13.31, 13.45])10.27s([10.27, 9.92, 10.43])-23.7%test_research_composition_gate.py49.14s24.28s-50.6%test_todo_update_lease_recovery.py-n auto(3x med)8.33s([8.01, 8.33, 8.53])7.52s([7.29, 7.63, 7.52])-9.7%test_todo_update_lease_recovery.py31.42s15.19s-51.7%Note: Remote GitHub Actions CI is not waited on per repository local-first policy (
wait_for_ci=false). PR left OPEN for maintainer merge.