Skip to content

Fence C1 first writebacks with the prepared task lease - #9097

Open
loopx-agent wants to merge 1 commit into
mainfrom
codex/c1-fence-first-writeback-20261119
Open

loopx-agent wants to merge 1 commit into
mainfrom
codex/c1-fence-first-writeback-20261119

Conversation

@loopx-agent

Copy link
Copy Markdown
Collaborator

Goal And Delivered Outcome

A C1 Turn can keep its original admission after the work lease changes. First writeback now checks the prepared lease under the existing coordination lock before saving a new result or a delivery pause. The original admission and committed receipts still support interrupted settlement and idempotent replay.

Related to #8266. Target main at 1047f3b4cdf9. The changed behavior is covered by test_first_writeback_refuses_generation_retired_by_later_work and the native App comparison below.

Author Declaration

Written by OpenAI Codex (model agent).

Implemented against

LoopX Turn protocol and the C1 recovery and acceptance criteria.

Criterion Disposition Implementation and evidence
Authority before the first durable effect Implemented The shared execution-preparation projection and canonical snapshot supply the proof for CLI and managed Turn writeback. The same guard covers explicit pause. File and SQLite native App negative cases verify zero added effects.
Preserve original admission and committed results Implemented The original receipt lineage and settlement identity remain the source for authorized recovery. The native App cases exercise renewal, retirement, and replay with one debit.
Production adoption and single-session effectiveness/cost qualification Deferred These remain part of the C1 program. The paired rollback work remains in #9007.

Scope And Continuation

This patch adds a check at the first durable writeback boundary. The execution-preparation module shares the authority snapshot and assembles the receipt fields. The existing settlement command carries the readiness evidence. The adjacent successor-replan type annotation now describes the optional input accepted by its implementation.

The exact head is an independently reviewable candidate. Independent review, the maintainer merge decision, and release qualification are separate steps.

Validation

Tested revision 2f4c4e92c33f592188bfed50a1276f784f65f5bf. Run state finished for the following checks. Input class synthetic and public_fixture.

Check Result Evidence
Static Passed Changed Python Ruff, configured mypy, control-plane typecheck, RFC pair and Git diff checks. The adjacent successor helper annotation now describes its existing optional plan input.
CLI and TypeScript Passed 65 targeted quota CLI/authority cases on the preceding candidate. The final head passed six focused File/SQLite writeback cases. Six successor-replan/workspace cases also passed. The tested TypeScript files are byte-identical to this head (94 tests).
Native App and installed Core Passed File and SQLite, Codex App Server 0.169.0-alpha.11.1, the stock local installer for the final commit, and scripted inference. Eight runs preserved the original session and capture. Revoked work left zero pause, writeback and debit. Stable, renewed and committed-replay cases each retained a single authorized effect.
Cross-version CLI Passed Four File/SQLite runs began with a previously installed Core and recovered through the final release. Active work kept the original claim and settled once. Replaced work was refused before writeback or debit.
PostgreSQL authority Passed Isolated PostgreSQL 17.12. The store suite passed 398 cases. The service suite passed 10 cases, including two real-provider cases. One optional duplicate probe was skipped.
Baseline sensitivity Passed The same synthetic native App case on source 1047f3b4cdf9 persisted one pause, one first writeback and one debit after the lease changed on each backend. The isolated final install refused both.
Full suite, Windows and installed production adoption Not run An exploratory larger suite was stopped after 81 passes to run the selected scope. The final commit has no full-suite qualification, Windows install coverage or production adoption evidence here.
Standard premerge Passed Six direct checks and 18 selected checks passed for the exact head with the configured change-quality receipt. The final revision owns lease field assembly in execution preparation. The budget and heartbeat checks pass under matching temporary-directory conditions on both base and head.

For the regression, run uv run --extra test python -m pytest -q tests/control_plane/test_quota_authority_settlement_journey.py::test_first_writeback_refuses_generation_retired_by_later_work. The isolated App comparison used scripted inference and stayed within the local fixtures.

Frontend / Visual Evidence

UI impact none. The native App journey uses the existing delivery and recovery interfaces.

Type of Change

  • Bug fix
  • Test update

LoopX Area

  • Control plane
  • Host or runtime integration

Shared-authority RFC fixture impact

N/A. The fixture work exercises current File, SQLite and PostgreSQL authority routes.

Boundary Checklist

  • Public-safe source and evidence.
  • Scoped synthetic tests and no benchmark execution.
  • RFC bilingual diff check passed. No paired document changed.
  • UI impact none.
  • DCO sign-off present.

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.2-sol · OpenAI (runtime_reported, max)

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

[P2] 首写重验应保留原来的租约代次

