Repository navigation
Fix lost-lease recovery and default task leases to three hours - #9487
Conversation
Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com>
huangruiteng
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · Codex · OpenAI · self_reported
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机
长任务的执行者在租约过期后,需要恢复同一任务并正确处理尚未交账的轮次。此前原租约过期但尚未重新领取时,系统提示普通工作准备,重新领取后却拒绝原轮次;现在直接进入已有的中断关闭路径。File/SQLite 实际 CLI 验证:释放原租约后能按提示领取当前写入证明,关闭原轮次且不完成任务、不扣额度。
本 PR 不实现新租约接管旧成果后正常结算,不增加 Codex App 自动续租,也不修改历史回执。旧成果自动接管与宿主自动续租仍需独立实现和验证。
改动思路
恢复判断复用现有 TS owner,提交权限继续由既有事务检查;默认值只抽成一个共享常量,没有新增同步状态。本次仅修复恢复观察和默认租期;旧成果自动接管仍是独立后续工作。只改提示文字不能识别原租约已经失效,而删除代际校验会让过期执行获得未授予的业务提交权,因此选择扩展观察分支、保留提交检查。
| 情况 | 本版行为 |
|---|---|
| 原执行租约仍有效 | 保持现有续租与执行路径 |
| 原租约已过期或释放 | 提示获取当前写入证明并关闭旧轮次 |
| 新租约用于关闭旧轮次 | 只允许已有无扣费关闭,不认定业务完成 |
该表来自 e5c920289aa883edcb22c33414e2c161ec2db085 的源码解释,不是额外执行证据。
具体改动
关键代码讲解
loopx/control_plane/quota/execution_loss_closeout.ts:145的observeFencedExecution从完整 File/SQLite 权威状态读取任务及租约。新增分支要求原 epoch 和 key hash 匹配、当前版本不倒退且租约不再有效,才将其视作原执行已经失去租约。有效原租约、错误 key、未来版本或没有正向执行准入均不能得到这条恢复提示。- 同文件第54行的
qualifyReceiptBoundExecutionLossCloseout是未改动但必须一起审查的权限边界:新租约只证明当前控制写入者,仍要求原轮次身份、新一代有效证明、限定的 blocked 意图。既有提交事务拒绝业务完成、额外字段和额度扣除,因此新增观察不会直接赋予交付权。 loopx/control_plane/work_items/task_lease_acquire.ts:192的normalizeTtl改用task_lease_record.ts中的共享三小时常量;协调层terminalFence复用该常量,Python 兼容归一化同步。显式1..86400秒边界不变,已有租约和回执不迁移。CLI help、claim 提示及 Pi 示例同步更新。
按改动前规范 docs/reference/canonical-lease-renew.md,固定版本 323b287ac7d0fde7326f0eda39017ed40370cd2e,核对 Operate the current lease 的精确当前证明与代际约束,以及 Repository-relative scope identity 的仓库绑定和历史回执保留。恢复、续租与负向测试覆盖这两项;文档本次新增解释不能作为自身实现正确的独立依据。三小时默认是明确披露的行为变化。
PASS:135项恢复/执行准备 Python 测试;98项租约/managed claim测试;最终类型检查及9项重点TS验证;标准 premerge 的10项catalog、8项风险检查及public boundary均通过。135项运行启动于最后类型保护整理前,最终准确head额外重跑原租约丢失/原轮次重入子集,4项通过,不混称所有历史运行均在同一冻结源码。新增回归在修复前出现 repair 缺失,修复后通过。标准门禁包含diff、Python编译和RFC双语检查。
对主干的风险
默认租约从45分钟延长到3小时,异常退出的持有人可能更晚被回收;显式短TTL、及时释放和存活宿主续租仍有意义。默认值进入独立租约操作的原始意图,升级后重放旧操作应明确传入当时记录的TTL,不能把旧操作默认为新的三小时请求。本PR不修改历史事实,也不绕过有效持有人和仓库绑定。回退代码不会缩短已发出的租约。
真实CLI覆盖File/SQLite;没有改动PostgreSQL provider,不将这些测试扩大解释为新的PG、已安装App或真实模型效果验证。相关 #9153 的native/report原始权限恢复已查看,其较大范围不由本补丁代替。远端CI在读回时仍有待完成项目,独立于本地代码结论,合并前继续执行配置要求的readiness。更完整的自动成果接管仍需当前权利、验收和幂等性设计,不能从这份行政关闭回执推断已经完成。
我的整体评价
APPROVE:这是一项可独立回退的有效增量,修复了已重现的恢复指引矛盾并交付三小时默认值,保留了原代际与提交权限边界。它没有交付自动接管旧成果的完整体验,该差距已明确保留。架构上复用现有owner和权威事实,避免另一套状态机;更长租约的代价及历史重放注意点已公开说明。
Inspected CLI recovery, apps/presentation/dashboard and lease settings: no rendered presentation or editor changes in this diff. Unverified scope: No visual changes; installed upgrade is not claimed.
English verdict: APPROVE e5c920289aa883edcb22c33414e2c161ec2db085. Lost-original-lease recovery and three-hour defaults are covered by local validation; automatic artifact adoption is outside this increment, and merge readiness remains a separate check.
Goal And Delivered Outcome
An admitted Turn whose original lease expires or is released can currently receive an ordinary claim instruction, even though a replacement generation cannot resume that execution. Route this case to the existing administrative execution-loss closeout: obtain a current control-writer proof, preview and close the original Turn without quota spend, then require fresh admission for delivery. Generation fencing, ownership checks and historical receipts remain intact.
Also change the default task lease from 45 minutes to 3 hours for managed claims and acquire/renew/transfer. Explicit TTLs and the 24-hour cap remain unchanged. Existing leases are not extended by upgrading; replaying an older standalone operation requires its original TTL. Longer defaults delay abandoned-holder takeover, so timely renewal and release remain necessary.
Intended base:
main. Related recovery work: #9153; this is a bounded observation/default fix, not its broader native execution or report recovery proposal.Author Declaration
docs/reference/canonical-lease-renew.mdat base323b287acsupplies the lease ownership and replay contract.observeFencedExecutionSelf-check: inspected the original and replacement generation boundaries, CLI help/readback, existing dashboard lease consumers and related PR. No new capability, storage migration or permission grant. The small adjacent refactor replaces a duplicated terminal-lease duration with the existing record owner's shared constant.
Scope And Continuation
Complete within this scope. This does not implement automatic renewal, extend active leases, restore old execution authority, or merge the broader recovery proposal. The CLI/native-host recovery contract is the affected entry point; dashboard/Lark have no independent lease-duration editor or policy to update and continue consuming the same typed state.
Validation
Coverage boundary: local File/SQLite control plane. No PostgreSQL provider implementation changed and no PostgreSQL promotion or performance claim. No benchmark jobs, private fixtures, live runtime mutation or model quality claim are included in this PR. An initial boundary-check invocation also inspected unrelated machine registry health; the isolated candidate-file boundary scan passed.
Frontend / Visual Evidence
UI impact: none. Existing typed lease/closeout consumers retain their schemas; no visual surface, settings editor or first viewport changed. Source data: synthetic fixtures only.
Type of Change / Area
Bug fix, documented default behavior change, documentation and tests; Core control plane (task ownership and quota recovery). Shared-authority promotion/RFC fixture impact: N/A; no provider selection or promotion change.
Boundary Checklist