fix: send last DAG_STATUS on WebSocket connect instead of skipping all

Previously all DAG_STATUS events were skipped during historical replay
on WS connect, so reconnecting clients (React strict mode remount,
page navigation) lost current DAG state. Now sends only the most
recent DAG_STATUS event on connect.
This commit is contained in:
Igor Loskutov
2026-02-09 15:26:59 -05:00
parent 499de45fdb
commit b1eeb651f6

View File

@@ -41,13 +41,19 @@ async def transcript_events_websocket(
try: try:
# on first connection, send all events only to the current user # on first connection, send all events only to the current user
# Find the last DAG_STATUS to send after other historical events
last_dag_status = None
for event in transcript.events: for event in transcript.events:
# for now, do not send TRANSCRIPT or STATUS options - theses are live event
# not necessary to be sent to the client; but keep the rest
name = event.event name = event.event
if name in ("TRANSCRIPT", "STATUS", "DAG_STATUS"): if name in ("TRANSCRIPT", "STATUS"):
continue
if name == "DAG_STATUS":
last_dag_status = event
continue continue
await websocket.send_json(event.model_dump(mode="json")) await websocket.send_json(event.model_dump(mode="json"))
# Send only the most recent DAG_STATUS so reconnecting clients get current state
if last_dag_status is not None:
await websocket.send_json(last_dag_status.model_dump(mode="json"))
# XXX if transcript is final (locked=True and status=ended) # XXX if transcript is final (locked=True and status=ended)
# XXX send a final event to the client and close the connection # XXX send a final event to the client and close the connection