Skip to content

Add widget comm state sync for multi-window support#293

Merged
rgbkrk merged 4 commits intomainfrom
widget-comm-sync
Feb 27, 2026
Merged

Add widget comm state sync for multi-window support#293
rgbkrk merged 4 commits intomainfrom
widget-comm-sync

Conversation

@rgbkrk
Copy link
Copy Markdown
Member

@rgbkrk rgbkrk commented Feb 27, 2026

Summary

Track active comm channels in daemon and send CommSync broadcast to newly connected clients, enabling widget reconstruction in secondary windows.

Fixes #276

Changes

  • Add CommState module for tracking comm_open/msg/close messages
  • Wire CommState into NotebookRoom and kernel manager's iopub handler
  • Send CommSync broadcast after initial Automerge sync on client connect
  • Handle comm_sync in frontend to synthesize comm_open messages for widget store
  • Clear comm state on kernel shutdown

Known Limitations (WIP)

  • Third window opened after execution may not receive comm_sync (needs investigation - may be timing issue with broadcast delivery)
  • Widget state not synced in real-time between windows (by design - avoids feedback loops during slider drag)
  • Buffer paths not fully reconstructed - binary widget state may not hydrate correctly
  • Replay order nondeterministic (HashMap iteration) - model dependencies may not resolve correctly

Test plan

  • Unit tests for CommState (open, update, close, clear, buffers)
  • Protocol test for CommSync serialization
  • Manual test: open notebook, create widget, open second window
  • Manual test: open third window after widget creation
  • E2E test for multi-window widget sync

Co-authored-by: QuillAid 261289082+quillaid@users.noreply.github.com

rgbkrk and others added 4 commits February 26, 2026 18:16
Track active comm channels in daemon and send CommSync broadcast to newly
connected clients, enabling widget reconstruction in secondary windows.

- Add CommState module for tracking comm_open/msg/close
- Wire CommState into NotebookRoom and kernel manager
- Send CommSync after initial Automerge sync on client connect
- Handle comm_sync in frontend to synthesize comm_open messages
- Clear comm state on kernel shutdown

Known limitations:
- Third window opened after execution may not receive comm_sync (needs investigation)
- Widget state not synced in real-time (by design - avoids feedback loops)
- Buffer paths not fully reconstructed (Codex review finding #1)
- Replay order nondeterministic (Codex review finding #2)

Closes #276

Co-Authored-By: QuillAid <261289082+quillaid@users.noreply.github.com>
- Use sequence numbers for deterministic comm replay order (finding #2)
  Widget models can reference other widgets via IPY_MODEL_. Returning comms
  in insertion order ensures dependencies are created before dependents.

- Clear comm state when launching new kernel (finding #3)
  If a kernel crashes without proper shutdown, stale comm snapshots could
  persist. Now cleared on new kernel launch, not just explicit shutdown.

Co-Authored-By: QuillAid <261289082+quillaid@users.noreply.github.com>
Previously, failed deserializations during init were silently ignored.
Now logs a warning with the error and payload size to help diagnose
issues like comm_sync not being received.

Co-Authored-By: QuillAid <261289082+quillaid@users.noreply.github.com>
Helps diagnose third window widget sync issue by logging:
- When comm_sync event is received
- Whether onCommMessage handler is available
- Unknown broadcast event types

Co-Authored-By: QuillAid <261289082+quillaid@users.noreply.github.com>
@rgbkrk rgbkrk marked this pull request as ready for review February 27, 2026 02:28
@rgbkrk rgbkrk merged commit 7f89b30 into main Feb 27, 2026
4 of 5 checks passed
@rgbkrk rgbkrk deleted the widget-comm-sync branch February 27, 2026 02:28
@rgbkrk rgbkrk added daemon runtimed daemon, kernel management, sync server ipywidgets Widget rendering, comm protocol, Output widgets frontend Webview, React, TypeScript UI test Test infrastructure and coverage labels Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

daemon runtimed daemon, kernel management, sync server frontend Webview, React, TypeScript UI ipywidgets Widget rendering, comm protocol, Output widgets test Test infrastructure and coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Widget state not synced across multiple windows in daemon mode

1 participant