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
2 changes: 1 addition & 1 deletion loopx/canary/module_metric_baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"lines": 662
},
"loopx/control_plane/agents/agent_scope.py": {
"any_count": 13,
"any_count": 0,
"dict_any_count": 0
},
"loopx/control_plane/agents/management_projection.py": {
Expand Down
30 changes: 15 additions & 15 deletions loopx/control_plane/agents/agent_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from collections.abc import Callable, Mapping, Sequence
from dataclasses import dataclass
from typing import Any, TypedDict, TypeGuard
from typing import TypedDict, TypeGuard, cast

from .agent_scope_frontier import (
AGENT_LANE_FRONTIER_HINT_SCHEMA_VERSION,
Expand Down Expand Up @@ -125,8 +125,8 @@ def _agent_identity_has_scoped_lane(


def _attach_agent_identity_contracts(
*, payload: dict[str, Any], agent_identity: Mapping[str, object] | None
) -> dict[str, Any]:
*, payload: dict[str, object], agent_identity: Mapping[str, object] | None
) -> dict[str, object]:
if not agent_identity:
return payload
payload["agent_identity"] = agent_identity
Expand Down Expand Up @@ -251,7 +251,7 @@ def _scoped_user_gate_fallback(
monitor_debt_backoff_active: bool = False,
requested_todo_id: str | None = None,
requested_candidate: dict[str, object] | None = None,
) -> dict[str, Any] | None:
) -> dict[str, object] | None:
gates = _open_user_gate_todo_items(user_todo_summary if isinstance(user_todo_summary, dict) else None)
if not gates or not isinstance(agent_todo_summary, dict):
return None
Expand Down Expand Up @@ -344,7 +344,7 @@ def _agent_scoped_user_todo_override(
user_todo_summary: Mapping[str, object] | None,
agent_todo_summary: Mapping[str, object] | None,
agent_identity: Mapping[str, object] | None,
) -> dict[str, Any] | None:
) -> dict[str, object] | None:
if state != "operator_gate" or not isinstance(agent_identity, dict) or not isinstance(user_todo_summary, dict):
return None
# Non-blocking user_action rows may remain a reminder without preserving an
Expand Down Expand Up @@ -392,7 +392,7 @@ def _agent_scoped_user_todo_override(
"waiting_on": "codex" if selected_action else "agent_scope",
"recommended_action": selected_action or "wait for work or a user action bound to this agent",
}
result: dict[str, Any] = {
result: dict[str, object] = {
"schema_version": "agent_scoped_user_action_override_v0",
"kind": "agent_scoped_user_action_override",
"agent_id": agent_id,
Expand Down Expand Up @@ -618,7 +618,7 @@ def _select_and_compact_candidates(
copy_fields: tuple[str, ...] = (),
copy_truthy_only: bool = False,
defaults: Mapping[str, object] | None = None,
) -> list[dict[str, Any]]:
) -> list[dict[str, object]]:
"""Filter, deduplicate, compact, and sort todo candidate records."""
unique: list[dict[str, object]] = []
seen: set[str] = set()
Expand Down Expand Up @@ -657,7 +657,7 @@ def _collect_lane_or_fallback(

def _agent_scope_deferred_resume_candidates(
agent_todo_summary: Mapping[str, object], *, agent_id: str | None
) -> list[dict[str, Any]]:
) -> list[dict[str, object]]:
candidates = _collect_lane_or_fallback(
agent_todo_summary,
lane_keys=("current_agent_deferred_resume_candidates", "unclaimed_deferred_resume_candidates"),
Expand All @@ -676,7 +676,7 @@ def _agent_scope_deferred_resume_candidates(

def _agent_scope_monitor_blocked_resume_candidates(
agent_todo_summary: Mapping[str, object] | None, *, agent_id: str | None
) -> list[dict[str, Any]]:
) -> list[dict[str, object]]:
if not isinstance(agent_todo_summary, Mapping):
return []
keys = (
Expand Down Expand Up @@ -704,13 +704,13 @@ def _agent_scope_handoff_gates_by_state(
agent_id: str | None,
gate_state: str,
preferred_key: str,
) -> list[dict[str, Any]]:
) -> list[dict[str, object]]:
if not agent_id:
return []
raw_gates = agent_todo_summary.get(preferred_key)
if not isinstance(raw_gates, list):
raw_gates = agent_todo_summary.get("handoff_gates")
selected: list[dict[str, Any]] = []
selected: list[dict[str, object]] = []
seen: set[str] = set()
for item in _dict_items(raw_gates):
if agent_id not in agent_scope_item_excluded_agents(item) or item.get("gate_state") != gate_state:
Expand All @@ -725,7 +725,7 @@ def _agent_scope_handoff_gates_by_state(

def agent_scope_blocking_handoff_gates(
agent_todo_summary: Mapping[str, object], *, agent_id: str | None
) -> list[dict[str, Any]]:
) -> list[dict[str, object]]:
selected = _agent_scope_handoff_gates_by_state(
agent_todo_summary,
agent_id=agent_id,
Expand All @@ -737,7 +737,7 @@ def agent_scope_blocking_handoff_gates(

def _agent_scope_route_continuation_replan_candidates(
agent_todo_summary: Mapping[str, object], *, agent_id: str
) -> list[dict[str, Any]]:
) -> list[dict[str, object]]:
candidates = _collect_lane_or_fallback(
agent_todo_summary,
lane_keys=(
Expand Down Expand Up @@ -1008,7 +1008,7 @@ def _cleared_handoff_frontier(context: _AgentScopeNoCandidateContext) -> dict[st
gate_state=HandoffGateState.CLEARED_WITHOUT_SUCCESSOR.value,
preferred_key="current_agent_cleared_without_successor_handoff_gates",
),
key=lambda item: (-int(item.get("index") or 0), str(item.get("todo_id") or "")),
key=lambda item: (-int(cast(int | float | str, item.get("index") or 0)), str(item.get("todo_id") or "")),
)
if not gates:
return None
Expand Down Expand Up @@ -1113,7 +1113,7 @@ def _agent_scope_no_candidate_frontier(
work_lane_contract: dict[str, object] | None,
candidate_should_run: bool,
vision_wait_state: Mapping[str, object] | None = None,
) -> dict[str, Any] | None:
) -> dict[str, object] | None:
if not candidate_should_run or not _agent_identity_has_scoped_lane(agent_identity):
return None
agent_id = normalize_todo_claimed_by(agent_identity.get("agent_id"))
Expand Down
Loading