Skip to content

Commit 33388bd

Browse files
authored
Merge pull request #10076 from loopx-project/codex/quota-publication-context-activation-20261204
Remove unused early recall from quota publication
2 parents c7095d2 + dbf01f7 commit 33388bd

5 files changed

Lines changed: 23 additions & 55 deletions

File tree

‎loopx/cli_commands/quota.py‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -257,25 +257,6 @@ def _prepare_quota_command_execution(
257257
return goal_ref, turn_start_hook_dispatch, context
258258

259259

260-
def _prepare_quota_result_context(
261-
payload: dict[str, object],
262-
args: argparse.Namespace,
263-
*,
264-
registry_path: Path,
265-
heartbeat_turn_id: str | None,
266-
attach_recall: bool = True,
267-
) -> tuple[dict[str, object], dict[str, Any]]:
268-
from .quota_result_delivery import prepare_quota_result_context
269-
270-
return prepare_quota_result_context(
271-
payload,
272-
args,
273-
registry_path=registry_path,
274-
heartbeat_turn_id=heartbeat_turn_id,
275-
attach_recall=attach_recall,
276-
)
277-
278-
279260
def _emit_quota_result(
280261
payload: dict[str, object],
281262
args: argparse.Namespace,

‎loopx/cli_commands/quota_result_delivery.py‎

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -145,32 +145,17 @@ def _emit_bounded_settlement(
145145
return 0 if payload.get("ok") is True else 1
146146

147147

148-
def prepare_quota_result_context(
149-
payload: dict[str, object],
148+
def _quota_result_context_activation(
149+
payload: Mapping[str, object],
150150
args: argparse.Namespace,
151-
*,
152-
registry_path: Path,
153-
heartbeat_turn_id: str | None,
154-
attach_recall: bool = True,
155-
) -> tuple[dict[str, object], dict[str, Any]]:
156-
"""Resolve presentation and optionally attach recall before composition."""
151+
) -> dict[str, Any]:
157152
try:
158-
activation = native_context_activation(args)
153+
return native_context_activation(args)
159154
except QuotaCommandValidationError:
160155
if payload.get("ok") is True:
161156
raise
162157
# Keep the original diagnostic on a refused guard.
163-
activation = {"progressive_enabled": False, "enabled": False}
164-
if attach_recall and args.quota_command == "should-run":
165-
attach_reward_memory_recall_after_should_run(
166-
payload,
167-
quota_command=args.quota_command,
168-
heartbeat_turn_id=heartbeat_turn_id,
169-
registry_path=registry_path,
170-
goal_id=args.goal_id,
171-
agent_id=args.agent_id,
172-
)
173-
return payload, activation
158+
return {"progressive_enabled": False, "enabled": False}
174159

175160

176161
def _observe_live_quota_result(
@@ -320,13 +305,7 @@ def _publish_quota_result(
320305
)
321306
activation = None
322307
if not budgeted_spend:
323-
payload, activation = quota_module._prepare_quota_result_context(
324-
payload,
325-
args,
326-
registry_path=registry_path,
327-
heartbeat_turn_id=heartbeat_turn_id,
328-
attach_recall=False,
329-
)
308+
activation = _quota_result_context_activation(payload, args)
330309
receipt = payload.get("heartbeat_receipt")
331310
if (
332311
args.quota_command == "should-run"

‎tests/control_plane/test_context_delivery_cli.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,10 @@ def native(payload, **kwargs):
773773
def unavailable_directory(**kwargs):
774774
raise OSError("native directory unavailable")
775775

776-
def unavailable_reference(*args, **kwargs):
776+
reference_attempts = []
777+
778+
def unavailable_reference(path, _digest, **kwargs):
779+
reference_attempts.append(path)
777780
raise OSError("synthetic reader metadata unavailable")
778781

779782
monkeypatch.setattr(quota_result_delivery, "project_captured_context", competing)
@@ -783,16 +786,23 @@ def unavailable_reference(*args, **kwargs):
783786
elif native_failure == "reader_reference":
784787
monkeypatch.setattr(quota_context_reader, "write_context_read_reference", unavailable_reference)
785788
printed = []
789+
transport_failure = native_failure in {"projection", "directory"}
786790
assert quota._emit_quota_result(original, args, context=None, registry_path=tmp_path / "absent.json",
787791
heartbeat_turn_id=None, usage_quota_started=0, capture_directory=tmp_path,
788-
detail_sections=frozenset(), print_payload=lambda value, *args: printed.append(value)) == (1 if native_failure else 0)
789-
if native_failure:
792+
detail_sections=frozenset(), print_payload=lambda value, *args: printed.append(value)) == int(transport_failure)
793+
if transport_failure:
790794
assert len(printed) == 1 and printed[0]["ok"] is False
791795
assert printed[0]["error_code"] == "quota_decision_transport_failed"
792796
assert printed[0]["heartbeat_receipt"] == original["heartbeat_receipt"]
793797
saved = tmp_path / "decision.json"
794798
assert printed[0]["captured_decision"]["path"] == str(saved)
795799
assert printed[0]["captured_decision"]["sha256"] == sha256(saved.read_bytes()).hexdigest()
800+
elif native_failure == "reader_reference":
801+
assert reference_attempts == [tmp_path / "delivery.json"]
802+
assert len(printed) == 1 and "reference_file" not in printed[0]
803+
page = quota_context_reader.read_context_capture(_native_reader_args(printed[0]["command"]))
804+
assert page["ok"] and page["eof"]
805+
assert json.loads(page["content"]) == {"native_projection": original}
796806
else:
797807
assert len(printed) == 1 and "content" not in printed[0]
798808
reference = read_context_read_reference(printed[0]["reference_file"])[1]

‎tests/control_plane/test_context_delivery_retention.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,6 @@ def test_callsite_integration_and_dry_run_preservation(
575575
fake_quota = SimpleNamespace(
576576
observe_quota_result=lambda *a, **k: None,
577577
_effective_spend_turn_instance_id=lambda *_a, **_k: "turn-live",
578-
_prepare_quota_result_context=lambda p, *a, **k: (
579-
p,
580-
{"enabled": False, "progressive_enabled": False},
581-
),
582578
_export=lambda _name: (lambda *a, **k: None),
583579
)
584580
ctx_c = cast(
@@ -597,6 +593,7 @@ def test_callsite_integration_and_dry_run_preservation(
597593
format="json",
598594
goal_id="g",
599595
agent_id="a",
596+
context_delivery="off",
600597
dry_run=True,
601598
scheduler_observation=False,
602599
),
@@ -622,6 +619,7 @@ def test_callsite_integration_and_dry_run_preservation(
622619
format="json",
623620
goal_id="g",
624621
agent_id="a",
622+
context_delivery="off",
625623
dry_run=False,
626624
scheduler_observation=False,
627625
),

‎tests/control_plane/test_selection_replan_reentry.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def test_inline_replan_failure_reports_the_actual_receipt(
626626
tmp_path, monkeypatch, capsys, provider, failure_stage, limit,
627627
):
628628
from loopx.cli import main
629-
from loopx.cli_commands import quota
629+
from loopx.cli_commands import quota, quota_result_delivery
630630
from loopx.control_plane.turn_driver import codex_context, decision_capture
631631
from tests.control_plane.canonical_authority_fixture import isolate_sqlite_runtime
632632

@@ -737,7 +737,7 @@ def refuse_short_reference(*args, reference_file=None, **kwargs):
737737
elif failure_stage == "registration":
738738
patch.setattr(codex_context, "record_native_claim_source", fail_registration)
739739
elif failure_stage in {"capture", "long_no_capture", "long_diagnostic_reference_io"}:
740-
patch.setattr(quota, "_prepare_quota_result_context", fail_capture)
740+
patch.setattr(quota_result_delivery, "_quota_result_context_activation", fail_capture)
741741
else:
742742
patch.setattr(quota, "build_live_quota_should_run_decision", fail_collection)
743743
code = main([*cli_prefix, "--registry", str(registry), "--runtime-root", str(runtime), "--format", "json",

0 commit comments

Comments
 (0)