Revert "refactor: remove legacy history and proxy migrations (#6518)"

This reverts commit cb3ba45317.

Keep JSONL history and legacy proxy migration available throughout 0.4.x. Mark their removal for 0.5.0 in code and release guidance, preserving later context graph, archive and recovery changes.
This commit is contained in:
chengyongru authored and chengyongru committed 2026-11-06 10:58:10 +08:00
1 parent 3918ece17f
commit 812b92d734
47 files changed
+1932 -204

No files matched your search

+62 -3
View File
@@ -1,4 +1,5 @@
import asyncio
import hashlib
import json
import subprocess
import sys
@@ -30,6 +31,8 @@ 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
@@ -270,8 +273,7 @@ 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):
child_key = SubagentSessions.key(task_id)
before = sessions.project_history(child_key, lambda history: history.all_facts())
before = {file.name: file.read_bytes() for file in root.glob("*.jsonl")}
response = await gateway.http.dispatch(connection, Request(path, headers))
assert response.status_code == 200
thread = json.loads(response.body)
@@ -284,7 +286,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 sessions.project_history(child_key, lambda history: history.all_facts()) == before
assert {file.name: file.read_bytes() for file in root.glob("*.jsonl")} == before
return thread
assert (await assert_activity(gateway, connection, headers))["active_turn_id"]
@@ -849,6 +851,63 @@ 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")