Skip to content
Open
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
6 changes: 4 additions & 2 deletions loopx/control_plane/goals/vision_checkpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ const GOAL_PATH_DELTA_LIST_LIMITS = {

// Guidance for the existing material-closeout qualification, not a new gate.
export const VISION_MATERIAL_CLOSEOUT_HINT =
"For material semantic_closeout, provide " +
"vision_patch.acceptance_summary and top-level path_delta (outcome=continue/no_change/replan, " +
"For progress semantic_closeout, provide " +
`vision_patch.acceptance_summary and top-level path_delta (outcome=${OUTCOME_CHECKPOINT_CONTINUATION_OUTCOMES.join("/")}, ` +
"prior_assumption, observed_reality, retained/changed/stopped, evidence_refs). " +
"An unchanged reason only reuses an already evidence-linked current vision. " +
"Checkpoint satisfied alone does not qualify the outcome.";
Expand Down Expand Up @@ -123,6 +123,7 @@ export function visionAuthoringContract(autonomousReplan = false): JsonObject {
path_delta: {
schema_version: GOAL_PATH_DELTA_SCHEMA_VERSION,
outcomes: [...GOAL_PATH_DELTA_OUTCOMES],
open_progress_outcomes: [...OUTCOME_CHECKPOINT_CONTINUATION_OUTCOMES],
required: ["outcome", "prior_assumption", "observed_reality"],
require_any: ["retained", "changed", "stopped"],
scalar_limits: {...GOAL_PATH_DELTA_SCALAR_LIMITS},
Expand All @@ -131,6 +132,7 @@ export function visionAuthoringContract(autonomousReplan = false): JsonObject {
)),
},
rule: "Material closeout: acceptance_summary + evidence-linked path_delta. " +
"Progress wait: reentry_condition. Gap allows wait. " +
(autonomousReplan
? `Autonomous review: changing ${GOAL_VISION_DURABLE_FIELDS.join(", ")} requires outcome=replan, even when the Goal objective stays unchanged. Retaining these fields permits continue/no_change. `
: "Changed mainline: outcome=replan. ") +
Expand Down
28 changes: 27 additions & 1 deletion tests/control_plane/test_quota_authority_settlement_journey.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,34 @@ def run(*args):
prep = ready["interaction_contract"]["cli_channel"]["execution_preparation"]
assert prep["state"] == "ready"
assert prep["lease_proof"] == {"idempotency_key": lease_key, "expected_version": int(version)}
code, refreshed = _refresh(project, runtime, registry, *proof_args)

captures = tmp_path / "captures"
captures.mkdir(mode=0o700)
code, captured = run(
"quota", "should-run", "--codex-app", "--agent-id", cli.AGENT_ID, "--todo-id", cli.TODO_ID,
"--turn-instance-id", cli.TURN_ID, "--context-delivery", "on", "--delta-delivery", "off",
"--decision-output-root", str(captures), "--codex-context-root", str(captures),
)
assert code == 0 and captured["ok"], captured
selector = "/interaction_contract/cli_channel/settlement_plan/ordered_steps/1/vision_authoring"
reader = shlex.split(captured["recovery"]["command"])
code, page = cli._run_cli(registry, runtime, *reader[reader.index("quota"):], "--select", selector, cwd=project)
assert code == 0 and page["eof"], page
authoring = selected_context_values(page["content"])[selector]
assert authoring["path_delta"]["open_progress_outcomes"] == ["continue", "no_change", "replan"]
assert "wait" in authoring["path_delta"]["outcomes"]
assert "Progress wait: reentry_condition. Gap allows wait." in authoring["rule"]

dependency = "Continue when the next verification input is available."
vision = authoring["minimal_example"]
vision["path_delta"]["reentry_condition"] = dependency
vision_file = tmp_path / "vision.json"
vision_file.write_text(json.dumps(vision))
code, refreshed = _refresh(project, runtime, registry, *proof_args, "--agent-vision-json", str(vision_file))
assert code == 0, refreshed
assert refreshed["vision_checkpoint"]["satisfied"] is True
persisted = json.loads(Path(refreshed["json_path"]).read_text())
assert persisted["agent_vision"]["path_delta"]["reentry_condition"] == dependency
command = refreshed["settlement_owed"]["command"]
code, spent = _execute(command, project, runtime, registry)
assert code == 0 and spent["appended"] is True, spent
Expand Down
82 changes: 74 additions & 8 deletions tests/control_plane/test_refresh_checkpoint_recovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import os
from pathlib import Path
import shlex
import subprocess
import sys
from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -438,18 +439,42 @@ def test_checkpoint_only_recovery_bypasses_open_todo_completion_validation(
assert _spend_run_count(runtime) == 0


def test_invalid_material_path_decision_uses_checkpoint_supplement(tmp_path: Path) -> None:
project, runtime, registry = _write_fixture(tmp_path, provider="sqlite")
@pytest.mark.parametrize("provider", ["file", "sqlite"])
@pytest.mark.parametrize("delivery_outcome", ["outcome_progress", "outcome_gap"])
def test_material_closeout_distinguishes_progress_from_blocked_wait(
tmp_path: Path, provider: str, delivery_outcome: str,
) -> None:
project, runtime, registry = _write_fixture(tmp_path, provider=provider)
binding = (
"--agent-id", AGENT_ID,
"--todo-id", TODO_ID,
"--turn-instance-id", "turn-invalid-material-path",
)
rc, guard = _run_cli(
captures = tmp_path / "captures"
captures.mkdir(mode=0o700)
rc, captured = _run_cli(
registry, runtime, "quota", "should-run", "--codex-app",
"--goal-id", GOAL_ID, *binding, cwd=project,
"--goal-id", GOAL_ID, *binding, "--context-delivery", "on", "--delta-delivery", "off",
"--decision-output-root", str(captures), "--codex-context-root", str(captures),
cwd=project,
)
assert rc == 0 and guard["decision"] == "run", guard
assert rc == 0 and captured["ok"], captured
reader = shlex.split(captured["recovery"]["command"])
identity_pointer = "/heartbeat_receipt/settlement_identity"
authoring_pointer = "/interaction_contract/cli_channel/settlement_plan/ordered_steps/1/vision_authoring"
rc, page = _run_cli(
registry, runtime, *reader[reader.index("quota"):], "--select", identity_pointer,
"--select", authoring_pointer, cwd=project,
)
assert rc == 0 and page["eof"], page
assert len(page["content"].encode()) == page["total_bytes"]
selected = {row["pointer"]: row["value"] for row in json.loads(page["content"])["selections"]}
authoring = selected[authoring_pointer]
assert authoring["path_delta"]["open_progress_outcomes"] == ["continue", "no_change", "replan"]
assert "wait" in authoring["path_delta"]["outcomes"]
assert "Progress wait: reentry_condition. Gap allows wait." in authoring["rule"]

dependency = "Resume once the external condition changes."

def vision(outcome: str, name: str) -> Path:
path = tmp_path / name
Expand All @@ -466,21 +491,55 @@ def vision(outcome: str, name: str) -> Path:
"observed_reality": "The external condition has not changed yet.",
"retained": ["Preserve the verified route and evidence."],
"evidence_refs": ["evidence:material-path"],
"reentry_condition": dependency,
},
}), encoding="utf-8")
return path

