Skip to content
Merged
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
16 changes: 8 additions & 8 deletions docs/product/releases/v2.4.0.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/bootstrap-command-pack-smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,8 @@ def test_start_goal_guided_requires_explicit_goal_for_multi_goal_project() -> No
"activation_state": "goal_selection_required",
"activation_allowed": False,
"activation_required_after_todo_write": False,
"host_surface": None,
"activation_method": None,
}, payload
assert payload["safety_contract"]["writes_registry"] is False, payload
assert payload["safety_contract"]["creates_heartbeat"] is False, payload
Expand Down
15 changes: 14 additions & 1 deletion loopx/control_plane/quota/execution_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import TYPE_CHECKING, Any

from ...file_lock import exclusive_cross_runtime_file_lock, exclusive_mutation_file_lock
from ..agents.agent_scope import AgentScopeFrontierAction
from ..coordination.local_authority import (
local_authority_is_promoted,
LOCAL_AUTHORITY_SOURCES,
Expand Down Expand Up @@ -455,10 +456,22 @@ def apply_selected_todo_execution_preparation(
receipt_bound: bool = False,
) -> None:
selected = payload.get("selected_todo")
fallback = payload.get("scoped_user_gate_fallback")
fallback_selected = (
fallback.get("selected_executable")
if isinstance(fallback, Mapping)
else None
)
scoped_fallback_admitted = (
isinstance(payload.get("scoped_user_gate_fallback"), Mapping)
isinstance(fallback, Mapping)
and obligation is not None
and obligation.get("delivery_allowed") is True
and payload.get("effective_action")
!= AgentScopeFrontierAction.SUCCESSOR_REPLAN_REQUIRED.value
and (
not isinstance(fallback_selected, Mapping)
or fallback_selected.get("fallback_kind") != "deferred_successor_replan"
)
)
if (
not isinstance(selected, dict)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import concurrent.futures
import json
import re
import threading
from collections.abc import Callable, Mapping, Sequence
from copy import deepcopy
from dataclasses import dataclass
Expand Down Expand Up @@ -1388,6 +1390,21 @@ def _contrast_result(
}


def _aborted_scenario_result(spec: _ScenarioSpec) -> dict[str, Any]:
return {
"scenario_id": spec.scenario_id,
"actor_kind": spec.actor_kind,
"phase": spec.phase,
"expected_route": spec.expected_route,
"status": "not_run",
"repeats_required": ACTUAL_DEFAULT_MODEL_BEHAVIOR_REPEAT_ATTEMPTS,
"repeats_completed": 0,
"observed_routes": [],
"failure_codes": ["portfolio_aborted_after_actor_error"],
"receipt_digests": [],
}


def run_actual_default_model_behavior_portfolio(
scenario_packets: Mapping[str, Mapping[str, Any]],
*,
Expand All @@ -1400,8 +1417,11 @@ def run_actual_default_model_behavior_portfolio(
scoped_gate_successor_actor: Callable[[str], Mapping[str, Any]],
capability_monitor_repair_actor: Callable[[str], Mapping[str, Any]],
terminal_settlement_actor: Callable[[str], Mapping[str, Any]],
max_workers: int = 1,
) -> dict[str, Any]:
"""Run the fixed low-frequency one-arm portfolio with bounded receipts."""
if isinstance(max_workers, bool) or not isinstance(max_workers, int) or max_workers < 1:
raise ValueError("max_workers must be a positive integer")
expected_ids = {spec.scenario_id for spec in _SCENARIOS}
supplied_ids = set(scenario_packets)
if supplied_ids != expected_ids:
Expand Down Expand Up @@ -1429,28 +1449,9 @@ def run_actual_default_model_behavior_portfolio(
for spec in _SCENARIOS
}
_validate_contrast_source_contracts(contracts)
results: list[dict[str, Any]] = []
observations: dict[str, list[dict[str, Any]]] = {}
actor_call_count = 0
aborted = False
for spec in _SCENARIOS:
if aborted:
results.append(
{
"scenario_id": spec.scenario_id,
"actor_kind": spec.actor_kind,
"phase": spec.phase,
"expected_route": spec.expected_route,
"status": "not_run",
"repeats_required": ACTUAL_DEFAULT_MODEL_BEHAVIOR_REPEAT_ATTEMPTS,
"repeats_completed": 0,
"observed_routes": [],
"failure_codes": ["portfolio_aborted_after_actor_error"],
"receipt_digests": [],
}
)
continue
result, actor_error, scenario_observations = _scenario_result(

def _run_one(spec: _ScenarioSpec) -> tuple[dict[str, Any], bool, list[dict[str, Any]]]:
return _scenario_result(
spec,
scenario_packets[spec.scenario_id],
expected=contracts[spec.scenario_id],
Expand All @@ -1463,12 +1464,48 @@ def run_actual_default_model_behavior_portfolio(
capability_monitor_repair_actor=capability_monitor_repair_actor,
terminal_settlement_actor=terminal_settlement_actor,
)
actor_call_count += int(result["repeats_completed"])
if actor_error:
actor_call_count += 1
aborted = True
results.append(result)
observations[spec.scenario_id] = scenario_observations

results: list[dict[str, Any]] = []
observations: dict[str, list[dict[str, Any]]] = {}
actor_call_count = 0
if max_workers == 1:
aborted = False
for spec in _SCENARIOS:
if aborted:
results.append(_aborted_scenario_result(spec))
continue
result, actor_error, scenario_observations = _run_one(spec)
actor_call_count += int(result["repeats_completed"])
if actor_error:
actor_call_count += 1
aborted = True
results.append(result)
observations[spec.scenario_id] = scenario_observations
else:
lock = threading.Lock()
aborted = False

def _worker(
spec: _ScenarioSpec,
) -> tuple[_ScenarioSpec, dict[str, Any], bool, list[dict[str, Any]]]:
nonlocal aborted
with lock:
if aborted:
return spec, _aborted_scenario_result(spec), False, []
result, actor_error, scenario_observations = _run_one(spec)
if actor_error:
with lock:
aborted = True
return spec, result, actor_error, scenario_observations

worker_count = min(max_workers, len(_SCENARIOS))
with concurrent.futures.ThreadPoolExecutor(max_workers=worker_count) as pool:
completed = list(pool.map(_worker, _SCENARIOS))
for spec, result, actor_error, scenario_observations in completed:
actor_call_count += int(result["repeats_completed"]) + (1 if actor_error else 0)
results.append(result)
if result["status"] != "not_run":
observations[spec.scenario_id] = scenario_observations

contrast_results = [_contrast_result(spec, observations) for spec in _CONTRASTS]
passed = all(result["status"] == "passed" for result in results) and all(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
REPLAN_SEMANTIC_ACTION_BEHAVIOR_MAX_CALLS = 7
REPLAN_SEMANTIC_ACTION_NATIVE_READ_MAX_CALLS = 3
_NATIVE_CONTEXT_READ_KINDS = frozenset({"context_read", "replan_context_read"})
_MAX_HOST_TOOL_ERROR_OUTPUT_CHARS = 8192


class _HostToolError(RuntimeError):
Expand Down Expand Up @@ -1760,7 +1761,8 @@ def _run_qualification_loop(
exit_code=exc.exit_code, error_code=exc.code)
_append_tool_response(state, tool_call=tool_call, output=json.dumps({
"error_code": exc.code, "exit_code": exc.exit_code,
"output": exc.output[:4096], "truncated": len(exc.output) > 4096,
"output": exc.output[:_MAX_HOST_TOOL_ERROR_OUTPUT_CHARS],
"truncated": len(exc.output) > _MAX_HOST_TOOL_ERROR_OUTPUT_CHARS,
}))
continue
except (RuntimeError, ValueError, json.JSONDecodeError) as exc:
Expand Down
12 changes: 10 additions & 2 deletions scripts/qualify-doubao-model-behavior-live.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import argparse
import json
import sys
import threading
from collections.abc import Mapping
from hashlib import sha256
from pathlib import Path
Expand Down Expand Up @@ -56,26 +57,32 @@ def _parser() -> argparse.ArgumentParser:
parser.add_argument("--timeout-seconds", type=float, default=90.0)
parser.add_argument("--required-vision-timeout-seconds", type=float, default=180.0)
parser.add_argument("--repo-root", type=Path, default=Path.cwd())
parser.add_argument("--max-workers", type=int, default=1)
return parser


def main() -> int:
args = _parser().parse_args()
if args.max_workers < 1:
raise ValueError("--max-workers must be at least 1")
source = collect_release_source_identity(args.repo_root)
if source["git_dirty"]:
raise RuntimeError(
"live Doubao qualification requires a clean candidate checkout"
)
provider_call_count = 0
provider_models: set[str] = set()
transport_lock = threading.Lock()

def counted_transport(
*, endpoint: str, headers: Mapping[str, str], body: bytes,
timeout_seconds: float,
) -> Mapping[str, Any]:
nonlocal provider_call_count
provider_call_count += 1
provider_models.add(json.loads(body)["model"])
model_id = json.loads(body)["model"]
with transport_lock:
provider_call_count += 1
provider_models.add(model_id)
return _direct_ark_transport(
endpoint=endpoint, headers=headers, body=body,
timeout_seconds=timeout_seconds,
Expand Down Expand Up @@ -162,6 +169,7 @@ def qualify_terminal_settlement(run_id: str) -> dict[str, object]:
scoped_gate_successor_actor=qualify_scoped_gate_successor,
capability_monitor_repair_actor=qualify_capability_monitor_repair,
terminal_settlement_actor=qualify_terminal_settlement,
max_workers=args.max_workers,
)
result["source"] = source
# An actor invocation can make several HTTP calls while using tools.
Expand Down
3 changes: 2 additions & 1 deletion tests/architecture/test_content_digest_single_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"loopx.chat.result_files_api",
"loopx.chat_action_normalization",
"loopx.capabilities.manager_context.chat_history",
"loopx.cli_commands.quota_capture",
"loopx.cli_commands.quota_context_reader",
"loopx.cli_commands.update_artifact",
"loopx.configuration_transaction",
Expand Down Expand Up @@ -220,7 +221,7 @@
"loopx.control_plane.work_items.progress_review_policy",
"loopx.domain_packs.issue_fix",
"loopx.extensions.lark.document_comment_provider",
"loopx.extensions.lark.private_conversations",
"loopx.extensions.lark.private_delivery_discovery",
"loopx.extensions.openviking_semantic_preference.history_export",
"loopx.extensions.presentation",
"loopx.hosts.checkpoint_retention",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1892,3 +1892,42 @@ def waiting_actor(run_id: str) -> dict[str, Any]:
assert scenario["status"] == "failed"
assert scenario["repeats_completed"] == 2
assert "source_mismatch:decision" in scenario["failure_codes"]


def test_portfolio_max_workers_matches_sequential_receipt(
tmp_path: Path,
) -> None:
sources, packets = _scenario_inputs(tmp_path)
sequential = run_actual_default_model_behavior_portfolio(
packets,
scenario_sources=sources,
qualification_id="actual-default-portfolio-seq",
turn_actor=_turn_actor,
onboarding_actor=_onboarding_actor,
selected_todo_actor=_selected_todo_actor,
replan_semantic_action_actor=_replan_semantic_action_actor,
)
parallel = run_actual_default_model_behavior_portfolio(
packets,
scenario_sources=sources,
qualification_id="actual-default-portfolio-seq",
turn_actor=_turn_actor,
onboarding_actor=_onboarding_actor,
selected_todo_actor=_selected_todo_actor,
replan_semantic_action_actor=_replan_semantic_action_actor,
max_workers=4,
)
assert parallel == sequential

for bad_workers in (0, -1, True):
with pytest.raises(ValueError, match="max_workers"):
run_actual_default_model_behavior_portfolio(
packets,
scenario_sources=sources,
qualification_id="actual-default-portfolio-invalid-workers",
turn_actor=_turn_actor,
onboarding_actor=_onboarding_actor,
selected_todo_actor=_selected_todo_actor,
replan_semantic_action_actor=_replan_semantic_action_actor,
max_workers=bad_workers,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from types import SimpleNamespace

import pytest
from canonical_authority_fixture import initialize_canonical_source_fixture
from tests.control_plane.canonical_authority_fixture import initialize_canonical_source_fixture

from loopx.control_plane.effect_runtime import effect_runtime_result
from loopx.control_plane.quota import live_decision, should_run_packet
Expand Down
65 changes: 65 additions & 0 deletions tests/control_plane/test_quota_execution_preparation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,3 +1650,68 @@ def test_todo_bound_autonomous_replan_admits_without_prepared_lease_only_on_repl
heartbeat_receipt={"status": "autonomous_replan_required", "details": {"delivery_allowed": False}},
),
)


def test_scoped_user_gate_fallback_execution_preparation_excludes_deferred_replan(monkeypatch):
from loopx.control_plane.quota import execution_preparation

replan_payload = {
"should_run": True,
"normal_delivery_allowed": False,
"effective_action": "successor_replan_required",
"selected_todo": {"todo_id": TODO, "status": "deferred", "resume_ready": True},
"scoped_user_gate_fallback": {
"selected_executable": {"todo_id": TODO, "fallback_kind": "deferred_successor_replan"}
},
"execution_obligation": {"must_attempt_work": True, "delivery_allowed": True},
}

def unexpected_read(**_):
pytest.fail("deferred_successor_replan fallback must not consult execution-lease preparation")

monkeypatch.setattr(execution_preparation, "project_selected_todo_execution_preparation", unexpected_read)
apply_selected_todo_execution_preparation(
replan_payload,
runtime_root=None,
goal_id=GOAL,
agent_id=AGENT,
obligation=replan_payload["execution_obligation"],
)
assert "execution_preparation" not in replan_payload
assert replan_payload["should_run"] is True
assert replan_payload["execution_obligation"]["delivery_allowed"] is True

monkeypatch.setattr(
execution_preparation,
"project_selected_todo_execution_preparation",
lambda **_: {
"schema_version": "execution_preparation_v0",
"todo_id": TODO,
"agent_id": AGENT,
"handoff_mode": "hard_lease",
"state": "claim_required",
"delivery_allowed": False,
"reason": "Acquire an atomic lease before advancing the open fallback.",
"claim": {"cli_args": ["todo", "claim", "--goal-id", GOAL, "--todo-id", TODO], "command_line": f"loopx todo claim --goal-id {GOAL} --todo-id {TODO} --thin"},
},
)
open_fallback_payload = {
"should_run": True,
"normal_delivery_allowed": False,
"effective_action": "scoped_user_gate_fallback",
"selected_todo": {"todo_id": TODO, "status": "open"},
"scoped_user_gate_fallback": {
"selected_executable": {"todo_id": TODO}
},
"execution_obligation": {"must_attempt_work": True, "delivery_allowed": True},
}
apply_selected_todo_execution_preparation(
open_fallback_payload,
runtime_root=None,
goal_id=GOAL,
agent_id=AGENT,
obligation=open_fallback_payload["execution_obligation"],
)
assert open_fallback_payload["execution_preparation"]["state"] == "claim_required"
assert open_fallback_payload["should_run"] is True
assert open_fallback_payload["execution_obligation"]["delivery_allowed"] is False
11 changes: 11 additions & 0 deletions tests/control_plane/test_replan_semantic_action_behavior.py
Original file line number Diff line number Diff line change
Expand Up @@ -1607,3 +1607,14 @@ def test_prose_intent_without_typed_action_is_rejected(tmp_path: Path) -> None:
assert receipt["qualification_passed"] is False
assert receipt["failure_code"] == "model_returned_without_semantic_action"
assert receipt["tool_call_count"] == 0


@requires_draft_shell
def test_real_tool_loop_preserves_writeback_rejection_recovery_under_deep_path(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
) -> None:
deep_root = tmp_path / ("deep-" + "x" * 64)
deep_root.mkdir(parents=True)
test_real_tool_loop_selects_composition_gap_and_creates_bound_successor(
deep_root, monkeypatch, "off",
)
Loading