refactor: remove legacy history and proxy migrations (#6518)
This commit is contained in:
1 parent
1c28b20c7e
commit
cb3ba45317
47 files changed
+207
-1925
No files matched your search
@@ -350,46 +350,6 @@ async def test_sidebar_allocates_handles_then_reads_during_pending_write(tmp_pat
|
||||
await state.aclose()
|
||||
|
||||
|
||||
def test_webui_session_list_fallback_time_when_missing(tmp_path: Path) -> None:
|
||||
legacy = tmp_path / "sessions"
|
||||
legacy.mkdir()
|
||||
path = legacy / "websocket_missing-time.jsonl"
|
||||
path.write_text(
|
||||
'{"_type": "metadata", "key": "websocket:missing-time"}\n'
|
||||
'{"_type": "message", "role": "user", "content": "hello"}\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
manager = SessionManager(tmp_path)
|
||||
|
||||
rows = list_webui_sessions(manager)
|
||||
assert len(rows) == 1
|
||||
assert rows[0]["key"] == "websocket:missing-time"
|
||||
assert rows[0]["created_at"] is not None
|
||||
assert rows[0]["updated_at"] is not None
|
||||
datetime.fromisoformat(rows[0]["created_at"])
|
||||
datetime.fromisoformat(rows[0]["updated_at"])
|
||||
|
||||
|
||||
def test_session_manager_list_sessions_fallback_time_when_missing(tmp_path: Path) -> None:
|
||||
legacy = tmp_path / "sessions"
|
||||
legacy.mkdir()
|
||||
path = legacy / "websocket_missing-time2.jsonl"
|
||||
path.write_text(
|
||||
'{"_type": "metadata", "key": "websocket:missing-time2"}\n'
|
||||
'{"_type": "message", "role": "user", "content": "hello"}\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
manager = SessionManager(tmp_path)
|
||||
|
||||
sessions = manager.list_sessions()
|
||||
assert len(sessions) == 1
|
||||
assert sessions[0]["key"] == "websocket:missing-time2"
|
||||
assert sessions[0]["created_at"] is not None
|
||||
assert sessions[0]["updated_at"] is not None
|
||||
datetime.fromisoformat(sessions[0]["created_at"])
|
||||
datetime.fromisoformat(sessions[0]["updated_at"])
|
||||
|
||||
|
||||
def test_sidebar_uses_durable_display_summary_and_filters_private_sessions(history):
|
||||
sessions = history.sessions
|
||||
sessions.types.register(SessionType("internal", needs_handle=False, public_history=False))
|
||||
|
||||
@@ -116,9 +116,7 @@ def test_session_mention_context_treats_titles_as_data() -> None:
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_session_mentions_do_not_isolate_workspaces(tmp_path, monkeypatch) -> None:
|
||||
webui_dir = tmp_path / "webui"
|
||||
monkeypatch.setattr("nanobot.webui.history.get_webui_dir", lambda: webui_dir)
|
||||
async def test_session_mentions_do_not_isolate_workspaces(tmp_path) -> None:
|
||||
manager = SessionManager(tmp_path)
|
||||
project_b = tmp_path / "b"
|
||||
project_b.mkdir()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""A restarted host replays task observations without recovering execution."""
|
||||
|
||||
import asyncio
|
||||
import hashlib
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -33,8 +32,6 @@ from nanobot.providers.base import (
|
||||
ProviderConversationState,
|
||||
ToolCallRequest,
|
||||
)
|
||||
from nanobot.session.jsonl_migration import WORKSPACE_BACKUP_DIR
|
||||
from nanobot.session.location import SessionLocation
|
||||
from nanobot.session.manager import SessionManager
|
||||
from nanobot.session.session_handles import SessionHandleResolver
|
||||
from nanobot.session.summary import SessionSummaryCheckpoint, is_summary_checkpoint
|
||||
@@ -271,7 +268,8 @@ async def test_child_activity_replays_real_tool_errors_and_file_diffs(tmp_path):
|
||||
path = f"/api/sessions/websocket%3Aparent/subagents/{task_id}/webui-thread"
|
||||
|
||||
async def assert_activity(gateway, connection, headers):
|
||||
before = {file.name: file.read_bytes() for file in root.glob("*.jsonl")}
|
||||
child_key = SubagentSessions.key(task_id)
|
||||
before = sessions.project_history(child_key, lambda history: history.all_facts())
|
||||
response = await gateway.http.dispatch(connection, Request(path, headers))
|
||||
assert response.status_code == 200
|
||||
thread = json.loads(response.body)
|
||||
@@ -284,7 +282,7 @@ async def test_child_activity_replays_real_tool_errors_and_file_diffs(tmp_path):
|
||||
assert "+after" in completed["diff"]["text"]
|
||||
assert "-before" in completed["diff"]["text"]
|
||||
assert (workspace / "example.txt").read_text(encoding="utf-8") == "after\n"
|
||||
assert {file.name: file.read_bytes() for file in root.glob("*.jsonl")} == before
|
||||
assert sessions.project_history(child_key, lambda history: history.all_facts()) == before
|
||||
return thread
|
||||
|
||||
assert (await assert_activity(gateway, connection, headers))["active_turn_id"]
|
||||
@@ -848,63 +846,6 @@ async def test_temporary_parent_never_persists_task_content(tmp_path, monkeypatc
|
||||
await manager.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_child_sessions_migrate_from_legacy_jsonl_and_reopen(tmp_path):
|
||||
workspace, root = tmp_path / "agent", tmp_path / "sessions"
|
||||
parent_key, task_id = "websocket:parent", "legacy-inspection"
|
||||
child_key = SubagentSessions.key(task_id)
|
||||
task_metadata = {
|
||||
"task_id": task_id, "owner": parent_key, "revision": 3,
|
||||
"label": "inspect", "task_description": "inspect", "state": "done", "phase": "done",
|
||||
"created_at": 1767225600.0, "completed_at": 1767225601.2, "elapsed_seconds": 1.2,
|
||||
"origin_turn_id": "turn-1", "iteration": 1, "result": "Verified", "stop_reason": "stop",
|
||||
}
|
||||
fixtures = {
|
||||
parent_key: [
|
||||
{"_type": "metadata", "key": parent_key, "metadata": {"webui": True},
|
||||
"created_at": "2026-01-01T00:00:00", "updated_at": "2026-01-01T00:00:00",
|
||||
"last_archived": 0},
|
||||
{"role": "user", "content": "Inspect config"},
|
||||
],
|
||||
child_key: [
|
||||
{"_type": "metadata", "key": child_key,
|
||||
"metadata": {SESSION_TYPE_KEY: SUBAGENT.name, PARENT_SESSION_KEY: parent_key,
|
||||
TASK_METADATA_KEY: task_metadata},
|
||||
"created_at": "2026-01-01T00:00:00", "updated_at": "2026-01-01T00:00:01.200000",
|
||||
"last_archived": 0},
|
||||
{"role": "user", "content": "inspect"},
|
||||
{"role": "assistant", "content": "Verified"},
|
||||
],
|
||||
}
|
||||
legacy = workspace / "sessions"
|
||||
legacy.mkdir(parents=True)
|
||||
for key, records in fixtures.items():
|
||||
(legacy / f"{SessionLocation.storage_key(key)}.jsonl").write_text(
|
||||
"\n".join(json.dumps(record) for record in records) + "\n", encoding="utf-8",
|
||||
)
|
||||
source_hashes = {path.name: hashlib.sha256(path.read_bytes()).hexdigest() for path in legacy.glob("*.jsonl")}
|
||||
|
||||
for _ in range(2):
|
||||
manager, sessions, _ = manager_with_storage(workspace, root)
|
||||
try:
|
||||
assert {row["key"] for row in sessions.list_sessions()} == set(fixtures)
|
||||
assert sessions.child_session_keys(parent_key) == [child_key]
|
||||
status = manager.check(task_id, parent_key)
|
||||
assert status.state == "done" and status.result == "Verified"
|
||||
assert status.origin_turn_id == "turn-1"
|
||||
assert manager.get_running_count() == 0
|
||||
for key, records in fixtures.items():
|
||||
restored = sessions.read_session_file(key)
|
||||
assert restored["metadata"] == records[0]["metadata"]
|
||||
assert restored["messages"] == records[1:]
|
||||
assert list(legacy.glob("*.jsonl")) == []
|
||||
backups = sessions.sessions_dir / WORKSPACE_BACKUP_DIR
|
||||
assert {path.name: hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
for path in backups.glob("*.jsonl")} == source_hashes
|
||||
finally:
|
||||
await manager.close()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_unreadable_task_history_is_not_an_empty_list(tmp_path):
|
||||
manager, sessions, runtime = manager_with_storage(tmp_path / "agent", tmp_path / "sessions")
|
||||
|
||||
Reference in new issue
Block a user