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
@@ -383,10 +383,10 @@ async def test_workspace_inspection_reaches_model_from_selected_chat(tmp_path: P
|
||||
]),
|
||||
LLMResponse(content="done", tool_calls=[]),
|
||||
])
|
||||
session = loop.sessions.get_or_create("websocket:inspection")
|
||||
session.metadata["workspace_scope"] = {
|
||||
session = await loop.sessions.state.get("websocket:inspection")
|
||||
await loop.sessions.state.update_metadata(session.key, {"workspace_scope": {
|
||||
"project_path": str(project), "access_mode": "restricted",
|
||||
}
|
||||
}})
|
||||
|
||||
response = await loop.process_direct(
|
||||
"Check the current directory and read marker.txt",
|
||||
@@ -475,9 +475,11 @@ async def test_access_changes_refresh_only_new_message_and_preserve_prefix(tmp_p
|
||||
provider = loop.provider
|
||||
provider.generation = GenerationSettings()
|
||||
provider.chat_stream_with_retry = AsyncMock(return_value=LLMResponse(content="done"))
|
||||
session = loop.sessions.get_or_create("websocket:scope-changes")
|
||||
session = await loop.sessions.state.get("websocket:scope-changes")
|
||||
for root, mode in [(project, "restricted"), (project, "full"), (other, "restricted")]:
|
||||
session.metadata["workspace_scope"] = {"project_path": str(root), "access_mode": mode}
|
||||
await loop.sessions.state.update_metadata(session.key, {"workspace_scope": {
|
||||
"project_path": str(root), "access_mode": mode,
|
||||
}})
|
||||
await loop.process_direct(
|
||||
"Check access", channel="websocket", chat_id="scope-changes", session_key=session.key,
|
||||
)
|
||||
@@ -497,9 +499,10 @@ async def test_access_changes_refresh_only_new_message_and_preserve_prefix(tmp_p
|
||||
assert {key: value for key, value in before.items() if key != "messages"} == {
|
||||
key: value for key, value in after.items() if key != "messages"
|
||||
}
|
||||
assert all(message["content"] == "Check access" for message in session.get_history(
|
||||
session = await loop.sessions.state.get(session.key)
|
||||
assert [message["content"] for message in session.get_history(
|
||||
include_runtime_context=False,
|
||||
) if message["role"] == "user")
|
||||
) if message["role"] == "user"] == ["Check access"] * 3
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -515,12 +518,14 @@ async def test_injected_channel_input_reports_active_tool_scope(tmp_path: Path)
|
||||
]),
|
||||
LLMResponse(content="done"),
|
||||
])
|
||||
session = loop.sessions.get_or_create(UNIFIED_SESSION_KEY)
|
||||
session = await loop.sessions.state.get(UNIFIED_SESSION_KEY)
|
||||
session.metadata["workspace_scope"] = {"project_path": str(project), "access_mode": "restricted"}
|
||||
session.add_message("user", "Start")
|
||||
await loop.sessions.state.prepare_input(session)
|
||||
pending = asyncio.Queue()
|
||||
await pending.put(InboundMessage("telegram", "user", "chat", "Read marker.txt"))
|
||||
await loop._run_agent_loop(
|
||||
TranscriptInput(history=[{"role": "user", "content": "Start"}], current_message=None),
|
||||
TranscriptInput(history=session.get_history(), current_message=None),
|
||||
runtime=loop.llm_runtime(), session=session, pending_queue=pending,
|
||||
request_context=RequestContext("websocket", "chat", session_key=session.key),
|
||||
)
|
||||
@@ -648,6 +653,8 @@ async def test_subagent_check_is_session_scoped(tmp_path, single_task, runtime):
|
||||
loop = _make_loop(tmp_path)
|
||||
manager = loop.subagents
|
||||
# Queued tasks must be scoped before their runner starts.
|
||||
for _ in range(manager.max_concurrent_subagents):
|
||||
await manager._run_slots.acquire()
|
||||
await manager.spawn("ALPHA_PRIVATE_TASK", label="ALPHA_LABEL", session_key="owner:a", runtime=runtime)
|
||||
await manager.spawn("BETA_PRIVATE_TASK", label="BETA_LABEL", session_key="owner:b", runtime=runtime)
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user