refactor(session): unify model and display history storage (#6336)

* refactor(session): persist display history in SQLite

* fix(session): preserve new fork activity timestamps

* test(agent): use SQLite-owned model failure recovery fixture

* test(agent): isolate session slash routing from loop shutdown

Exercise the real inbound dispatcher and await its session worker. Keep response deadlines and behavioral assertions, while leaving full SQLite cleanup to the existing async fixture rather than an unrelated two-second shutdown deadline.

* fix(webui): admit direct deliveries to display history

* docs: clarify session history migration guidance
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-21 16:13:59 +08:00
1 parent d617b723aa
commit b32b1327ce
50 files changed
+2123 -3235

No files matched your search

+20 -6
View File
@@ -83,14 +83,26 @@ async def _deliver_to_channel(
if session_generation is not None
else raw_generation if isinstance(raw_generation, str) else None
)
key = session_key or (raw_key if isinstance(raw_key, str) else None)
if key is None:
key = session_key_for_channel(
msg.channel, msg.chat_id, unified_session=unified_session,
)
if msg.channel == "websocket":
from nanobot.agent.turn_delivery import TurnRoute
from nanobot.session.display_history import HISTORY_GENERATION_METADATA_KEY
from nanobot.session.webui_turns import WebuiTurnRoutePolicy
from nanobot.webui.session_identity import webui_session_key
route = await WebuiTurnRoutePolicy(session_manager).admit(
TurnRoute(msg.channel, msg.chat_id, metadata), key, expected_generation,
)
metadata = route.metadata
if key == webui_session_key(msg.chat_id):
expected_generation = cast(str, metadata[HISTORY_GENERATION_METADATA_KEY])
if metadata != (msg.metadata or {}):
msg = replace(msg, metadata=metadata)
if record and msg.channel != "cli" and msg.content.strip():
key = session_key or (raw_key if isinstance(raw_key, str) else None)
if key is None:
key = session_key_for_channel(
msg.channel, msg.chat_id, unified_session=unified_session,
)
if expected_generation is None:
# Cross-target sends admit their target before recording; subsequent
# deletion or reset must still revoke this delivery's generation.
@@ -525,9 +537,11 @@ def _run_gateway(
cron = CronService(cron_store_path)
trigger_store = LocalTriggerStore(config.workspace_path)
webui_route_policy = WebuiTurnRoutePolicy(session_manager)
turn_delivery_factory = TurnDeliveryFactory(
bus,
route_policy=WebuiTurnRoutePolicy(session_manager),
route_policy=webui_route_policy,
route_admission=webui_route_policy.admit,
)
tools = ToolRegistry()