fix: gateway sync race condition + hybrid session data loss — v0.50.93 (PR #714)

Fixes and extends PR #676 (yunyunyunyun-yun). Race guard in sessions.js SSE handler; prefix-equality check in routes.py _handle_session_import_cli. Closes #676.

Co-authored-by: yunyunyunyun-yun <yunyunyunyun-yun@users.noreply.github.com>
This commit is contained in:
nesquena-hermes
2026-04-18 23:18:28 -07:00
committed by GitHub
parent 877a32f49c
commit 66fbfbaa2b
3 changed files with 38 additions and 1 deletions

View File

@@ -2869,9 +2869,17 @@ def _handle_session_import_cli(handler, body):
sid = str(body["session_id"])
# Check if already imported — idempotent
# Check if already imported — refresh messages from CLI store if new ones arrived
existing = Session.load(sid)
if existing:
fresh_msgs = get_cli_session_messages(sid)
if fresh_msgs and len(fresh_msgs) > len(existing.messages):
# Prefix-equality guard: only extend if existing messages are a prefix of
# the fresh CLI messages. Prevents silently dropping WebUI-added messages
# on hybrid sessions (user sent messages via WebUI while CLI continued).
if existing.messages == fresh_msgs[:len(existing.messages)]:
existing.messages = fresh_msgs
existing.save(touch_updated_at=False)
return j(
handler,
{