def persisted_path_delta(receipt: dict) -> dict:
path = receipt.get("json_path")
if path is None:
readback = shlex.split(receipt["result_details"]["command"])
rc, detail = _run_cli(
registry, runtime, *readback[readback.index("quota"):], "--select", "/json_path", cwd=project,
)
assert rc == 0 and detail["eof"], detail
[entry] = json.loads(detail["content"])["selections"]
path = entry["value"]
return json.loads(Path(path).read_text())["agent_vision"]["path_delta"]

wait_packet = vision("wait", "wait.json")
delivery = (
"refresh-state", "--goal-id", GOAL_ID, *binding,
"--classification", "verified_wait",
"--delivery-batch-scale", "single_surface",
"--delivery-outcome", "outcome_progress",
"--delivery-boundary", "semantic_closeout",
"--delivery-outcome", delivery_outcome,
"--agent-vision-json", str(wait_packet),
"--no-global-sync", "--suppress-external-sinks",
)
if delivery_outcome == "outcome_gap":
delivery += (
"--progress-result-class", "blocked", "--progress-work-item-id", TODO_ID,
"--progress-blocker-id", "blocker:external-condition",
"--progress-evidence-id", "evidence:material-path", "--settle-turn", "--settlement-receipt",
)
rc, first = _run_cli(registry, runtime, *delivery, cwd=project)
assert rc == 0 and first["appended"] is True, first
assert first["settlement_identity"] == selected[identity_pointer]
assert _spend_run_count(runtime) == 0
if delivery_outcome == "outcome_gap":
assert first["vision_checkpoint"]["satisfied"] is True
assert first["settlement_progress"]["closeout_kind"] == "typed_blocked_writeback_no_spend"
path = persisted_path_delta(first)
assert path["outcome"] == "wait"
assert path["reentry_condition"] == dependency
rc, replay = _run_cli(registry, runtime, *delivery, cwd=project)
assert rc == 0 and replay["idempotent_replay"] and not replay["appended"], replay
assert replay["settlement_result"] == first["settlement_result"]
assert _spend_run_count(runtime) == 0
return

