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: 1 addition & 5 deletions loopx/control_plane/quota/effect_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -310,10 +310,6 @@ def writeback_command(boundary: str) -> str:
writeback_command(" --delivery-boundary semantic_closeout")
+ " --agent-vision-json <file>"
)
# 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()
Expand Down
6 changes: 1 addition & 5 deletions loopx/control_plane/turn_driver/decision_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
7 changes: 7 additions & 0 deletions loopx/control_plane/turn_driver/native_context_profile.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
34 changes: 10 additions & 24 deletions tests/control_plane/test_quota_settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down