Skip to content

Support JupyterLab v4.6 (Jupyter YDoc v4)#264

Merged
dlqqq merged 6 commits into
jupyter-ai-contrib:mainfrom
dlqqq:20260701-jsd-ydoc-v4/jupyter-server-documents
Jul 8, 2026
Merged

Support JupyterLab v4.6 (Jupyter YDoc v4)#264
dlqqq merged 6 commits into
jupyter-ai-contrib:mainfrom
dlqqq:20260701-jsd-ydoc-v4/jupyter-server-documents

Conversation

@dlqqq

@dlqqq dlqqq commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Adds support for Jupyter YDoc v4 to Jupyter Server Documents, along with the Jupyter Collaboration v5 / JupyterLab 4.6 stack it depends on, and hardens the project against observer-related memory leaks introduced by that upgrade.

Description

Raised version ceilings to include jupyter_ydoc~=4.0, pycrdt~=0.14, and jupyter_collaboration~=5.0.0a0 across both the lab and server extension. Identified a memory leak regression introduced by pycrdt==0.14.0 (described in #270) and applied a workaround to ensure no memory leaks exist in JSD.

Testing

Added a comprehensive suite of tests that rigorously guard against future memory leak regressions — coverage across different observer levels (document, root shared type, and nested shared type), and rooms backed by every shared model (YFile, YNotebook, and YChat), asserting that consumers, rooms, and the shared models themselves are all garbage collected on teardown. CI now installs Jupyter Chat so the YChat cases run, and the E2E integration tests were updated to run against JupyterLab v4.6.

Closes #262

@dlqqq dlqqq added the enhancement New feature or request label Jul 1, 2026
Widen the @jupyter/ydoc (npm) and jupyter_ydoc (Python) dependency ranges
to accept v4 alongside v3, so the extension works on JupyterLab 4.6+, which
ships @jupyter/ydoc v4 as its shared singleton.

- package.json: @jupyter/ydoc "^2.1.3 || ^3.0.0" -> "^3.0.0 || ^4.0.0"
- package.json: pin @jupyter/ydoc to ^4.0.0 in resolutions so the dev/CI
  build dedupes to a single v4 copy (transitive @jupyterlab/* still declare
  ^3); ydoc is a webpack singleton at runtime so this is build-time only.
- pyproject.toml: jupyter_ydoc ">=3.0.0,<4.0.0" -> ">=3.0.0,<5.0.0"

Also removes the temporary 'jupyterlab<4.6' CI ceilings added to unblock
main, restoring 'jupyterlab>=4.0.0,<5' now that JSD supports ydoc v4.

Closes jupyter-ai-contrib#262
dlqqq added 3 commits July 7, 2026 12:46
pycrdt >=0.14 / yrs >=0.27 defers observer removal: dropping a
subscription only queues the callback for removal, drained lazily on
the next observe/transaction. On an idle room being torn down that drain
never happens, so observer callbacks -- bound methods capturing the
YRoom and its YDoc -- are never released, leaking the room.

- Add rooms/yroom_utils.drain_observer_removals(): forces the pending
  queue to drain across every shared type reachable from the doc.
- YRoom.stop(): fire on_stop callbacks first, then drain observers only
  after all callbacks (incl. async ones, now awaited) have completed, so
  consumers that unsubscribe from a stop callback are covered. Draining
  runs in a scheduled _finalize_stop task awaited by until_saved; stop()
  stays synchronous.
- Bump requires-python to >=3.10.
- Tests: test_yroom_utils.py (drain releases doc/root/nested observers,
  content-neutral, empty-doc safe) and test_yroom_gc.py (3x2 matrix:
  consumer freed after stop, per observer level x stop mode).

This is a temporary workaround; remove once fixed upstream in pycrdt/yrs.
The YDoc v4 frontends only ship in jupyter-collaboration v5 (docprovider /
collaboration-ui 3.x) and JupyterLab 4.6+. Widen the relevant bounds so JSD
resolves and its labextension federates against that stack:

- pyproject.toml: jupyter-collaboration-ui / jupyter-docprovider <3 -> <4
  (admits the 3.x line that declares @jupyter/ydoc v4).
- package.json: @jupyter/docprovider + @jupyter/collaborative-drive allow
  ^5.0.0-alpha.0 alongside ^4.4.0, so the built labextension shares the
  docprovider singleton collaboration v5 requires (^5.0.0-alpha.0).
- ui-tests: bump @jupyterlab/galata ^5.4.0 -> ^5.6.0 to match JupyterLab 4.6
  (5.5.x targets 4.5 and its readiness fixture hangs on 4.6).
Extend the room GC coverage so leaks in the Jupyter YDoc shared models
themselves (not just consumer-added observers) are caught -- e.g. YChat
previously never removed its __init__ observers, leaking the room.

- test_yroom_gc.py: add TestYRoomGC (the YRoom is collected after stop)
  and TestYRoomSharedModelGC (the YBaseDoc model is collected), each
  parametrized over file/notebook/chat x graceful/immediate. The chat
  cases skip when jupyterlab_chat is not installed.
- conftest: make_room_file / make_yroom take a
  (file|notebook|chat), build the right file + room_id, and create rooms
  via the manager factory (so YNotebookRoom is used for notebooks).
  Track rooms weakly so the fixture never pins a room. Give
  MockServerDocsApp an outputs_manager=None attribute so notebook rooms
  load with the outputs service disabled (the default).
- unit-tests CI: install jupyterlab-chat so the YChat GC tests run. The
  YChat cases require the observer-cleanup fix in jupyter-chat >=0.23.0a2
  (jupyterlab/jupyter-chat#463); until that releases these tests fail in
  CI, surfacing the leak.
@dlqqq

dlqqq commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

The new memory-leak tests added here discovered a memory leak in Jupyter Chat, fixed by jupyterlab/jupyter-chat#463. This test suite is expected to fail until that PR is merged and released as jupyterlab_chat==0.23.0a2.

Also, although not required by this PR, jupyterlab/jupyter-chat#462 will be required for Jupyter AI v3.1 to support JupyterLab v4.6.

@dlqqq dlqqq changed the title Support Jupyter YDoc v4 Support JupyterLab v4.6 (Jupyter YDoc v4) Jul 8, 2026
Run every Python version even if one fails, so a failure on one version
doesn't cancel and mask the others.
0.23.0a2 supports jupyter-collaboration v5 (so it no longer drags in a
pre-YDoc-v4 stack that downgrades pycrdt to 0.13) and removes YChat's
observers on unobserve() (jupyterlab/jupyter-chat#462 + #463).
@dlqqq

dlqqq commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

Jupyter Chat v0.23.0a2 is now released, downstream tests should pass.

@dlqqq

dlqqq commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator Author

Excellent! Merging this and releasing it now as JSD v0.3.0. This will not get pulled in automatically by Jupyter AI users as v3.0.1 has a version ceiling now. We will continue to iterate on JSD v0.3 as we approach the Jupyter AI v3.1 official release.

@dlqqq dlqqq merged commit 97054a0 into jupyter-ai-contrib:main Jul 8, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Upgrade Jupyter YDoc v4

1 participant