assert first["vision_checkpoint"]["decision"] == "missing_required"
assert first["vision_checkpoint"]["satisfied"] is False
assert first["vision_checkpoint"]["unqualified_components"] == [
Expand All @@ -494,14 +553,21 @@ def vision(outcome: str, name: str) -> Path:
assert rc == 0, context
corrected = list(delivery)
corrected[corrected.index(str(wait_packet))] = str(vision("no_change", "corrected.json"))
corrected += ["--checkpoint-read-context", context["read_context_id"]]
corrected += ["--checkpoint-read-context", context["read_context_id"], "--settle-turn", "--settlement-receipt"]
rc, repaired = _run_cli(registry, runtime, *corrected, cwd=project)
assert rc == 0 and repaired["appended"] is True, repaired
assert repaired["refresh_recovery"]["decision"] == "supplement_checkpoint"
assert repaired["vision_checkpoint"]["decision"] == "patched"
assert repaired["vision_checkpoint"]["satisfied"] is True
assert repaired["settlement_identity"] == first["settlement_identity"]
assert _spend_run_count(runtime) == 0
assert repaired["settlement_progress"]["state"] == "settled"
path = persisted_path_delta(repaired)
assert path["outcome"] == "no_change"
assert path["reentry_condition"] == dependency
rc, replay = _run_cli(registry, runtime, *corrected, cwd=project)
assert rc == 0 and replay["idempotent_replay"] and not replay["appended"], replay
assert replay["settlement_result"] == repaired["settlement_result"]
assert _spend_run_count(runtime) == 1


def test_invalid_supplement_leaves_original_writeback_intact(tmp_path: Path):
Expand Down
18 changes: 15 additions & 3 deletions tests/control_plane_ts/vision_checkpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,14 @@ test("semantic closeout retains the strict material vision checkpoint", () => {
});

test("material closeout leaves an invalid path decision recoverable", () => {
const allowedOutcomes = ["continue", "no_change", "replan"];
const authoring = visionAuthoringContract();
const pathAuthoring = authoring.path_delta as Record<string, unknown>;
assert.deepEqual(pathAuthoring.open_progress_outcomes, allowedOutcomes);
assert.deepEqual(pathAuthoring.outcomes, ["ask_human", "continue", "no_change", "replan", "stop", "wait"]);
assert.match(String(authoring.rule), /Progress wait: reentry_condition\. Gap allows wait\./);

const dependency = "Resume after the independent result is available.";
const packet = (outcome: string) => ({
state: "vision_patch_proposed",
vision_patch: {acceptance_summary: "Verified result; scoped work remains."},
Expand All @@ -566,15 +574,18 @@ test("material closeout leaves an invalid path decision recoverable", () => {
observed_reality: "Fresh evidence confirms the bounded next step.",
retained: ["Continue from the verified evidence."],
evidence_refs: ["evidence:verified-result"],
reentry_condition: dependency,
},
});
const prepared = (outcome: string) =>
buildVisionCheckpoint(prepareRequest({
agent_vision_packet: packet(outcome),
})).agent_vision;

for (const outcome of ["continue", "no_change", "replan"]) {
const result = buildVisionCheckpoint(finalizeRequest({agent_vision: prepared(outcome)}));
for (const outcome of allowedOutcomes) {
const vision = prepared(outcome) as {path_delta: Record<string, unknown>};
assert.equal(vision.path_delta.reentry_condition, dependency);
const result = buildVisionCheckpoint(finalizeRequest({agent_vision: vision}));
assert.equal(result.decision, "patched");
assert.equal(result.satisfied, true);
}
Expand All @@ -588,9 +599,10 @@ test("material closeout leaves an invalid path decision recoverable", () => {

const reportedGap = buildVisionCheckpoint(finalizeRequest({
delivery_outcome: "outcome_gap",
agent_vision: prepared("replan"),
agent_vision: prepared("wait"),
}));
assert.equal(reportedGap.decision, "patched");
assert.equal(reportedGap.satisfied, true);
});

test("missing checkpoint offers unchanged only with a persisted vision", () => {
Expand Down
Loading