首次写回前重新读取原 Turn 时,readiness 只要求准备版本更大。一次续租与一次重新分配都满足版本递增,后者还会换 lease epoch 和 key。旧 Turn 的有效回执因此可以采纳替代租约,写回处的三方比对随后只看到新 proof。 保留首次有效准备绑定的租约代次,已有 proof 时仅允许同代续租推进 CAS version。首次准备尚未取到 proof 的 Turn 仍可在其原认领流程补齐,已提交结果继续沿原回执重放。 相关代码

动机 / Motivation

Codex App 与 managed CLI 可在工作已经产出、结算尚未结束时恢复原 Turn。如果负责人刚停止目标,或同一 Todo 已换过执行租约,迟到的首份结果会影响后续工作和额度。本次把租约与 Stop 检查移到持久化前。恢复时,应能继续已提交结果的原回执,也应拒绝已经失去原执行资格的首次写回。这次复核覆盖 Core 的执行与恢复契约。C1 的默认切换、安装采用以及真实单会话收益继续由原计划验收。

改动思路 / Approach

这个切片复用原来的 Todo 权威快照、协调锁与结算回执。首写包括可选暂停,由现有提交路径统一验证。历史结果继续从结算前缀读回。准备回执可以记录同代的新版本,其原始代次应当保持稳定。本次边界是 C1 的首次持久化资格、正确的续租重验和原回执恢复。实际安装采用及单会话成果和完整成本仍由 C1 计划验收。现有简化空间集中在 requalification 的代次等价判断。暂停和业务 run 的提交点继续由同一处协调。

具体改动 / Changes

精确 head 2f4c4e92c33f592188bfed50a1276f784f65f5bf,diff base 1047f3b4cdf90e8912f7d8457d6d4e8d3e3542c9,16 个文件 +459/-82。逐项复核 Role isolation and recovery、Shared production paths、Outcome and cost benefit。验收约定

关键代码讲解

  • refresh-state 把第一次暂停和 run append 放在围栏之后。同代正常路径写入后,以原 Turn 的回执接续。源码
  • 同代续租只递增 version。新认领同时推进 version 和 epoch,两者必须按不同的因果关系对待。源码
  • readiness 追加保留原 admission 血缘,但新 proof 的核验缺少代次条件。源码

对主干的风险 / Risks

在 File 和 SQLite 的隔离 CLI fixture 中,续租后 epoch 与 key 保持,version 增长,原 Turn 的 admission 事件和 effect identity 保持。写回及扣额各一次。换代后重读原结果,两张回执仍逐项相同,额外扣额为零。同一原 Turn 尚未写回时,使用合法 owner Stop。File 和 SQLite 均返回 refresh_task_lease_unavailable,Stop 后日志逐字不变,pause、writeback、debit 各零。候选内置的 complete/defer 矩阵保留旧 proof,两个后端也都拒绝写回及扣额。 风险集中在未提交首写的 readiness 演进。

语义与 CI 对齐

pytest 9 项,独立 File/SQLite CLI 四个场景,TypeScript 256 项,改动 Python Ruff、双语差分和 git diff --check 均通过。在相同 File fixture 中,base 和 head 都能消费返回的 settlement 命令、补回执并保持一次扣额。现代 lease_readiness 分支由这个 PR 引入,base 没有可替换的准备 proof。 独立观察通过真实 Core CLI 的 Codex App 投影和 File/SQLite authority 完成。App Server、旧版安装接续和 PostgreSQL 的运行证据来自 PR 作者,本轮未独立重跑。跨代重验问题来自源码路径核对,未声称执行了该失败用例。

我的整体评价 / Verdict

请求修改。保留首次有效准备绑定的租约代次,已有 proof 时仅允许同代续租推进 CAS version。首次准备尚未取到 proof 的 Turn 仍可在其原认领流程补齐,已提交结果继续沿原回执重放。 请在两个后端加入新旧 lease epoch 的重验回归,并保留 Stop 及提交后重放的断言。

English verdict: REQUEST_CHANGES. Keep the original lease generation immutable during same-Turn requalification while allowing a same-generation renewal and receipt replay.

const previousVersion = previous?.prepared_lease_version ?? 0;
// A delayed readiness evaluation can never replace a newer lease. Only
// the preparation proof changes; admission, billing and workspace stay bound.
if (preparedLease.prepared_lease_version <= previousVersion) return replay;

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.

本分支把更大的 version 当成同代续租的证据。新认领也递增 version,同时改变 epoch。请让已有 preparation proof 仅从同一代次推进版本,首次准备和已提交回执的恢复继续使用现有分支。

This branch has not been deployed

No deployments
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