Skip to content

Commit a120f29

Browse files
authored
Merge pull request #10079 from loopx-project/codex/retire-live-legacy-quota-projection-20261204
Keep legacy quota projection on saved captures
2 parents 8336f52 + 663a781 commit a120f29

6 files changed

Lines changed: 56 additions & 47 deletions

File tree

‎loopx/cli_commands/quota_native_context.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,12 @@ def authority_refusal(error: Exception) -> dict[str, Any]:
274274
transport = _capture_selection_transport_template(payload, args, capture_root=root)
275275
presentation = payload
276276
if args.initial_read and activation["progressive_enabled"] and not complete:
277-
from .quota_presentation import _project_quota_cli_payload
278-
from ..control_plane.quota.turn_envelope import project_captured_replan_cli_view
277+
from .quota_presentation import project_saved_quota_initial_view
279278

280279
# Keep the saved bytes intact. Stage unstaged readers against the
281280
# exact path just verified here, including a digest-bound copy.
282-
presentation = _project_quota_cli_payload(
283-
project_captured_replan_cli_view(payload, captured_decision_path=str(path)),
284-
argparse.Namespace(quota_command="should-run"), detail_sections, None,
281+
presentation = project_saved_quota_initial_view(
282+
payload, detail_sections, captured_decision_path=str(path),
285283
)
286284
if "host_poll_receipt" in payload:
287285
presentation["host_poll_receipt"] = payload["host_poll_receipt"]

‎loopx/cli_commands/quota_presentation.py‎

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ def compose_quota_work_contract(payload: dict[str, object], args: argparse.Names
1414
capture_directory: Path | None,
1515
record_capture: Callable[[dict[str, object], str], None] | None = None) -> dict[str, object]:
1616
"""Compose Complete Turn sources before capture and display."""
17-
if args.quota_command != "should-run" or not isinstance(payload.get("interaction_contract"), Mapping):
17+
if args.quota_command != "should-run":
18+
return payload
19+
if payload.get("ok") is not True and not isinstance(payload.get("interaction_contract"), Mapping):
1820
return payload
1921
from ..command_invocation import current_loopx_cli_argv
2022
from ..control_plane.effect_runtime import EffectRuntimeRemoteError, EffectRuntimeStartupError
@@ -173,24 +175,23 @@ def _project_quota_cli_payload(
173175
args: argparse.Namespace,
174176
detail_sections: frozenset[str],
175177
scheduler_context: object,
176-
*,
177-
captured_decision_path: str | None = None,
178178
) -> dict[str, object]:
179179
"""Project decided contracts; failed collection retains its diagnostic.
180180
181181
Optional presentation must not call a runtime that failed during collection.
182182
A rejected envelope likewise retains the already-decided facts (issue #3687).
183183
"""
184184
from ..control_plane.effect_program import reject_retired_quota_format
185+
186+
reject_retired_quota_format(payload)
187+
if payload.get("schema_version") == COMPLETE_TURN_DECISION_VERSION or args.quota_command == "should-run":
188+
return payload
189+
185190
from ..control_plane.quota.cli_projection import (
186191
compact_quota_monitor_poll_cli_payload,
187192
compact_quota_plan_cli_payload,
188-
compact_quota_should_run_cli_payload,
189193
)
190194

191-
reject_retired_quota_format(payload)
192-
if payload.get("schema_version") == COMPLETE_TURN_DECISION_VERSION:
193-
return payload
194195
if payload.get("ok") is False and not isinstance(payload.get("interaction_contract"), Mapping):
195196
if (getattr(args, "quota_command", None) == "monitor-poll"
196197
and isinstance(payload.get("before"), Mapping)):
@@ -203,22 +204,32 @@ def _project_quota_cli_payload(
203204
# its unavailable runtime. Decided refusals still need signed views.
204205
# Keep the decided diagnostic, including its original recovery/receipt.
205206
return payload
206-
if args.quota_command == "should-run":
207-
if captured_decision_path is not None and "vision" not in detail_sections:
208-
from ..control_plane.quota.turn_envelope import project_captured_replan_cli_view
209-
210-
payload = project_captured_replan_cli_view(payload, captured_decision_path=captured_decision_path)
211-
return compact_quota_should_run_cli_payload(
212-
payload,
213-
include_todo_summary_detail="agent-todos" in detail_sections,
214-
include_user_todo_summary_detail="user-todos" in detail_sections,
215-
include_goal_boundary_detail="goal-boundary" in detail_sections,
216-
include_vision_detail="vision" in detail_sections,
217-
)
218207
if args.quota_command in {"status", "plan"}:
219208
return compact_quota_plan_cli_payload(payload, detail_sections=detail_sections)
220209
if args.quota_command == "monitor-poll":
221210
return compact_quota_monitor_poll_cli_payload(
222211
payload, include_decision_detail="decisions" in detail_sections,
223212
)
224213
return payload
214+
215+
216+
def project_saved_quota_initial_view(
217+
payload: dict[str, object],
218+
detail_sections: frozenset[str],
219+
*,
220+
captured_decision_path: str,
221+
) -> dict[str, object]:
222+
"""Stage the initial view of a verified historical quota capture."""
223+
from ..control_plane.effect_program import reject_retired_quota_format
224+
from ..control_plane.quota.cli_projection import compact_quota_should_run_cli_payload
225+
from ..control_plane.quota.turn_envelope import project_captured_replan_cli_view
226+
227+
staged = project_captured_replan_cli_view(payload, captured_decision_path=captured_decision_path)
228+
reject_retired_quota_format(staged)
229+
return compact_quota_should_run_cli_payload(
230+
staged,
231+
include_todo_summary_detail="agent-todos" in detail_sections,
232+
include_user_todo_summary_detail="user-todos" in detail_sections,
233+
include_goal_boundary_detail="goal-boundary" in detail_sections,
234+
include_vision_detail="vision" in detail_sections,
235+
)

‎loopx/cli_commands/quota_result_delivery.py‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -472,16 +472,6 @@ def _publish_quota_result(
472472
}
473473
if additions:
474474
payload = attach_complete_turn_context(payload, additions)
475-
else:
476-
attach_reward_memory_recall_after_should_run(
477-
payload,
478-
quota_command=args.quota_command,
479-
heartbeat_turn_id=heartbeat_turn_id,
480-
registry_path=registry_path,
481-
goal_id=args.goal_id,
482-
agent_id=args.agent_id,
483-
decision=pre_contract_decision,
484-
)
485475
captured_digest = capture_decision(
486476
capture_directory,
487477
payload,
@@ -551,11 +541,6 @@ def _publish_quota_result(
551541
args,
552542
detail_sections,
553543
scheduler_context,
554-
captured_decision_path=(
555-
str(capture_directory / "decision.json")
556-
if capture_directory is not None
557-
else None
558-
),
559544
)
560545
succeeded = bool(payload.get("ok"))
561546
# Handoff releases the immutable original before any presentation. Native

‎tests/control_plane/test_context_delivery_cli.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ def test_native_projection_never_layers_host_projection(tmp_path, monkeypatch, n
756756
"heartbeat_receipt": {"turn_instance_id": "original-turn", "status": "committed"}}
757757
monkeypatch.setattr(quota_result_delivery, "handoff_decision",
758758
lambda *args, capture_sha256: ({"scope": "host-request"}, capture_sha256))
759+
monkeypatch.setattr(quota_result_delivery, "compose_quota_work_contract", lambda payload, *args, **kwargs: payload)
759760
monkeypatch.setattr(quota_result_delivery, "_project_quota_cli_payload", lambda payload, *args, **kwargs: payload)
760761

761762
def competing(*args, **kwargs):

‎tests/control_plane/test_context_delivery_retention.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ def flaky_rmtree(path: Path) -> None:
497497
def test_callsite_integration_and_dry_run_preservation(
498498
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
499499
) -> None:
500+
from loopx.cli_commands import quota_result_delivery
501+
502+
monkeypatch.setattr(quota_result_delivery, "compose_quota_work_contract", lambda payload, *args, **kwargs: payload)
500503
monkeypatch.setenv("LOOPX_CONTEXT_DELIVERY_MIN_AGE_SECONDS", "60")
501504
monkeypatch.setenv("LOOPX_CONTEXT_DELIVERY_KEEP_RECENT", "1")
502505
monkeypatch.setenv("LOOPX_CONTEXT_DELIVERY_SWEEP_INTERVAL_SECONDS", "0")

‎tests/control_plane/test_quota_decision_capture.py‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,11 @@ def test_real_guard_saved_before_envelope_and_read_without_reexecution(tmp_path,
478478

479479

480480
def test_full_display_is_unchanged_by_capture_location():
481-
from loopx.cli_commands.quota import _project_quota_cli_payload
481+
from loopx.cli_commands.quota_presentation import project_saved_quota_initial_view
482482
from tests.test_turn_envelope import _full_decision
483-
args = argparse.Namespace(turn_envelope=False, quota_command='should-run')
484483
source = _full_decision()
485-
baseline = _project_quota_cli_payload(source, args, frozenset(), None)
486-
captured = _project_quota_cli_payload(source, args, frozenset(), None,
487-
captured_decision_path='/tmp/observation/decision.json')
484+
baseline = project_saved_quota_initial_view(source, frozenset(), captured_decision_path='/first/decision.json')
485+
captured = project_saved_quota_initial_view(source, frozenset(), captured_decision_path='/other/decision.json')
488486
assert captured == baseline
489487

490488

@@ -891,11 +889,15 @@ def test_composed_guard_refusal_keeps_turn_envelope_markdown():
891889

892890

893891
@pytest.mark.parametrize('provider', ['file', 'sqlite'])
894-
@pytest.mark.parametrize(('delivery', 'output_format'), [('off', 'json'), ('off', 'markdown'), ('on', 'json')])
892+
@pytest.mark.parametrize(('delivery', 'output_format', 'fault_kind'), [
893+
('off', 'json', 'unavailable'), ('off', 'markdown', 'unavailable'), ('on', 'json', 'unavailable'),
894+
('off', 'json', 'missing_contract'),
895+
])
895896
def test_failed_complete_composition_captures_only_recovery_evidence(
896-
tmp_path, monkeypatch, capsys, provider, delivery, output_format,
897+
tmp_path, monkeypatch, capsys, provider, delivery, output_format, fault_kind,
897898
):
898899
from loopx.cli import main
900+
from loopx.cli_commands import quota_result_delivery
899901
from loopx.control_plane.effect_runtime import EffectRuntimeStartupError
900902
from loopx.control_plane.quota import turn_envelope
901903
from loopx.control_plane.turn_driver import codex_context
@@ -922,14 +924,23 @@ def test_failed_complete_composition_captures_only_recovery_evidence(
922924
binding = ['--goal-id', GOAL_ID, '--agent-id', AGENT_ID, '--turn-instance-id', TURN_ID]
923925
captured = []
924926
run_typed = turn_envelope._turn_envelope_result
927+
compose = quota_result_delivery.compose_quota_work_contract
928+
929+
def compose_without_contract(payload, *args, **kwargs):
930+
unsigned = {**payload}
931+
del unsigned['interaction_contract']
932+
return compose(unsigned, *args, **kwargs)
925933

926934
def interrupt_compose(action, **kwargs):
927935
if action == 'compose_complete':
928936
captured.append(kwargs['payload'])
929-
raise EffectRuntimeStartupError('fixture composition unavailable', diagnostic_code='fixture_unavailable')
937+
if fault_kind == 'unavailable':
938+
raise EffectRuntimeStartupError('fixture composition unavailable', diagnostic_code='fixture_unavailable')
930939
return run_typed(action, **kwargs)
931940

932941
with monkeypatch.context() as fault:
942+
if fault_kind == 'missing_contract':
943+
fault.setattr(quota_result_delivery, 'compose_quota_work_contract', compose_without_contract)
933944
fault.setattr(turn_envelope, '_turn_envelope_result', interrupt_compose)
934945
code = main(['--registry', str(registry), '--runtime-root', str(runtime), '--format', output_format,
935946
'quota', 'should-run', *binding, '--todo-id', TODO_ID, *delivery_args, '--decision-output-dir', str(capture)])

0 commit comments

Comments
 (0)