Skip to content

Verify original quota debit receipts on Turn replay - #8860

Merged
loopx-agent merged 8 commits into
mainfrom
codex/quota-original-debit-replay-20261116
Nov 16, 2026
Merged

loopx-agent merged 8 commits into
mainfrom
codex/quota-original-debit-replay-20261116

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Behavior

Exact Turn replay verifies that the debit Run and its rollout receipt agree on slots and billing source. It also verifies that the indexed artifact belongs to that debit. A conflict blocks both direct spend replay and combined settlement before either can write a replacement receipt or charge again.

The shared TypeScript reader now checks the Turn, effect, Agent, Todo/replan and Goal-instance bindings retained by older writers. Matching timestamps cannot authenticate a different Turn, including two debits recorded in the same second. The same check covers file-backed and inline events and the existing quota-void caller. Omitted, null or empty historical fields retain their compatibility behavior.

When an older artifact is unavailable, replay checks explicit receipt terms against the matching original admission. A missing receipt can be repaired with the recorded debit's slots, source and original Turn identity. An unverifiable debit cannot repair a receipt.

This makes the shared quota correction independently reviewable on main. The cases originated in the C1 settlement review. Receipt term conflict · Combined settlement replay. The additional legacy-binding regression addresses the review of the previous head.

Validation

  • The same-second legacy-file regression failed for File and SQLite with the previous reader integrated onto current main, then passed after the repair. Both CLI entry points reject the wrong file with current, legacy or missing receipts, leave the log and debit count unchanged, and recover after the original file association is restored.
  • A clean macOS arm64 wheel installation passed all 10 scoped CLI cases with its installed Python and TypeScript runtime: billing conflicts, original receipt repair and current/legacy debit identity on File and SQLite.
  • The full refresh/settlement CLI suites passed 267 cases with 10 skips.
  • The 49 TypeScript spend/void transaction tests and control-plane type checking passed. The standard premerge gate passed six direct checks and 18 selected checks.

Integration and limits

The current proposal retains the original PR history and integrates main at cac86bbad92ba99c3430b3f7eaa9632727573821. Its head is 75d0ccdf43bd015646359bab41f4a8f79a878cc9; both PR commits carry DCO sign-off.

The bounded refactor reuses one comparison in the existing TypeScript accounting owner for artifact and inline reads. No new storage owner, public vocabulary, configuration or UI entry point is introduced. Existing error paths carry the conflict. Hosted CI, native Windows, real PostgreSQL and installed-host adoption are not established by these local results. Independent exact-head review and applicable merge checks remain required.

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 · gpt-6.1-sol · OpenAI · runtime_reported · reasoning_effort=max

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

评审提交 041bf8187aeb325282240a5a70f4099e9e52e2b2,对照目标主干 f599a60ce64fd78db80d6318c84e3af58bfc1df9。现代扣额工件的冲突检查通过。已找到会影响历史回执补写的身份缺口。

动机 / Motivation

影响通过 CLI 恢复原 Turn 的 Agent 和维护者。回执一旦补写,后续接续会把原轮当成已结算。
主干允许同一 effect 的账本记录 1 槽而回执明写 2 槽,重放仍成功。历史没有提交元数据的扣额文件也可被误认。
同一个已准入 Turn 经真实 File/SQLite 完成写回和扣额后,分别再次调用两个命令。控制组验证准确回执可重放,现代错误关联及账务冲突会拒绝。
8 个候选回归通过,覆盖两入口、File/SQLite、账务冲突、真正缺省旧字段、合法缺回执修复和现代索引路径错指。历史同秒错指仍能通过。
采用隔离的合成 Goal。未验证现有安装态的升级采用或真实 PostgreSQL。排队的托管 CI 未查询。

改动思路 / Approach

TS 精确读回读取匹配的扣额文件并比较账本与回执的账务字段。Python spend_quota_slot 使用验证过的 slots/source 走原有回执修复路径。
复用结算 owner 能修复现代格式和槽数冲突。仍有一条受支持的旧格式路径用时间替代已有 Turn 身份,导致原身份保证不成立。
当前提交对索引和工件重复的提交元数据做比较,并保留旧格式缺字段回退。已验证回执交由原 Python 入口提交,没有新增 quota 状态、公共指令或结算步骤。

