Skip to content

Commit 02ee861

Browse files
authored
Merge pull request #7793 from loopx-project/codex/trajectory-claim-guidance-20261101
fix(quota): include hard-lease execution preparation in settlement recipes
2 parents 1b81d78 + ba487a6 commit 02ee861

14 files changed

Lines changed: 153 additions & 6 deletions

‎docs/reference/handoff-mode.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ A read-only quota guard never claims or renews. Long-running delegated Hosts ret
6262
their existing supervision; this CLI path does not supervise an idle external
6363
process. The App's manual completion boundary described above is unchanged.
6464

65+
For a selected `hard_lease` Todo, the quota settlement plan now gives the ordinary
66+
claim command before task execution and carries its returned reference in the
67+
completion template. Quota and TurnEnvelope share that plan. The policy comes
68+
from the canonical Todo snapshot through `goal_boundary.handoff_mode`, including
69+
reads that omit lease records; display Markdown does not supply it. `soft_claim` retains its existing completion
70+
recipe. Supplied explicit proof is preserved, and an unavailable policy is not
71+
inferred as a new lease requirement. This is caller guidance, not acquisition,
72+
renewal or a replacement for validation and the existing fences.
73+
6574
Goal-mode MCP uses the same task reference: retain `claim_operation_id` from
6675
`claim_task` and pass it to `complete_task`, including retries. This is a breaking
6776
tool-schema change: `complete_task` no longer accepts
@@ -375,6 +384,13 @@ CLI 由明确的 `--agent-id` 认领给自己时,会在同一 canonical 事务
375384
重复写入或续租。只读 quota guard 不做认领或续租;长期委派 Host 仍走已有监督,
376385
本 CLI 路径不监督空闲外部进程,也不改变 App 手工完成的现有边界。
377386

387+
选中的 Todo 使用 `hard_lease` 时,quota 结算计划会在执行前给出普通认领命令,完成
388+
模板携带其返回的原引用;quota 与 TurnEnvelope 共用该计划。策略取自 canonical Todo
389+
快照,经 `goal_boundary.handoff_mode` 传递;即使读取未请求租约记录,也不从展示
390+
Markdown 推断。`soft_claim` 保持原完成命令;调用方已有显式证明时原样保留,策略
391+
不可用时不臆造租约要求。这是调用指引,
392+
不执行认领或续租,也不替代验收及已有 fence。
393+
378394
Goal-mode MCP 同样传递任务引用:保存 `claim_task` 返回的 `claim_operation_id`,
379395
在 `complete_task` 及其重试中原样使用。本次为 breaking change,`complete_task`
380396
移除 `task_lease_idempotency_key` 和 `task_lease_expected_version` 参数;调用方须

