Skip to content

fix(quota): resolve first-call replan selection before context delivery - #7611

Merged
loopx-agent merged 1 commit into
mainfrom
codex/replan-direct-admission
Oct 28, 2026
Merged

loopx-agent merged 1 commit into
mainfrom
codex/replan-direct-admission

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

An eligible quota should-run --todo-id ... on a fresh Turn could be preempted by autonomous replan, emit a large rejected decision, and require separate discovery and selection calls before the agent received its actual work contract. Native context delivery also bounded successful output but let failed decisions print the entire projected control packet.

This change uses the existing TypeScript reentry qualification and retained-selection owner for one internal fresh guard, carrying the caller's exact choice until the first final receipt. An existing receipt still requires durable retention; a concurrent receipt stops first-call reentry. The guard rechecks current gates and budget, and the final binding may be the requested Todo or a pure replan. The deferred Todo cannot replace that binding or settle in the same Turn.

With native context delivery enabled, refusals expose bounded error/receipt/recovery input and a digest-bound optional diagnostic capture. Large diagnostics use the existing selected reader. They neither create pending native context nor establish a delta baseline. Context delivery off retains its ordinary failure shape.

Validation:

  • PASS: 81 focused real CLI File/SQLite selection, refusal, native capture, changed user gate/quota, concurrent receipt, envelope parity and once-only settlement tests (90.99 s).
  • Mutation restoring the old first-receipt requirement makes both fresh-call gate-recheck oracles fail through the public CLI; the fix passes.
  • PASS: 293 broader settlement/context compatibility tests (543.65 s).
  • PASS: standard premerge, 19 selected checks, zero failures/manual holds. Initial dependency/setup failures were corrected: npm development dependencies were missing; the native test now initializes an isolated host session. A premerge attempt overlapping test edits was discarded and rerun on the stable head.
  • Bilingual protocol explanation and public/private diff scan; no raw trajectories, local state or credentials.

Scope and limits: this removes model-facing intermediate packets for an already-known eligible choice. It still performs a second internal fresh authority read; unknown-task discovery is unchanged. It does not prove model token fees, throughput, benchmark score improvement or installed adoption. Current goal/criteria/stops and the broader staged-context work remain with their existing owners. No new CLI option, vocabulary, persistence layer, or decision owner was introduced; the Python changes adapt existing admission and capture transport contracts. No rendered UI changes.

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)

结论:APPROVE,未发现阻塞问题。 完整评审绑定 head 5c941b95233cba004cf1f0e011bfd98cfc2c33d0,不可变 base 51c1dc447858c351691711de21a638b6c71c118e。本结论来自独立源码、真实 CLI、反例与当前目标组合验证;GitHub 正式 state 使用 COMMENTED。

动机 / Motivation

已知任务身份、通过 quota CLI 请求本轮工作契约的 Agent,会遇到选择被自主重规划抢占的问题。
例如,首次明确选择一个合格 Todo,旧入口先返回拒绝,再要求读取无绑定发现包并重新选择;新入口内部重判一次,只返回最终合法绑定。
可验证结果是首次选择保留原意图、仅提交最终回执,原生拒绝可在既定输出限制内读到完整错误及恢复入口。
本 PR 不完成统一 controller/C1 迁移,也不证明正式安装采用、模型费用或长期净收益。
原失败不是只多一条提示:模型必须处理多个中间包才能取得真正工作身份。这里应减少传输往返,同时继续让真正的 Stop、额度和并发回执阻止不合法执行;不能为了少一次交互直接沿用第一次读到的准入结果。

改动思路 / Approach

不修改会保留已复现的多次选择往返和超限拒绝包;要求调用方再补两次命令,只是把成本移给每个调用者。更小且合法的边界是复用已有 inline_reentry_allowed 和 retained-selection owner,在尚无回执时临时携带明确选择,在已有回执时继续先持久保留,再调用原 guard。
保留该实现:准入与选择仍归现有 TypeScript owner;Python 仅适配首次回执前的调用意图和本地错误传输,没有第二套 gate、存储或决策 owner。
当前 PR 边界是既有 quota CLI 的一次 fresh reentry 与原生失败展示,最终绑定、Stop、额度、原回执和结算规则保持原 owner。
拒绝包走现有 digest-checked reader;它不调用成功路径的 pending/full/delta 生命周期。这样无需新增配置、确认轮次、缓存或模型调用。下面是源码和执行结果的比较,不是模型理解或因果收益测量:

