Skip to content

fix(quota): resume unfinished turns with fenced lease takeover - #9488

Merged
huangruiteng merged 1 commit into
mainfrom
codex/automatic-lease-takeover-20261126
Nov 26, 2026
Merged

huangruiteng merged 1 commit into
mainfrom
codex/automatic-lease-takeover-20261126

Conversation

@huangruiteng

Copy link
Copy Markdown
Collaborator

An expired lease could leave completed work stranded: reclaiming the same Todo changed its generation, so the original Turn could neither validate its saved result nor settle it. A fresh eligible guard now records an append-only takeover for the same Agent under current local authority, then uses the original settlement identity with current validation.

The change preserves old receipts, admission, workspace obligations and quota source. It rejects stale keys and competing holders, checks cold-read provenance, and keeps completion validators and exactly-once settlement in the existing owners. Ordinary same-generation preparation keeps its current payload; extra source evidence is read only for takeover. Explicit administrative no-spend closeout remains available.

Validation: the new real CLI regression failed before the change; File and SQLite coverage now includes saved-result progress, completion, revised validators, stale-key rejection, implicit/explicit original-Turn reentry and idempotent replay. The selected Python suite passed 189 tests; selected TypeScript suites passed 267 with 2 environment-dependent skips. Type checking, lint, diff hygiene, and the standard premerge catalog/risk/public-boundary checks were also run; final-head results are recorded in review.

Scope: same Agent, unfinished local File/SQLite Turn. This does not install a detached Codex App renewal timer, accept another Agent's authority, reopen an existing closeout, or migrate saved automation prompts. Remote-provider takeover remains unsupported. The existing supervised live-host renewal path is unchanged.

Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com>

@huangruiteng huangruiteng 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 · OpenAI · self_reported

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

没有发现阻塞项。此结论针对 6c8eb35f0bdb291382efc72b81aff38aeab0ff49 的完整 diff;允许当前合法持有人恢复原轮次,但并不承认旧凭据或旧测试结果继续有效。

动机 / Motivation

使用本地 File/SQLite 权威源、在租约过期后恢复未完成任务的 Agent。以前,同一 Agent 重新领取任务后,新租约代际与原轮次不匹配,已有工作无法正常交账;现在,当前持有人通过原 guard 核验后可接续原轮次,保留原始记录并重新验收成果。真实 CLI 回归已验证:当前租约可继续交账,旧 key 被拒绝,当前验收不通过就不能完成,重复提交只结算一次。不支持跨 Agent 或远端 provider 接管,不增加 Codex App 后台续租,不修改自动化提示词,也不自动承认旧结果。

改动思路 / Approach

资格判断与历史校验复用现有 TypeScript receipt owner,Python 只负责锁和 IO;无需新增命令、调度器或第二套任务状态。本 PR 完成交账前、同一 Agent、File/SQLite 的接续闭环;远端 provider、跨 Agent 接管和 Codex App 后台续租均不在本次边界内。仅当租约代际变化时,Python 在 rollout 锁和非阻塞 canonical maintenance fence 下读取权威源,TypeScript 判断当前持有人是否满足接续条件。普通 preparation 不增加完整 Todo 或验收快照。成功后追加历史事实,不改写原准入;新记录带两代租约和当前验收摘要,后续冷读沿原有 lineage 找回原始准入。

更长 TTL 只能降低发生概率;直接放松代际比较会放过旧执行者;一律关闭旧轮次又会丢掉可复用成果。这里复用既有 receipt owner、claim、completion validator 和 settlement,避免另造恢复命令或要求用户反复确认。

场景 原行为 本次行为
同一 Agent 领取新租约后回到原轮次 被代际不匹配阻断 当前 guard 核验后追加接续回执
使用旧 key 或竞争持有人 拒绝 继续拒绝
旧成果不满足当前验收 不能据此完成 当前 validator 拒绝,修复后再完成
相同交账再次提交 原身份恢复 保留原身份且只结算一次

具体改动 / Changes

独立判据来自 docs/reference/protocols/turn-envelope-v0.md,审阅版本 6daf9eaefac75351ddd96246e6244d31aef72107。original-effect 对应原 effect、workspace 和 quota source 不变;fresh-authority 对应当前权威源核验以及写入时的租约约束;exact-retry 对应首次交账和重放只能扣一次。三个判据均已实现并经真实 CLI 路径验证。本 PR 对协议文档的增补明确披露新的接续行为,不能反过来代替原有判据。

关键代码讲解

  1. heartbeat_receipt_identity.ts:312 的 heartbeatLeaseTakeover 要求原始正向准入、同一身份、本地权威源、当前有效 owner、严格递增 epoch/version、正确 key hash、时间顺序和 repository grant。输出是 scalar 回执字段,不持久化整份私有源。
  2. heartbeat_receipt.py:754 的 requalify_bound_heartbeat_receipt 只在代际变化时增加带锁读取,先丢弃外部传入的 source,使用真实权威源;追加仍走原 rollout owner。非阻塞维护锁避免反转普通锁顺序造成等待死锁。
  3. settlement_readback.ts:703 的 heartbeatValidationEvent 沿 receipt parent 冷读,调用 validateHeartbeatTakeoverParent 检查原身份、两代租约及字段保留,避免仅内存返回正确、落盘后却丢失证明。
  4. read_transaction.ts:391 的 readExecutionPreparationSource 仅在明确请求 takeover basis 时附带 Todo、验收摘要和租约时间/grant,普通调用保持原字段形状。observeFencedExecution 让符合条件的同一 owner 回到普通 guard;该观察自身不授权执行。

