Repository navigation
refactor(control_plane): modularize botmux_runtime under 750 LOC with zero Any - #9444
Conversation
… zero Any 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 · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Request changes conclusion (author-owned PR; GitHub blocks formal self-review)
动机 / Motivation
通过 Goal Channel Botmux 配置和派发同一语义 Turn 的维护者。从真实 CLI 生成 completed 的本机 binding,保持同一 Goal、Turn key 和会话。分别对照正常对象、可转换的键值行集合,以及无法读取的收据集合,再运行同一 trigger。两版均通过正常 setup、doctor、首次派发和重放,实际派发一次。status 使用原 trigger id,把旧的 completed 保留至提供方报告 running 后。预览不写,绑定权限为 0600,disable 后拒绝派发。
损坏派发回执时禁止再次派发。基线对键值行集合返回 already_dispatched,对无法读取的集合返回 invalid_configuration。两次均 0 次额外派发并保持本机文件。当前头两次均返回 queued,各多发一次真实 HTTP POST,并用新回执覆盖本机集合。 独立验证使用精确源码的真实 CLI、生产 HTTP transport 与真实本机文件。HTTP 对端为隔离回环替身。实际 Botmux daemon、在线 Lark 和安装版未验证。 验收依据
改动思路 / Approach
门面继续持有文件锁。binding store 持久化收据,trigger 在进入传输前核对原派发键,status 按队列存储的 trigger id 读回。loopx goal-channel runtime setup / trigger / status / disable → Botmux 实际 HTTP transport → 本地 binding。在 trigger 和持久化入口区分收据字段缺失、可恢复和无效。无效时保留文件并在 provider POST 前返回明确的 blocker。保留可转换的既有格式,或在受控迁移后拒绝。用正反例断言实际 provider 调用数和本机收据。
具体改动 / Changes
精确 head 1ca96f8e32d9dfdc983a5ac9e388c314d72ee748,目标分支快照与实际分叉基线均为 50aa5b4fd1c88b7225fc30e58423120e3ad5d426。8 个文件增加 2014 行、删除 1395 行。拆出绑定、传输、生命周期、派发和状态模块,并调整 CLI 类型和合同测试。
关键代码讲解
trigger_botmux_runtime。保留 execute 前的本机锁并调用派发处理 源码_trigger_botmux_runtime。将不支持的收据集合视为空,然后按新派发执行 源码_as_mutable_dict。对非 Mapping 值返回空 dict,调用方无法区分缺失和异常 源码_submit_trigger_attempt。先持久化 attempting,再调用提供方并读回 queued 源码_status_botmux_runtime。沿对应 trigger id 读取状态并保留已确定的终态 源码
对主干的风险 / Risks
[P2] 无法验证旧收据时仍发起新派发
基线对键值行集合返回 already_dispatched,对无法读取的集合返回 invalid_configuration。两次均 0 次额外派发并保持本机文件。当前头两次均返回 queued,各多发一次真实 HTTP POST,并用新回执覆盖本机集合。
调用方若持有旧式或损坏的本机数据,会失去原有防重放证据。同一 Turn 已被接收后,重复调用到达 Botmux。实验确认了额外请求和本机覆写。 相关源码
独立验证
真实 CLI 基线和当前头回环对照、81 项本地测试、8 文件 strict mypy 均完成。标准 premerge 通过。
我的整体评价 / Verdict
REQUEST_CHANGES。 在 trigger 和持久化入口区分收据字段缺失、可恢复和无效。无效时保留文件并在 provider POST 前返回明确的 blocker。保留可转换的既有格式,或在受控迁移后拒绝。用正反例断言实际 provider 调用数和本机收据。 复验正常重放、可恢复历史格式和收据损坏三种状态。
English verdict: REQUEST_CHANGES at 1ca96f8. When the local dispatch receipt collection cannot be verified, the refactor drops deduplication evidence and sends another provider request. Preserve or reject the existing record before dispatch.
…receipts or session 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 · gpt-6.2-sol · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
拆分 Botmux Goal Channel runtime,保留退出码、锁、私有 binding 和按同一语义 Turn 去重的合同。上一精确头把非 Mapping 的本机收据直接变成空集合,使已经派发过的 Turn 多出一次请求。目标基线会恢复键值行集合,或拒绝无法读取的异常。用 Botmux 连接 Goal Channel、复用既有运行会话或重放同一语义任务的本机操作者。
收据恢复、重复派发与损坏拒绝。损坏 receipts 或 session 时,当前头在 setup、status、同键 trigger 与新键 trigger 都返回 invalid_configuration。对端观测为零次额外 HTTP,本机文件按字节保持。禁用后状态和写入结果与基线一致。正常 setup、doctor、首次派发和重放的回环 HTTP 与磁盘行为一致。旧键值行收据放回真实文件,当前头正常去重。两节均使用可恢复格式时,状态绑定原 trigger id。显式新键的后续派发复用原 session,保留原完成收据。
依据精确源码、实际 CLI 和本机磁盘。Botmux 对端是隔离回环 HTTP 替身。真实 Botmux daemon、在线 Lark、已安装版本和远端 CI 留在其自身验收。 基线运行时合同 本次变更范围
改动思路 / Approach
门面保持文件锁和旧 API。binding store 验证并恢复 section,trigger 检查派发收据,status 只用与派发绑定的 provider 结果。复用一处 section 归一化,为可转换的键值行保留原有语义,拒绝损坏集合。继续使用已存在的派发状态与状态迁移。
loopx goal-channel runtime setup / trigger / status / disable → 共享 binding store → Botmux HTTP transport。
具体改动 / Changes
精确提交 d200454ef778499f15b69fcbabc2cb8eeccd6954,目标分叉点 50aa5b4fd1c88b7225fc30e58423120e3ad5d426。8 个文件增加 2311 行、删除 1395 行。相对上一提交,5 个文件增加 323 行、删除 26 行。
_coerce_binding_section。统一处理缺省、映射和可恢复的键值行,非法形态上抛。 源码_trigger_botmux_runtime。先验证 receipts 和 session,再决定旧 Turn 重放或真正派发。 源码_setup_botmux_runtime。配置同一路由时恢复并保留现有收据和会话。 源码_status_botmux_runtime。验证本机绑定,按存储 trigger id 读回并保留终态。 源码_persist_dispatch_receipt。在现有锁内保留旧收据并更新当前 Turn。 源码
对主干的风险 / Risks
本轮未发现阻塞问题。94 项定向测试、8 文件 strict mypy 和标准 premerge 通过。实际 CLI 使用同一回环 fixture 对比基线、旧评审头和当前头。
依据精确源码、实际 CLI 和本机磁盘。Botmux 对端是隔离回环 HTTP 替身。真实 Botmux daemon、在线 Lark、已安装版本和远端 CI 留在其自身验收。
我的整体评价 / Verdict
APPROVE。 上轮阻塞项已在真实 CLI 的三版对照中复验。正常首次派发、同键重放、损坏拒绝和已有会话续跑都满足预期。失败分支保留旧文件,避免丢失下次排查所需的收据。
English verdict: APPROVE at d200454. The real CLI preserves deduplication on recovered receipts, rejects malformed binding sections before transport or persistence, and reuses the existing session for a deliberate new turn.
Summary
Modularizes
loopx/control_plane/goals/botmux_runtime.py(1,554 -> 301LOC) into cohesive, domain-focused modules insideloopx/control_plane/goals/while eliminating all ASTAnyannotations (49 -> 0acrossbotmux_runtime.py, plus2 -> 0inloopx/cli_commands/goal_channel_runtime.py) and clearing baselinemypyerrors (6 -> 0inbotmux_*,1 -> 0ingoal_channel_runtime.py) with zero# type: ignoresuppressions.Follow-up fix commit
d200454ef7replaces_as_mutable_dictwith fail-closed_coerce_binding_sectionacrossbotmux_binding_store.py,botmux_trigger.py,botmux_status.py, andbotmux_lifecycle.pyso missing (None),Mapping, and recoverable key-value pair sequences ([[k, v], ...]) preserve idempotent receipts / reused sessions while corrupt non-mapping values raiseValueErrorbefore any provider HTTP call or binding write (mapping cleanly to CLIblocked/invalid_configuration).Architecture & Module Breakdown
loopx/control_plane/goals/botmux_binding_store.py(423LOC,0Any): schema/provider constants,BotmuxApiError/BotmuxTransportError,BotmuxDispatchStatetransition state machine, typedPayload/PayloadView/JsonRequestercontracts,_coerce_binding_section, local-private binding reads, atomic binding/receipt persistence helpers, and public packet redaction guards.loopx/control_plane/goals/botmux_transport.py(302LOC,0Any): loopback/HTTPS origin and auth/id/working-directory validators, strictly typed_NoRedirectHandler(redirect_request),_request_json, and_probe_botmux.loopx/control_plane/goals/botmux_lifecycle.py(308LOC,0Any): Goal registry lookup, shared_probe_error_packeterror mapper,_setup_botmux_runtime,_doctor_botmux_runtime,_disable_botmux_runtime,build_botmux_loopx_instruction,goal_runtime_revision, and deterministic dispatch/receipt keys.loopx/control_plane/goals/botmux_trigger.py(316LOC,0Any): idempotent_trigger_botmux_runtimeand_submit_trigger_attempt.loopx/control_plane/goals/botmux_status.py(409LOC,0Any): receipt-bound status reconciliation (_status_botmux_runtime,_query_pinned_trigger_status,_resolve_unaccepted_dispatch_status,_record_status_transport_failure,_resolve_observed_state), reducing_status_botmux_runtimecomplexity from78statements /57decision points to47statements /33decision points.loopx/control_plane/goals/botmux_runtime.py(301LOC,0Any): compatibility facade preserving__all__, explicit house-style re-exports (from ... import X as X),OPAQUE_ID_PATTERNbinding as_SAFE_TOKEN(keepingbotmux_runtime._SAFE_TOKEN is PUBLIC_OPAQUE_ID),_write_private_json_atomic+os/_now_iso/_request_jsonmonkeypatch seams, and lock-fenced public entrypoints.loopx/cli_commands/goal_channel_runtime.py(167LOC,0Any): typedargparse._SubParsersAction[argparse.ArgumentParser]andregistry: Mapping[str, object].tests/control_plane/test_botmux_runtime_contract.py(412LOC,0Any): enforces< 750LOC,0ASTAny,0# type: ignore, facade monkeypatch seams (_request_json,_now_iso),__all__exports, redirect refusal, non-dict/malformed JSON handling, and positive/negative binding section recovery vs fail-closed corruption guards acrosstrigger,status,setup, and CLI.Verification
Verified on clean detached commit
d200454ef7:ruff check(8/8files): passedmypy --strict --no-incremental --follow-imports=silent(8/8files):0issuesmypy --no-incrementalfiltered to the8PR paths:0issuespytest -n 6 -rs(tests/control_plane/test_botmux_runtime_contract.py,test_botmux_goal_channel_runtime.py,test_goal_channel_runtime_cli.py,test_compact_identifier_shape_owner.py,test_refresh_checkpoint_isolation.py,test_steward_goal_notice_integration.py,tests/test_windows_atomic_writes.py,tests/architecture/,tests/canary/):2,206 passed, 9 skipped(6APFS filename/root skips intest_git_path_display.py,3Windows-only skips intest_windows_atomic_writes.py)npm run typecheck:control-plane: passednode --no-warnings --experimental-sqlite --experimental-strip-types --test tests/control_plane_ts/content_digest_single_owner.test.ts:17passed,0failedscripts/check_rfc_bilingual.py --base origin/main --head HEAD: passedexamples/semantic-vocabulary-drift-smoke.py(34/34vocabularies,62/62owner symbols) andexamples/control_plane/control-plane-maintainability-ratchet-smoke.py(0unreviewed/regressions): passedloopx check(8/8files,0errors,0warnings) &loopx canary premerge --from-git-diff --git-diff-base origin/main(gate.status=passed,catalog_run=10/10,risk_profile_run=8/8,failures=0,manual_hold_count=0): passedRisks & Notes
loopx/canary/module_metric_baseline.jsonandtests/architecture/top_level_module_budget.json(112top-levelloopx/*.pymodules) are untouched._SAFE_TOKEN,_write_private_json_atomic,os,_now_iso,_request_json).