Repository navigation
pairing: align records and pair-method descriptors - #269
Conversation
Brings the pairing wire and record semantics up to merged spec PRs Sendspin/spec#178, #179 and #189, plus the record rules from #183. Wire (#178, #179, #189): - client/hello advertises pair_methods as a map of method name to a PairMethodDescriptor carrying the method's supported formats, instead of a flat list of names. - Rename the pairing-code methods to dynamic_pairing_code and static_pairing_code across the wire, ClientCapabilities and the KATs, and drop the negotiable minimum length: a dynamic code is 6 digits and a static code is 8. - server/activate's pairing object carries the chosen emission format, and server/hello carries the languages hint, which is surfaced to the app on PairingCodePresentation together with the recommended display grouping. - At most one pairing-code method may be offered at a time; the SDK validates that when capabilities are built. Records (#183): - IPairingRecordStore.Upsert returns void and stores declare a Capacity. A pairing at capacity must succeed, so the SDK evicts the least recently used record itself (never its own Pairing PSK, never a record backing an open connection) before it writes. - PairingRecord gains ServerId, so there is exactly one record per server and re-pairing replaces rather than appends, and replaces Used with LastUsedUtc, which orders eviction. FilePairingRecordStore still reads the 9.x used field and only writes the new one. - A long-term (paired) PSK no longer admits a pairing activity, and server/unpair drops the record for the server that sent it. Docs: README and the v10 migration guide describe the new descriptors, the store contract, the eviction rule and the record fields. The interop client and harness follow the renamed methods. Tests: net8.0 1113/1113 and net10.0 1115/1115 passing. Stacked on chrisuthe/protocol-remove-management-namespace. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Legacy lockout migration, format handling, and concurrent live-record eviction have correctness and security gaps.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Aligns pairing wire formats and record handling with the latest Sendspin specifications.
Changes:
- Renames pairing-code methods and adds descriptor formats/languages.
- Adds capacity-aware LRU record eviction, timestamps, server binding, and unpair handling.
- Updates interop tooling, documentation, migration guidance, and tests.
File summaries
| File | Description |
|---|---|
tools/interop/server.py |
Updates pairing method terminology. |
tools/interop/InteropClient/Program.cs |
Uses renamed static method. |
tests/Sendspin.SDK.Tests/Protocol/MessageSerializerTests.cs |
Tests descriptors, formats, and abort reasons. |
tests/Sendspin.SDK.Tests/Connection/StoreHardeningTests.cs |
Updates lockout keys. |
tests/Sendspin.SDK.Tests/Connection/pin-kats.json |
Updates pairing-code vectors. |
tests/Sendspin.SDK.Tests/Connection/PairingWindowEndToEndTests.cs |
Updates static pairing flow. |
tests/Sendspin.SDK.Tests/Connection/PairingRecordStoreFormatTests.cs |
Tests timestamp migration and persistence. |
tests/Sendspin.SDK.Tests/Connection/PairingRecordSemanticsTests.cs |
Adds record eviction and uniqueness tests. |
tests/Sendspin.SDK.Tests/Connection/NoiseWireFramingTests.cs |
Tracks timestamps in snapshots. |
tests/Sendspin.SDK.Tests/Client/TimeSyncPairingGatingTests.cs |
Updates pairing activation semantics. |
tests/Sendspin.SDK.Tests/Client/TestClient.cs |
Adds bounded record-store double. |
tests/Sendspin.SDK.Tests/Client/SendspinHostServiceArbitrationTests.cs |
Separates pairing and long-term credentials. |
tests/Sendspin.SDK.Tests/Client/SendspinClientServiceUnpairTests.cs |
Adds unpair behavior coverage. |
tests/Sendspin.SDK.Tests/Client/SendspinClientServicePairingTests.cs |
Tests eviction and timestamp refresh. |
tests/Sendspin.SDK.Tests/Client/SendspinClientServicePairingCodeTests.cs |
Updates fixed-length pairing-code flows. |
tests/Sendspin.SDK.Tests/Client/SendspinClientServiceEncryptedFlowTests.cs |
Tests long-term pairing rejection. |
tests/Sendspin.SDK.Tests/Client/PairMethodLocationsTests.cs |
Updates keyed descriptor assertions. |
tests/Sendspin.SDK.Tests/Client/PairingWindowOptionsTests.cs |
Tests live-record callback wiring. |
tests/Sendspin.SDK.Tests/Client/PairingQuiescenceTests.cs |
Updates unpaired pairing sessions. |
tests/Sendspin.SDK.Tests/Client/PairingInitiationTests.cs |
Verifies last-use timestamps. |
tests/Sendspin.SDK.Tests/Client/PairingGatingTests.cs |
Tests format validation and gating. |
tests/Sendspin.SDK.Tests/Client/PairingConfigSeedingTests.cs |
Tests descriptor generation and method limits. |
tests/Sendspin.SDK.Tests/Client/PairingCodePresentationTests.cs |
Updates presentation tests. |
tests/Sendspin.SDK.Tests/Client/PairingAttemptTimeoutTests.cs |
Updates static method identifiers. |
tests/Sendspin.SDK.Tests/Client/ManagementRemovedTests.cs |
Tests long-term activity restrictions. |
src/Sendspin.SDK/Sendspin.SDK.csproj |
Updates v10 release notes. |
src/Sendspin.SDK/README.md |
Documents pairing-code configuration. |
src/Sendspin.SDK/Protocol/Messages/ServerHelloMessage.cs |
Adds server language hints. |
src/Sendspin.SDK/Protocol/Messages/ServerActivateMessage.cs |
Replaces length with emission format. |
src/Sendspin.SDK/Protocol/Messages/PairingMessages.cs |
Adds descriptors and vocabulary constants. |
src/Sendspin.SDK/Protocol/Messages/ClientHelloMessage.cs |
Keys descriptors by method. |
src/Sendspin.SDK/MIGRATION-10.0.0.md |
Documents breaking pairing changes. |
src/Sendspin.SDK/Connection/Noise/PairingRecordStore.cs |
Adds capacity, timestamps, and eviction. |
src/Sendspin.SDK/Connection/Noise/Pairing/PairingCodes.cs |
Uses fixed-length derivation. |
src/Sendspin.SDK/Connection/Noise/Pairing/PairingCodeLockoutStoreJsonContext.cs |
Updates persisted-key documentation. |
src/Sendspin.SDK/Client/SendSpinHostService.cs |
Supplies live-record information. |
src/Sendspin.SDK/Client/SendspinClientOptions.cs |
Adds internal live-record callback. |
src/Sendspin.SDK/Client/SendSpinClient.cs |
Implements revised pairing and record behavior. |
src/Sendspin.SDK/Client/PairingPskOperations.cs |
Generates unique pairing PSKs. |
src/Sendspin.SDK/Client/PairingGestureRequestedEventArgs.cs |
Updates method documentation. |
src/Sendspin.SDK/Client/PairingCodePresentation.cs |
Updates fixed-length presentation guidance. |
src/Sendspin.SDK/Client/ClientCapabilities.cs |
Enforces one pairing-code method. |
Review details
Suppressed comments (1)
src/Sendspin.SDK/Client/SendSpinClient.cs:2410
- The selected format is stored here but never read;
PairingCodePresentationis still constructed with only the code and languages. This contradicts the PR's stated API behavior that the activation format reaches the app. Add the format toPairingCodePresentationand pass this value to the presenter, or remove that claim and this dead state.
_activationPairingCodeFormat = format;
- Files reviewed: 42/42 changed files
- Comments generated: 7
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Harden shared record-store eviction, migrate legacy lockout keys, validate pairing formats, and correct migration guidance.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Resolves the four conflicts with the management-namespace doc fixes that landed with #268: the pairing-record and lock comments and the migration guide's pair-method wording take this branch's versions, and the migration table keeps the new row for the removed management surface.
…commit The pairing wire this branch sends exists only on aiosendspin main, which the unpublished 10.0.0 release targets; 9.1.1 rejects the client/hello outright. Pin the interop server to that commit until 10.0.0 is published, and keep the 9.x line on 9.1.1.
…ce server aiosendspin, on 9.1.1 and on the 10.0.0 draft alike, still declares supported_pair_methods as a list of descriptors where the spec (PR #179) keys them by method. Patch the installed copy in the interop job, as the next PR in this stack already does, so the scenarios run against the draft.
…be the new pin The Python harness still named PairMethod.STATIC_PIN, which the reference server renamed with the pairing-code wire; the README still said this line's interop runs against 9.1.1.
aiosendspin renamed PairingAttempt.pin_provider with the pairing-code wire.
…ct in the migration guide and release notes The migration table and section 3 said nothing about the removed MinPairingCodeLength, the renamed methods and abort reason, the unauthorized refusal of a pairing activity on a paired session, or server/unpair, and the package release notes did not mention the record-store contract change.
There was a problem hiding this comment.
🟡 Changes recommended
Record persistence invariants, a host lock-order deadlock, and compatibility documentation remain unresolved.
Get a fresh assessment by requesting another Copilot review.
Review details
Suppressed comments (2)
src/Sendspin.SDK/Connection/Noise/PairingRecordStore.cs:224
- This fallback violates the requirement that a completed pairing persist: the host does not cap provisional paired connections below
Capacity, so every stored long-term record can be live here. The followingUpsertthen either throws in a bounded store or exceeds the declared capacity in the shipped stores, after the server has already accepted pairing. Enforce the connection cap/reserve an evictable slot so this state cannot be reached.
if (victim is null)
{
// Every record is either live or the Pairing PSK. The spec makes this the client's
// own error - it must cap concurrent paired connections below its record capacity -
// so the Upsert that follows is left to overflow the store's own limit rather than
// silently dropping a pairing the server has already persisted.
src/Sendspin.SDK/Connection/Noise/PairingRecordStore.cs:435
- Keeping a migrated, unbound record alongside the newly bound record breaks the stated one-record-per-server rule: every re-pair leaves the retired credential consuming capacity and still accepted by the resolver. When a legacy record successfully authenticates, the client knows the server ID and can backfill that binding (or otherwise retain it across the pairing re-handshake), allowing
PersistLongTermto replace the old record instead of appending.
// A long-term record with no server_id predates the one-record-per-server model
// (spec #183), when a long-term PSK was not bound to one server. Kept as-is
// rather than dropped or invented: the PSK still authenticates the server that
// knows it, and discarding it would unpair a working device on upgrade. It
// simply never matches the replace-this-server's-record rule, so the first
// re-pair with that server writes a properly bound record alongside it.
- Files reviewed: 48/48 changed files
- Comments generated: 4
- Review effort level: Balanced
| lock (_connectionsLock) | ||
| { | ||
| _openClients.Remove(client); |
| /// <exception cref="InvalidOperationException"> | ||
| /// Every attempt collided, which no working CSPRNG produces. | ||
| /// </exception> | ||
| internal static byte[] GenerateUniquePsk(IPairingRecordStore store, Func<byte[]>? draw = null) |
There was a problem hiding this comment.
Declined: a psk_id collision on 32 CSPRNG bytes is not a reachable state, and the helper exists for the Pairing PSK; adding a store-null branch here buys nothing.
| the method it is offered reads as absent. The interop workflow for this line runs against | ||
| the aiosendspin commit the unpublished 10.0.0 release targets, because the pairing wire | ||
| the 10.x client sends (spec PR #179's object-keyed `supported_pair_methods` and the | ||
| pairing-code method names) exists only there, with the reference server's model patched | ||
| in CI to accept the object-keyed shape it has not yet adopted; the 9.x line runs against | ||
| 9.1.1. So the 9.0.0 pairing floor and the 7.0.0 playback floor both rest on inspection |
| **Server requirement**: a 10.x client requires a server speaking the encrypted protocol — `aiosendspin >= 7.0.0`. There is no negotiation and no fallback: against an older server the handshake fails. **The 9.x line remains maintained** for deployments that need to talk to those servers. | ||
|
|
||
| **Pairing requires `aiosendspin >= 9.0.0`**, a higher floor than connecting. 9.0.0 is the first release carrying the current pairing wire shape: `server/activate` names the chosen method inside a `pairing` object, with `pin_length` alongside it, rather than in a flat `selected_pair_method` field. 7.0.0 and 8.0.0 still send the old shape, so a 10.x client reads the offered method as absent and refuses every pairing attempt with `pair/abort` reason `method_not_supported`. Connecting and playback — including unpaired access — are unaffected and still work against `>= 7.0.0`. | ||
| **Pairing requires `aiosendspin >= 9.0.0`**, a higher floor than connecting. 9.0.0 is the first release carrying the current pairing wire shape: `server/activate` names the chosen method inside a `pairing` object (with the emission `format` alongside it) rather than in a flat `selected_pair_method` field. 7.0.0 and 8.0.0 still send the old shape, so a 10.x client reads the offered method as absent and refuses every pairing attempt with `pair/abort` reason `method_not_supported`. Connecting and playback — including unpaired access — are unaffected and still work against `>= 7.0.0`. |
…lient state Bring PR #269's current tip onto PR #270's client-state stream configuration: the shared pairing-record store lock, live-record PSK collection over open and adopted clients, lockout key migration, long-term capacity accounting, the server/activate format rejection for static/PSK methods, pairing-code presentation, the migration-guide fixes, and the aiosendspin 10.0.0-draft interop pin. Interop: take #269's interop.yml and pair-method patch script verbatim. #270's three 9.1.1-era interop workarounds are obsolete under #269's 10.0.0-draft pin, which accepts the current wire and runs the static-pin scenario: the redundant patch step and the static-pin skip are dropped. The Program.cs artwork opt-out is left in place.
main advanced past #270's branch point: #269 landed (fe3b263) and #275 and #281 followed. #281 (830368e, forward-port of #280) folds the player's output latency into both reported leads (required_lead_time_ms and min_buffer_ms) from the first client/state on, re-reporting on OutputLatencyChanged and debouncing unchanged repeats. Reconcile with #270's single full-state client/state path so the structure carries #281's behaviour: BuildPlayerState sources both lead values from ReportedLeads(); SendClientStateAsync keeps the _lastReported* dedupe in step with the leads it puts on the wire (read back from the built player object); the OutputLatencyChanged subscription re-sends the full client/state. #281's AudioPipeline / IAudioPipeline / ClientCapabilities.ExpectedOutputLatencyMs and its live-lead tests are taken as-is. #281 and #275 tests pass unchanged.
Brings the pairing wire and pairing-record semantics up to merged spec PRs Sendspin/spec#178, #179, #189, plus the record rules from #183.
Wire changes (#178, #179, #189)
client/helloadvertisespair_methodsas a map of method name →PairMethodDescriptor(carrying each method's supported emission formats) instead of a flat list of names.dynamic_pin/static_pinbecomedynamic_pairing_code/static_pairing_codeacross the wire,ClientCapabilities.PairingCodeMethods, and the PIN KATs.ClientCapabilities.MinPairingCodeLengthis removed.server/activate'spairingobject carries the chosen emissionformat;server/hellocarries thelanguageshint. Both reach the app throughPairingCodePresentation, which also exposes the spec's recommended displayGroups.Record semantics (#183)
IPairingRecordStore.Upsertreturnsvoid(wasbool) and stores declare aCapacity. A pairing that completes at capacity must succeed, so the SDK evicts the least recently used record itself — never its own Pairing PSK, never a record backing a currently open connection — before it writes.PairingRecordgainsServerId: there is exactly one record per server, so re-pairing replaces rather than appends.PairingRecord.Used(bool) becomesLastUsedUtc(DateTimeOffset?), which orders eviction.FilePairingRecordStorestill reads the 9.xusedfield (mappingtruetoDateTimeOffset.MinValue) and only ever writes the new one.pairingactivity.server/unpairdrops the record for the server that sent it.Breaking behaviour
IPairingRecordStorefails to compile (CS0535) untilUpsertreturnsvoid; "the store is full" is no longer an outcome the SDK can be told about.ClientCapabilities.MinPairingCodeLengthand thedynamic_pin/static_pinmethod names no longer compile / no longer match on the wire.PresentPairingCodeAsynctakes aPairingCodePresentationrather than a bare code string.pairingon a long-term session is refusedunauthorized.Docs: README and
MIGRATION-10.0.0.mdcover the descriptors, the store contract, the eviction rule and the record fields. The interop client and Python harness follow the renamed methods.Tests
New:
PairingRecordSemanticsTests,SendspinClientServiceUnpairTests. ThePairingConfigSeedingTestsassertions dropped in PR #1 return here against theclient/hellopair-method descriptors.Stack
chrisuthe/protocol-remove-management-namespace— management namespace removal (Clear the concurrency and timing residue in SendspinConnection #183)mainchrisuthe/state-stream-configuration-in-client-state— client state authority (Run the test suite on net8.0 as well as net10.0 #175/Zeroize handshake and CPace key material #176/Stop blaming the server version for an abnormal listen-path close #181/Controller role has no seek support: seek/seek_relative, position_ms/offset_ms, and seek_max_ms are all missing #195/Provisional-connection timeout sends goodbye reason 'handshake_timeout', outside the spec's closed reason set #204)Merge in order; this PR's diff only reads correctly once (1) has landed.