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
2 changes: 1 addition & 1 deletion loopx/agent_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def agent_profile_for_goal(goal: dict[str, Any] | None, agent_id: str | None) ->

def load_goal_from_registry(registry_path: Path, goal_id: str) -> dict[str, Any] | None:
from .control_plane.hook_runtime.request_scope import current_hook_request_scope
from .history import load_registry
from .control_plane.projects.registry_codec import load_registry
from .registry import registry_goals

scope = current_hook_request_scope()
Expand Down
194 changes: 194 additions & 0 deletions loopx/capabilities/explore/harness_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,200 @@
GATE_STATE_DISABLED = "disabled"
GATE_STATE_ANALYSIS_ONLY = "analysis_only"
GATE_STATE_COMMANDS_SUGGESTED = "commands_suggested"
MAX_BRANCH_WIDTH = 8
WORKER_HARNESS_PROFILE_SCHEMA_VERSION = "loopx_explore_worker_harness_profile_v0"
DEFAULT_TODOS_PER_WORKER_BRANCH = 3
MAX_TODOS_PER_WORKER_BRANCH = 8
DEFAULT_WORKER_HARNESS_PROFILE = "generic"

WORKER_HARNESS_PROFILES: dict[str, dict[str, Any]] = {
"generic": {
"schema_version": WORKER_HARNESS_PROFILE_SCHEMA_VERSION,
"profile": "generic",
"source": "loopx_explore_worker_branch_plan_default",
"design_intent": "Generic dry-run worker-lane planning without runtime policy assumptions.",
"branch_fill_policy": "bundle-by-affinity",
"concurrency_policy": {
"mode": "bounded_confidence_prefix",
"fixed_worker_count": False,
"does_not_force_requested_width": True,
},
"duration_guard": {
"enabled": False,
"controlled_by_planner": False,
},
"retry_policy": {
"enabled": False,
"controlled_by_planner": False,
},
"infra_cooldown": {
"enabled": False,
"controlled_by_planner": False,
},
"todo_batching_policy": {
"mode": "fixed_safety_ceiling",
"default_ceiling": DEFAULT_TODOS_PER_WORKER_BRANCH,
"external_ceiling_role": "planner_batch_ceiling",
},
},
"adaptive-resilient": {
"schema_version": WORKER_HARNESS_PROFILE_SCHEMA_VERSION,
"profile": "adaptive-resilient",
"source": "generalized_from_long_horizon_calibration_evidence",
"design_intent": (
"Generalize the best observed harness traits without copying an experimental "
"N value, duration limit, or saturated-fill policy. Lane width uses "
"independent-lane admission -- the serial survival-product prefix was a "
"structural mismatch for parallel lanes and under-filled requested width "
"in early calibration."
),
"branch_fill_policy": "value-first",
"marginal_score_floor": 0.72,
"todo_batching_policy": {
"mode": "adaptive_value_scheduled",
"default_ceiling": MAX_TODOS_PER_WORKER_BRANCH,
"external_ceiling_required": False,
"external_ceiling_role": "optional_safety_cap_only",
"intent": (
"Let the planner decide whether to bundle extra todos into a worker lane "
"from marginal value, rather than forcing a per-worker todo count."
),
},
"concurrency_policy": {
"mode": "independent_lane_admission",
"fixed_worker_count": False,
"does_not_force_requested_width": True,
"worker_width_is_ceiling": True,
"branch_count_is_value_scheduled": True,
},
"lane_start_stagger_seconds": 1.25,
"retry_policy": {
"enabled": True,
"uses_backoff": True,
"retryable_error_families": [
"provider_service_unreachable",
"transient_infra_failure",
],
},
"infra_cooldown": {
"enabled": True,
"failure_threshold": 2,
"cooldown_epochs": 2,
"strict_skip_when_healthy_width_available": True,
},
"duration_guard": {
"enabled": False,
"controlled_by_planner": False,
"reason": "Duration limits are runner policy, not part of the generalized harness design.",
},
"coverage_floor": {
"enabled": False,
"reason": "An earlier coverage-floor calibration arm did not show enough value to become the default design.",
},
},
"moe-router": {
"schema_version": WORKER_HARNESS_PROFILE_SCHEMA_VERSION,
"profile": "moe-router",
"source": "moe_style_router_redesign",
"design_intent": (
"MoE-style value-first routing under a fixed worker ceiling: task families "
"are the experts, todos are routed tokens. Width via independent-lane "
"admission (interference-priced, never a fill rule); coverage via an "
"aux-loss-free per-family bias that only reorders routing (DeepSeek-V3 "
"invariant: bias never touches value bookkeeping); bundle length via the "
"DSpark confident-prefix cutoff (arXiv:2607.05147) with per-family "
"accept-rate calibration plus a wall-clock straggler guard."
),
"branch_fill_policy": "confident-prefix",
"marginal_score_floor": 0.72,
"bundle_confidence_threshold": 0.6,
# 2.5 x median permits a 2-deep bundle at uniform measured durations
# while still fencing slow families; 1.25 would cap everything at 1
# and make the confident-prefix rule unreachable.
"bundle_straggler_factor": 2.5,
"todo_batching_policy": {
"mode": "confident_prefix_scheduled",
"default_ceiling": MAX_TODOS_PER_WORKER_BRANCH,
"external_ceiling_required": False,
"external_ceiling_role": "optional_safety_cap_only",
"intent": (
"DSpark-faithful bundle sizing: append todos while calibrated per-todo "
"acceptance confidence clears the threshold; truncate at the first "
"below-threshold todo; cap the serial tail by predicted wall-clock."
),
},
"concurrency_policy": {
"mode": "independent_lane_admission",
"fixed_worker_count": False,
"does_not_force_requested_width": True,
"worker_width_is_ceiling": True,
"branch_count_is_value_scheduled": True,
},
"opportunistic_lane_policy": {
"enabled": True,
"target_utilization_floor": 0.65,
"min_lane_value_floor": 0.01,
"min_lane_value_ratio": 0.2,
"intent": (
"Keep the high-confidence core from the theta peak, "
"then admit additional positive-yield lanes up to a utilization floor "
"so B does not waste worker capacity after proving active-lane quality."
),
},
"router_policy": {
"enabled": True,
"state_schema": "loopx_explore_router_state_v0",
"bias_affects_routing_order_only": True,
"admission_uses_unbiased_value": True,
"experts": "affinity families (scope:artifacts/<family>) declared via work-item write scopes",
},
"lane_start_stagger_seconds": 1.25,
"retry_policy": {
"enabled": True,
"uses_backoff": True,
"retryable_error_families": [
"provider_service_unreachable",
"transient_infra_failure",
],
},
"infra_cooldown": {
"enabled": True,
"failure_threshold": 2,
"cooldown_epochs": 2,
"strict_skip_when_healthy_width_available": True,
},
"duration_guard": {
"enabled": False,
"controlled_by_planner": False,
"reason": "Duration limits are runner policy, not part of the harness design.",
},
"coverage_floor": {
"enabled": False,
"reason": "Replaced by the aux-loss-free routing bias plus coverage recency bonus.",
},
},
}


