From e5f7567a9348360cfd5a76e163ee11652d3afa8e Mon Sep 17 00:00:00 2001 From: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:53:09 +0800 Subject: [PATCH] Keep quota replan recovery inside control-plane boundaries Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com> --- loopx/cli_commands/quota.py | 2 +- loopx/cli_commands/quota_scheduler_followup.py | 2 ++ loopx/cli_commands/quota_should_run.py | 9 +++++++-- loopx/cli_commands/turn_decision.py | 9 ++++++++- loopx/control_plane/quota/live_decision.py | 14 +++++++++----- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/loopx/cli_commands/quota.py b/loopx/cli_commands/quota.py index 22985998b1..3063a762fc 100644 --- a/loopx/cli_commands/quota.py +++ b/loopx/cli_commands/quota.py @@ -64,7 +64,7 @@ "spend_quota_slot", "void_quota_slot", ), - "loopx.status": ("collect_status",), + "loopx.status": ("collect_status", "external_progress_review_context"), "loopx.upgrade": ("resolve_codex_app_automation_rrule",), "loopx.cli_commands.lark_inbox": ( "build_lark_operator_inbox_urgency_projector", diff --git a/loopx/cli_commands/quota_scheduler_followup.py b/loopx/cli_commands/quota_scheduler_followup.py index 8772c91299..08fcd08c33 100644 --- a/loopx/cli_commands/quota_scheduler_followup.py +++ b/loopx/cli_commands/quota_scheduler_followup.py @@ -26,6 +26,7 @@ resolve_scheduler_execution_context, ) from ..quota import record_quota_scheduler_ack +from ..status import external_progress_review_context from ..upgrade import resolve_codex_app_automation_rrule @@ -71,6 +72,7 @@ def _build_scheduler_followup_decision( bounded_research_frontier_projector=project_live_explore_composition_frontier, receipt_bound_todo_id=receipt_todo_id, receipt_bound_replan_obligation_id=receipt_replan_id, + external_progress_review_loader=external_progress_review_context, turn_instance_id=turn_instance_id, interaction_projection_hooks=( repository_delivery_interaction_hook(repo_path=Path.cwd()), diff --git a/loopx/cli_commands/quota_should_run.py b/loopx/cli_commands/quota_should_run.py index dd79c10c7a..9e1bea58ba 100644 --- a/loopx/cli_commands/quota_should_run.py +++ b/loopx/cli_commands/quota_should_run.py @@ -5,6 +5,7 @@ import argparse from collections.abc import Callable, Mapping from dataclasses import dataclass, field +from functools import partial from pathlib import Path from typing import TYPE_CHECKING, Any @@ -367,7 +368,11 @@ def execute_quota_should_run( todo_id=args.todo_id, ) complete_context = not getattr(args, "scheduler_observation", False) - payload = export("build_live_quota_should_run_decision")( + decision_builder = partial( + export("build_live_quota_should_run_decision"), + external_progress_review_loader=export("external_progress_review_context"), + ) + payload = decision_builder( status_payload, goal_id=args.goal_id, agent_id=args.agent_id, @@ -482,7 +487,7 @@ def execute_quota_should_run( find_monitor_poll_turn=export("find_quota_monitor_poll_turn"), monitor_poll_recorder=export("record_quota_monitor_poll"), status_collector=export("collect_status"), - decision_builder=export("build_live_quota_should_run_decision"), + decision_builder=decision_builder, host_observation_resolver=export("resolve_codex_app_automation_rrule"), ) execution.heartbeat_receipt_ready = True diff --git a/loopx/cli_commands/turn_decision.py b/loopx/cli_commands/turn_decision.py index edc067f02b..102a5de13b 100644 --- a/loopx/cli_commands/turn_decision.py +++ b/loopx/cli_commands/turn_decision.py @@ -48,7 +48,11 @@ SchedulerExecutionContextResolution, scheduler_execution_context_for_turn, ) -from ..status import AUTONOMOUS_REPLAN_PERIODIC_LOOKBACK, collect_status +from ..status import ( + AUTONOMOUS_REPLAN_PERIODIC_LOOKBACK, + collect_status, + external_progress_review_context, +) from ..control_plane.effect_runtime import effect_runtime_result from ..control_plane.work_items.autonomous_replan_obligation import replan_obligation_id_from_packet from .lark_inbox import build_lark_operator_inbox_urgency_projector @@ -192,6 +196,7 @@ def build_turn_decision( # Preserve ordinary Todo decision/context behavior. Only an # already bound empty-frontier replan needs this scoped reentry. receipt_bound_replan_obligation_id=bound_replan, + external_progress_review_loader=external_progress_review_context, turn_instance_id=turn_instance_id if bound_replan else None, turn_start_hook_dispatch=dict(turn_start_hook_dispatch or {}), turn_context_projector=turn_context_projector, @@ -387,6 +392,7 @@ def current_turn_host_launch_decision( bounded_research_frontier_projector=project_live_explore_composition_frontier, receipt_bound_todo_id=identity.todo_id or None, receipt_bound_replan_obligation_id=identity.replan_obligation_id, + external_progress_review_loader=external_progress_review_context, turn_instance_id=identity.turn_instance_id, turn_start_hook_dispatch=turn_start_hook_dispatch, workspace_path=Path(args.project).expanduser().resolve(), goal_ref=goal_ref, @@ -484,6 +490,7 @@ def current_heartbeat_host_launch_decision( bounded_research_frontier_projector=project_live_explore_composition_frontier, receipt_bound_todo_id=selection.receipt_bound_todo_id, receipt_bound_replan_obligation_id=selection.receipt_bound_replan_obligation_id, + external_progress_review_loader=external_progress_review_context, retained_action_selection_todo_id=selection.retained_todo_id_for_decision, turn_instance_id=original_turn, workspace_path=project, goal_ref=goal_ref, interaction_projection_hooks=(periodic_report_pending_intent_interaction_hook( diff --git a/loopx/control_plane/quota/live_decision.py b/loopx/control_plane/quota/live_decision.py index 96aabb2a72..eb72f498d7 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] +ExternalProgressReviewLoader = Callable[[dict[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, + external_progress_review_loader: ExternalProgressReviewLoader | 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 = ( + external_progress_review_loader(source_goal, runtime_root) + if external_progress_review_loader 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, + external_progress_review_loader: ExternalProgressReviewLoader | 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, + external_progress_review_loader=external_progress_review_loader, ) fresh_operator_inbox_read = _fresh_operator_inbox_read_required( turn_start_hook_dispatch