Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,16 @@ the ordinary agent-owned writeback and spend plan is unchanged.
When an old pre-claim capture is resumed, the ready capture is newly produced
under the complete contract; the original claim and Turn remain bound to their
original receipts. A ready capture expected to be complete cannot be used as a
historical carrier after it loses its version or binding. Other ordinary quota
and thin heartbeat callers retain their existing behavior pending qualification.
historical carrier after it loses its version or binding.

Turn-scoped Trae App and Antigravity App heartbeats also use the checked source.
Their saved launchers and same-Turn recovery guards keep the caller's delivery
setting. Automatic delivery uses the stateless reader and explicit off delivers
the full source inline. Both retain the agent's original writeback and single
spend. Turnless scheduler probes keep their observation route. For Trae App,
the generated activation bootstrap and its reads are exercised over File and
SQLite. Adoption in a live Trae App session and matched model costs remain open.

Explicit `--complete-turn` and managed handoff keep the checked source
through selection and native lease preparation. An unbound visible Goal also
keeps `--complete-turn` in its emitted Turn-binding command. The File and SQLite
Expand All @@ -1034,6 +1042,7 @@ the capture's format fields.
| Reader boundary | Current behavior and retirement condition |
| --- | --- |
| Codex App thin heartbeat and guided start | New decisions use the existing TypeScript composer with or without native delivery. The native hook pins the expected ready version for same-Turn recovery. |
| Trae App and Antigravity App heartbeats with a bound Turn | Use the same TypeScript composer and stateless reader. Selection and recovery carry the original Turn and delivery mode. The scheduler and spend retain their existing owners. |
| Other ordinary quota and thin heartbeat | Keep the existing compact decision and settlement until their actual callers qualify. Saved unsigned captures retain their original source and pinned recovery. |
| Explicit `--complete-turn` and managed handoff | Keep the checked complete source through selection and lease preparation. If a ready capture loses its complete version and binding, it offers receipt diagnosis only. |
| Explicit `--turn-envelope` | Progressive or Delta uses the complete source. With both off and without a managed handoff, retain the bounded v0 compatibility display from the same composition. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,15 @@ Codex App 心跳的新决定统一采用经校验的完整来源,贯穿普通
命令无需添加 flag。两种交付都关闭时,App 直接收到完整来源,不读写原生上下文;
原本由 Agent 执行的写回和扣额方案保持不变。若从旧的认领前捕获
恢复,新生成的就绪捕获使用完整契约,认领和 Turn 仍沿原回执绑定。预期完整的就绪捕获
丢失版本或绑定时,不得按历史载体用于工作。其他普通 quota 和 thin heartbeat 调用方
在验收前沿用现有行为。显式 `--complete-turn` 和托管 handoff 在选题与原生 lease 准备中
丢失版本或绑定时,不得按历史载体用于工作。

Trae App 和 Antigravity App 已绑定 Turn 的心跳也采用经校验的完整来源。已保存的启动
指令及同一 Turn 的恢复指令保留调用方的交付设置。自动交付采用无状态读取器,显式 off
以内联方式交付完整来源。两种方式都由 Agent 执行原有写回,并且只扣额一次。无 Turn
的调度探测仍走观察入口。Trae App 在 File 和 SQLite 上用实际生成的启动指令验证了
这条读取链路。真实 Trae App 会话采用和匹配模型成本对照仍待验证。

