From 5eab03a8103b4f1d2b44553da25064b3a07abccc Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:40:16 +0800 Subject: [PATCH 1/3] fix(cli): retain the qualified public quota default Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/cli_commands/quota_presentation.py | 25 +++++++++++- loopx/cli_commands/quota_registration.py | 4 +- .../testing/cli_output_budget.py | 14 +++---- tests/control_plane/test_cli_output_budget.py | 39 ++++++++++++++++--- .../control_plane/test_refresh_settle_turn.py | 3 +- tests/test_runtime_snapshot_publication.py | 13 +------ 6 files changed, 71 insertions(+), 27 deletions(-) diff --git a/loopx/cli_commands/quota_presentation.py b/loopx/cli_commands/quota_presentation.py index c4ff6a54dc..966a3145d6 100644 --- a/loopx/cli_commands/quota_presentation.py +++ b/loopx/cli_commands/quota_presentation.py @@ -13,9 +13,19 @@ def compose_quota_work_contract(payload: dict[str, object], args: argparse.Names scheduler_context: Mapping[str, object] | SchedulerExecutionContextResolution | None, capture_directory: Path | None, record_capture: Callable[[dict[str, object], str], None] | None = None) -> dict[str, object]: - """Compose every decided should-run source once before capture and display.""" + """Compose Complete Turn sources before capture and display.""" if args.quota_command != "should-run" or not isinstance(payload.get("interaction_contract"), Mapping): return payload + if ( + args.format == "json" + and scheduler_context is None + and not any(getattr(args, option, None) for option in ( + "complete_turn", "turn_envelope", "codex_context_dir", "codex_context_root", + "prepared_capture_reference", "defer_context_presentation", "decision_handoff_socket", + )) + ): + # Undeclared JSON callers use the currently qualified public quota packet. + return payload from ..control_plane.effect_runtime import EffectRuntimeRemoteError, EffectRuntimeStartupError from ..control_plane.quota.error_codes import QuotaDecisionTransportError from ..control_plane.quota.turn_envelope import compose_turn_decision @@ -121,6 +131,7 @@ def _project_quota_cli_payload( from ..control_plane.quota.cli_projection import ( compact_quota_monitor_poll_cli_payload, compact_quota_plan_cli_payload, + compact_quota_should_run_cli_payload, ) reject_retired_quota_format(payload) @@ -138,6 +149,18 @@ def _project_quota_cli_payload( # its unavailable runtime. Decided refusals still need signed views. # Keep the decided diagnostic, including its original recovery/receipt. return payload + if args.quota_command == "should-run": + if captured_decision_path is not None and "vision" not in detail_sections: + from ..control_plane.quota.turn_envelope import project_captured_replan_cli_view + + payload = project_captured_replan_cli_view(payload, captured_decision_path=captured_decision_path) + return compact_quota_should_run_cli_payload( + payload, + include_todo_summary_detail="agent-todos" in detail_sections, + include_user_todo_summary_detail="user-todos" in detail_sections, + include_goal_boundary_detail="goal-boundary" in detail_sections, + include_vision_detail="vision" in detail_sections, + ) if args.quota_command in {"status", "plan"}: return compact_quota_plan_cli_payload(payload, detail_sections=detail_sections) if args.quota_command == "monitor-poll": diff --git a/loopx/cli_commands/quota_registration.py b/loopx/cli_commands/quota_registration.py index d1fec55ce8..40c23ef81c 100644 --- a/loopx/cli_commands/quota_registration.py +++ b/loopx/cli_commands/quota_registration.py @@ -221,12 +221,12 @@ def register_quota_command( "--turn-envelope", action="store_true", help=( - "Compatibility alias: quota should-run already returns the complete v1 work contract. " + "Select the complete v1 work contract for quota should-run. " "Context and Delta delivery remain independent." ), ) turn_view.add_argument("--complete-turn", action="store_true", - help="Compatibility alias: quota should-run already returns the complete v1 work contract " + help="Select the complete v1 work contract for JSON quota should-run " "and its shared exact-Turn settlement. Context and Delta delivery remain independent.") capture_group = quota_parser.add_mutually_exclusive_group() capture_group.add_argument( diff --git a/loopx/control_plane/testing/cli_output_budget.py b/loopx/control_plane/testing/cli_output_budget.py index c32c1228b2..8f2d6f6bc6 100644 --- a/loopx/control_plane/testing/cli_output_budget.py +++ b/loopx/control_plane/testing/cli_output_budget.py @@ -132,7 +132,7 @@ class CliOutputCommandClassification: ), CliOutputBudgetSpec( surface_id="quota_should_run", - command="quota should-run --context-delivery off", + command="quota should-run --turn-envelope --context-delivery off", owner="quota guard", consumer_action="inspect the complete inline quota policy", qualification_policy="absolute_hot_path", @@ -418,7 +418,7 @@ class CliOutputCommandClassification: CliOutputModeVariantSpec( variant_id="quota_should_run_scheduler_detail", parent_surface_id="quota_should_run", - command="quota should-run --context-delivery off --include-detail scheduler", + command="quota should-run --turn-envelope --context-delivery off --include-detail scheduler", output_formats=("json", "markdown"), semantic_json_keys=("schema_version", "contract_binding", "interaction_contract", "scheduler_hint", "selected_todo"), markdown_anchor="# LoopX Turn Envelope", @@ -429,7 +429,7 @@ class CliOutputCommandClassification: CliOutputModeVariantSpec( variant_id="quota_should_run_todo_summary_detail", parent_surface_id="quota_should_run", - command="quota should-run --context-delivery off --include-detail agent-todos", + command="quota should-run --turn-envelope --context-delivery off --include-detail agent-todos", output_formats=("json", "markdown"), semantic_json_keys=("schema_version", "contract_binding", "interaction_contract", "scheduler_hint", "selected_todo"), markdown_anchor="# LoopX Turn Envelope", @@ -440,7 +440,7 @@ class CliOutputCommandClassification: CliOutputModeVariantSpec( variant_id="quota_should_run_user_todo_summary_detail", parent_surface_id="quota_should_run", - command="quota should-run --context-delivery off --include-detail user-todos", + command="quota should-run --turn-envelope --context-delivery off --include-detail user-todos", output_formats=("json", "markdown"), semantic_json_keys=("schema_version", "contract_binding", "interaction_contract", "scheduler_hint", "selected_todo"), markdown_anchor="# LoopX Turn Envelope", @@ -451,7 +451,7 @@ class CliOutputCommandClassification: CliOutputModeVariantSpec( variant_id="quota_should_run_goal_boundary_detail", parent_surface_id="quota_should_run", - command="quota should-run --context-delivery off --include-detail goal-boundary", + command="quota should-run --turn-envelope --context-delivery off --include-detail goal-boundary", output_formats=("json", "markdown"), semantic_json_keys=("schema_version", "contract_binding", "interaction_contract", "scheduler_hint", "selected_todo"), markdown_anchor="# LoopX Turn Envelope", @@ -462,7 +462,7 @@ class CliOutputCommandClassification: CliOutputModeVariantSpec( variant_id="quota_should_run_vision_detail", parent_surface_id="quota_should_run", - command="quota should-run --context-delivery off --include-detail vision", + command="quota should-run --turn-envelope --context-delivery off --include-detail vision", output_formats=("json", "markdown"), semantic_json_keys=("schema_version", "contract_binding", "interaction_contract", "scheduler_hint", "selected_todo"), markdown_anchor="# LoopX Turn Envelope", @@ -475,7 +475,7 @@ class CliOutputCommandClassification: CliOutputModeVariantSpec( variant_id="quota_should_run_all_detail", parent_surface_id="quota_should_run", - command="quota should-run --context-delivery off --include-detail all", + command="quota should-run --turn-envelope --context-delivery off --include-detail all", output_formats=("json", "markdown"), semantic_json_keys=("schema_version", "contract_binding", "interaction_contract", "scheduler_hint", "selected_todo"), markdown_anchor="# LoopX Turn Envelope", diff --git a/tests/control_plane/test_cli_output_budget.py b/tests/control_plane/test_cli_output_budget.py index 4250010db7..2d0e3341ac 100644 --- a/tests/control_plane/test_cli_output_budget.py +++ b/tests/control_plane/test_cli_output_budget.py @@ -7,7 +7,7 @@ import shlex import shutil import tempfile -from dataclasses import dataclass +from dataclasses import dataclass, replace from datetime import datetime, timezone from pathlib import Path @@ -365,9 +365,10 @@ def _surface_commands( state_file: Path, output_format: str, context_delivery: str | None = "off", + complete_quota: bool = True, ) -> dict[str, list[str]]: - # These ceilings characterize the complete inline policy, not its shorter - # file-navigation descriptor. Qualify default progressive recovery below. + # Keep the Complete Turn budget workload on its declared carrier. + quota_view = ["--turn-envelope"] if complete_quota else [] delivery = ["--context-delivery", context_delivery] if context_delivery else [] common = [ "--registry", @@ -417,7 +418,7 @@ def _surface_commands( GOAL_ID, "--agent-id", AGENT_IDS[0], - ] + delivery, + ] + quota_view + delivery, "loopx_turn_plan": common + [ "turn", @@ -612,7 +613,7 @@ def _mode_variant_commands( "quota_should_run_goal_boundary_detail": quota + ["--include-detail", "goal-boundary"], "quota_should_run_vision_detail": quota + ["--include-detail", "vision"], "quota_should_run_all_detail": quota + ["--include-detail", "all"], - "quota_should_run_turn_envelope": quota + ["--turn-envelope"], + "quota_should_run_turn_envelope": quota, "loopx_turn_plan_transaction_detail": common + [ "turn", @@ -1045,6 +1046,34 @@ def test_quota_should_run_no_format_uses_machine_contract_json( assert not markdown_text.lstrip().startswith("{") +@pytest.mark.parametrize("scenario", SCENARIOS, ids=lambda scenario: scenario.name) +def test_public_quota_packet_keeps_original_control_keys_and_output_budget( + tmp_path: Path, scenario: Scenario, +) -> None: + with _stable_budget_fixture_root(tmp_path / scenario.name) as stable_root: + project, runtime, registry_path, state_file = _write_fixture(stable_root, scenario) + import_fixture_authority(registry_path, GOAL_ID) + command = _surface_commands( + project=project, runtime=runtime, registry_path=registry_path, state_file=state_file, + output_format="json", complete_quota=False, + )["quota_should_run"] + exit_code, output = _invoke_cli(command) + assert exit_code == 0, output + measurement = _measure_context_output(output, output_format="json") + + packet = _measured_payload(measurement) + assert packet.get("schema_version") is None + assert packet["goal_id"] == GOAL_ID + assert packet["interaction_contract"]["schema_version"] == "loopx_interaction_contract_v0" + spec = replace( + CLI_OUTPUT_BUDGET_BY_ID["quota_should_run"], output_contract_version=None, + semantic_json_keys=("interaction_contract", "scheduler_hint", "selected_todo"), + ) + assert_cli_output_baseline( + spec, scenario=scenario.name, output_format="json", text=output, measurement=measurement, + ) + + def test_quota_cli_keeps_full_agent_todo_diagnostics_on_explicit_cold_path( tmp_path: Path, ) -> None: diff --git a/tests/control_plane/test_refresh_settle_turn.py b/tests/control_plane/test_refresh_settle_turn.py index e98a0224fb..af1896b2db 100644 --- a/tests/control_plane/test_refresh_settle_turn.py +++ b/tests/control_plane/test_refresh_settle_turn.py @@ -440,10 +440,11 @@ def unavailable(*args, **kwargs): assert original_packet.get("schema_version") is None assert failed["heartbeat_receipt"]["settlement_identity"] == original_packet["heartbeat_receipt"]["settlement_identity"] assert _heartbeat_receipt_count(runtime, TURN_ID) == 1 and _spend_run_count(runtime) == 0 + page_bytes = min(8000, len(original) // 2) recovered_bytes, page_count = b"", 0 while True: rc, page = _run_cli(registry, runtime, "quota", "context-read", "--capture-file", str(saved), - "--capture-sha256", hashlib.sha256(original).hexdigest(), "--page-bytes", "8000", + "--capture-sha256", hashlib.sha256(original).hexdigest(), "--page-bytes", str(page_bytes), "--max-page-output-bytes", "12000", "--offset", str(len(recovered_bytes)), cwd=project) assert rc == 0 and page["ok"], page assert page["offset"] == len(recovered_bytes) diff --git a/tests/test_runtime_snapshot_publication.py b/tests/test_runtime_snapshot_publication.py index 5245c1d0c4..b4279a5063 100644 --- a/tests/test_runtime_snapshot_publication.py +++ b/tests/test_runtime_snapshot_publication.py @@ -365,15 +365,6 @@ def observe(source: Path) -> dict: def test_release_probe_observes_real_default_without_model_or_active_goal(): from scripts.qualify_runtime_artifact import observe_default_contract - # The probe observes the real writer rather than inheriting the intended - # distribution profile. Main currently exercises C1, which remains outside - # the supported public scope until its original qualification is complete. + # Check the actual CLI output against the supported release contract. observed = observe_default_contract(ROOT) - assert observed == { - "surface": "complete_turn", - "schema_version": "loopx_turn_envelope_v1", - "interaction_schema_version": "loopx_interaction_contract_v0", - } - assert observed != PUBLIC_DEFAULT_CONTRACT - with pytest.raises(ValueError, match="unqualified for public adoption"): - validate_default_contract(observed) + assert validate_default_contract(observed) == PUBLIC_DEFAULT_CONTRACT From ecb303e952a8736d538bd95fa94c5ea5af5da392 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Thu, 19 Nov 2026 23:45:12 +0800 Subject: [PATCH 2/3] Keep successor replan settlement plans optional Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> (cherry picked from commit 3656ae36a0bf83e60776381aa7e62ffac58c7c4b) Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/control_plane/work_items/interaction_contract.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopx/control_plane/work_items/interaction_contract.py b/loopx/control_plane/work_items/interaction_contract.py index 561f6c1208..74ec33dba7 100644 --- a/loopx/control_plane/work_items/interaction_contract.py +++ b/loopx/control_plane/work_items/interaction_contract.py @@ -762,7 +762,7 @@ def _successor_replan_required_cli_actions( goal_id: str, lifecycle_actor_args: str, typed_quota_guard: str, - settlement_plan: Mapping[str, object], + settlement_plan: Mapping[str, object] | None, scheduler_args: str, settlement_args: str, scoped_cli_args: str, From 35c9b103540bcd5a26e0be6bb1756a57e67ffa2b Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:01:15 +0800 Subject: [PATCH 3/3] Remove the unused pytest import from Steward monitor tests Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> (cherry picked from commit be17fad48c4d3cae4043fe158ecf75f75f49862c) Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- tests/test_steward_generic_monitor_todo.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_steward_generic_monitor_todo.py b/tests/test_steward_generic_monitor_todo.py index c5dea880c1..f3e57adc83 100644 --- a/tests/test_steward_generic_monitor_todo.py +++ b/tests/test_steward_generic_monitor_todo.py @@ -4,7 +4,6 @@ from datetime import datetime, timedelta, timezone import json from pathlib import Path -import pytest from loopx.capabilities.native_chat.steward_monitor import ( StewardMonitor,