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
@@ -140,7 +140,8 @@ async def test_legacy_run_identity_is_captured_before_the_first_move(tmp_path):
|
||||
cron.stop()
|
||||
|
||||
|
||||
def test_target_identity_scope_and_channel_lifecycle(tmp_path):
|
||||
@pytest.mark.asyncio
|
||||
async def test_target_identity_scope_and_channel_lifecycle(tmp_path):
|
||||
sessions, _, job = seed(tmp_path)
|
||||
(tmp_path / "other").mkdir()
|
||||
workspaces = WebUIWorkspaceController(session_manager=sessions,
|
||||
@@ -154,41 +155,40 @@ def test_target_identity_scope_and_channel_lifecycle(tmp_path):
|
||||
session = sessions.get_or_create(key)
|
||||
session.metadata.update(metadata)
|
||||
sessions.save(session)
|
||||
chats = automation_chats(job, sessions, workspaces, {"telegram": {"running": True}})
|
||||
chats = await automation_chats(job, sessions, workspaces, {"telegram": {"running": True}})
|
||||
assert {chat.binding.session_key for chat in chats} == {"websocket:source", "telegram:-100:topic:42"}
|
||||
target = next(chat for chat in chats if chat.title == "Product team")
|
||||
assert target.binding == target_binding()
|
||||
assert set(target.public_payload()) == {"id", "title", "channel"}
|
||||
assert "-100" not in json.dumps(target.public_payload())
|
||||
assert len(automation_chats(job, sessions, workspaces, {})) == 1
|
||||
assert len(await automation_chats(job, sessions, workspaces, {})) == 1
|
||||
job.payload.session_key = "telegram:-100:topic:42"
|
||||
job.payload.origin_channel = "telegram"
|
||||
job.payload.origin_chat_id = "-100"
|
||||
offline = automation_chats(job, sessions, workspaces, {})
|
||||
offline = await automation_chats(job, sessions, workspaces, {})
|
||||
current = next(chat for chat in offline if chat.title == "Product team")
|
||||
assert current.public_payload()["unavailable"] is True
|
||||
# Only identical display names need a visible disambiguator.
|
||||
session = sessions.get_or_create("websocket:source")
|
||||
session.metadata["title"] = "Product team"
|
||||
sessions.save(session)
|
||||
duplicates = automation_chats(job, sessions, workspaces, {})
|
||||
await sessions.state.update_metadata(session.key, {"title": "Product team"})
|
||||
duplicates = await automation_chats(job, sessions, workspaces, {})
|
||||
assert len({chat.title for chat in duplicates}) == 2
|
||||
assert all(" · @" in chat.title for chat in duplicates)
|
||||
|
||||
|
||||
def test_untitled_chat_uses_message_preview_until_renamed(tmp_path):
|
||||
@pytest.mark.asyncio
|
||||
async def test_untitled_chat_uses_message_preview_until_renamed(tmp_path):
|
||||
sessions, _, job = seed(tmp_path)
|
||||
chat = sessions.get_or_create("websocket:reminder")
|
||||
chat.add_message("user", "十分钟后提醒我喝水")
|
||||
sessions.save(chat)
|
||||
workspaces = WebUIWorkspaceController(session_manager=sessions,
|
||||
default_workspace=tmp_path / "workspace", default_restrict_to_workspace=False)
|
||||
chats = automation_chats(job, sessions, workspaces, {})
|
||||
chats = await automation_chats(job, sessions, workspaces, {})
|
||||
choice = next(item for item in chats if item.binding.session_key == chat.key)
|
||||
assert choice.public_payload()["title"] == "十分钟后提醒我喝水"
|
||||
chat.metadata.update(title="My reminders", title_user_edited=True)
|
||||
sessions.save(chat)
|
||||
renamed = next(item for item in automation_chats(job, sessions, workspaces, {})
|
||||
await sessions.state.update_metadata(chat.key, {"title": "My reminders", "title_user_edited": True})
|
||||
renamed = next(item for item in await automation_chats(job, sessions, workspaces, {})
|
||||
if item.binding.session_key == chat.key)
|
||||
assert renamed.id == choice.id
|
||||
assert renamed.title == "My reminders"
|
||||
|
||||
Reference in new issue
Block a user