‎loopx/cli_commands/todo.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def _todo_settlement_plan(
144144
path_args = ""
145145
for name, option in (
146146
("project", "--project"), ("state_file", "--state-file"),
147+
("claim_operation_id", "--claim-operation-id"),
147148
("task_lease_idempotency_key", "--task-lease-idempotency-key"),
148149
("task_lease_expected_version", "--task-lease-expected-version"),
149150
):

‎loopx/control_plane/coordination/canonical_snapshot_page.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export async function readCanonicalSnapshotFromStore(value: unknown, store: Auth
109109
const metadata = {todo_read_model: readModel,
110110
...(!!configuredGoalChecks(acceptance) || acceptance.outcome_requirements || acceptance.goal_objective ? {goal_acceptance_contract: acceptance} : {}),
111111
...(oracleObservationBasis === null ? {} : {goal_acceptance_oracle_observation_basis: oracleObservationBasis}),
112-
...(leases === null ? {} : {handoff_mode: head.head.handoff_mode ?? "legacy"}),
112+
handoff_mode: head.head.handoff_mode ?? "legacy",
113113
...(readback === null ? {} : {projection_readback: confirmProjectionReadback(readback, head.provider_revision)})};
114114
function result(chosenTodos: readonly string[], chosenLeases: readonly string[], guards: JsonObject): JsonObject {
115115
const todoEnd = todoStart + chosenTodos.length, leaseEnd = leaseStart + chosenLeases.length;

‎loopx/control_plane/quota/effect_program.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def build_codex_app_settlement_plan(
110110
quota_spend_source: str = "heartbeat",
111111
goal_ref: Mapping[str, object] | None = None,
112112
autonomous_replan: bool = False,
113+
handoff_mode: str | None = None,
113114
) -> SettlementPlan:
114115
return build_turn_scoped_cli_settlement_plan(
115116
goal_id=goal_id,
@@ -125,6 +126,7 @@ def build_codex_app_settlement_plan(
125126
quota_spend_source=quota_spend_source,
126127
goal_ref=goal_ref,
127128
autonomous_replan=autonomous_replan,
129+
handoff_mode=handoff_mode,
128130
)
129131

130132

@@ -144,6 +146,7 @@ def build_turn_scoped_cli_settlement_plan(
144146
quota_spend_source: str = "heartbeat",
145147
goal_ref: Mapping[str, object] | None = None,
146148
autonomous_replan: bool = False,
149+
handoff_mode: str | None = None,
147150
) -> SettlementPlan:
148151
if sum(bool(value) for value in (todo_id, replan_obligation_id, request_subject)) != 1:
149152
raise ValueError(
@@ -186,6 +189,17 @@ def build_turn_scoped_cli_settlement_plan(
186189
# Returned settlement commands are machine-readable without caller surgery.
187190
# Keep this global option before every subcommand, including quota spend-slot.
188191
cli_prefix = f"{command_prefix.strip() or 'loopx'} --format json"
192+
task_claim = (
193+
f"{cli_prefix} todo claim --goal-id {shlex.quote(goal_id)}{binding_arg}"
194+
f" --agent-id {shlex.quote(agent_id)} --claimed-by {shlex.quote(agent_id)}"
195+
f"{goal_ref_arg}"
196+
)
197+
# Preserve a caller's accepted execution reference or explicit lease proof.
198+
# This only renders CLI syntax; the canonical lifecycle still checks it.
199+
proof_options = {"--claim-operation-id", "--task-lease-idempotency-key", "--task-lease-expected-version"}
200+
completion_proof_supplied = any(
201+
token.partition("=")[0] in proof_options for token in shlex.split(lifecycle_actor_args)
202+
)
189203
ordinary_completion = (
190204
f"{cli_prefix} todo complete --goal-id {shlex.quote(goal_id)}{binding_arg}"
191205
f"{lifecycle_actor_args}{turn_arg}{goal_ref_arg} --evidence '<validated evidence>'"
@@ -205,9 +219,12 @@ def build_turn_scoped_cli_settlement_plan(
205219
payload = effect_runtime_result("settlement.turn_scoped_cli_plan", {
206220
"identity": identity.as_dict(), "delivery_boundary": delivery_boundary,
207221
"autonomous_replan": autonomous_replan,
222+
"handoff_mode": handoff_mode,
223+
"completion_proof_supplied": completion_proof_supplied,
208224
"delivery_batch_scale_choices": list(DELIVERY_BATCH_SCALE_INPUT_CHOICES),
209225
**({"goal_ref": normalized_goal_ref} if normalized_goal_ref is not None else {}),
210226
"command_templates": {
227+
**({"todo_claim": task_claim} if todo_id else {}),
211228
"todo_completion": ordinary_completion, "durable_writeback": writeback,
212229
"quota_spend": spend, "terminal_closeout": terminal_closeout,
213230
},

‎loopx/control_plane/quota/settlement_plan.ts‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import {
66
} from "../effect_program.ts";
77
import {VISION_MATERIAL_CLOSEOUT_HINT, visionAuthoringContract} from "../goals/vision_checkpoint.ts";
88
import {parseExactGoalRef} from "../goals/goal_instance_identity.ts";
9-
import {requireBoolean, requireJsonObject, requireNonEmptyString, requireStringArray} from "../runtime_decode.ts";
9+
import {requireBoolean, requireJsonObject, requireNonEmptyString, requireStringArray, requireStringLiteral} from "../runtime_decode.ts";
1010
import {MATERIAL_DELIVERY_OUTCOMES} from "../work_items/delivery_outcome.ts";
1111
import {DELIVERY_BOUNDARIES} from "../turn_driver/delivery_continuity.ts";
1212
import {PROGRESS_RESULT_CLASSES} from "../work_items/replan_history.ts";
13+
import {HANDOFF_MODES} from "../coordination/handoff_mode_vocabulary.ts";
1314

1415
export function turnScopedCliSettlementPlan(params: JsonObject): SettlementPlan {
1516
const identity = settlementIdentity(
@@ -54,15 +55,28 @@ export function turnScopedCliSettlementPlan(params: JsonObject): SettlementPlan
5455
const inFlight = params.delivery_boundary === "in_flight_continuation";
5556
const autonomousReplan = (params.autonomous_replan === undefined ? false
5657
: requireBoolean(params.autonomous_replan, "autonomous_replan")) || identity.binding_kind === "autonomous_replan";
58+
const mode = params.handoff_mode == null ? null
59+
: requireStringLiteral(params.handoff_mode, HANDOFF_MODES, "handoff_mode");
60+
const managedClaim = identity.binding_kind === "todo" && mode === "hard_lease";
61+
const proofSupplied = params.completion_proof_supplied === undefined ? false
62+
: requireBoolean(params.completion_proof_supplied, "completion_proof_supplied");
63+
const completionProof = managedClaim && !proofSupplied
64+
? " --claim-operation-id '<original claim_operation_id>'" : "";
5765
const validation: SettlementStep = {
5866
kind: "validation", owner: "agent", idempotency_key_ref: "$.identity.effect_id",
5967
expected_receipt: "validation_receipt",
6068
precondition: "delivery result is independently validated",
6169
};
6270
if (identity.binding_kind === "todo") {
63-
validation.command_template = requireNonEmptyString(commands.todo_completion, "todo_completion");
71+
validation.command_template = requireNonEmptyString(commands.todo_completion, "todo_completion") + completionProof;
6472
validation.command_condition = "todo_deliverable_complete";
65-
validation.precondition = "validate the original Todo deliverable; when complete, run ordinary Todo completion " +
73+
const claimHint = managedClaim ? "Before task execution, prepare it with ordinary Todo claim: `" +
74+
requireNonEmptyString(commands.todo_claim, "todo_claim") +
75+
"`. Reuse an already accepted current claim or explicit lease proof; keep the original " +
76+
"claim_operation_id for managed progress/completion retries. claimed_by alone is not an execution lease. " +
77+
"An expired, released or replaced execution requires normal ownership recovery; " +
78+
"this plan neither acquires nor renews execution. " : "";
79+
validation.precondition = claimHint + "validate the original Todo deliverable; when complete, run ordinary Todo completion " +
6680
"with its original declaration and current lease before writeback/spend. Use --evidence for " +
6781
"an artifact pointer; --result-file requires approved Goal acceptance criteria bound to this Todo, " +
6882
"not merely a Todo validator. No invented successor " +
@@ -108,7 +122,7 @@ export function turnScopedCliSettlementPlan(params: JsonObject): SettlementPlan
108122
precondition: "the selected Todo is final with no runnable successor and matching " +
109123
"writeback and quota spend receipts exist",
110124
idempotency_key_ref: "$.identity.effect_id", expected_receipt: "terminal_closeout_receipt",
111-
command_template: requireNonEmptyString(commands.terminal_closeout, "terminal_closeout"),
125+
command_template: requireNonEmptyString(commands.terminal_closeout, "terminal_closeout") + completionProof,
112126
conditional: true,
113127
});
114128
return {

‎loopx/control_plane/quota/should_run_packet.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,10 @@ def _quota_payload_context(prepared: _QuotaDecisionPreparation, route: _QuotaDec
13641364
if isinstance(prepared.item.get("long_task_cadence_hint"), dict)
13651365
else None,
13661366
"handoff_readiness": prepared.item.get("handoff_readiness"),
1367-
"goal_boundary": prepared.goal_boundary,
1367+
"goal_boundary": (
1368+
{**(prepared.goal_boundary or {}), "handoff_mode": prepared.item["handoff_mode"]}
1369+
if prepared.item.get("handoff_mode") is not None else prepared.goal_boundary
1370+
),
13681371
"plan_summary": prepared.plan.get("summary")
13691372
}
13701373

‎loopx/control_plane/todos/active_state_todos.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ def active_state_todo_fields(
111111
from .goal_todo_projection import observe_todo_acceptance
112112
fields = observe_todo_acceptance(canonical["_todo_fields"], canonical,
113113
registry_path=source_registry, goal_id=goal_id)
114+
# Execution guidance must use the same canonical policy as the Todo read,
115+
# never the historical Markdown frontmatter or a registry default.
116+
fields["handoff_mode"] = canonical.get("handoff_mode")
114117
# Material existence is a local read projection, not persisted Todo state.
115118
# Derive it from the canonical text so stale display links cannot take over.
116119
for key in ("user_todos", "agent_todos"):

‎loopx/control_plane/work_items/accountable_settlement.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def build_accountable_work_item_settlement_plan(
2929
command_prefix: str = "loopx",
3030
goal_ref: Mapping[str, object] | None = None,
3131
autonomous_replan: bool = False,
32+
handoff_mode: str | None = None,
3233
) -> SettlementPlan | None:
3334
if runtime_profile in APP_HEARTBEAT_SETTLEMENT_RUNTIME_PROFILES:
3435
normalized_turn_instance_id = normalize_turn_instance_id(turn_instance_id)
@@ -44,6 +45,7 @@ def build_accountable_work_item_settlement_plan(
4445
delivery_boundary=delivery_boundary,
4546
goal_ref=goal_ref,
4647
autonomous_replan=autonomous_replan,
48+
handoff_mode=handoff_mode,
4749
)
4850
if runtime_profile in VISIBLE_GOAL_SETTLEMENT_RUNTIME_PROFILES:
4951
normalized_turn_instance_id = normalize_turn_instance_id(turn_instance_id)
@@ -62,6 +64,7 @@ def build_accountable_work_item_settlement_plan(
6264
quota_spend_source="visible-goal",
6365
goal_ref=goal_ref,
6466
autonomous_replan=autonomous_replan,
67+
handoff_mode=handoff_mode,
6568
)
6669
if runtime_profile is not SchedulerRuntimeProfile.GENERIC_CLI_AGENT_LOOP:
6770
return None
@@ -80,4 +83,5 @@ def build_accountable_work_item_settlement_plan(
8083
delivery_boundary=delivery_boundary,
8184
goal_ref=goal_ref,
8285
autonomous_replan=autonomous_replan,
86+
handoff_mode=handoff_mode,
8387
)

‎loopx/control_plane/work_items/interaction_contract.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ def _turn_scoped_cli_settlement_context(
475475
replan_obligation_id=replan_obligation_id,
476476
scoped_cli_args=scoped_cli_args,
477477
lifecycle_actor_args=f" --agent-id {shlex.quote(agent_id)}",
478+
handoff_mode=(payload.get("goal_boundary") or {}).get("handoff_mode"),
478479
turn_instance_id=turn_instance_id,
479480
autonomous_replan=semantic_replan_obligation_id is not None,
480481
delivery_boundary=(

‎loopx/quota.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ def build_quota_plan(
925925
"missing_gates",
926926
"next_handoff_condition",
927927
"handoff_readiness",
928+
"handoff_mode",
928929
"user_todos",
929930
"agent_todos",
930931
"active_state_next_action",

0 commit comments

Comments
 (0)