fix(webui): preserve cross-session provenance at display persistence (#6379)

* fix(session): bind internal input identity before acceptance

* fix(webui): bind cross-session display writes at persistence boundary

* fix(webui): simplify session messages to current-target display writes

* chore: trim redundant session message comments
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 01:24:18 +08:00
1 parent b37a23698d
commit d5cf09d738
7 files changed
+107 -11

No files matched your search

+2 -2
View File
@@ -456,12 +456,12 @@ class SqliteSessionStore:
return project(HistoryReader(db, key, self.path))
def append_history(
self, key: str, facts: list[HistoryFact], *, expected_generation: str,
self, key: str, facts: list[HistoryFact], *, expected_generation: str | None,
) -> None:
encoded = [(fact, fact.encode()) for fact in facts]
with self.transaction() as db:
row = db.execute("SELECT generation FROM sessions WHERE key=?", (key,)).fetchone()
if row is None or row[0] != expected_generation:
if row is None or (expected_generation is not None and row[0] != expected_generation):
raise SessionConflictError("history belongs to a deleted or replaced session")
db.execute("INSERT OR IGNORE INTO history_heads (session_key) VALUES (?)", (key,))
tail = db.execute(
+2 -1
View File
@@ -715,8 +715,9 @@ class SessionState:
)
async def append_history(
self, key: str, facts: Sequence[HistoryFact], *, expected_generation: str,
self, key: str, facts: Sequence[HistoryFact], *, expected_generation: str | None,
) -> None:
"""Append to an existing session; None selects its current generation."""
records = list(facts)
await self._execute(
key,
+2 -3
View File
@@ -678,20 +678,19 @@ class WebuiTurnCoordinator:
return
public_metadata = _session_message_public_metadata(envelope)
try:
assert event.context.session_generation is not None
await append_session_message_input(
session_key,
sessions=self.sessions,
expected_generation=event.context.session_generation,
content=event.content,
created_at_ms=envelope["created_at_ms"],
session_message=public_metadata,
)
except (OSError, TypeError, ValueError):
except (OSError, TypeError, ValueError, SessionConflictError):
logger.opt(exception=True).warning(
"Failed to persist session input {}",
envelope["message_id"],
)
return
await self.bus.publish_outbound(outbound_message_for_event(
channel="websocket",
chat_id=session_key.split(":", 1)[1],
+2 -2
View File
@@ -486,7 +486,7 @@ def append_transcript_object(
async def append_session_message_input(
session_key: str, *, sessions: SessionManager, content: str, created_at_ms: int,
session_message: Mapping[str, Any], expected_generation: str,
session_message: Mapping[str, Any],
) -> None:
chat_id = _chat_id_from_session_key(session_key)
if chat_id is None:
@@ -496,7 +496,7 @@ async def append_session_message_input(
return
event.update(created_at_ms=created_at_ms, session_message=dict(session_message))
await sessions.state.append_history(session_key, [fact_from_record(event)],
expected_generation=expected_generation)
expected_generation=None)
def normalize_webui_turn_id(value: Any) -> str: