* fix(session): move persistence off event loop * refactor(session): isolate async persistence boundary * refactor(session): keep a single session manager * refactor(session): use stateless async adapters * fix(session): serialize local persistence without file-lock contention * refactor(session): own async persistence and snapshot commits * refactor(session): narrow persistence changes to async adapters * refactor(session): remove redundant async forwarding helpers * fix(command): offload compact session persistence * fix(session): adapt idle compaction to current main * fix(webui): offload session metadata persistence * refactor(session): centralize state ownership in SQLite * fix(session): skip storage for non-recoverable followups * test(webui): honor the full gateway event deadline * perf(session): persist incremental changes and reuse owner snapshots * test(agent): allow durable worker shutdown in burst test * fix(gateway): drain session storage on Windows console shutdown * fix(session): enforce bounded ownership and lifecycle-safe persistence * fix: reject unresolved home paths and stabilize platform tests * fix(session): preserve request context compatibility and owner-backed tests * docs: focus configuration guide on user-facing behavior * fix(session): adapt goal admission to async ownership after rebase * fix(session): integrate current gateway and subagent contracts * fix(session): align rebased workspace admission and async tests * fix(session): support compatible SQLite schema evolution * test(agent): use session owner in workspace context regressions * test: stabilize Windows lifecycle and browser checks * refactor(session): remove premature JSONL file export * ci: bound Windows full-suite worker concurrency * chore: remove session state refactor notes * fix(session): queue writes and retain worker connections * perf(webui): read detached metadata for session and task lists * perf(agent): bound prompt preparation and local token counting * docs: remove internal session storage guide * perf(session): skip archived transcripts during idle scans * fix(session): coordinate turns and isolate legacy session data Bind WebUI input generations to the execution session and serialize idle and SDK compaction with turns. Keep turn drafts through preparation so the latest channel route persists. Move imported workspace JSONL and checkpoints to durable private backups before gateway admission, resuming cleanup after interruptions. Remove committed child sessions when task creation is cancelled. Validation: focused Python and frontend regressions, Ruff, BasedPyright, import boundaries, WebUI build, and isolated gateway/browser flows. * fix(agent): keep cancellation hooks independent of prompt preparation * fix(session): preserve admission, delivery, and migration contracts * fix(agent): preserve cancellation settlement after rebase * fix(session): preserve request attribution through async ownership
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
"""Session-worker completion helpers for integration tests."""
|
|
|
|
import asyncio
|
|
import time
|
|
|
|
from nanobot.agent.loop import AgentLoop
|
|
from nanobot.agent.subagent_status import SubagentStatus
|
|
from nanobot.bus.events import InboundMessage
|
|
from nanobot.runtime_context import (
|
|
RUNTIME_CONTEXT_HISTORY_META,
|
|
RUNTIME_CONTEXT_MESSAGE_META,
|
|
public_history_message,
|
|
)
|
|
|
|
|
|
def visible_message(message: dict) -> dict:
|
|
"""Project raw runner or persisted messages without model-only context."""
|
|
marker = message.get("_meta", {}).get(RUNTIME_CONTEXT_MESSAGE_META)
|
|
if marker is not None:
|
|
message = {**message, RUNTIME_CONTEXT_HISTORY_META: marker}
|
|
return public_history_message(message)
|
|
|
|
|
|
async def save_completed_subagent(loop: AgentLoop, task_id: str, owner: str) -> None:
|
|
"""Persist the child that owns a synthetic completion notification."""
|
|
assert loop.subagents.sessions is not None
|
|
now = time.monotonic()
|
|
await loop.subagents.sessions.create(SubagentStatus(
|
|
task_id=task_id, label=task_id, task_description="Background work",
|
|
owner=owner, started_at=now, finished_at=now, completed_at=time.time(),
|
|
state="done", phase="done",
|
|
))
|
|
|
|
|
|
async def run_session(loop: AgentLoop, msg: InboundMessage) -> None:
|
|
"""Submit input and wait for its session worker to finish."""
|
|
(await loop._enqueue_session_message(msg))
|
|
await asyncio.gather(*loop._active_tasks[loop._effective_session_key(msg)])
|
|
|
|
|
|
def mock_session_manager(*_args, **_kwargs):
|
|
"""Model the asynchronous state boundary in scheduler-only unit tests."""
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
from nanobot.session.manager import Session, SessionManager
|
|
from nanobot.session.state import SessionState
|
|
|
|
manager = MagicMock(spec=SessionManager)
|
|
manager.get_or_create.side_effect = lambda key: Session(key=key)
|
|
manager.state = MagicMock(spec=SessionState)
|
|
manager.state.get = AsyncMock(side_effect=lambda key: manager.get_or_create(key))
|
|
manager.state.read = AsyncMock(return_value=None)
|
|
manager.state.read_metadata = AsyncMock(return_value=None)
|
|
manager.state.list_sessions = AsyncMock(return_value=[])
|
|
manager.state.peek.return_value = None
|
|
return manager
|