具体改动 / Changes

5 个文件新增 341 行、删除 30 行。按 docs/reference/protocols/loopx-turn-v0.md 核对以下要求。 原契约

  • billing-terms。在精确重放前拒绝已写明的槽数或来源冲突。 本轮实际入口对照通过。
  • retained-debit-binding。用于重放或回执修复的扣额文件必须能关联原始 Turn。 本轮复现下述缺口。
  • receipt-repair。真实缺回执按已有原 debit 重建,保留原账本。 本轮实际入口对照通过。

关键代码讲解

  • readQuotaSpendEventFromRun。现代工件的提交元数据必须和索引匹配。旧行沿分类、Goal 和日期对比,没有比较已存在的 Turn 身份。 按提交核对
  • readQuotaSettlement。比较实际 debit 与 rollout 回执。只有明确字段冲突才拒绝,读取原 admission 处理工件已缺失的历史案例。 按提交核对
  • spend_quota_slot。已有 debit 且缺回执时传回已验证的槽数和来源,保留原 effect。 按提交核对

对主干的风险 / Risks

  • [P2] 同秒的旧扣额文件可认证另一轮 将两次真实结算的扣额记录按旧 Python 写入格式保留不同的 Turn 和 settlement effect,设为同一秒,然后把原轮的索引路径指到另一轮的扣额 JSON。 readQuotaSpendEventFromRun 对缺少 quota_spend_commit 的行只校验分类、Goal 和时间,两个不同 Turn 在同一秒即可通过。 File、SQLite 两种隔离后端均复现。已有回执时,两个入口退出 0,接受重放。移除原轮回执后,两个入口分别退出 0 并写入原 effect 的新回执。扣额仍为两笔。 在现有 readQuotaSpendEventFromRun 统一核对索引和文件已经持久化的 Turn/effect 标识,拒绝明确冲突,同时保留真正缺省的旧字段兼容。 旧版扣额写入器 精确身份契约
  • 独立执行两份结算 CLI 测试,265 项通过、10 项跳过。其中新增 8 项在目标主干失败、在候选通过。20 项 TypeScript void 事务用例通过,包含同秒但现代提交元数据不同的拒绝。
  • 基于同一 main 的单个签署提交通过 git diff --check。独立 quick premerge 的四项直接检查、Python 编译与三项 canary 通过。

语义与 CI 对齐

正常重放和当前格式的错指验证与原协议一致。旧格式显式身份冲突时接受的是另一轮的账务事实。独立本地检查覆盖当前目标与候选;托管 CI 未查询。

我的整体评价 / Verdict

请求修改。候选处理了原槽数冲突,也能阻止现代格式路径错指。旧格式已有 Turn/effect 身份可校验,先补齐这一读取边界,再重跑两个入口的同秒错指用例。

English verdict: REQUEST_CHANGES on 041bf8187aeb325282240a5a70f4099e9e52e2b2. Both replay entry points can accept another Turn's same-second legacy debit and recreate the original receipt. Reject conflicting persisted Turn or effect bindings before trusting that debit.

