Skip to content

fix(quota): settle a claim_required Turn after its own completion - #10247

Open
mojunzi wants to merge 1 commit into
loopx-project:mainfrom
mojunzi:codex/settle-claim-required-turn
Open

mojunzi wants to merge 1 commit into
loopx-project:mainfrom
mojunzi:codex/settle-claim-required-turn

Conversation

@mojunzi

@mojunzi mojunzi commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Goal And Delivered Outcome

Author Declaration

  • Written by: model_agent (Anthropic Claude, via Claude Code), reviewed and submitted by the human operator.

Implemented against

Criterion (spec clause) Disposition Symbol / path Test or command
A done Todo whose Turn was admitted with claim_required (no prepared lease) can settle implemented _hard_lease_execution_bound, loopx/control_plane/quota/execution_preparation.py test_claim_required_turn_settles_after_its_own_completion (claim and --recover-execution)
Such a Turn cannot settle on another Turn's completion implemented the existing completed-Todo receipt check below the new branch; a hard_lease completion needs the lease (handoff_mode_requires_lease) test_claim_required_turn_cannot_borrow_another_turns_completion
A deferred (not done) Todo still refuses an unprepared Turn implemented status == "done" existing test_unprepared_turn_does_not_become_admitted_after_deferral
Turns that did prepare a lease keep #9097's generation check implemented the new branch requires prepared_lease is None existing test_first_writeback_refuses_generation_retired_by_later_work, test_replacement_lease_requires_original_turn_guard_before_writeback
  • Self-check before submission: Ran the checks in Validation on macOS with Python 3.13 (file and sqlite providers; PostgreSQL not run). Read _hard_lease_execution_bound, the TS retired_lease_proof projection and findStepEvent to confirm which existing checks bind the lease owner and the Turn's completion receipt. A first draft refused the completion instead; I dropped it because it removed the fix(todo): recover execution idempotently with route-bound lease remediation #8310 one-command recovery. I then removed three conditions from the new branch. prepared_required is implied by the earlier not (todo_open or prepared_required) return. The retired-proof checks are implied because the completion receipt the branch relies on cannot be written without the lease. A draft without the done condition admitted deferred Todos, and the existing deferral test caught it.

Scope And Continuation

Validation

  • Tested revision: ccf1d46
  • Run state: finished
  • Input classes: synthetic
Check kind Result Public-safe evidence / limitation
regression_parity passed tests/control_plane/test_quota_authority_settlement_journey.py::test_claim_required_turn_settles_after_its_own_completion (file/sqlite × claim/--recover-execution): all 4 fail on base 3a4f084 and pass on head. The same sequences were also checked on #9097's first parent a05425b (settles) and merge f5da544 (fails).
regression_parity passed Mutation checks: dropping status == "done" fails the existing deferral test; dropping prepared_lease is None fails the two #9097 generation tests; disabling the existing completed-Todo receipt check fails test_claim_required_turn_cannot_borrow_another_turns_completion.
integration passed All 31 test files that complete a Todo Turn-scoped under hard_lease: 2135 passed, 13 skipped, 0 failed. Run with the checkout's scripts/ first on PATH, because tests/test_delegation_turn_context.py calls the bare loopx.
static passed scripts/loopx canary premerge --from-git-diff --git-diff-base origin/main: 23 selected checks passed, 0 failed (after npm ci --ignore-scripts).
  • Coverage and gaps: The new branch is reachable only for a done Todo whose Turn reports prepared_lease_required with no prepared_lease. The regression set is every test file that completes a Todo Turn-scoped under hard_lease. The repro was also run with the codex_app, claude_code and generic_cli runtime profiles. Not covered: PostgreSQL provider.

See validation disclosure guidance.

Frontend / Visual Evidence

  • UI impact: none
  • Before: N/A
  • After: N/A
  • First viewport and preview: N/A
  • States and viewports shown: N/A
  • Source data: none
  • Attention review: N/A
  • Craft review: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring (no functional changes)
  • Documentation update
  • Test update

LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)
  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)
  • Capability or extension (providers, adapters, skills)
  • Public docs or presentation surface (README, protocols, dashboard)
  • Build, packaging, installer, or CI
  • Host or runtime integration

Technical Direction

  • Direction / acceptance reference, when applicable: Core control-plane hardening.

Shared-authority RFC fixture impact

N/A

Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).
  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.
  • I kept the change scoped to the linked issue/task.
  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.
  • I completed the visual evidence section for UI changes, or marked UI impact none.
  • Every commit includes a DCO Signed-off-by trailer (git commit -s).

A hard_lease Turn guarded before its Todo is claimed is admitted with
execution_preparation.state=claim_required and records no prepared lease.
Since loopx-project#9097, its first writeback after a Turn-scoped completion (after a
separate claim, or via todo complete --recover-execution from loopx-project#8310) is
refused with refresh_task_lease_unavailable, and the guard's
unsettled_host_turn_recovery command fails the same way, so the Turn can
never settle.

Accept that writeback when the Todo is done and the Turn has no prepared
lease. The existing completed-Todo check below still requires this
Turn's own completion receipt, which a hard_lease completion can only
write while holding the Todo's lease. Deferred Todos and Turns that
prepared a lease keep their current checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Wang, Xiang-Han <wanghank00@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 6, 2026 04:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@BigDataDZ BigDataDZ left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立评审(native Windows)——APPROVE

精确核对 head:ccf1d4629(合并基点为当前 main)。评审域恰好是我此前多次验证过的 claim_required 语义(#9490、#9435 系列的同一文件)。

代码:5 行早退分支,触发条件收敛于 todo.status == "done" 且 prepared_lease is None(即 claim_required 准入、无准备租约可比对)。安全性锚在"下方完成回执检查必须绑定本 Turn",并由新增的负面测试证明:test_claim_required_turn_cannot_borrow_another_turns_completion 断言另一个已就绪 Turn 的完成不能被借用(refresh_task_lease_unavailable,零扣额)。其余分支(prepared lease 比对、recovery lease bound、autonomous replan guard bound)顺序与语义未动。

实测(Windows 10 / Python 3.12 / Node 24.20)

  • 两个新测试 → 6 passed(file+sqlite × recover_execution 双模式;负面用例双 provider)。正面用例完整走通正文声明的链路:claim_required 准入 → claim → todo complete --recover-execution → 结算一次 → 幂等重放 → 后续 guard 不再报 unsettled_host_turn_recovery,且 validated_progress 分类恰好 1 次、扣额恰好 1 次。
  • 周边 bound 相关用例(hard_lease/claim_required/replacement_lease/execution_bound 选择器)→ 8 passed;2 个 test_migrated_hard_lease_can_write_settle_retry_and_continue 失败经 main tip 9e4730c13 对照为既有环境失败(private capture validation is unsupported on this platform——POSIX 专用私有捕获门,即 #9398/#9559 家族),与本 PR 无关。

CI:分片按两级门控策略跳过、无完整套件结果。本机可验证的一切均通过,且修复域与我的既有验证记录重叠,故直接批准。

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.

3 participants