diff --git a/loopx/control_plane/quota/effect_program.py b/loopx/control_plane/quota/effect_program.py index 741ede25e3..9fef088c13 100644 --- a/loopx/control_plane/quota/effect_program.py +++ b/loopx/control_plane/quota/effect_program.py @@ -32,7 +32,7 @@ ) from ..goals.goal_ref_validation import exact_goal_ref from ..work_items.delivery_batch_scale import DELIVERY_BATCH_SCALE_INPUT_CHOICES -from ..turn_driver.native_context_profile import NATIVE_CONTEXT_PAGE_OUTPUT_BYTES +from ..turn_driver.native_context_profile import NATIVE_CONTEXT_PAGE_OUTPUT_BYTES, private_capture_supported _PLATFORM_IS_POSIX = os.name == "posix" @@ -310,10 +310,6 @@ def writeback_command(boundary: str) -> str: writeback_command(" --delivery-boundary semantic_closeout") + " --agent-vision-json " ) - # Imported here so the settlement-plan kernel stays loadable on its own: the - # capture-binding owner is orchestration a command template never needs. - from ..turn_driver.decision_capture import private_capture_supported - max_output_arg = ( f" --max-page-output-bytes {NATIVE_CONTEXT_PAGE_OUTPUT_BYTES}" if private_capture_supported() diff --git a/loopx/control_plane/turn_driver/decision_capture.py b/loopx/control_plane/turn_driver/decision_capture.py index 046e4c42bf..c335eec925 100644 --- a/loopx/control_plane/turn_driver/decision_capture.py +++ b/loopx/control_plane/turn_driver/decision_capture.py @@ -23,14 +23,10 @@ NATIVE_CONTEXT_HISTORY_TOKENS as NATIVE_CONTEXT_HISTORY_TOKENS, NATIVE_CONTEXT_OUTPUT_ENV as NATIVE_CONTEXT_OUTPUT_ENV, native_context_page_budget as native_context_page_budget, + private_capture_supported as private_capture_supported, ) -def private_capture_supported() -> bool: - """Whether this host has the POSIX identity needed for private capture IO.""" - return os.name == "posix" and callable(getattr(os, "getuid", None)) - - def private_capture_uid() -> int: """Fail closed until this IO boundary has a qualified non-POSIX ACL reader. diff --git a/loopx/control_plane/turn_driver/native_context_profile.py b/loopx/control_plane/turn_driver/native_context_profile.py index 9a61c20511..0a1ad90890 100644 --- a/loopx/control_plane/turn_driver/native_context_profile.py +++ b/loopx/control_plane/turn_driver/native_context_profile.py @@ -1,6 +1,8 @@ """Native context transport defaults, independent of capture and quota IO.""" from __future__ import annotations +import os + # Use the configured output profile for every native caller, including App # shells that do not inherit the generated environment override. Smaller @@ -19,5 +21,10 @@ NATIVE_CONTEXT_OUTPUT_ENV = "LOOPX_CONTEXT_PAGE_OUTPUT_BYTES" +def private_capture_supported() -> bool: + """Whether this host has the POSIX identity needed for private capture IO.""" + return os.name == "posix" and callable(getattr(os, "getuid", None)) + + def native_context_page_budget() -> tuple[int, int]: return NATIVE_CONTEXT_PAGE_BYTES, NATIVE_CONTEXT_PAGE_OUTPUT_BYTES diff --git a/tests/control_plane/test_quota_settlement.py b/tests/control_plane/test_quota_settlement.py index 3053e19960..0b98372a66 100644 --- a/tests/control_plane/test_quota_settlement.py +++ b/tests/control_plane/test_quota_settlement.py @@ -48,6 +48,7 @@ scheduler_execution_context_for_runtime_profile, ) from loopx.control_plane.turn_driver import decision_capture as decision_capture_module +from loopx.control_plane.turn_driver import native_context_profile from loopx.control_plane.work_items.interaction_contract import ( build_interaction_contract, interaction_next_cli_actions, @@ -890,9 +891,10 @@ def quote(value: object) -> str: (SimpleNamespace(name="posix", getuid=None), False), (SimpleNamespace(name="posix", getuid=lambda: 0), True), ]) -def test_private_capture_support_matches_uid_boundary( +def test_private_capture_support_matches_uid_and_settlement_command( platform: SimpleNamespace, supported: bool, monkeypatch: pytest.MonkeyPatch, ) -> None: + monkeypatch.setattr(native_context_profile, "os", platform) monkeypatch.setattr(decision_capture_module, "os", platform) assert decision_capture_module.private_capture_supported() is supported if supported: @@ -901,29 +903,13 @@ def test_private_capture_support_matches_uid_boundary( with pytest.raises(ValueError, match="unsupported on this platform"): decision_capture_module.private_capture_uid() - -def test_settlement_command_uses_private_capture_support() -> None: - # The generated command and the CLI's private-capture check must share one - # platform qualification; a POSIX-looking host without getuid is unsupported. - # The settlement kernel resolves the predicate at its owner, because keeping - # capture IO out of the plan module's cold import is itself a guard. - with patch.object(decision_capture_module, "private_capture_supported", return_value=False): - plan = quota_effect_program.build_turn_scoped_cli_settlement_plan( - goal_id=GOAL_ID, agent_id=AGENT_ID, todo_id=TODO_ID, - turn_instance_id=TURN_ID, scoped_cli_args="", lifecycle_actor_args="", - ).as_dict() - command = settlement_step_command(plan, SettlementStepKind.QUOTA_SPEND) - assert command is not None - assert "--max-page-output-bytes" not in command - - with patch.object(decision_capture_module, "private_capture_supported", return_value=True): - plan = quota_effect_program.build_turn_scoped_cli_settlement_plan( - goal_id=GOAL_ID, agent_id=AGENT_ID, todo_id=TODO_ID, - turn_instance_id=TURN_ID, scoped_cli_args="", lifecycle_actor_args="", - ).as_dict() - command = settlement_step_command(plan, SettlementStepKind.QUOTA_SPEND) - assert command is not None - assert "--max-page-output-bytes" in command + plan = quota_effect_program.build_turn_scoped_cli_settlement_plan( + goal_id=GOAL_ID, agent_id=AGENT_ID, todo_id=TODO_ID, + turn_instance_id=TURN_ID, scoped_cli_args="", lifecycle_actor_args="", + ).as_dict() + command = settlement_step_command(plan, SettlementStepKind.QUOTA_SPEND) + assert command is not None + assert ("--max-page-output-bytes" in shlex.split(command)) is supported def test_cli_validation_projects_ordinary_completion_not_terminal_intent() -> None: