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

+12 -5
View File
@@ -11,6 +11,8 @@ from loguru import logger
from nanobot.bus.events import InboundMessage
from nanobot.session.manager import Session
from nanobot.session.message_metadata import persisted_message
from nanobot.session.session_messages import session_message_envelope, session_message_input
RUNTIME_CHECKPOINT_KEY = "runtime_checkpoint"
PENDING_USER_TURN_KEY = "pending_user_turn"
@@ -66,7 +68,7 @@ class RecoveryAdmission(Protocol):
def record_pending_followup(session: Session, message: InboundMessage) -> str | None:
"""Durably journal a WebUI follow-up before injecting it into a live turn."""
if message.channel != "websocket":
if message.channel != "websocket" and session_message_input(message) is None:
return None
try:
metadata_value: object = json.loads(json.dumps(message.metadata))
@@ -115,7 +117,7 @@ def pending_followups(session: Session) -> list[InboundMessage]:
sender_id = cast(object, record.get("sender_id"))
chat_id = cast(object, record.get("chat_id"))
content = cast(object, record.get("content"))
metadata = cast(object, record.get("metadata"))
metadata_value = cast(object, record.get("metadata"))
if (
not isinstance(followup_id, str)
or not followup_id
@@ -125,8 +127,9 @@ def pending_followups(session: Session) -> list[InboundMessage]:
or not chat_id
):
continue
if not isinstance(content, str) or not isinstance(metadata, dict):
if not isinstance(content, str) or not isinstance(metadata_value, dict):
continue
metadata = cast(dict[str, Any], metadata_value)
media_value = cast(object, record.get("media"))
media = (
[item for item in cast(list[object], media_value) if isinstance(item, str)]
@@ -136,15 +139,18 @@ def pending_followups(session: Session) -> list[InboundMessage]:
timestamp = record.get("timestamp")
# Older journals did not retain admission time; retain their existing recovery policy.
received_at = datetime.fromisoformat(timestamp) if isinstance(timestamp, str) else datetime.now()
envelope = session_message_envelope(metadata)
is_session_input = envelope is not None and envelope["target_session_key"] == session.key
messages.append(
InboundMessage(
channel="websocket",
channel="system" if is_session_input else "websocket",
input_role="user" if is_session_input else None,
sender_id=sender_id,
chat_id=chat_id,
content=content,
timestamp=received_at,
media=media,
metadata={**cast(dict[str, Any], metadata), PENDING_FOLLOWUP_ID_KEY: followup_id},
metadata={**metadata, PENDING_FOLLOWUP_ID_KEY: followup_id},
session_key_override=session.key,
require_existing_session=True,
)
@@ -378,6 +384,7 @@ def restore_runtime_checkpoint(session: Session) -> bool:
}
)
restored = [persisted_message(message) for message in restored]
overlap = 0
# Cumulative checkpoints contain only the delta after accepted input. The
# owner commits it and clears the checkpoint in one transaction, so none of