Repository navigation
Reuse identical CLI settlement plans within a quota decision - #8406
Conversation
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.1-sol, OpenAI, runtime_reported, reasoning_effort=max
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
同一次 quota guard 会两次渲染输入相同的 CLI 结算计划。对照在 File 和 SQLite 上各跑两个连续 Turn,实际执行 guard、结算和回执读回。四次 guard 均少一次 TypeScript RPC,计划、通知结论和最终扣额一致。这是隔离的真实 CLI 和 TypeScript runtime,使用合成 Todo 与本地权威库。未测真实模型用量或长期任务收益。
改动思路 / Approach
保留原 interaction contract 的两次投影,只复用纯结算计划渲染。作用域限定在一次 quota decision,完整请求变化时重新渲染。缓存用实际 RPC 序列化字节作键,每个调用者拿独立副本;用户通知 cooldown 后仍重算当前 contract。
具体改动 / Changes
评审 0813bdb,基线 71190b6,3 个文件,+77/−4。现有 Turn 契约 保留准入、停止、结算身份与命令。reuse-identical-plan、distinct-inputs-and-copy、original-turn-parity 已验证;production-efficiency 另验。
关键代码讲解
- quota decision 在初次和 cooldown 后投影外建立作用域,退出时恢复外层作用域。
- 缓存与副本 只对完整相同请求复用,TypeScript renderer 仍生成原计划。
对主干的风险 / Risks
最大风险是把前一 Turn 或不同命令权限带到当前计划。File/SQLite 实际 CLI 每次 guard 的渲染调用为 2→1,少传 15,693–15,927 字节;基线与候选逐轮给出相同的 Todo、Turn、通知、完整计划和输出长度。第二轮加入 capability,只有该轮命令带此参数;两轮各扣一次。修改返回副本和同一作用域内输入不同的反例也通过。257 项相关测试通过、1 个 Windows 专项跳过,标准预合并 6 项直接和 13 项自动检查通过。
我的整体评价 / Verdict
认可当前提交。省掉的是一次重复的本地渲染,当前决策仍重新投影。准入、通知和写回顺序都能从最终输出读回,每个调用者仍拿独立副本。未验证真实模型成本变化。
English verdict: APPROVE. Reusing the identical pure CLI rendering saves one RPC per quota decision while preserving distinct inputs, mutation isolation, and original-Turn settlement.
huangruiteng
left a comment
There was a problem hiding this comment.
Reviewer: model_agent, GPT-5, OpenAI, self_reported
Independent approval
动机 / Motivation
同一次 quota guard 会两次渲染输入相同的 CLI 结算计划。受影响的同一次 quota decision 中重复渲染 settlement plan 的原 Turn 运行者和本地 Host。对照在 File 和 SQLite 上各跑两个连续 Turn,实际执行 guard、结算和回执读回;四次 guard 均少一次 TypeScript RPC,计划、通知结论和最终扣额一致。每次 guard 的渲染调用从 2 次降到 1 次,输出计划相同。计划、通知结论和最终扣额一致,调用者拿到独立副本。这是隔离的真实 CLI 和 TypeScript runtime,使用合成 Todo 与本地权威库;未测真实模型用量或长期任务收益。不改变 quota decision、通知、扣额或持久状态。
改动思路 / Approach
保留原 interaction contract 的两次投影,只复用纯结算计划渲染。作用域限定在一次 quota decision,完整请求变化时重新渲染。缓存用实际 RPC 序列化字节作键,每个调用者拿独立副本;用户通知 cooldown 后仍重算当前 contract。缓存只覆盖同一次 decision 内的纯渲染,完整请求变化时重新渲染。本次覆盖相同请求复用、不同输入、返回副本和原 Turn 路径;生产规模另验。
具体改动 / Changes
评审 0813bdba4184961796203e735cec31b6ec612c0d,基线 71190b6b4ef4e146f3bf4a10d31ce61ac42fd021,3 个文件,+77/−4。现有 Turn 契约 保留准入、停止、结算身份与命令。reuse-identical-plan、distinct-inputs-and-copy、original-turn-parity 已验证;production-efficiency 另验。
关键代码讲解
- quota decision 在初次和 cooldown 后投影外建立作用域,退出时恢复外层作用域。
- 缓存与副本 只对完整相同请求复用,TypeScript renderer 仍生成原计划。
对主干的风险 / Risks
最大风险是把前一 Turn 或不同命令权限带到当前计划。缓存 key 是完整 _encode_rpc_json(request),包含 identity、delivery、scope 和 command 参数;request 不同会调用 renderer。缓存值用 deepcopy 返回,测试修改第一份 vision_authoring 后第二份仍完整。作用域由 ContextVar 限定在 _build_quota_should_run_payload,退出后恢复原作用域,不会跨 Turn 泄漏。
File/SQLite 实际测试只覆盖纯 Python 计划构造;同 head 的既有真实 CLI 对照记录 2→1 render,输出长度和 Turn/Todo/通知/扣额一致。exact head 的 tests/control_plane/test_quota_settlement.py 通过 83/83、1 skipped;Git diff 与最新 main merge-tree 均无冲突。生产规模与真实模型成本另行验收。
我的整体评价 / Verdict
认可当前提交。省掉的是一次重复的本地纯渲染,当前 decision 仍重新投影。准入、通知和写回顺序都能从最终输出读回,每个调用者仍拿独立副本。缓存不会跨 Turn,且不同输入不会命中同一结果。
English verdict: APPROVE for 0813bdb. Reusing the identical pure CLI rendering saves one RPC per quota decision while preserving distinct inputs, mutation isolation, and original-Turn settlement.
Change
quota should-runcan render CLI settlement guidance during the initial interaction projection and again after notification cooldown. For an identical TypeScript request, reuse that pure rendering within the same quota decision. Recompute the interaction contract after cooldown, and render a fresh plan if any request field changes. There is no cache across decisions.Validation
Matched the real original-quota CLI over two Turns in one synthetic session, with the same progressive context delivery, 12 KB reader page budget, Todo, and independent validator. Main used the built wheel. The C1 control and treatment included the same
mainrevision.ruff checkpassed. The replay used a deterministic fixture. Live model token use and task efficiency remain unmeasured.