fix(sessions): preserve cross-session input ownership and history (#6613)

* fix(webui): reconcile cross-session history by message ID

* fix(sessions): preserve target authority and input ownership

Resolve cross-session follow-ups through the target route, carry stable input IDs through admission and recovery, and associate live and replayed answers with the inputs actually consumed.

Keep ordinary input scope isolation and omit historical anomaly repair. Resolves NAN-430.

* fix(sessions): complete input identity integration across boundaries

Carry input identity explicitly in projected input events, keep runner annotations out of public history, and reuse the canonical WebUI session parser during recovery.

Type validated recovery metadata and align existing channel and subagent regressions with explicit response ownership. All nine failed compatibility cases and adjacent recovery coverage pass in a focused 58-test run.

* fix(sessions): unify input recording and block remote commands

* fix(webui): keep input ownership checks page-bounded

Look up referenced inputs through the existing identity index before invoking transcript backfill. Complete pages no longer scan the full prompt history, including answers whose inputs live on earlier pages.

Cover cold-cache pagination and cross-turn ownership in existing regressions. Focused pagination, replay and follow-up recovery checks: 88 passed.

* fix(webui): preserve response ownership during history replay

* fix: resolve strict typing in response replay

* fix: preserve continuation ownership during recovery

* test: diagnose stuck gateway asyncio shutdown

* test: retain gateway thread stack diagnostics

* test(webui): stabilize native autoscroll browser setup
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-11 10:46:44 +08:00
1 parent 0ce335bf12
commit 394a78e82d
51 files changed
+1412 -334

No files matched your search

+20 -11
View File
@@ -20,6 +20,7 @@ from nanobot.session.recovery import (
pending_followups,
record_pending_followup,
)
from nanobot.session.session_messages import SESSION_MESSAGE_METADATA_KEY
from nanobot.webui import history as history_module
from nanobot.webui.recovery import RecoveryActionError, RecoveryCoordinator
@@ -204,20 +205,21 @@ async def test_scan_loads_only_sessions_that_need_webui_recovery(
@pytest.mark.asyncio
async def test_live_turn_followup_survives_restart_until_it_is_committed(tmp_path: Path) -> None:
@pytest.mark.parametrize("cross_session", [False, True])
async def test_live_turn_followup_survives_restart_until_it_is_committed(tmp_path: Path, cross_session: bool) -> None:
sessions = SessionManager(tmp_path)
session = sessions.get_or_create("websocket:chat")
_persist(sessions, session)
followup_id = record_pending_followup(
session,
InboundMessage(
channel="websocket",
sender_id="user",
chat_id="chat",
content="also check the logs",
metadata={"webui": True},
),
metadata = {SESSION_MESSAGE_METADATA_KEY: {
"message_id": "source-message", "created_at_ms": 1, "expect_reply": False,
"source_handle": "luma", "source_session_key": "websocket:source", "target_session_key": session.key,
}} if cross_session else {"webui": True}
message = InboundMessage(
channel="system" if cross_session else "websocket", sender_id="session" if cross_session else "user",
chat_id=session.key if cross_session else "chat", content="/stop" if cross_session else "also check the logs", metadata=metadata,
session_key_override=session.key, input_role="user" if cross_session else None,
)
followup_id = record_pending_followup(session, message)
assert followup_id is not None
sessions.save(session)
@@ -225,9 +227,16 @@ async def test_live_turn_followup_survives_restart_until_it_is_committed(tmp_pat
await coordinator.scan()
queued = bus.inbound.get_nowait()
assert queued.content == "also check the logs"
assert (queued.channel, queued.content, queued.input_role, queued.timestamp) == (
message.channel, message.content, message.input_role, message.timestamp,
)
assert queued.session_key == session.key
assert queued.require_existing_session
if cross_session:
assert queued.metadata[SESSION_MESSAGE_METADATA_KEY] == metadata[SESSION_MESSAGE_METADATA_KEY]
assert queued.metadata["_recovery_followup_id"] == followup_id
restored = restarted.get_or_create("websocket:chat")
assert record_pending_followup(restored, queued) == followup_id
assert len(pending_followups(restored)) == 1
acknowledge_pending_followups(restored, [followup_id])