refactor(quota): consume EffectTurn in TurnEnvelope runtime path - #2983
Conversation
huangruiteng
left a comment
There was a problem hiding this comment.
Review: APPROVED
head 02fc7d17c4fde507afd8d5667ec52a2444e79afa。这是对 refactor(quota): consume EffectTurn in TurnEnvelope runtime path 的完整 PR 解读,覆盖 3 个改动文件、TurnEnvelope 运行时路径、RFC 状态与 parity 测试。GitHub 不允许作者审批自己的 PR,因此以 COMMENTED 发布作者自有回退态,但评审结论是无 blocker。
动机
interpret_quota_should_run_packet 已经能把 quota should-run payload 解释成 EffectTurn,但 build_turn_envelope 仍直接手写读取 recommended_action、next_cli_actions、scheduler action/cadence 等 canonical slots。两条路径会漂移。这个 PR 让真实运行时 TurnEnvelope 消费同一个 EffectTurn,统一来源。
改动思路
build_turn_envelope内部新增_quota_effect_turn(),用interpret_quota_should_run_packet生成EffectTurn。_action_projection/_scheduler接收EffectTurn,canonical slots 优先从EffectTurn派生,缺失时 fallback 到原 payload 字段。quota_action_signature_document与 CLI turn-envelope view 复用同一 interpreter,保持 parity。- RFC 更新 R5 完成状态,Q6 标记 in progress。
具体改动
loopx/control_plane/quota/turn_envelope.py:新增_quota_effect_turn(),_scheduler()/_action_projection()消费EffectTurn。tests/test_turn_envelope.py:新增 parity 测试,证明 envelope 的 recommended_action、next_cli_actions、scheduler.action/cadence_class 与interpret_quota_should_run_packet一致。docs/architecture/rfcs/agent-loop-effect-interpreter-v0.md:更新 R5/Q6 状态。
关键代码讲解
_quota_effect_turn():从 payload 解析 agent identity,调用interpret_quota_should_run_packet(payload, goal_id, agent_id),返回 EffectTurn。_scheduler(payload, turn):优先取effect_turn.next_effect.scheduler_action/cadence_class,再 fallback 到scheduler_hint原字段;reason_code/spend_policy 仍来自 source。_action_projection(payload, turn):recommended_action优先effect_turn.observation.recommended_action,writeback.next_cli_actions优先effect_turn.next_effect.cli_actions,保留原 payload fallback。- parity 测试:直接用
interpret_quota_should_run_packet构造 turn,再与build_turn_envelope(source)输出比较,锁住 canonical slots。
正向路径
调用 build_turn_envelope(source),内部先解释 EffectTurn;action/writeback/scheduler 的 canonical slots 从 effect turn 派生;quota_action_signature_document 与 CLI view 得到相同值。新测试直接证明 envelope 与 interpreter 一致。
负向路径
如果 EffectTurn 的 canonical slot 为空,代码 fallback 到原 payload 字段,避免输出缺字段;如果 interpreter 与 payload 冲突,parity 测试会暴露,而不会让 envelope 悄悄使用另一套来源。
对主干的风险
低。39 个 focused pytest(turn envelope、live quota effect、maintainability ratchet)通过,ruff/diff check 通过,git merge-tree origin/main HEAD 无冲突,canary premerge 全绿。GitHub pytest 当前 in-progress,但本地等价覆盖已通过。
我的整体评价
这是 Q6 的正确第一片:把解释器从测试侧接入真实运行时路径,并用 parity 测试固定契约。无 blocker,按仓库 merge policy 路由合并。
English Verdict
Approved (author-owned fallback; cannot formally approve). Head 02fc7d17c4fde507afd8d5667ec52a2444e79afa. TurnEnvelope now derives canonical action, writeback, and scheduler slots through interpret_quota_should_run_packet, with parity tests, RFC status updates, no merge conflict, and green focused tests plus canary. No blocking findings.
huangruiteng
left a comment
There was a problem hiding this comment.
Review: APPROVED
head 02fc7d17c。这是对 PR #2983 的完整 owner review。该 PR 是 M6 Q6 的第一片真实运行时替换:quota should-run --turn-envelope 的 canonical action/writeback/scheduler 槽现在通过 interpret_quota_should_run_packet 消费 EffectTurn,不再是测试-only 映射;同时更新 RFC replacement status。
验证
tests/control_plane+ turn driver/envelope tests:910 passed- turn envelope 聚焦测试:
29 passed - maintainability ratchet:clean
- ruff:通过
loopx canary premerge --from-git-diff:selected=13 failures=0,self_merge_allowed=true,public boundary 通过- GitHub checks:dependency-review / pytest / build 全部通过
结论
无 blocker。CLI quota 的 TurnEnvelope 热路径现在真实消费 EffectTurn,公共输出保持不变。按仓库 merge policy 路由合并。
Summary
Q6 first slice: make the real runtime path consume
interpret_quota_should_run_packetinstead of parsing raw payload fields directly for the canonical slots.build_turn_envelopenow derivesaction.recommended_action,writeback.next_cli_actions, andscheduler.action/cadence_classthroughEffectTurn.quota_action_signature_documentand the CLI turn-envelope view use the same interpreter, so the parity contract is preserved.interpret_quota_should_run_packet.No public CLI output changes.
Validation
tests/control_plane+ turn driver/envelope tests:910 passed29 passedloopx canary premerge --from-git-diff:selected=13 failures=0,self_merge_allowed=true, public boundary passed