From 88f58ea468a32911c4e8105ff9c31f52a3f4175a Mon Sep 17 00:00:00 2001 From: faumaray Date: Wed, 21 Oct 2026 06:34:17 +0300 Subject: [PATCH] Record the review round in the design of the session seam Sections 3, 4.1 to 4.4 and 13 say what changed (notify, the talking hint, the address text, the close reason of a connect, the chat scope limit and the SyncEnd of a CHAT scope, the seat across tsclientlib's reconnect), the risk table has the lagging consumer, and section 14 lists the eight findings with their fix and test. Follow-ups P13 (a speaking hint for the own channel) and P14 (what a backend that reconnects inside a session tells its consumer) are for the protocol repository. Co-Authored-By: Claude Sonnet 5.5 --- docs/session-seam.md | 106 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 89 insertions(+), 17 deletions(-) diff --git a/docs/session-seam.md b/docs/session-seam.md index ff74355..9ac20d9 100644 --- a/docs/session-seam.md +++ b/docs/session-seam.md @@ -1,7 +1,8 @@ # The session seam: the engine on `voelin_proto::link::Session` Status: design (2026-10-20); slice 1 is implemented (section 13 says how it -differs from this text); section 10 has the slices. +differs from this text, section 14 what the review changed); section 10 has +the slices. Design for the first half of plan step 7 (Phase 4): the engine consumes `voelin_proto::link::Session`, `ServerLink` becomes an adapter over it, and @@ -130,6 +131,13 @@ Requests with a `RequestId` that cannot be sent (no session yet, closed) answer as today: `session.rs` already reports "not connected with voice" before a link exists; SessionLink reports `SessionError` texts (4.6). +`LinkSession::notify` follows the `Session` contract (it errors for a closed +session or a misplaced op, as `FakeSession` does): `Hello`, `List`, +`FileRead` and `FileWrite` are `Protocol` errors, because they have a stream +and an answer of their own (`placement`); our own mute flags go to the link; +any other op of the control stream is run as the request it is, and its +answer, or its refusal, is told to nobody. + ### 3.2 `Session` → `LinkEvent` Every variant of `voelin_core::link::LinkEvent`. @@ -138,11 +146,11 @@ Every variant of `voelin_core::link::LinkEvent`. |---|---|---| | `Connected{name, backend, capabilities, own_client, server_uid, own_uid}` | `Welcome`, the SERVER(S) sync, the answer to the first `JoinVoice`, the own `User`. | Sent once, after the connect sequence (4.2). `name` = `Server.name`; `backend` from `Welcome.host.backend` (table 4.7); `capabilities` from `features()` (table 4.7); `own_client` = `P` as `u16`; `server_uid` = `server_key(Server.uid)` (5.3, F3); `own_uid` = `uid_text` of the own `User` (the `User` of our `VoiceState.user_id`, else `Welcome.user_id`), `None` when the replica has none yet. | | `Presence(Box)` | `Change`/`SyncEnd` of SERVER(S) and LIVE(S); talk tracker. | After the pushes that are there now are applied (drain, then one snapshot), if SERVER or LIVE changed: `replica.presence_model(S)` with the fix-ups F1-F10. One TeamSpeak book update is one inner `Presence`, one or two `Change`s, and still one snapshot. | -| `OwnChannel(cid)` | Our `VoiceState.channel_id` in LIVE. | After every `Presence`, when known and not 0 (as `TsLink` does after every snapshot). | -| `Chat(ChatMessage)` | `Change.put` of a `Message`, and messages of a `SyncBegin`..`SyncEnd`, in a subscribed CHAT scope (4.3). | Once per `(channel_id, id)` per connection; `replica.chat_message(channel, id)` gives target, author name, author uid, author participant, `ts_ms`, `via_relay` (`MESSAGE_FLAG_RELAYED`). Answers to our own `Put` are not applied to the replica: our own message is reported when its `Change` arrives, which is today's echo, and `session.rs` merges it with the row it stored (test `a_sent_message_and_its_echo_are_one_message`). | +| `OwnChannel(cid)` | Our `VoiceState.channel_id` in LIVE. | After every `Presence`, when known and not 0 (as `TsLink` does after every snapshot). Our `VoiceState` is the one of the seat, and behind a TeamSpeak server it follows the seat to the participant that is us after the link's own reconnect (4.4); the `OwnChannel` of the inner link only tells `LinkSession` that a move has arrived. | +| `Chat(ChatMessage)` | `Change.put` of a `Message`, and messages of a `SyncBegin`..`SyncEnd`, in a subscribed CHAT scope (4.3). | Once per `(channel_id, id)` per connection, and only once the replica can show it: a full sync stages its messages until its `SyncEnd`, so the messages of a CHAT scope are reported at its `SyncEnd` as well (4.3). `replica.chat_message(channel, id)` gives target, author name, author uid, author participant, `ts_ms`, `via_relay` (`MESSAGE_FLAG_RELAYED`). Answers to our own `Put` are not applied to the replica: our own message is reported when its `Change` arrives, which is today's echo, and `session.rs` merges it with the row it stored (test `a_sent_message_and_its_echo_are_one_message`). | | `Poke{from, from_uid, from_name, message}` | Push `Signal{from_user, from_participant, body: Poke{message}}`. | `from` = `from_participant` as `u16`; `from_uid` = `uid_text` of `User(from_user)`; `from_name` = the participant's `VoiceState.nick`, else the `User.name`. A sender outside our view is delivered as a bare `User` first (5.2). | | `Audio(VoicePacket)` | `MediaSink` packets on a voice slot. | Section 6.1. | -| `Talking{client, talking}` | `MediaSink` packets on a voice slot (protocol 6.4: talking in the own channel comes from media). | The first packet of a slot → `true`; 400 ms without one → `false` (250 ms tick): the rule of `voice.rs` today. Also fills `ClientInfo.talking` (F8). | +| `Talking{client, talking}` | `MediaSink` packets on a voice slot (protocol 6.4: talking in the own channel comes from media), and `Signal{speaking}` (below). | The first packet of a slot → `true`; 400 ms without one → `false` (250 ms tick): the rule of `voice.rs` today. `TsLink` also hears talkers whose packets it does not forward as Opus (Speex, CELT): `LinkSession` passes the inner link's `Talking` on as `Signal{speaking}`, and SessionLink holds such a talker as talking until the host says `on: false` (no silence ends it). Also fills `ClientInfo.talking` (F8). | | `OwnStream(OwnStreamEvent)` | `StreamPort` events. | Passed through. | | `StreamAudio{stream, time, data}` | `StreamPort` events. | Passed through. | | `StreamAudioEnded(stream)` | `StreamPort` events. | Passed through. | @@ -163,11 +171,12 @@ decision for each: | `Signal{encoder_hint}` | Ignored. Follow-up (client): Opus bitrate and `packet_loss_perc` from it (protocol 6.7). | | `Signal{reminder}` | Ignored (no events feature in the engine). | | `Signal{notice{level: INFO}}` | Logged at info. | -| `Signal{speaking}` | Not asked for (no `SUBSCRIBE_OPTION_SPEAKING`). Follow-up with talking in other channels. | +| `Signal{speaking}` | A hint next to the media: the host says a participant talks or stopped (`LinkSession` sends it for the inner link's `Talking`, which is all there is for a talker without Opus). Not asked for with `SUBSCRIBE_OPTION_SPEAKING`; talking in other channels stays a follow-up (P13). | | Media on stream slots (sub 0-4), `FlowId::FEEDBACK`, `FlowId::PROBE` | Dropped (no SFU streams in this half). | | `stats()` (`LinkStats`) | Section 4.7. | | `Connected.host_uid` | Not pinned for TeamSpeak (`[0; 32]`, no host key). Kept for a later pin store for `voelin://` hosts. | -| `Welcome.resume_token`, `Welcome.ice`, `Welcome.observed_addr`, `Welcome.time_ms`, `Welcome.limits` | Kept by SessionLink, unused in this half (4.4). `limits.max_message_chars` is not enforced (the UI's own limit stays). | +| `Welcome.resume_token`, `Welcome.ice`, `Welcome.observed_addr`, `Welcome.time_ms` | Kept by SessionLink, unused in this half (4.4). | +| `Welcome.limits` | `max_chat_subscriptions` bounds the CHAT scopes (4.3). `max_message_chars` is not enforced (the UI's own limit stays). | ## 4. How the engine owns a `Session` @@ -189,7 +198,7 @@ decision for each: Lookup: the scheme of `ConnectParams.address` (lowercase, before `://`); an address without a scheme is a TeamSpeak bookmark and gets `ts3server`. A local connector for the scheme wins over a plain one; none → `Disconnected` -with "no connector for {address}" (the text of `Connectors::connect`). +with "no connector for {address}" (the text of `Connectors::connect`, but with the address cut at `?` and `#`: the text is shown and logged, and a TeamSpeak link carries a channel password and a pin). `Engine::start` and `start_with` use `Backends::default()`, which registers `TsConnector` (schemes `ts3server`, `teamspeak`) with the engine's myTeamSpeak @@ -230,7 +239,9 @@ and shows `Connecting` until `Connected`. `Server` stub in HOME (follow-up P9), so HOME is not used to find it. 4. `Subscribe` HOME, SERVER(S) and LIVE(S), each after `replica.subscribe`. 5. Apply pushes until the three `SyncEnd`s. 30 s without them → close, - `Disconnected(Some("timed out while connecting"))`. + `Disconnected(Some("timed out while connecting"))`. If the push channel + ends meanwhile the session has ended: `closed()` says why, and that is + the reason of `Disconnected` (a kick during the syncs is shown as one). 6. `request(JoinVoice{server_id:S, channel_id, password})`: `channel_id` from the bookmark's channel (`/` directly, a path resolved in the synced tree with `split_channel_path`), else `Server.default_channel_id`. The @@ -257,12 +268,28 @@ own state, without an inner command; an op it does not implement is TeamSpeak delivers the chat of our own channel, the server chat and private messages; everything else needs a gateway. SessionLink subscribes exactly that: CHAT(server chat channel), CHAT(our channel) (re-subscribed when we -move, the old one unsubscribed; `Limits.max_chat_subscriptions` is 16), and -CHAT(dm) for each DM channel HOME holds. A message that arrives before its +move, the old one unsubscribed), and CHAT(dm) for each DM channel HOME +holds. + +The number of CHAT scopes is `Welcome.limits.max_chat_subscriptions` (0 or +no `Limits`: the v1.0 default, 16). `LinkSession` says 65,536 and enforces +it: it is no limit a connection reaches, because a private message from +somebody new makes a conversation, and a connection on a busy server meets +more than 16 people. Against a host with a small limit the server chat and +our channel come first, then the private conversations, the newest +(highest id) first. + +A message that arrives before its scope is subscribed is not lost: `LinkSession` keeps the messages of the connection per channel (the 50 newest, the default CHAT window of protocol 5.4) and sends them in the full sync; SessionLink reports each -`(channel, id)` once. A first private message from someone new therefore +`(channel, id)` once. A full sync is staged by the replica until its +`SyncEnd`, so a message of its `Change`s cannot be read when the `Change` +is applied (and `SyncBegin`, `Change` and `SyncEnd` may come in different +batches): SessionLink marks a message as reported only once it has shown it, +and at the `SyncEnd` of a CHAT scope it shows the messages of that channel +it has not shown yet (test +`the_messages_of_a_chat_sync_are_reported_when_the_sync_ends`). A first private message from someone new therefore arrives as: HOME `Change` (the DM channel), Subscribe CHAT(dm), its sync. A cursor kept per CHAT scope makes a re-subscription after moving back a delta where the session offers `sync.delta` (`LinkSession` does, within one @@ -276,9 +303,26 @@ connection). generation filter drops what the old one still says. - **Transport**: TeamSpeak's own reconnect inside `tsclientlib` (`DisconnectedTemporarily`) stays invisible at the seam, as it is today - (the snapshots go on). A new client id after such a reconnect is not - announced, as today. The native TeamSpeak session of the second half - starts a new epoch instead (H1). + (the snapshots go on). The connection comes back as another client: a new + client id, the same unique id and database id. `LinkEvent::Connected` is + not repeated (as today), but the engine does not stay the client of the + connect: *we are the client of our unique id*. + `LinkSession` takes the client it was for as long as that client is in + the snapshots, and when it is gone the client of our unique id (the + newest, when a ghost of the old connection lingers: while the ghost is + there we stay on it, as a second client of one identity may be a second + connection of ours); the own client keeps the database id when two + clients share it, so the user we are is the same through the reconnect; + `Session.send_media` follows the slot. SessionLink (behind a TeamSpeak + host only: a participant is ours for the life of any other session) keeps + its seat while the participant is ours, and moves it to the participant + that carries our user id when the seat is gone or no longer carries it; a + seat whose user id changed by itself (the snapshot that tells our database + id came after the seat) is followed. `OwnChannel`, the voice flags, the + uplink slot and the chat scope of our channel follow the seat (tests + `the_engine_follows_a_reconnect_that_makes_us_another_client`, + `we_stay_the_client_we_were_while_it_is_there`). The native TeamSpeak + session of the second half starts a new epoch instead (H1). - **Resume**: `LinkSession` does not offer `resume`. SessionLink keeps the last `Welcome.resume_token` and the CHAT cursors per session and address, and sends neither in this half: no `voelin://` connector is registered. @@ -841,6 +885,7 @@ Nothing here blocks this half: each has a workaround above. | A presence field gets lost between the two translations (a UI detail disappears). | Round-trip tests on the book fixtures and generated presences; F1-F10 listed; live smoke against the baseline. | | Event timing changes: `Connected` now follows three syncs and a `JoinVoice`; snapshots are coalesced. | All in process for TeamSpeak (microseconds); the FakeLink tests pin the order; `session.rs` is unchanged. | | The inner bus of `LinkSession` lags and a request never gets its answer. | Capacity 4096, a timeout on every pending request, lag logged. | +| The consumer of the push channel lags and stalls the voice and the commands that share the task. | The task never waits on the channel: what does not fit is dropped and the scope is sent again whole when there is room (14). | | A uid that round-trips through `User.uid` on one side and through `Foreign` on the other (F10) would key contacts and private history differently. | Both sides use one rule (canonical base64 → bytes, anything else → `Foreign`), asserted by the round-trip test on TeamSpeak 3 and 6 uids, ServerQuery login names and the FakeLink fixtures' `alice=`; checked live (contacts and private history keyed by uid). | | The model crate switch collides with other branches. | 11.3; the switch is manifest-only. | | Two adapters cost CPU per voice packet (RTP wrap and unwrap in process). | About a hundred bytes copied per 20 ms per talker; measured in slice 1 by a unit test (`a_voice_packet_costs_microseconds_through_both_adapters`, section 13). | @@ -918,17 +963,28 @@ public item was removed. Where the code differs from the text above: streaming flag in the book comes back as `Some(false)` (v1 has no "unknown"). - **Known limits.** Two clients with one identity (one database id) are two - users of the replica (the higher client id gets a user id made of its - client id). A `Put Message` before any snapshot is handed to the link + users of the replica (the own client keeps the database id, else the lower + client id; the other gets a user id made of its client id). A `Put Message` before any snapshot is handed to the link whatever the channel. `Welcome.limits` is partly filled. `Backends` has a slot for an `AccountAgent` and for a `HostTrust` (refusing by default); nothing sets either yet. -Follow-up for the protocol repository, found while writing the code: +Follow-ups for the protocol repository, found while writing the code: - **P12.** `FileEntry.from_path` should say whether it includes the file's name. The TeamSpeak side reads it as the whole old path (`/dir/name`), with `path` and `name` of the entry the new place. +- **P13.** `Signal{speaking}` is for talking in channels the user is not in + (protocol 5.6, 6.4). A host that hears a talker in our own channel and + does not carry the voice as media (TeamSpeak's Speex and CELT talkers) has + no way to say so but that signal, which `LinkSession` uses for them + (SessionLink believes it until `on: false`). The protocol should say that + the signal may do this, or give such a talker a flag on the `VoiceState`. +- **P14.** Say what a backend that reconnects inside a session (TeamSpeak's + `tsclientlib`) tells its consumer: today the participant id of the session + changes without a word, and a consumer has to find itself again by its + user. A `Change` that puts the new `VoiceState` and deletes the old one is + all there is; the native session of H1 starts a new epoch instead. What ran against the baseline (main `59fec5b`; the dev servers of `dev/docker-compose.yml` as the compose project `voelin-seam`, TeamSpeak @@ -958,3 +1014,19 @@ the engine over the protocol repository's `FakeConnector` through `Engine::start_with_backends` (connect, the server's name, the channels, a move, disconnect), and the registry's error text for an address no connector serves. + +## 14. Review round 2 of slice 1 + +The review of the first implementation found eight defects; each is fixed in +its own place above and tested. + +| Finding | Fix | Test | +|---|---|---| +| Chat messages of a CHAT scope's initial full sync were lost when `SyncBegin` and `Change` were in one batch and `SyncEnd` in the next: `(channel, id)` was marked as reported before the replica could show the message. | A message is marked as reported only when it was shown; at the `SyncEnd` of a CHAT scope the messages of that channel not shown yet are (4.3). | `the_messages_of_a_chat_sync_are_reported_when_the_sync_ends`, `a_message_that_comes_before_its_scope_is_reported_with_the_sync` (`link/session_link.rs`) | +| The own client id was pinned for the connection: after `tsclientlib`'s reconnect (a new client id) `OwnChannel` and the own channel's chat stopped. | Both sides find us again by our unique id and user (4.4); the own client keeps the database id of an identity that is there twice. | `the_engine_follows_a_reconnect_that_makes_us_another_client`, `we_stay_the_client_we_were_while_it_is_there`, `the_own_client_keeps_the_database_id_of_an_identity_that_is_there_twice` | +| CHAT subscriptions were capped at 16 in process: the 15th private peer's messages were never delivered. | `LinkSession` says 65,536; SessionLink sizes its scopes from `Welcome.limits` (16 only when the host says nothing), server chat and own channel first, newest private conversations next (4.3). | `private_messages_from_more_than_16_peers_all_arrive`, the limits in `the_welcome_names_the_host_the_user_and_what_the_link_can_do` | +| `LinkSession::notify` accepted `List`, `FileRead` and `FileWrite` and ignored them. | A misplaced op is a `Protocol` error; any other op of the control stream is run (3.1). | `a_notify_needs_the_control_stream_and_is_run_as_the_request_it_is` | +| A push channel that ended during the connect syncs threw the session's close reason away. | The reason of `closed()` is the reason of `Disconnected` (4.2). | `a_session_that_ends_during_the_connect_syncs_says_why` | +| `LinkSession` awaited `pushes.send()`: a lagging consumer stalled voice and commands. | Nothing in the task waits: a push that finds the channel full is dropped, the scope is marked as lagged and sent again whole (`SyncBegin`..`SyncEnd`, all or none) when the channel has room, as `ConnectParams.push_capacity` documents. Signals have no scope: they are dropped. | `a_consumer_that_lags_loses_the_queue_and_gets_the_scope_again` | +| An address no connector serves was echoed in full, with `?channelpassword=`. | The text cuts the address at `?` and `#` (4.1). | `the_text_of_an_address_nobody_serves_keeps_the_channel_password_out`, `an_address_is_shown_without_its_secrets` | +| `LinkEvent::Talking` of the inner link was ignored, and its documentation unchanged: Speex and CELT talkers were no longer shown as talking. | The docs of `Talking`, `OwnChannel` and `Connected.own_client` say what the adapter derives; the inner link's `Talking` goes on as `Signal{speaking}`, a hint that SessionLink believes until it is over (P13). | `a_talker_the_link_hears_but_does_not_forward_is_shown_as_talking`, `a_host_that_says_someone_talks_is_believed_until_it_says_otherwise` |