Repository navigation
Conversation
Several clients on one App, each with its own Session and State, while app.py and the plugins stay one shared instance. Three levels: endpoint, SessionStore, ConnectionManager; six phases; what each plugin keeps for one client. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each client will have its own Session and State while app.py and the plugins stay one instance. This phase adds the parts, with every client still in the default session, so nothing changes in behaviour: - State: a client's workspaces, registries (geometry, materials, metadata, buttons, actions) and plugin data. Inbox keeps its registries' old names, as views onto the current session's State; each Workspace registers into its own. - Session and SessionManager: the live sessions; a default one that never ends. - SessionStore: the records of sessions - MemorySessionStore, and RedisSessionStore (extra "sessions"), Redis in docker-compose.yml. - current_session/current_state/current_workspace, bound for every message in App.on_message (not only plugin messages); Session.bind for threads. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What is registered outside of any session (at startup) is everyone's; what a session registers is its own and comes first. Kept once, in the default session's State; Inbox.buttons and Inbox.action_registry look in the session's, then in those. A shared callback runs with the clicking session bound. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ConnectionManager (connections.py) takes the sockets and the persisted messages out of AppServer, keyed by session and workspace, at three reaches: one workspace, every workspace of a session, everyone. The default session's messages are everyone's, so what app.py adds at startup reaches and is replayed to every session. Every send carries its session: a Workspace its own, other code the bound one, else the default. Plugin.send_all follows the reach rule (inside a session: that session; outside: everyone); Plugin.send_everyone is new. Sessions count their open tabs; an ended session's persisted messages are dropped. AppServer.resolve_session picks a connection's session, set in phase 3. Older code keeps working: on_message(data, workspace_id) overrides, a replaced Plugin._send, outboxes without session_id. Co-Authored-By: Claude Opus 5.5 <[email protected]>
App(sessions=True): SessionMiddleware (endpoint.py), one ASGI middleware for HTTP and the WebSocket, finds each request's session from a cookie - random id, HttpOnly, SameSite=Lax, Secure over HTTPS - starts one if there's none or it expired, asks App.authorize_session callbacks (403 when refused), and binds it: plugin routes, sync or async, see current_session(). Remote(session=...) joins one with the cookie. The store is touched at most every timeout/10; AppServer.every sweeps expired sessions while serving. examples/sessions.py and docker/Dockerfile: the example with Redis in Docker (docker compose up --build), checked with two real browsers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er session Phase 4: each session's State reads through to everyone's (the default session's, holding what app.py added at startup) and copies what it changes (State.own): a gizmo move, a color edit, an object action or Workspace.transform_geometry from a session changes that session's own copy, with the same guid, so only its tabs swap it. Removing everyone's object from a session is kept for that session's tabs. Without sessions, objects are changed in place, as before. Phase 5: Plugin.session_state() / Plugin.state, per session; Plugin.new_session / end_session; hide/show/disable/enable for the current session inside one, for everyone outside. Plugin handlers are found on the class, so properties aren't run. examples/sessions.py gets "Move the box", checked in two browsers in Docker. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e the App Plugin.inherit_state(everyone) makes a new session's data from the default session's (by default a fresh session_state()); Plugin.everyone is that data. Plugin.state also works before the plugin is added to an App: what is set then becomes everyone's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
State.own_material no longer copies the geometry too: restyling everyone's object (ghosting a layer) leaves its geometry everyone's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Declared on the plugin class (_history = per_session(None), _unsnappable = per_session(set, inherit=set)); read and set like any attribute, the current session's value. For plugins with many attributes per client, without writing a property for each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an option for one running
Appto serve several users, each with their own session: their own scene, workspaces and plugin data. Sessions are off by default (App(sessions=True)turns them on), so existing apps behave as before.The design and its decisions are in
src/compas_threejs/viewer/SESSIONS.md. Its first commit (92c9637) is the plan, written for review.The model
App→Session→State→WorkspacesSession, not in copies of the plugins.Stateholds everything one client has: objects, buttons, actions and workspaces. A session is not a workspace: every session has all of the App's features, including several workspaces.app.pyadds at startup is everyone's. That includes geometry, buttons and actions. A session sees it, and anything the session adds itself comes first.State.own), so one user moving a beam doesn't move it for everyone else.What's in it
session.py:State,Session,SessionManager,current_session/current_state/current_workspace(contextvars),Session.bind.stores.py:MemorySessionStore,RedisSessionStore(session records only; the liveStatestays in the process)ConnectionManagerkeyed by (session, workspace). Messages sent outside a session reach everyone and are replayed to new sessions.Plugin.send_everyoneApp(sessions=True).SessionMiddleware: a cookie namedcompas_threejs_sessionfor HTTP and WebSocket, with anauthorize_sessionhook.Remote(session=...). Expired sessions are swept withAppServer.everyState.own,State.shared). Plugin data per session:Plugin.state/session_state/new_session/end_session. Hiding and disabling follow the same rule as messagesper_sessiondescriptor: a plugin attribute kept per session, with.everyone(plugin)for everyone's value. Plugin data can start from everyone's, and can be set before the App existsRedis is an optional extra (
pip install compas_threejs[sessions]).docker compose up --buildrunsexamples/sessions.pywith Redis on http://127.0.0.1:9001.Plugins
How each plugin keeps its data per session is in phase 6 of SESSIONS.md:
feature/sessionsbranch.Open questions for review
Appshorthands called outside a session (for example inapp.loop) whensessions=True: should they act on everyone, or raise an error? Proposed: act on everyone, by the same rule as messages.session_timeout=).Testing
pytest: 118 passed, 5 skipped. The skipped tests need a real Redis: rundocker compose up -d redis, then setCOMPAS_THREEJS_REDIS_URL=redis://localhost:6379/0. Without it, the Redis tests usefakeredis.tests/test_endpoint.py::test_the_server_sweeps_while_it_runsdepends on timing. It failed once on a cold first run and passed on every rerun.Before merging
feature/sessionsbranches after this PR🤖 Generated with Claude Code