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

+1 -3
View File
@@ -1,14 +1,12 @@
import importlib
from nanobot.session import webui_turns
from nanobot.webui import thread_disk, transcript
from nanobot.webui import transcript
def test_legacy_webui_utils_imports_resolve_to_new_modules() -> None:
legacy_thread_disk = importlib.import_module("nanobot.utils.webui_thread_disk")
legacy_transcript = importlib.import_module("nanobot.utils.webui_transcript")
legacy_turn_helpers = importlib.import_module("nanobot.utils.webui_turn_helpers")
assert legacy_thread_disk.delete_webui_thread is thread_disk.delete_webui_thread
assert legacy_transcript.append_transcript_object is transcript.append_transcript_object
assert legacy_turn_helpers.mark_webui_session is webui_turns.mark_webui_session
-38
View File
@@ -1,38 +0,0 @@
"""Tests for WebUI on-disk cleanup (legacy JSON + transcript JSONL)."""
from __future__ import annotations
from nanobot.webui.thread_disk import delete_webui_thread, webui_thread_file_path
from nanobot.webui.transcript import (
append_transcript_object,
webui_transcript_path,
webui_transcript_segments_dir,
)
def test_delete_webui_thread_removes_legacy_json_and_transcript(tmp_path, monkeypatch) -> None:
monkeypatch.setattr("nanobot.config.paths.get_data_dir", lambda: tmp_path)
monkeypatch.setattr("nanobot.webui.transcript._MAX_TRANSCRIPT_FILE_BYTES", 520)
monkeypatch.setattr("nanobot.webui.transcript._ACTIVE_TRANSCRIPT_ROTATE_BYTES", 520)
monkeypatch.setattr("nanobot.webui.transcript._TARGET_ACTIVE_TRANSCRIPT_BYTES", 260)
key = "websocket:k1"
json_path = webui_thread_file_path(key)
json_path.parent.mkdir(parents=True, exist_ok=True)
json_path.write_text('{"x":1}', encoding="utf-8")
for idx in range(1, 5):
append_transcript_object(
key,
{"event": "user", "chat_id": "k1", "text": f"question {idx} " + ("x" * 24)},
)
append_transcript_object(
key,
{"event": "message", "chat_id": "k1", "text": f"answer {idx} " + ("y" * 24)},
)
append_transcript_object(key, {"event": "turn_end", "chat_id": "k1"})
assert webui_transcript_path(key).is_file()
assert webui_transcript_segments_dir(key).is_dir()
assert delete_webui_thread(key) is True
assert not json_path.is_file()
assert not webui_transcript_path(key).is_file()
assert not webui_transcript_segments_dir(key).exists()
assert delete_webui_thread(key) is False
File diff suppressed because it is too large. Load diff
+4 -2
View File
@@ -310,7 +310,7 @@ async def test_session_input_is_projected_by_the_webui_coordinator(
"source_session_key": "websocket:source",
"target_session_key": "websocket:target",
}
append_input = MagicMock()
append_input = AsyncMock()
monkeypatch.setattr(wth, "append_session_message_input", append_input)
coordinator = wth.WebuiTurnCoordinator(
bus=bus,
@@ -324,12 +324,14 @@ async def test_session_input_is_projected_by_the_webui_coordinator(
channel="system",
chat_id="websocket:target",
session_key="websocket:target",
session_generation=target_session.generation,
metadata={SESSION_MESSAGE_METADATA_KEY: envelope},
),
content="Review this",
))
append_input.assert_called_once()
append_input.assert_awaited_once()
assert append_input.await_args.kwargs["expected_generation"] == target_session.generation
outbound = bus.publish_outbound.await_args.args[0]
assert outbound.channel == "websocket"
assert outbound.chat_id == "target"