变更为六个 runtime 文件、三个测试文件和一份双语协议文档,总计 +363/-92。没有新调度器、独立配置或自动化迁移流程。

对主干的风险 / Risks

最大风险是把“当前有租约”误当成“旧成果已验收”,或者重放重复扣账。真实 CLI 测试先使用旧 key 验证拒绝,再使用当前证明完成进度/完成交账并重放;另一个用例在原准入后更改 validator,缺少当前产物时拒绝,生成符合当前要求的产物后才允许完成。Typed negatives 覆盖竞争 owner、已释放/过期租约、时间倒置、已完成 Todo、错误 claim、非权威来源、重复 lease 和破坏的回执字段。

PASS:相同 fixture 在不可变基线首次原轮次重入失败,在当前实现的 File/SQLite 六项关键用例全部通过。广泛 Python 回归 189 项通过,最终相关回归 54 项通过;TypeScript 267 项通过,两个需要独立 PostgreSQL URL 的既有用例跳过,不属于本地 takeover 支持范围。TypeScript/mypy/ruff、diff hygiene、双语检查及 exact-head premerge 的 10 项 catalog、8 项 risk 检查通过。远端 CI 当时仍有排队/运行项,作为诊断记录,合并前仍执行独立 readiness 判断。

语义与 CI 对齐

本次扩展既有 receipt revision 语义;语义 diff advisory 没检出受支持的新 vocabulary carrier,不等同于没有行为变化。新行为在协议及测试中明确披露。普通 readiness、已开始 closeout 的恢复以及显式 no-spend closeout 保持原 owner;不宣称 PostgreSQL 或跨 Agent 接管。安装后的验证尚待部署步骤执行,测试运行并不证明模型一定正确选择所有受影响复验。

我的整体评价 / Verdict

长程工作连续性和使用体验得到有界改善:同一 Agent 能保留已有工作并完成当前验收,用户无需增加确认回合;原身份和一次结算仍受机器约束。资格判断与历史校验复用现有 TypeScript receipt owner,Python 只负责锁和 IO;无需新增命令、调度器或第二套任务状态。追加历史回执有持久化成本,但比改写原记录或引入第二套恢复状态更小,也保留审计能力。本 PR 完成交账前、同一 Agent、File/SQLite 的接续闭环;远端 provider、跨 Agent 接管和 Codex App 后台续租均不在本次边界内。

本次只改变 quota CLI 结果与恢复分支,没有渲染界面改动。已验证 CLI 路径;尚未验证升级后安装包,作为部署验收单独执行。未发现应阻止此范围交付的问题;独立远端 provider、真实模型复验采纳和 Codex App 后台续租均未被本结论证明。发布前核对远端 head 不变;作者自评以 COMMENTED 发布,不伪称 GitHub 正式自批准,合并另按已有维护者授权和 readiness 处理。

English verdict: APPROVE — 6c8eb35; no blocking finding. Real CLI recovery, current validation and exactly-once replay pass for File/SQLite; remote providers and installed deployment are outside this review evidence.

@huangruiteng

Copy link
Copy Markdown
Collaborator Author

Exact-head merge decision: 6c8eb35.

本次已有明确维护者自合并授权。作者自评以 COMMENTED 发布并读回,check-result 通过;approval closeout 没有有效阻塞 review 或未解决 thread。独立 required validation 已通过:File/SQLite 真实 CLI 的恢复、当前验收、旧 proof 拒绝和一次结算;最终相关 Python 54 项、广泛 Python 189 项、TypeScript 267 项及标准 premerge。两个可选 PostgreSQL 测试未运行。

最新 readiness 仍为 false:远端有 pending 检查,且 PostgreSQL store conformance 报告 TAP failure。现有日志只暴露聚合断言,具体失败原因保留 unresolved,不能称为通过或已经定位的历史故障。该任务执行的是 store-direct ladder;本次不改变 PostgreSQL store,read_transaction 的改动仅限未由该 suite 调用的 execution-preparation 读取函数。受影响的本地 authority、receipt 与 settlement 路径已有上述独立覆盖。此项作为 diagnostic CI 风险保留,不扩展本 PR 修复无关的存储实现。

按照仓库允许的显式维护者授权路径,仅覆盖 readiness/GitHub policy hold,使用 admin merge;不覆盖 exact-head review、required validation 或未解决 finding。合并后继续验证真实安装运行时;不把源码测试宣称成已安装结果。

@huangruiteng
huangruiteng merged commit 988a80c into main Nov 26, 2026
20 of 43 checks passed
@huangruiteng
huangruiteng deleted the codex/automatic-lease-takeover-20261126 branch November 26, 2026 09:45
huangruiteng added a commit that referenced this pull request Nov 27, 2026
…-renew-20261127

test(control-plane): align canonical lease expiry test with #9488 takeover
JadeCong pushed a commit to CloudEngineHub/loopx that referenced this pull request Nov 27, 2026
…fenced takeover

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
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