xiaobaifly7 and others added 6 commits November 16, 2026 16:34
…eout (#8854)

A replan admitted for a Monitor's no-change streak lost its receipt
source once the agent completed the Monitor inside that Turn, so the
same Turn's writeback and guard re-entry failed with
heartbeat_receipt_identity_conflict. Treat the streak as a scalar review
source, with a fixed kind precedence independent of trigger order.

Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
Co-authored-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Preserve requested scheduler detail during recovery waits

Prior-Turn recovery rebuilds the scheduler hint when the unchanged admission limit is reached. Forward the CLI detail selector to that projection so the DSH Driver receives the bounded recheck cadence it requested.

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

* Keep App scheduler reconciliation executable during recovery waits

Reuse observed host cadence and persisted backoff when projecting a prior-Turn recovery wait. Preserve the registered scheduler scope and place CLI options after the standalone interpreter prefix so the matched host can be acknowledged using the original receipt.

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

---------

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Revalidate the captured Session and combined admission signal before publishing a queue or scheduler wait plan. Cover Pause and native maintenance cancellation for both plans, followed by a fresh evaluation.

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

* fix(monitor): project User gate completion for an observed prerequisite

An admitted due Monitor that still has open User gates now gets the
existing User lifecycle completion command ahead of its poll actions,
on unchanged observations too. The Monitor Turn's settlement identity
stays separate; observation never grants approval.

Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>

* fix(monitor): never project a User gate completion from an observation

Replace the projected completion command with a read-only notice. A due
Monitor that is admitted while the agent has open User gates is told that
its observation cannot complete or approve a gate, which attempts stay
rejected, and that work continuing on an observed change belongs in the
poll's own successor. Unrelated owner decisions receive no command.

Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>

* fix(monitor): do not point an observation at any User gate

The notice told the agent to report the observed evidence as the pending
user action of an open gate, even when the gate was unrelated to the
observation. Keep only the boundary (an observation never completes or
approves a gate) and the original poll.

Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
Co-authored-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
#8584)

* fix(turn): enable builtin Codex durable Todo completion

Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>

* fix(turn): validate terminal Todo before accountable refresh

Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>

* refactor(turn): remove redundant lease shape check

Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>

* Recheck the original Goal after built-in Codex validation

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

---------

Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Co-authored-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
Co-authored-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
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; gpt-6.1-sol; OpenAI; runtime_reported; reasoning_effort=max

Exact head: 8860@75d0ccdf43bd015646359bab41f4a8f79a878cc9

动机 / Motivation

运行长程任务、重试已扣费 Turn 的 CLI 使用者会遇到这个问题。两个 Turn 同秒扣费后,旧记录的文件索引误指另一 Turn,旧版仍可能接受重放或补出错误收据;修复后在任何补写前拒绝,恢复原关联后继续成功且不重复扣费。已验证原扣费证据、原身份及计费条件相互一致才可重放,合法缺失收据仍可修复。本 PR 不新增扣费权限、迁移协议、存储后端或可视化功能。

改动思路 / Approach

原身份和扣费条件是现有结算不变量,应由共享 TypeScript 读取 owner 校验;Python 继续只负责原有写入和收据修复。当前边界是扣费证据读取、结算交叉核验与两条真实 CLI 的无重复副作用重放。

两条入口都先通过原 Turn 的索引找到 Run,再核对原 JSON artifact 或历史 inline 事件,最后才允许收据修复。现代 commit metadata、outer artifact 与 nested quota_event 都必须一致,不能凭外层字段正确跳过内部证据。合法旧记录真正未写某字段时继续兼容;显式写了另一个身份则是矛盾。void 的既有 caller 仍使用同一 reader,并保留自身 Goal 边界。

具体改动 / Changes

关键代码讲解

  • spendIdentityMismatch:集中比较已有显式身份。旧版nested/inline错Turn可接受;head拒绝;逐字段显式canonical值相等;缺失/null/empty不伪造矛盾。

  • readQuotaSpendEventFromRun:安全打开并验证原扣费artifact。modern commit必须检查metadata及nested;legacy inline也验证identity;outer/nested/metadata一致,路径confinement仍保持。

  • readQuotaSettlement:交叉核对原receipt与debit条款。拒绝不同slots/source/identity;合法missing receipt恢复原terms;先验证再推荐补写,missing artifact可用原admission source。

  • spend_quota_slot:执行既有写事务和收据补写。补写复用已验证spend_request而非caller覆盖;原debit只计一次。

规格依据:docs/reference/protocols/loopx-turn-v0.md,不可变修订 cac86bb。按变更前文本判断,以下名称仅标记协议条款映射,不是新增要求。

  • billing-terms:implemented。同一原 Turn 的扣费条件来自原始合法扣费,而非新重放参数。 对应 readQuotaSettlement / readQuotaSpendEventFromRun / spend_quota_slot,由 same-second-regression.py + independent-replay-probe.py source/wheel File+SQLite 验证。

  • retained-debit-binding:implemented。重放只采用与原 Goal、Agent、Todo/重规划、Turn、effect 一致的扣费证据。 对应 readQuotaSettlement / readQuotaSpendEventFromRun / spend_quota_slot,由 same-second-regression.py + independent-replay-probe.py source/wheel File+SQLite 验证。

  • receipt-repair:implemented。合法已扣费但缺失收据可恢复,不产生第二次 debit。 对应 readQuotaSettlement / readQuotaSpendEventFromRun / spend_quota_slot,由 same-second-regression.py + independent-replay-probe.py source/wheel File+SQLite 验证。

GitHub 的缓存 base f599 显示 26 文件,其中 21 文件是整合 main 已接受的上游上下文;当前完整净差异为 5 文件,428 行增加、31 行删除。两次取到的 main cac86/02cc 在这 5 个路径完全一致;没有把上游 UI 文件当作本次新增交付。

对主干的风险 / Risks

PASS:完整 Python CLI 两组 267 passed、10 个既有平台 skip;TS spend/void 49 passed;真实 Python transaction 45 passed;control-plane typecheck 与标准 premerge(6 direct、18 selected)通过。原 P2 同秒反例用同一 harness 对照旧 head 041bf8 和本 head:旧版 legacy File/SQLite 两例仍接受错指,修复版全部 4 例通过。另独立构造 outer 正确但 nested Turn 错,以及 legacy inline 错 Turn:旧版 16 个不合法用例被接受,修复版全部拒绝且日志、索引、artifact 字节不变;恢复原关联后 4 个合法对照均继续成功,debit 保持一次。

PASS:独立安装的合格 wheel 在实际 site-packages 上再次完成同一组 20 例,没有 source checkout fallback。共享 reader 的 void 路径由 49 TS 与 45 runtime 测试覆盖。直接 spend 的通用 collection error 与 combined 路径的详细身份错误不同,未宣称诊断完全同形。初始缺少已构建 Chat bundle 的 package 失败已保留,按原构建流程生成合格资源后 wheel 成功,没有删断言或放宽阈值。

语义与 CI 对齐

复用既有词汇和 owner,没有新增共享枚举或授权。已逐句核对诊断的触发、来源、范围、先后和停止条件;文本是有意纠正并经真实任务验证,未声称模型理解已验证。按当前策略不查询、不轮询 CI,本结论基于本地必需验证;审查结论与平台合并条件分开。

我的整体评价 / Verdict

long_horizon:重复 Turn 的真实重放不增加 debit,并且错误索引先拒绝、修复后继续;未推断长程模型分数或总成本。 user_experience:两个 Turn 同秒扣费后,旧记录的文件索引误指另一 Turn,旧版仍可能接受重放或补出错误收据;修复后在任何补写前拒绝,恢复原关联后继续成功且不重复扣费。 没有新增必需确认轮次。

实际净差异只涉及 quota/refresh-state CLI 与内部收据读取,没有新增渲染页面;GitHub 展示的上游整合文件已在 main。未声称执行浏览器视觉审查;此变更没有受影响的渲染布局。

原身份和扣费条件是现有结算不变量,应由共享 TypeScript 读取 owner 校验;Python 继续只负责原有写入和收据修复。当前边界是扣费证据读取、结算交叉核验与两条真实 CLI 的无重复副作用重放。 兼容性和复杂度已重新按完整范围判断,当前共享 owner 的局部改动有明确必要性,未发现应在此 PR 强制拆分的新架构。

UNVERIFIED:nativeWindows、真实PostgreSQL、实际主机升级采纳、模型对文字理解及长程效果/总成本未验证;syntheticFile/SQLite和独立wheel只证明当前局部CLI边界。 当前没有复现阻塞 finding;若 head、原证据格式或入口变化,需要重做对应证据。先前方法性经验仅用于检查真实恢复和有用结果,不作为当前结论或记忆效用的证明。

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

English verdict: APPROVE. Original debit identity and terms are verified before replay or receipt repair; the reported legacy counterexample is resolved at this exact head.

@loopx-agent
loopx-agent merged commit d0ca48d into main Nov 16, 2026
40 of 50 checks passed
@loopx-agent
loopx-agent deleted the codex/quota-original-debit-replay-20261116 branch November 16, 2026 13:47
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