From 8467c8ec990b4f0bedc9c7e159a48f3a1448d4e1 Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Thu, 19 Nov 2026 01:44:06 +0800 Subject: [PATCH] fix(quota): reuse replan projection owners during recovery Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/cli_commands/quota_monitor_poll.py | 2 ++ loopx/cli_commands/quota_scheduler_followup.py | 2 ++ loopx/cli_commands/quota_should_run.py | 2 ++ loopx/cli_commands/turn_decision.py | 4 ++++ loopx/control_plane/quota/live_decision.py | 14 +++++++++----- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/loopx/cli_commands/quota_monitor_poll.py b/loopx/cli_commands/quota_monitor_poll.py index 49b58f44b8..00126c3ac3 100644 --- a/loopx/cli_commands/quota_monitor_poll.py +++ b/loopx/cli_commands/quota_monitor_poll.py @@ -210,6 +210,7 @@ def record_automatic_heartbeat_stall( from ..capabilities.explore.composition_frontier import ( project_live_explore_composition_frontier, ) + from ..capabilities.progress_review.context import external_progress_review_context poll = monitor_poll_recorder( status_payload, @@ -255,6 +256,7 @@ def record_automatic_heartbeat_stall( scheduler_execution_context=context.scheduler_context, operator_inbox_urgency_projector=context.operator_inbox_urgency_projector, bounded_research_frontier_projector=project_live_explore_composition_frontier, + progress_review_context_reader=external_progress_review_context, receipt_bound_todo_id=action_selection.receipt_bound_todo_id, receipt_bound_replan_obligation_id=( action_selection.receipt_bound_replan_obligation_id diff --git a/loopx/cli_commands/quota_scheduler_followup.py b/loopx/cli_commands/quota_scheduler_followup.py index 8772c91299..eddb843e2b 100644 --- a/loopx/cli_commands/quota_scheduler_followup.py +++ b/loopx/cli_commands/quota_scheduler_followup.py @@ -8,6 +8,7 @@ from ..capabilities.explore.composition_frontier import ( project_live_explore_composition_frontier, ) +from ..capabilities.progress_review.context import external_progress_review_context from ..capabilities.repository_change_window import ( repository_delivery_interaction_hook, ) @@ -69,6 +70,7 @@ def _build_scheduler_followup_decision( scheduler_execution_context=scheduler_context, operator_inbox_urgency_projector=operator_inbox_urgency_projector, bounded_research_frontier_projector=project_live_explore_composition_frontier, + progress_review_context_reader=external_progress_review_context, receipt_bound_todo_id=receipt_todo_id, receipt_bound_replan_obligation_id=receipt_replan_id, turn_instance_id=turn_instance_id, diff --git a/loopx/cli_commands/quota_should_run.py b/loopx/cli_commands/quota_should_run.py index dd79c10c7a..e65679bdc8 100644 --- a/loopx/cli_commands/quota_should_run.py +++ b/loopx/cli_commands/quota_should_run.py @@ -8,6 +8,7 @@ from pathlib import Path from typing import TYPE_CHECKING, Any +from ..capabilities.progress_review.context import external_progress_review_context from ..control_plane.quota.effective_action import EffectiveAction from ..control_plane.quota.effect_program import SettlementIdentity from ..control_plane.quota.error_codes import HeartbeatReceiptIdentityConflictError @@ -384,6 +385,7 @@ def execute_quota_should_run( bounded_research_frontier_projector=export( "project_live_explore_composition_frontier" ), + progress_review_context_reader=external_progress_review_context, receipt_bound_todo_id=action_selection.receipt_bound_todo_id, requested_action_todo_id=action_selection.requested_todo_id_for_decision, receipt_bound_replan_obligation_id=( diff --git a/loopx/cli_commands/turn_decision.py b/loopx/cli_commands/turn_decision.py index edc067f02b..a1e1de678f 100644 --- a/loopx/cli_commands/turn_decision.py +++ b/loopx/cli_commands/turn_decision.py @@ -30,6 +30,7 @@ from ..capabilities.periodic_report.pending_intent import ( periodic_report_pending_intent_interaction_hook, ) +from ..capabilities.progress_review.context import external_progress_review_context from ..control_plane.quota.live_decision import build_live_quota_should_run_decision from ..control_plane.capability_hooks import TurnStartContextProjector from ..control_plane.quota.effective_action import EffectiveAction @@ -188,6 +189,7 @@ def build_turn_decision( bounded_research_frontier_projector=( project_live_explore_composition_frontier ), + progress_review_context_reader=external_progress_review_context, requested_action_todo_id=requested_action_todo_id, # Preserve ordinary Todo decision/context behavior. Only an # already bound empty-frontier replan needs this scoped reentry. @@ -385,6 +387,7 @@ def current_turn_host_launch_decision( scheduler_execution_context=scheduler_execution_context, operator_inbox_urgency_projector=operator_inbox_urgency_projector, bounded_research_frontier_projector=project_live_explore_composition_frontier, + progress_review_context_reader=external_progress_review_context, receipt_bound_todo_id=identity.todo_id or None, receipt_bound_replan_obligation_id=identity.replan_obligation_id, turn_instance_id=identity.turn_instance_id, @@ -482,6 +485,7 @@ def current_heartbeat_host_launch_decision( scheduler_execution_context=scheduler_execution_context_for_runtime_profile("generic_cli"), operator_inbox_urgency_projector=build_lark_operator_inbox_urgency_projector(runtime_root_arg=runtime_root), bounded_research_frontier_projector=project_live_explore_composition_frontier, + progress_review_context_reader=external_progress_review_context, receipt_bound_todo_id=selection.receipt_bound_todo_id, receipt_bound_replan_obligation_id=selection.receipt_bound_replan_obligation_id, retained_action_selection_todo_id=selection.retained_todo_id_for_decision, diff --git a/loopx/control_plane/quota/live_decision.py b/loopx/control_plane/quota/live_decision.py index 96aabb2a72..f3985881a6 100644 --- a/loopx/control_plane/quota/live_decision.py +++ b/loopx/control_plane/quota/live_decision.py @@ -53,6 +53,7 @@ HostObservationResolver = Callable[..., Mapping[str, Any]] BoundedResearchFrontierProjector = Callable[..., Mapping[str, Any] | None] +ProgressReviewContextReader = Callable[[Mapping[str, Any], Path], dict[str, Any] | None] def _receipt_bound_guard_fields( @@ -676,12 +677,10 @@ def _restore_replan_obligation_without_foreign_acks( registry_goal: Mapping[str, Any] | None, registry_path: Path, runtime_root: Path, + progress_review_context_reader: ProgressReviewContextReader | None, ) -> 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 ..status.autonomous_replan_projection import autonomous_replan_obligation_from_runs 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 @@ -739,7 +738,10 @@ def _restore_replan_obligation_without_foreign_acks( 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) + review = ( + progress_review_context_reader(source_goal, runtime_root) + if progress_review_context_reader is not None else None + ) cadence_goal_ref = dict(goal_ref) if isinstance(goal_ref, Mapping) else None attach_active_state_project_asset_fields( item, latest_runs=filtered, @@ -773,6 +775,7 @@ def build_live_quota_should_run_decision( | None = None, operator_inbox_urgency_projector: Callable[..., dict[str, Any]] | None = None, bounded_research_frontier_projector: BoundedResearchFrontierProjector | None = None, + progress_review_context_reader: ProgressReviewContextReader | None = None, receipt_bound_todo_id: str | None = None, requested_action_todo_id: str | None = None, receipt_bound_replan_obligation_id: str | None = None, @@ -894,6 +897,7 @@ def build_live_quota_should_run_decision( _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, + progress_review_context_reader=progress_review_context_reader, ) fresh_operator_inbox_read = _fresh_operator_inbox_read_required( turn_start_hook_dispatch