The writer already produces a bounded complete page and readers publish it atomically. Remove the per-message/reaction envelopes and Browser/Node reassembly, retaining request, binding, transaction and live-change owners. The mixed-page component control cuts serialized bytes by 47.4% and signatures from 101 to 1. Advance private Domain wire to 51; stored formats are unchanged. Core, actual IndexedDB, Server, Node and protocol checks pass.
6.3 KiB
ADR-0015: Browser Session Lifetime Owners
- Status: accepted on 2026-11-25; steps 4 and 7 start after the refinements named under Consequences
- Date: 2026-11-24
Context
ChannelSession in session.ts is one
4,000-line class with about 45 private fields. It carries the domain connection
and every activity a page can start: room reading and history, Browser room
hosting, the App link, screen viewing, source selection and sharing,
watch-together, voice, and archive restore. One reconciler, applyState,
retires all of them from each snapshot.
Three properties of this shape produce repeated defects. Each was verified on
f17a57e3:
- Lifetimes share fields.
local,watching,screenShares,voiceParticipationandrequestseach have several writers, including one another's retirement paths. - Currency after an await is proved again with a different predicate at each site: socket identity, binding IDs, map-entry identity, symbols, a generation counter, abort controllers and pending keys.
- The view is an input.
view.pendingis the lock thataction()tests and that the reconciler reads to decide retirement.view.state, a projection filtered by local intent, is read back as the previous authority state.
On this line the file was changed by about 250 commits in thirty days. About 140 were fixes, which added 967 lines net, and a third of all fix subjects on the line begin with keep, preserve or retain. The 15,000-line test writes private fields at about 44 places, which makes the class expensive to split.
Engineering requires one owner per lifetime. This decision applies that rule to the Browser session.
Decision
- Each lifetime has one owner for its resources, pending work and retirement. Its interface follows the operations its callers need.
ChannelSessionkeeps the domain connection, signaling recovery, the request correlator and the previous and current raw snapshots.applyStatestores the snapshot, updates affected owners in dependency order and publishesderive(snapshot, owners).- The view is output only.
pendingand every per-activity field are projections of owners. Edge detection compares raw snapshots. - An operation's failure belongs to its caller.
action()rejects and the surface that started the operation shows the result.view.errorkeeps connection and session facts.reportError,clearErroranderrorRoomIdare removed. - After an await, verify the resource and operation are still current before publishing success or failure. A newer request may supersede work within a live binding.
- Replacing the session identity for an archive or domain restore is done by
the session's owner,
useChannel, which closes one session and constructs the next. A session does not reconnect itself as another identity from inside one of its own actions. - Inject an external dependency with a production default when a public-action test needs control over it.
Owners And Order
| Step | Owner | Lifetime it owns | Leaves the class |
|---|---|---|---|
| 0 | First RoomReader test seam, if needed | First binding-scoped history scenario | Its private test setup |
| 1 | RoomReader per room binding |
History pages, follow-latest, the interaction session and the read cursor | PendingHistory in the request map, three loops that walk every request, readings and historyChannel bookkeeping |
| 2 | Initiating dialog or page control | One result per started operation | The flags that arbitrate the global error slot |
| 3 | VoiceParticipation |
Participation, mute, deafen and the voice publication per room, and the microphone the rooms share | voiceParticipation, microphone and microphoneRequest, the voice arms of applyState, reconcileLocalMedia and projectActivity, and the microphone release in action(), refreshActivity and applyState |
| 4 | Stage per room |
Source selection, screen share and watch-together, which share one stage slot | sourceSelections, screenShares, both watch-player maps and the three per-share setting loops |
| 5 | ScreenWatches |
Viewing subscriptions and the App helper | watching and its playback-error edges |
| 6 | BrowserHosting |
Hosted rooms and their cleanup | hostedRooms and hostCleanup |
| 7 | Identity replacement in useChannel |
The session itself | Restore's close, reconnect and rollback inside actions |
Each step is a few commits that keep npm test passing, and the line can merge
between steps. Step 0 adds only the dependency needed by the first RoomReader test.
Request correlation stays with the session. RoomReader projects confirmed pages
and applies live changes within the binding. Optimistic updates keep their
operation identity until confirmation or failure.
Room voice and share commentary capture separate microphones. The voice rooms
share one microphone, which VoiceParticipation releases after its last
consumer, and commentary stays with its share in step 4. The session keeps the
local publications, personal playback and the input preference, and voice uses
them through one interface.
Consequences
- A transition no longer carries another lifetime's state by hand. That is the
defect class behind most of the
preserveandretainfixes in this file. applyStateshrinks to ordering, which becomes the explicit place to reason about dependencies between lifetimes.- Step 2 changes where failures appear.
ChannelPage.rundiscards rejections today and relies on the global slot, so page-level display moves first. - Step 7 needs a handoff design, because dialogs hold the session reference
that
useChannelcreates once. - While a step is in progress the file it restructures is on hold.
- Core returns one bounded, validated history page per reply. RoomHistory merges it with live changes received during the read. The shape of the per-operation result surface remains open.
References
- Engineering: one owner per lifetime
- OTP supervision principles: a parent owns the start, stop and failure of its children.
- AbortSignal, the platform's cancellation primitive.