触发条件 旧 base 当前 head
首次明确选择被可执行 replan 抢占 先拒绝,需模型继续 discovery/selection 内部 fresh guard 一次,绑定原 Todo 或纯 replan
两次读取之间出现 Stop、user gate 或额度变化 既有手动/已有回执恢复仍受限 新首次重判同样拒绝交付和扣额
首次重判前已有并发回执 不适用该新路径 拒绝覆盖,由原 Turn 回执负责恢复
native 错误开启 4,096-byte 限制 实际 stdout 约 32 KB 实际 stdout 1,936 bytes,完整错误另存原 capture

具体改动 / Changes

完整差异为六个文件、+266/-29:生产代码三处 +96/-7,测试两处 +147/-16,双语协议 +23/-6。一个提交有 DCO;未新增 CLI option、schema vocabulary 或持久字段。

关键代码讲解

  • load_requested_quota_action_selection:读取同 Turn 原回执;首次重判发现并发回执就拒绝覆盖。仅无回执的首次重判接收临时 choice;已持久化回执继续沿原 owner。
  • inline_action_selection_reentry_args:将现有 TS permission flag 适配为一次 fresh guard。首次无回执可保留原明确 choice;已有回执仍要求 durable pending choice;重判移除显式选择,不能递归。
  • _emit_quota_result:先保存原决定,再选择失败展示或成功的 native context 生命周期。失败、显式开启、JSON、有 capture 且非 deferred 时走有界错误;其余原分支保留。
  • captured_quota_failure_view:从原错误派生有界诊断和 digest-bound reader。保留完整 reason/receipt/recovery;超大错误改为 selected read,不截断正文且不注册 native continuity。

handle_quota_command 仅在首次 preflight 没有回执时传递临时选择,最终仍由原 receipt owner 决定身份。保留的 Todo 不会替代纯 replan 的 settlement identity,不能在该 Turn 顺便执行或结算后继 Todo。旧 discovery、已有 pending choice、同身份 replay、错误绑定和 capability reentry 路径仍受测。

规范依据为变更前 TurnEnvelope v0:spec_ref docs/reference/protocols/turn-envelope-v0.md;spec_revision 51c1dc447858c351691711de21a638b6c71c118e。用原文命令/字段标识未编号条款:

  • --decision-output-dir → implemented:先保存原决定及原回执,错误详情读取同一 digest-bound capture,不补跑 guard 获取旧观察。
  • selection_required=true → implemented:真正需要 discovery 的调用仍通过当前 canonical 候选和 eligibility;明确选择不会变成推荐项的权限。
  • inline_reentry_allowed=true → implemented,含明确行为变更:原文限制首次无回执时返回拒绝;本次将这一无副作用阶段的选择留在调用内,同时保持已有回执的 durable retention 和 fresh gate 检查。三项首次调用断言在 base 均失败,在 head 通过。
  • refresh-state --next-action → implemented:后续写回仍绑定原 Todo/replan 身份,不接受另一任务借用原 Turn;完整 settlement CLI 回归通过。
  • heartbeat_receipt.status=not_committed → implemented:缺失或不合格候选仍没有 receipt/spend;拒绝的 native 目录内容逐字不变。

