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
11 changes: 4 additions & 7 deletions loopx/control_plane/goals/goal_frontier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
_latest_runs_for_goal,
latest_agent_vision_from_runs as latest_agent_vision_from_runs,
latest_agent_vision_from_status_payload,
latest_autonomous_replan_ack_from_status_payload,
receipt_bound_replan_ack_history,
latest_missing_vision_checkpoint_from_status_payload,
latest_replan_ack_feedback_from_status_payload,
)
Expand Down Expand Up @@ -1451,11 +1451,12 @@ def build_goal_frontier_projection_context_from_status(
if replan_scope.get("required") and not replan_scope.get("applies"):
replan_obligation = None

latest_agent_replan_ack = latest_autonomous_replan_ack_from_status_payload(
latest_agent_replan_ack, scoped_ack_history = receipt_bound_replan_ack_history(
status_payload,
goal_id=goal_id,
agent_id=agent_id,
neutral_classifications=neutral_replan_ack_classifications,
receipt_bound_replan_obligation_id=receipt_bound_replan_obligation_id,
)
latest_replan_ack_feedback = latest_replan_ack_feedback_from_status_payload(
status_payload,
Expand Down Expand Up @@ -1667,11 +1668,7 @@ def build_goal_frontier_projection_context_from_status(
# current-frontier transition: the settlement owner validates its exact
# Goal, Agent, obligation, chronology, and Turn before it can close the old
# writeback. Projected asset ACKs never enter this candidate.
raw_historical_ack_candidates = (
status_payload.get("receipt_bound_replan_ack_candidates")
if receipt_bound_replan_obligation_id
else None
)
raw_historical_ack_candidates = scoped_ack_history
historical_ack_candidates = [
{"historical_ack": dict(candidate)}
for candidate in (
Expand Down
32 changes: 32 additions & 0 deletions loopx/control_plane/goals/goal_frontier/semantic_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,38 @@ def latest_autonomous_replan_ack_from_status_payload(
)


def receipt_bound_replan_ack_history(
status_payload: dict[str, Any],
*,
goal_id: str,
agent_id: str | None,
neutral_classifications: set[str],
receipt_bound_replan_obligation_id: str | None,
) -> tuple[dict[str, Any] | None, list[dict[str, Any]] | None]:
"""Choose the ACK history a receipt-bound review may use.

A supplied candidate list is the whole owned history, including when it
is empty. Without that list, the status snapshot's newest ACK remains
the existing fallback.
"""

latest = latest_autonomous_replan_ack_from_status_payload(
status_payload,
goal_id=goal_id,
agent_id=agent_id,
neutral_classifications=neutral_classifications,
)
supplied = (
status_payload.get("receipt_bound_replan_ack_candidates")
if receipt_bound_replan_obligation_id
else None
)
if not isinstance(supplied, list):
return latest, None
owned = [candidate for candidate in supplied if isinstance(candidate, dict)]
return (owned[0] if owned else None), owned


def latest_replan_ack_feedback_from_status_payload(
status_payload: dict[str, Any],
*,
Expand Down
91 changes: 90 additions & 1 deletion loopx/control_plane/quota/live_decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,91 @@ def _project_unbound_work_fields(payload: dict[str, Any]) -> None:
recommendation["spend_policy"] = reason


def _restore_replan_obligation_without_foreign_acks(
status_payload: dict[str, Any], *, goal_id: str, agent_id: str,
goal_ref: Mapping[str, Any] | None,
registry_goal: Mapping[str, Any] | None,
registry_path: Path,
runtime_root: Path,
) -> None:
"""Recompute the open review after removing another instance's ACK rows."""
from ...status import (
autonomous_replan_obligation_from_runs,
external_progress_review_context,
)
from ..work_items.autonomous_replan_ack import drop_unowned_recorded_replan_acks
from ..work_items.project_asset import attach_active_state_project_asset_fields
from ..work_items.replan_history_codec import effective_turn_cadence_context

run_history = status_payload.get("run_history")
goals = run_history.get("goals") if isinstance(run_history, dict) else None
goal = next(
(
item for item in goals
if isinstance(item, dict) and str(item.get("id") or "") == goal_id
),
None,
) if isinstance(goals, list) else None
if not isinstance(goal, dict) or not isinstance(goal.get("latest_runs"), list):
return
filtered, changed = drop_unowned_recorded_replan_acks(
goal["latest_runs"], goal_id=goal_id, goal_ref=goal_ref,
)
if not changed:
return
goal["latest_runs"] = filtered
kept_ack_times = {
run.get("generated_at")
for run in filtered
if isinstance(run.get("autonomous_replan_ack"), dict)
}
semantic = goal.get("semantic_history")
agents = semantic.get("agents") if isinstance(semantic, dict) else None
if isinstance(agents, list):
for context in agents:
if not isinstance(context, dict):
continue
ack_run = context.get("latest_autonomous_replan_ack_run")
if (
isinstance(ack_run, dict)
and ack_run.get("generated_at") not in kept_ack_times
):
context.pop("latest_autonomous_replan_ack_run", None)
queue = status_payload.get("attention_queue")
items = queue.get("items") if isinstance(queue, dict) else None
item = next(
(
entry for entry in items
if isinstance(entry, dict) and entry.get("goal_id") == goal_id
),
None,
) if isinstance(items, list) else None
if not isinstance(item, dict):
return
for target in (item, item.get("project_asset")):
if not isinstance(target, dict):
continue
target.pop("autonomous_replan_obligation", None)
target.pop("autonomous_replan_obligations_by_agent", None)
target.pop("autonomous_replan_ack", None)
source_goal = dict(registry_goal) if isinstance(registry_goal, Mapping) else {"id": goal_id}
source_goal.setdefault("id", goal_id)
review = external_progress_review_context(source_goal, runtime_root)
cadence_goal_ref = dict(goal_ref) if isinstance(goal_ref, Mapping) else None
attach_active_state_project_asset_fields(
item, latest_runs=filtered,
autonomous_replan_obligation_from_runs=autonomous_replan_obligation_from_runs,
external_progress_review=review,
effective_turn_cadence=effective_turn_cadence_context(
source_goal, runtime_root, registry_path=registry_path,
goal_ref=cadence_goal_ref if all(
isinstance(value, str) for value in (cadence_goal_ref or {}).values()
) else None,
),
agent_lane_id=agent_id,
)


def build_live_quota_should_run_decision(
status_payload: dict[str, Any],
*,
Expand Down Expand Up @@ -803,7 +888,11 @@ def build_live_quota_should_run_decision(
obligation_id=receipt_bound_replan_obligation_id,
guard_recorded_at=receipt_bound_guard_fields["receipt_bound_guard_recorded_at"],
guard_turn_instance_id=receipt_bound_guard_fields["receipt_bound_guard_turn_instance_id"],
admission_event_id=admission_event_id)
goal_ref=goal_ref, admission_event_id=admission_event_id)
_restore_replan_obligation_without_foreign_acks(
decision_status_payload, goal_id=goal_id, agent_id=agent_id, goal_ref=goal_ref,
registry_goal=registered_goal, registry_path=registry_path, runtime_root=runtime_root,
)
fresh_operator_inbox_read = _fresh_operator_inbox_read_required(
turn_start_hook_dispatch
)
Expand Down
1 change: 1 addition & 0 deletions loopx/control_plane/runtime/run_compaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"turn_instance_id",
"replan_obligation_id",
"goal_id",
"goal_ref",
"parent_run_id",
"spawned_by_goal_id",
"agent_role",
Expand Down
Loading
Loading