Skip to content

refactor(turn): share route qualification across real callers - #7520

Merged
huangruiteng merged 1 commit into
mainfrom
codex/turn-route-owner
Oct 28, 2026
Merged

huangruiteng merged 1 commit into
mainfrom
codex/turn-route-owner

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Turn planning and the loop controller still classified admitted actions in Python while envelope interpretation lived in TypeScript. This independently usable prerequisite extracts the route work from #7430 onto main (b69021498), removes the Python classification tables/branches, and makes both callers use the existing quota/turn_envelope.ts owner.

The plan receives route and signature in one projection. Managed-step receives an immutable local envelope/route result from its existing producer call; a wire dictionary cannot forge that qualification. Python retains the historical scalar/numeric codecs, while disposition, receipt, budget, validation and settlement retain their existing owners. The deleted intermediate fresh-envelope builder has no remaining caller. Historical dictionaries continue through the shared route reader; their adapter can retire only with the actual historical consumers, not with the new producer.

The vocabulary registry now points to the real TypeScript producer. Its bounded scanner supports explicitly declared TypeScript return producers without requiring a global field-name scan, preserving unknown flows rather than inferring safety from declarations. The protocol notes and generated bindings are synchronized; the bilingual RFC index corrects the existing 16→18 ledger count.

Validation on the frozen source committed as 862f988cc:

  • 598 Python tests passed, including real File/SQLite CLI planning/managed retry, unchanged failed journals, source/route rejection, recovery and settlement. The earlier extraction run had 349 passes and four missing-import failures; the final run follows the fix. Baseline characterization had 209 passes.
  • TypeScript typecheck, generated-binding freshness, semantic vocabulary smoke/advisory, Ruff, documentation governance, exact-head bilingual and diff checks passed. The advisory found no supported new vocabulary carrier; the table reuses registered action/route unions.
  • Standard premerge passed: four direct checks, changed Python compilation, ten catalog checks, eight risk checks and public-boundary validation; zero manual holds. All 18 publication files were read by a clean boundary scan.

A 1,751-byte public synthetic input, 61 alternating warm samples per arm, used the same candidate TypeScript endpoint for both arms. Plan projection kept two calls: median/p95 18.907/21.966→18.665/23.938 ms. Managed build+route kept one call: 6.517/8.766→6.356/8.359 ms. The standalone historical route helper changes from zero calls (0.004/0.006 ms) to one (6.245/7.468 ms): an explicit local regression. These are component measurements, with uncontrolled other machine load; they exclude complete CLI/backend/startup/child CPU, model/cache/billing, human attention and accepted outcomes. They do not establish net efficiency or long-horizon benefit.

This PR is usable and reversible on main without the complete-contract writer or scoped outcome delivery. #7430 remains an unfinished integration candidate and currently contains the earlier integrated route work; rebase it after this prerequisite is adopted, rather than merging duplicated implementations. Revert this coherent caller/owner/registry change together if rollback is needed. No merge, installation, model trial or benchmark launch is performed here.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>

@loopx-agent loopx-agent 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.

Reviewer: model_agent; model=gpt-6.1-sol; provider=OpenAI; declaration_source=runtime_reported; reasoning_effort=max

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

动机 / Motivation

普通 Turn 的规划和失败恢复原先包含重复的路由判断。同一个已准入动作原先先由 Python 分类、再由 TypeScript 解释封套;修改后由同一 TypeScript owner 给出 route,原计划、拒绝原因和恢复结果保持一致。独立对照确认 29 组完整计划相等,File/SQLite 的真实 CLI 规划、重复读取、等待与错误 attempt 拒绝保持原结果。本 PR 交付路由判断的共享前置切片;不宣称完成 C1/C3/C4、两会话执行、安装采用或长期净收益。完整工作契约 writer、controller/executor 会话与实际模型收益仍由原后续工作验收。

改动思路 / Approach

路由资格归既有 TypeScript owner,Python 保留历史编码和既有 receipt、budget、disposition 的各自职责;没有第二套准入或状态权威。当前边界是两个真实 caller 共用 route 判断并保持原恢复链,可以整体回滚;后续完整契约不作为本切片的泛化前置。真实 CLI 返回 ready_for_host 且 host_invocation_allowed=false;失败 journal 的 managed-step 保持等待 30 秒,没有启动 Host 或扣额。