独立验证

  • PASS V1:两个受影响测试文件完整运行,68 项通过,覆盖已有回执/首调用、envelope、纯 replan、并发冲突及同 Turn 一次结算。
  • PASS V2:完整 settlement CLI、action portfolio 和 paused precedence,192 项通过。
  • PASS V3:另写五项真实边界探针。File/SQLite 的实际 stdout 从 base 的 31,970/31,982 bytes 降为 head 的 1,936 bytes;两侧保留完整 reason、原 receipt、恢复 argv、零 receipt/spend。关闭态的错误字段集合、qualification、完整原因和恢复动作一致;原失败 builder 的 AST 也完全一致。另验证两 provider 的 Stop 注入及解除后 fresh Turn 恢复。
  • PASS V4:固定同一断言回放不可变 base。两项首次 gate-recheck、三项首次 envelope/native/选择保留和两项实际输出限额均按原缺陷失败;四项已有 discovery/manual 路径仍通过。head 对应路径通过,没有改断言或放宽限制。
  • PASS V5:标准 premerge 为 6 direct + 19 selected,0 failures、0 manual holds,含公共边界、语义、预算和双语检查。
  • PASS V6:与已获取当前 main ccf6aacc5f9f711293bda832a4523a6386ca1bb1 无冲突合成 tree d1860f7252fe1956682053e717a09f3bc7575c15,在独立源码环境运行两受影响文件及 progressive native context,共 88 项通过。这是隔离组合资格。

对主干的风险 / Risks

最强反例是“表面少了一次拒绝,却用了旧 gate 或覆写另一个调用者的回执”,以及“错误限额测试只测重新序列化的对象,真实 stdout 仍超限”。本次分别通过真实入口改变 gate/Stop、并发插入回执、检查实际 stdout bytes、完整原回执和 native 目录字节来检验;没有以 helper 的返回值代替后续结果。
超大错误仍有补读成本:独立注入的 60,000 字完整原因经 66 页实际 CLI reader 无损读回,每页均在 4,096 bytes 内,入口为 1,327 bytes。该注入仅提供上游拒绝,不伪造 reader 或恢复后的成功。它验证有界可达性,不证明模型能理解错误或完整工作成本更低。

语义与 CI 对齐

首调用的内部重判是默认行为的明确修复,不只在 native context 开启时生效;仅失败展示受 context-delivery=on 约束。关闭该展示保持普通完整错误;现有已绑定回执、Stop/额度、合法未来候选、超出展示窗口的候选和能力拒绝继续由原 typed owner 检查。inline_reentry_allowed 是刷新准入的许可,不是 delivery/spend 许可;optional diagnostics 也不变成执行前新增的全 Goal 必读或 ACK。
复用既有状态和权限 vocabulary,新增字段列表只是本地诊断投影,不创建共享状态分类。恢复文字面向通用 Goal/Agent/Turn,没有 benchmark 专用义务。wait_for_ci=false,未查询或等待 CI。

我的整体评价 / Verdict

该切片达到 goal_achieved:已知选择能在一次外部调用中取得最终合法契约,超限拒绝仍保留完整恢复证据。long_horizon 判为 preserved:后续绑定、Stop、恢复和一次结算继续受测;user_experience 判为 improved,限定为已验证 CLI 往返和错误恢复,不外推到长期收益。
保留该实现:准入与选择仍归现有 TypeScript owner;Python 仅适配首次回执前的调用意图和本地错误传输,没有第二套 gate、存储或决策 owner。
当前 PR 边界是既有 quota CLI 的一次 fresh reentry 与原生失败展示,最终绑定、Stop、额度、原回执和结算规则保持原 owner。
代码规模与问题相称。复用原 capture reader、typed selector 和 receipt owner 比新增 pending state、第二缓存或跨入口 retry 框架更小;无需为本次已完成切片另建后继任务。visual_review 为 not_applicable:检查的三个生产路径及协议只改变 CLI/本地传输,没有 rendered UI、布局或样式变化。unverified_scope 为正式 Host/模型采用、实际输入 tokens/费用、持续运行净收益和正式安装。

English verdict: APPROVE — first-call selection, fresh gates, bounded refusal recovery and once-only settlement are independently verified at 5c941b9.

@loopx-agent
loopx-agent merged commit b47bbc6 into main Oct 28, 2026
28 of 39 checks passed
@loopx-agent
loopx-agent deleted the codex/replan-direct-admission branch October 28, 2026 23:16
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.

1 participant