def worker_harness_profile_names() -> tuple[str, ...]:
"""Return available worker-harness profile identifiers in canonical sorted order."""

return tuple(sorted(WORKER_HARNESS_PROFILES))


def resolve_todo_branch_plan_gate(
orchestration: Mapping[str, Any] | None,
*,
requested_width: int,
) -> dict[str, Any]:
"""Resolve the shared explore-harness gate with the branch planner's lane ceiling."""

return resolve_explore_harness_gate(
orchestration,
requested_width=requested_width,
max_lanes=MAX_BRANCH_WIDTH,
max_lanes_label="max_branch_width",
)


def explore_harness_required_contract(*, default_profile: str) -> dict[str, Any]:
Expand Down
19 changes: 2 additions & 17 deletions loopx/capabilities/explore/todo_branch_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
from .harness_gate import (
GATE_STATE_ANALYSIS_ONLY,
GATE_STATE_DISABLED,
MAX_BRANCH_WIDTH as MAX_BRANCH_WIDTH,
explore_harness_required_contract,
resolve_explore_harness_gate as _resolve_explore_harness_gate,
resolve_todo_branch_plan_gate as resolve_todo_branch_plan_gate,
)
from .speculative_scheduler import (
build_branch_plan_ab_result,
Expand All @@ -42,7 +43,6 @@

TODO_BRANCH_PLAN_SCHEMA_VERSION = "loopx_explore_todo_branch_plan_v0"
DEFAULT_BRANCH_WIDTH = 3
MAX_BRANCH_WIDTH = 8
TOKEN_PATTERN = re.compile(r"[A-Za-z0-9_:\-]{3,}")
SHARED_DEPENDENCY_CAPABILITY_PREFIXES = (
"shared_artifact:",
Expand Down Expand Up @@ -249,21 +249,6 @@ def _claim_command(*, goal_id: str, todo_id: str, agent_id: str | None) -> str |
)


def resolve_todo_branch_plan_gate(
orchestration: Mapping[str, Any] | None,
*,
requested_width: int,
) -> dict[str, Any]:
"""Resolve the shared explore-harness gate with this planner's lane ceiling."""

return _resolve_explore_harness_gate(
orchestration,
requested_width=requested_width,
max_lanes=MAX_BRANCH_WIDTH,
max_lanes_label="max_branch_width",
)


def _disabled_todo_branch_plan(
*,
goal_id: str,
Expand Down
8 changes: 4 additions & 4 deletions loopx/capabilities/explore/turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@
explore_result_log_path,
load_explore_result_events_strict,
)
from .todo_branch_plan import (
build_explore_todo_branch_plan,
resolve_todo_branch_plan_gate,
)
from .harness_gate import resolve_todo_branch_plan_gate


def _policy(registry_path: Path, goal_id: str, runtime_root: Path | None = None) -> tuple[dict[str, Any], Any, dict[str, Any]]:
Expand Down Expand Up @@ -146,8 +143,11 @@ def explore_turn_context(
status="open",
agent_id=agent_id,
runtime_root_arg=str(runtime_root),
include_acceptance=False,
)
if gate["enabled"]:
from .todo_branch_plan import build_explore_todo_branch_plan

plan = build_explore_todo_branch_plan(
goal_id=goal_id,
agent_id=agent_id,
Expand Down
Loading
Loading