具体改动 / Changes

  • TypeScript 的 TURN_ACTION_ROUTES 对既有 action/frontier union 显式分类;保留 unknown action 的历史 Host 路由,未给拼写相似的值增加 repair 权限。
  • Python 删除分类表和无调用者的中间 builder,保留历史 scalar codec。plan 合并 route/signature 投影;managed-step 接收本地不可变结果,旧字典仍走共享 reader。
  • 生成绑定和协议同步同一 owner;scanner 只扩展明确登记的 TS return producer,动态未知仍保留 unresolved;双语索引的 16→18 是现有 ledger 数量纠正。

关键代码讲解

  • build_turn_controller_input:将现有构建调用的完整 envelope 和 route 作为不可变本地结果传给 controller。managed-step 从构建后再读 route 改为同一次投影;字典额外字段不能携带这个本地资格。
  • build_loopx_turn_plan:规划入口组合共享 route 和签名投影,不执行 Host。删除 Python 分类表;同一 driver_lineage 返回 route/signature,保留 session/lineage checks。
  • _ControllerInputs:在既有 ordered checks 中消费当前本地投影或历史 wire。仅本地 TurnControllerInput 复用预先算好的 route;普通 Mapping 继续走共享 typed reader。

规范依据:docs/reference/protocols/turn-controller-contract-v0.md,不可变 revision b69021498ef7483b1d2b190bc3f4c7bb6675c882。按修改前的契约评审,不用本 PR 改写的规范证明自身:

  • Runtime adoption and compatibility — implemented:29 raw full-plan base/head comparisons; historical scalar tests; 369 adjacent tests。
  • The decision is not a result-kind string map — implemented:File/SQLite plan/managed-step replay, false signature and wrong observed attempt; full payload comparison。
  • Production evidence and generated provenance — implemented:182 invariant/architecture tests, typecheck, generation and standard premerge。

对主干的风险 / Risks

最强风险是把局部缓存 route 当成可由 wire 伪造的准入资格,或让坏签名在 user notice 前失去拒绝优先级;当前不可变本地投影、普通字典重新校验及实际反例均覆盖。独立历史 route helper 从零次变一次本地 RPC,是明确代价;本次未复测作者的组件延迟,也未将它解释为整轮提速。

PASS:182 项路由/managed/语义架构测试、369 项相邻 controller/driver/envelope/settlement 测试;29 组原始完整计划逐值相同。真实 File/SQLite CLI 完整响应、原始 quota producer 输入及签名前像都已保存并比较;仅规范化临时 fixture 地址、provider incarnation、经核验的派生 digest 和 0/1 秒观测时钟,原 due/retry、身份、错误详情、完整义务与 effects 未删除。错误 route 的进程内 mutation 经真正 turn plan 入口触发独立 oracle 失败,恢复 head 后通过。

标准 premerge 的 6 项直接检查、19 项选中检查与 Ruff 均 PASS,零 manual hold。TypeScript typecheck、生成绑定新鲜度、语义 producer 与双语差分检查通过。未查询、轮询或等待 CI。

语义与 CI 对齐

复用现有 EffectiveAction/frontier/route 词表,登记实际 TS return producer;未知静态流不伪称安全,原 persisted scalar 编码、签名与拒绝顺序保持。指导、机器门禁和实际操作授权保持分开。当前源码切片的独立验证支持结论,CI 状态不替代这些证据。

我的整体评价 / Verdict

未发现阻塞性问题,APPROVE 此精确 head 862f988cca3c72557616811dccf1d6cf062a055e 的 justified increment。long_horizon 与 user_experience 在已验证源码边界内 preserved;当前边界是两个真实 caller 共用 route 判断并保持原恢复链,可以整体回滚;后续完整契约不作为本切片的泛化前置。兼容分支保留了实际消费者,删除重复分类表和死 builder 是本次已实施的有界简化。不以测试数、回执或该 PR 代替父级整体交付与收益证明。

本次未改变渲染页面,检查的是 Turn CLI、managed-step 及完整封套输出。已安装宿主、实际模型行为及完整成本收益未验证。独立历史 helper 新增一次本地 RPC 的代价仍明确保留。批准不授予合并、安装或其它受保护操作权限。

English verdict: APPROVE 862f988; the bounded source change is independently validated, with installed/model adoption and full-cost benefit unverified.

@huangruiteng
huangruiteng merged commit a78f977 into main Oct 28, 2026
35 of 47 checks passed
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.

2 participants