Repository navigation
Require fresh source starts after input streams end - #273
Merged
Merged
Conversation
kahrendt
approved these changes
Sep 16, 2026
Contributor
|
Thanks! |
2 tasks done
chrisuthe
added a commit
to Sendspin/aiosendspin
that referenced
this pull request
Sep 17, 2026
…thout an open stream (#430) Part of #386. Implements the server-side MUSTs of Sendspin/spec#273 for `source@v1` ("Source command semantics", "Default streaming behavior", "Source Audio Chunks"). - [x] **S-8** – A `client-stream/start` with no unused `start` is flagged and opens nothing, so a strict server closes the connection. A start answering a `start` that crossed a `stop`, an `available: false`/`true` pair or a role removal is no longer flagged. - [x] **S-12** – `client-stream/start`, `client-stream/end` and source audio are tracked when no source role is active. Audio with no open input stream, or after the latest `client/state` reported `available: false`, is flagged, so a strict server closes the connection. ## How - `SendspinConnection` tracks the client's input stream for the lifetime of the connection: - It counts every `start` sent. An opening `client-stream/start` uses one. - A `client-stream/start` on an already open stream replaces its format and needs no `start`. - `client-stream/end` closes the stream. `stop`, unavailability and role removal leave it open. - Because this state outlives the role instance, messages that arrive after the role is removed are still handled in received order. - A single flag is not enough. After `start`, `stop`, `start`, a compliant client can send `client-stream/start`, `client-stream/end`, `client-stream/start`, and all three are valid. - `SourceV1Role` now only serves consumers: - It records each `start` it sends on the connection. - It opens a stream handle only if a `start` was sent after its latest `stop`, unavailability, removal or disconnect. - Otherwise it discards the input stream until `client-stream/end`, with no `SourceStreamStartedEvent` or `SourceStreamEndedEvent`. - An authorized stream whose format is rejected or whose decoder cannot be built still counts as open, so its chunks are dropped rather than flagged. ## Limitations - **Short stale stream:** after `start`, `stop`, `start`, the server cannot tell which `start` the first opening answers. It serves that opening as a real stream, so consumers may see a short stream that is then replaced (started, ended, started). Discarding it instead could stall a client that ignored the first `start`. - **Extra leniency from repeated starts:** every `start` sent is counted, including one the client ignores because a stream is already pending or open. The server cannot tell such a repeat from a `start` that crossed the client's own `client-stream/end`, so this only makes the server more lenient and never flags a valid client. - **No format checks on discarded streams:** format checks are skipped for an input stream opened in discard mode. ## Compatibility - **More tolerant:** the `client-stream/start` path now accepts more. - **Stricter:** only source audio sent with no open input stream, or after reporting `available: false`, is now rejected. - Earlier spec text already required `client-stream/start` before the first chunk and `client-stream/end` before `available: false`. - The client SDK sends chunks only with an open stream, and ends the stream before it reports unavailable. - It opens a stream only with a synced clock, and it only loses sync when it disconnects. So `_wire_available()` cannot report `available: false` while a source stream is open. - No `DEPRECATED(spec-pr-273)` marker is needed. ## Tests - `tests/server/test_source_input_stream.py` (new) uses a real connection, client and role. It covers: - a `stop` crossing an in-flight `start`; - an availability round trip; - role removal with a `start` outstanding and with a stream open, including a strict server closing on audio received after `client-stream/end`; - reactivation; - an undecodable authorized stream. - `tests/server/test_source_connection_dispatch.py` covers: - unsolicited openings; - one opening per `start`; - in-place replacement; - `start`s that cross the client's `client-stream/end`; - audio with no open stream or while unavailable; - quiet drops with no source role. - The role-level tests for flagging unsolicited starts and dropping audio while unavailable moved to the connection, which now owns those rules.
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.
Clarify source start authorization, stopping, and receiver behavior. Changes beyond keyword normalization:
stophandling from a recommendation to a MUST: cancel pending startup, stop sending audio, and sendclient-stream/endif an input stream is open - stopping before startup completes must prevent the pending opening too.startto one opening and require a newly received serverstartbefore reopening afterclient-stream/end. Repeated starts while starting or streaming cannot accumulate permission for later openings.start, not merely the server sending it. Distinguish opening an input stream from an in-place format update.startbefore receiving the preceding end or availability update - messages in opposite directions can cross, so that command may still be fresh when the client receives it.stopor removing the source role does not itself close the input stream at the server. Tolerate valid in-flight responses, including a delayedclient-stream/start, untilclient-stream/endarrives, and process start/end messages in received order even when discarding audio.Addresses part of #100.