显式 `--complete-turn` 和托管 handoff 在选题与原生 lease 准备中
保留经校验的来源。尚未绑定 Turn 的可见 Goal,给出的绑定命令也保留
`--complete-turn`。File 和 SQLite 的用例执行该命令,核对仅有一张原回执、绑定
不扣额度,以及对照组仍沿用普通来源。渐进与差分仍独立于来源格式。
Expand All @@ -743,6 +750,7 @@ Benchmark checkpoint 预检按自身调用选择普通或完整来源校验,
| Reader 边界 | 当前行为与退役条件 |
| --- | --- |
| Codex App thin heartbeat 和引导启动 | 新决定不论是否使用原生交付,都调用已有 TypeScript 组合。原生 hook 在同一 Turn 恢复时固定预期的就绪版本。 |
| 已绑定 Turn 的 Trae App 和 Antigravity App 心跳 | 共用 TypeScript 组合和无状态读取器。选题和恢复沿用原 Turn 与交付模式。调度和扣额仍由原有执行方负责。 |
| 其他普通 quota 和 thin heartbeat | 保留现有紧凑决定与结算,直到实际调用方通过验收。已保存的未签名捕获沿原来源和固定引用恢复。 |
| 显式 `--complete-turn` 和托管 handoff | 在选题和 lease 准备中保留经校验的完整来源。ready capture 丢失完整来源版本和绑定时,只允许回执诊断。 |
| 显式 `--turn-envelope` | 渐进或差分开启时使用完整来源。两者都关闭且没有托管 handoff 时,仍展示同一次组合产生的有界 v0 兼容视图。 |
Expand Down
13 changes: 7 additions & 6 deletions loopx/cli_commands/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def _publish_quota_result(
host_todo_settlement = getattr(args, "host_todo_settlement", False)
complete_source = False
app_source = False
antigravity_work_turn = False
stateless_app_work_turn = False
runtime_root = context.runtime_root if context is not None else None
if not budgeted_spend:
try:
Expand All @@ -529,11 +529,12 @@ def _publish_quota_result(
)

profile = scheduler_runtime_profile_for_execution_context(context.scheduler_context)
# Antigravity also uses this command for turnless sidecar and Stop probes.
antigravity_work_turn = (
profile is SchedulerRuntimeProfile.ANTIGRAVITY_APP and heartbeat_turn_id is not None
# Turnless App probes retain their observation route.
stateless_app_work_turn = (
heartbeat_turn_id is not None
and profile in {SchedulerRuntimeProfile.TRAE_APP, SchedulerRuntimeProfile.ANTIGRAVITY_APP}
)
app_source = profile is SchedulerRuntimeProfile.CODEX_APP_HEARTBEAT or antigravity_work_turn
app_source = profile is SchedulerRuntimeProfile.CODEX_APP_HEARTBEAT or stateless_app_work_turn
complete_source = (host_todo_settlement or app_source
or any(getattr(args, name, None) for name in (
"complete_turn", "turn_envelope", "decision_handoff_socket",
Expand All @@ -542,7 +543,7 @@ def _publish_quota_result(
payload, args, context=context, registry_path=registry_path, heartbeat_turn_id=heartbeat_turn_id,
capture_directory=capture_directory, reader_argv=reader_argv,
complete_source=complete_source,
preserve_app_delivery=antigravity_work_turn and not getattr(args, "complete_turn", False),
preserve_app_delivery=stateless_app_work_turn and not getattr(args, "complete_turn", False),
activation=activation, remember_result=remember_result,
)
_observe_live_quota_result(
Expand Down
105 changes: 81 additions & 24 deletions tests/control_plane/test_heartbeat_envelope_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,7 @@ def test_codex_app_thin_guard_uses_complete_source_for_new_captures(tmp_path, mo


@pytest.mark.parametrize("provider", ["file", "sqlite"])
@pytest.mark.parametrize("loader", ["saved-alias-off", "sidecar-auto"])
def test_antigravity_wake_defaults_to_complete_source_and_recovers_agent_spend(
tmp_path, monkeypatch, provider, loader,
):
def test_antigravity_sidecar_gate_does_not_admit_work(tmp_path, monkeypatch, provider):
from loopx.agy_goal_mode import build_antigravity_sidecar_template
from loopx.control_plane.scheduler.scheduler_hint import SCHEDULER_HOST_FACTS_CHUNK_FLAG
from tests.control_plane.canonical_authority_fixture import isolate_sqlite_runtime
Expand Down Expand Up @@ -778,43 +775,90 @@ def followup(argv):
else:
assert actual == expected, field

if loader == "saved-alias-off":
rc, prompt = _run_cli(
registry, runtime, "heartbeat-prompt", "--thin", "--antigravity_app", "--context-delivery", "off",
"--goal-id", GOAL_ID, "--agent-id", AGENT_ID, cwd=project,

@pytest.mark.parametrize("provider", ["file", "sqlite"])
@pytest.mark.parametrize("host", ["antigravity_app", "trae_app"])
@pytest.mark.parametrize("delivery", ["auto", "off"])
def test_stateless_app_wake_defaults_to_complete_source_and_recovers_agent_spend(
tmp_path, monkeypatch, provider, host, delivery,
):
from loopx.agy_goal_mode import build_antigravity_sidecar_template
from loopx.host_loop_activation import build_host_loop_activation_packet
from tests.control_plane.canonical_authority_fixture import isolate_sqlite_runtime
from tests.control_plane.test_quota_settlement_cli import _configure_read_only_todo

isolate_sqlite_runtime(tmp_path, monkeypatch)
monkeypatch.delenv("LOOPX_CONTEXT_DELIVERY", raising=False)
monkeypatch.setenv("LOOPX_RUNTIME_ROOT", str(tmp_path / "runtime"))
project, runtime, registry = _write_fixture(tmp_path)
state = _configure_read_only_todo(project)
acceptance = "Verify the aggregate before submitting evidence. 保留验收记录。\n" * 168
state.write_text(
state.read_text(encoding="utf-8").replace("## Next Action", acceptance + "\n## Next Action", 1),
encoding="utf-8",
)
_initialize_fixture_authority(project, runtime, provider=provider)
if host == "trae_app":
activation = build_host_loop_activation_packet(
agent_type="trae_app", goal_id=GOAL_ID, agent_id=AGENT_ID,
registered_agents=[AGENT_ID], runtime_root=str(runtime), registry=str(registry),
)
command = activation["activation_input_command"]
if delivery == "off":
command += " --context-delivery off"
rc, loader = _run_generated_cli(command, registry_path=registry, cwd=project)
assert rc == 0 and loader["ok"], loader
bootstrap = loader["task_body"]
elif delivery == "auto":
bootstrap = build_antigravity_sidecar_template(
goal_id=GOAL_ID, agent_id=AGENT_ID, runtime_root=str(runtime),
)["sidecar"]["loopx-heartbeat"]["bootstrap_prompt"]
else:
command = template["bootstrap_prompt"].split("```sh\n", 1)[1].split("\n```", 1)[0]
rc, prompt = _run_generated_cli(command, registry_path=registry, cwd=project)
rc, loader = _run_cli(
registry, runtime, "heartbeat-prompt", "--thin", "--antigravity_app", "--context-delivery", "off",
"--goal-id", GOAL_ID, "--agent-id", AGENT_ID, "--bootstrap", cwd=project,
)
assert rc == 0 and loader["ok"], loader
bootstrap = loader["task_body"]
command = bootstrap.split("```sh\n", 1)[1].split("\n```", 1)[0]
rc, prompt = _run_generated_cli(command, registry_path=registry, cwd=project)
assert rc == 0 and prompt["ok"], prompt
command = next(line for line in prompt["task_body"].splitlines() if " quota should-run " in line)
guard = shlex.split(command)
assert not {"--complete-turn", "--turn-envelope", "--codex-context-root"} & set(guard)
assert guard[guard.index("--context-delivery") + 1] == ("off" if loader == "saved-alias-off" else "auto")
assert guard[guard.index("--context-delivery") + 1] == delivery
guard[guard.index("--turn-instance-id") + 1] = TURN_ID
guard = guard[guard.index("quota"):]

def read_current(view):
if loader == "saved-alias-off":
assert not {"context_delivery", "first_read_command", "reference_file"} & view.keys()
return view
assert view["schema_version"] == "context_capture_navigation_v1" and view["mode"] == "full"
command = view["recovery"]["command"]
digest, body = None, b""
def read_pages(command, *, max_output_bytes, selection=False):
reference, body = None, b""
schema = "context_capture_selection_page_v1" if selection else "context_capture_page_v1"
pin = "reference_file" if selection else "sha256"
while True:
result = subprocess.run(
shlex.split(command), cwd=project, capture_output=True, text=True, timeout=30,
shlex.split(command), cwd=project, capture_output=True, timeout=30,
)
assert result.returncode == 0, result.stdout + result.stderr
assert len(result.stdout) <= max_output_bytes
page = json.loads(result.stdout)
digest = digest or page["sha256"]
assert page["ok"] and page["sha256"] == digest and page["offset"] == len(body), page
assert page["ok"] and page["schema_version"] == schema and page["offset"] == len(body), page
reference = reference or page[pin]
assert page[pin] == reference, page
body += page["content"].encode()
if page["eof"]:
assert len(body) == page["total_bytes"] and hashlib.sha256(body).hexdigest() == digest
return json.loads(body)
assert len(body) == page["total_bytes"]
if not selection:
assert hashlib.sha256(body).hexdigest() == reference
return body
command = page["next_command"]

def read_current(view):
if delivery == "off":
assert not {"context_delivery", "first_read_command", "reference_file"} & view.keys()
return view
assert view["schema_version"] == "context_capture_navigation_v1" and view["mode"] == "full"
return json.loads(read_pages(view["recovery"]["command"], max_output_bytes=64000))

rc, refused = _run_cli(
registry, runtime, *guard, "--context-delivery", "on", "--delta-delivery", "auto",
cwd=project, raw_guard=False,
Expand All @@ -836,9 +880,22 @@ def read_current(view):
spend = next(step for step in plan["ordered_steps"] if step["kind"] == "quota_spend")
assert spend["owner"] == "agent" and "--settle-turn" not in writeback["command_template"]

if delivery == "auto":
body = read_pages(view["first_read_command"], max_output_bytes=12000, selection=True)
rows = {row["pointer"]: row["value"] for row in json.loads(body)["selections"]}
agent_path = "/interaction_contract/agent_channel"
assert rows["/heartbeat_receipt"]["settlement_identity"] == identity
assert rows["/selected_todo"]["todo_id"] == TODO_ID
assert any(acceptance in value for pointer, value in rows.items()
if pointer.startswith(agent_path + "/work_context/sources/") and pointer.endswith("/content/text"))
assert rows[agent_path + "/required_reads"] == source["interaction_contract"]["agent_channel"]["required_reads"]
assert rows["/interaction_contract/cli_channel/settlement_plan/identity"] == identity
else:
assert not (runtime / "context-delivery").exists()

command = writeback["command_template"]
for token, value in {
"<validated_progress>": "antigravity_fixture_progress", "<scale>": "implementation",
"<validated_progress>": "stateless_app_fixture_progress", "<scale>": "implementation",
"<outcome>": "outcome_progress", "<boundary>": "in_flight_continuation",
}.items():
command = command.replace(token, value)
Expand Down
52 changes: 31 additions & 21 deletions tests/control_plane/test_interrupted_turn_continuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,30 @@
)


@pytest.mark.parametrize("profile", ["codex", "antigravity-explicit-capture", "antigravity-inline"])
def test_original_turn_can_resume_and_settle_without_mutating_todo(tmp_path: Path, profile: str) -> None:
@pytest.mark.parametrize(("host", "delivery", "envelope"), [
pytest.param("--codex-app", None, False, id="codex"),
pytest.param("--antigravity_app", "auto", True, id="antigravity-explicit-capture"),
pytest.param("--antigravity_app", "off", False, id="antigravity-inline"),
pytest.param("--trae_app", "off", False, id="trae-inline"),
pytest.param("--trae_app", "auto", False, id="trae-progressive"),
])
def test_original_turn_can_resume_and_settle_without_mutating_todo(
tmp_path: Path, host: str, delivery: str | None, envelope: bool,
) -> None:
project, runtime, registry = _write_fixture(tmp_path)
_configure_read_only_todo(project)
_initialize_fixture_authority(project, runtime, provider="sqlite")
prior_turn = "interrupted-original"
recovery_turn = "interrupted-recovery"
capture_root = tmp_path / "private captures"
capture_root.mkdir(mode=0o700)
if profile == "antigravity-explicit-capture":
transport = ("--antigravity_app", "--turn-envelope", "--context-delivery", "auto",
"--decision-output-root", str(capture_root))
elif profile == "antigravity-inline":
transport = ("--antigravity_app", "--context-delivery", "off")
else:
transport = ("--codex-app",)
transport = (host,)
if delivery is not None:
transport += ("--context-delivery", delivery)
if delivery == "auto":
transport += ("--decision-output-root", str(capture_root))
if envelope:
transport += ("--turn-envelope",)

def guard(turn: str):
before = set(capture_root.glob("*/decision.json"))
Expand All @@ -41,10 +49,10 @@ def guard(turn: str):
"--turn-instance-id", turn, "--todo-id", TODO_ID,
)
assert rc == 0, result
if profile == "antigravity-explicit-capture":
if delivery == "auto":
decision, = set(capture_root.glob("*/decision.json")) - before
result = json.loads(decision.read_text())
if profile != "codex":
if delivery is not None:
assert_complete_turn_decision(result)
return result

Expand All @@ -56,24 +64,26 @@ def guard(turn: str):
actions = interrupted["interaction_contract"]["cli_channel"]["next_cli_actions"]
assert not any("--resume-when" in action for action in actions)
for action in (actions[1], actions[-1]):
if profile == "antigravity-explicit-capture":
argv = shlex.split(action)
assert "--turn-envelope" in argv and "--complete-turn" not in argv
if delivery is None:
continue
argv = shlex.split(action)
assert host in argv and "--complete-turn" not in argv
assert ("--turn-envelope" in argv) is envelope
assert argv[argv.index("--context-delivery") + 1] == delivery
if delivery == "auto":
assert argv[argv.index("--decision-output-root") + 1] == str(capture_root)
assert argv[argv.index("--context-delivery") + 1] == "auto"
if profile == "antigravity-inline":
argv = shlex.split(action)
assert argv[argv.index("--context-delivery") + 1] == "off"
assert not {"--turn-envelope", "--complete-turn", "--decision-output-root"} & set(argv)
else:
assert "--decision-output-root" not in argv
state_path = project / f".codex/goals/{GOAL_ID}/ACTIVE_GOAL_STATE.md"
state_before = state_path.read_bytes()
rc, resumed = _run_generated_cli(actions[1], registry_path=registry)
assert rc == 0, resumed
if profile != "codex":
if delivery is not None:
assert_complete_turn_decision(resumed)
assert state_path.read_bytes() == state_before
assert resumed["effective_action"] != "unsettled_host_turn_recovery", resumed
assert resumed["selected_todo"]["todo_id"] == TODO_ID
assert resumed["heartbeat_receipt"]["settlement_identity"] == admitted["heartbeat_receipt"]["settlement_identity"]
assert _spend_run_count(runtime) == 0

rc, writeback = _run_cli(
Expand All @@ -98,7 +108,7 @@ def guard(turn: str):
assert _spend_run_count(runtime) == 1
rc, next_guard = _run_generated_cli(actions[-1], registry_path=registry)
assert rc == 0, next_guard
if profile != "codex":
if delivery is not None:
assert_complete_turn_decision(next_guard)
assert next_guard["effective_action"] != "unsettled_host_turn_recovery", next_guard
assert next_guard["selected_todo"]["todo_id"] == TODO_ID
Expand Down
Loading
Loading