refactor(session): centralize state ownership in SQLite (#5943)
* 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
This commit is contained in:
1 parent
33ff520d12
commit
8f6a5594fb
144 files changed
+8293
-4912
No files matched your search
+17
-15
@@ -124,8 +124,16 @@ class _EmptyGatewaySessionManager:
|
||||
def list_sessions(self) -> list[dict[str, object]]:
|
||||
return []
|
||||
|
||||
def flush_all(self) -> int:
|
||||
return 0
|
||||
def list_session_metadata(self) -> list[dict[str, object]]:
|
||||
return []
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return SimpleNamespace(
|
||||
list_sessions=AsyncMock(return_value=[]),
|
||||
record_delivery=AsyncMock(),
|
||||
aclose=AsyncMock(),
|
||||
)
|
||||
|
||||
|
||||
def test_gateway_signal_handler_first_signal_stops_and_second_forces() -> None:
|
||||
@@ -2157,7 +2165,7 @@ def test_heartbeat_empty_response_is_not_evaluated(
|
||||
bus.publish_outbound = AsyncMock()
|
||||
seen: dict[str, object] = {}
|
||||
|
||||
class _FakeSessionManager:
|
||||
class _FakeSessionManager(_EmptyGatewaySessionManager):
|
||||
def __init__(self, _workspace: Path) -> None:
|
||||
pass
|
||||
|
||||
@@ -3197,7 +3205,7 @@ def test_gateway_unbound_agent_cron_is_skipped(
|
||||
def add_message(self, role: str, content: str, **kwargs) -> None:
|
||||
self.messages.append({"role": role, "content": content, **kwargs})
|
||||
|
||||
class _FakeSessionManager:
|
||||
class _FakeSessionManager(_EmptyGatewaySessionManager):
|
||||
def __init__(self, _workspace: Path) -> None:
|
||||
self.session = _FakeSession()
|
||||
seen["session_manager"] = self
|
||||
@@ -3318,7 +3326,7 @@ def test_gateway_bound_cron_runs_as_session_turn(
|
||||
)
|
||||
monkeypatch.setattr("nanobot.bus.queue.MessageBus", lambda: bus)
|
||||
|
||||
class _FakeSessionManager:
|
||||
class _FakeSessionManager(_EmptyGatewaySessionManager):
|
||||
def __init__(self, _workspace: Path) -> None:
|
||||
pass
|
||||
|
||||
@@ -3533,7 +3541,7 @@ def test_gateway_local_trigger_queue_submits_agent_turns(
|
||||
class _FakeContext:
|
||||
memory = _FakeMemory()
|
||||
|
||||
class _FakeSessionManager:
|
||||
class _FakeSessionManager(_EmptyGatewaySessionManager):
|
||||
def flush_all(self) -> int:
|
||||
return 0
|
||||
|
||||
@@ -3833,7 +3841,7 @@ def test_gateway_health_endpoint_binds_and_serves_expected_responses(
|
||||
config.gateway.port = 18791
|
||||
captured: dict[str, object] = {}
|
||||
|
||||
class _FakeSessionManager:
|
||||
class _FakeSessionManager(_EmptyGatewaySessionManager):
|
||||
def flush_all(self) -> int:
|
||||
return 0
|
||||
|
||||
@@ -4036,7 +4044,7 @@ def test_gateway_agent_task_owns_initial_mcp_provider_close(
|
||||
config.gateway.port = 18791
|
||||
seen: dict[str, object] = {}
|
||||
|
||||
class _FakeSessionManager:
|
||||
class _FakeSessionManager(_EmptyGatewaySessionManager):
|
||||
def flush_all(self) -> int:
|
||||
return 0
|
||||
|
||||
@@ -4190,11 +4198,6 @@ def test_gateway_shutdown_event_exits_forever_runtime_tasks(
|
||||
channel_finished = asyncio.Event()
|
||||
channels_stopping = asyncio.Event()
|
||||
|
||||
class _FakeSessionManager:
|
||||
def flush_all(self) -> int:
|
||||
seen["sessions_flushed"] = True
|
||||
return 0
|
||||
|
||||
class _FakeAgentLoop(_GatewayAgentContractStub):
|
||||
@classmethod
|
||||
def from_config(cls, config, bus=None, **extra):
|
||||
@@ -4203,7 +4206,7 @@ def test_gateway_shutdown_event_exits_forever_runtime_tasks(
|
||||
def __init__(self, **_kwargs) -> None:
|
||||
self.model = "test-model"
|
||||
self.provider = object()
|
||||
self.sessions = _FakeSessionManager()
|
||||
self.sessions = _EmptyGatewaySessionManager()
|
||||
self.runtime_resolver = MagicMock()
|
||||
|
||||
def llm_runtime(self) -> None:
|
||||
@@ -4326,7 +4329,6 @@ def test_gateway_shutdown_event_exits_forever_runtime_tasks(
|
||||
assert seen["channel_task_cleaned_up"] is True
|
||||
assert seen["channels_stopped"] is True
|
||||
assert seen["cron_stopped"] is True
|
||||
assert seen["sessions_flushed"] is True
|
||||
assert seen["shutdown_handlers_restored"] is True
|
||||
if shutdown_signal is not None:
|
||||
assert seen["graceful_shutdown_requested"] is True
|
||||
|
||||
Reference in new issue
Block a user