refactor(goal): sustain one ReAct run until the goal closes (#6538)

* refactor(goal): sustain one ReAct run until the goal closes

Keep active goals in the same runner beyond the ordinary iteration limit, with a final answer after successful closure. Remove cross-turn goal handoffs, continuation allowances and rollback bookkeeping while preserving input authorization, recovery, cancellation and terminal lifecycle ownership.

Contributes to NAN-392

Co-authored-by: chengyongru <chengyongru.ai@gmail.com>

* test(goal): consolidate sustained-run regression coverage

Retain lifecycle, history, usage, provider-state privacy and checkpoint cancellation assertions in the existing long-run scenarios. Remove duplicate smoke cases and parameter combinations that do not exercise distinct behavior; keep real Gateway, authorization and generation regressions.
This commit is contained in:
chengyongruandchengyongru authored and GitHub committed 2026-11-03 22:47:00 +08:00
1 parent 3545539128
commit 62c2ed4e7e
68 files changed
+2683 -1421

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
"""WebUI projection of persisted sustained-goal state."""
from __future__ import annotations
from typing import Any, Mapping
from nanobot.session.goal_state import goal_state_raw, parse_goal_state
_MAX_OBJECTIVE_WS = 600
def goal_state_ws_blob(metadata: Mapping[str, Any] | None) -> dict[str, Any]:
"""JSON-safe snapshot for WebSocket ``goal_state`` events (one chat_id per frame)."""
goal = parse_goal_state(goal_state_raw(metadata))
if isinstance(goal, dict) and goal.get("status") in {"active", "blocked"}:
status = str(goal.get("status"))
objective = str(goal.get("objective") or "").strip()
if len(objective) > _MAX_OBJECTIVE_WS:
objective = objective[:_MAX_OBJECTIVE_WS].rstrip() + "…"
summary = str(goal.get("ui_summary") or "").strip()[:120]
blob: dict[str, Any] = {"active": status == "active", "status": status}
if summary:
blob["ui_summary"] = summary
if objective:
blob["objective"] = objective
recap = str(goal.get("recap") or "").strip()[:240]
if recap:
blob["recap"] = recap
return blob
return {"active": False}
+2 -1
View File
@@ -16,7 +16,8 @@ from websockets.asyncio.server import ServerConnection
from nanobot.bus.events import INBOUND_META_LOCAL_MEDIA, INBOUND_META_USER_SHELL
from nanobot.channels.websocket.attachment_policy import validate_attachment_batch
from nanobot.channels.websocket.attachment_store import AttachmentUploadError
from nanobot.command.builtin import USER_SHELL_COMMAND, builtin_command_starts_agent_turn
from nanobot.command.application import builtin_command_starts_agent_turn
from nanobot.command.builtin import USER_SHELL_COMMAND
from nanobot.runtime_context import (
RUNTIME_CONTEXT_INPUT_META,
WEBUI_QUOTE_METADATA,
+6 -7
View File
@@ -6,11 +6,11 @@ from loguru import logger as default_logger
from nanobot.agent.subagent import SubagentControlError
from nanobot.providers.base import LLMUsage
from nanobot.session.goal_state import goal_state_ws_blob
from nanobot.session.model_selection import model_preset_from_metadata
from nanobot.session.recovery import recovery_state_from_metadata
from nanobot.session.state import SessionState
from nanobot.session.webui_turns import websocket_turn_id, websocket_turn_wall_started_at
from nanobot.webui.goal_state import goal_state_ws_blob
if TYPE_CHECKING:
from nanobot.agent.subagent import SubagentManager
@@ -98,16 +98,15 @@ class WebUISessionProjection:
return tuple(events)
async def persisted_goal_state(self, session_key: str) -> dict[str, Any] | None:
"""Return an actionable persisted goal state for reconnect hydration."""
"""Return the persisted goal snapshot, including an inactive state on reconnect."""
if self._sessions is None:
return None
snapshot = await self._sessions.state.read_metadata(session_key)
raw_metadata = snapshot.get("metadata") if snapshot is not None else None
metadata = cast(dict[str, Any], raw_metadata) if isinstance(raw_metadata, dict) else {}
goal_state = goal_state_ws_blob(metadata)
if not goal_state.get("active") and goal_state.get("status") != "blocked":
if snapshot is None:
return None
return goal_state
raw_metadata = snapshot.get("metadata")
metadata = cast(dict[str, Any], raw_metadata) if isinstance(raw_metadata, dict) else {}
return goal_state_ws_blob(metadata)
@staticmethod
def active_turn_status(chat_id: str) -> tuple[float, str | None] | None:
+1 -1
View File
@@ -11,7 +11,7 @@ from nanobot.bus.events import (
InboundMessage,
)
from nanobot.bus.queue import MessageBus
from nanobot.command.builtin import register_builtin_commands
from nanobot.command.application import register_builtin_commands
from nanobot.command.router import CommandRouter
from nanobot.security.workspace_access import WorkspaceScope
from nanobot.session.manager import SessionManager
+1 -1
View File
@@ -28,7 +28,7 @@ from websockets.http11 import Response
from nanobot.agent.subagent import SubagentControlError
from nanobot.agent.subagent_status import SubagentSessionError
from nanobot.command.builtin import builtin_command_palette
from nanobot.command.application import builtin_command_palette
from nanobot.cron.binding import CronBindingError, binding_revision
from nanobot.cron.session_turns import is_bound_cron_job
from nanobot.cron.types import CronJob, CronSchedule