Skip to content

Advertise application-specific roles and support objects in client/hello - #218

Merged
kahrendt merged 8 commits into
mainfrom
chrisuthe/task/advertise-application-specific-roles-and-support
Nov 5, 2026
Merged

kahrendt merged 8 commits into
mainfrom
chrisuthe/task/advertise-application-specific-roles-and-support

Conversation

@chrisuthe

@chrisuthe chrisuthe commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Add SendspinClientConfig::application_roles so an application can list its own _-prefixed, versioned roles in client/hello supported_roles, after the library's roles. A role can also carry a support object, which is sent as "<role>_support" (messaging.md "client/hello", README.md "Application-Specific Roles"). The roles defined in the spec are unchanged.

start() refuses to start (it logs an error and returns false) when:

  • a role name is not _<name>@<version> in visible ASCII;
  • a role name is listed twice;
  • a support object is not exactly one JSON object.

ArduinoJson's parser accepts input that isn't strict JSON, such as unquoted keys and single quotes. So instead of embedding the caller's text, start() re-serializes each support object and sends that. A support object is also refused if a string in it is not valid UTF-8, or has a control character the serializer would write back unescaped.

Application-specific versions of defined roles (player@_x) are out of scope: the library implements those roles itself.

This is the generic hook that local pairing with Music Assistant needs, e.g. "_ma_local_pairing@v1_support": {"port": N}.

Part of Sendspin/backlog#86.

Allocation and limit fixes

Merged main twice (#227 onward) and fixed what the allocation series requires of client/hello (Sendspin/backlog#92):

  • The hello views the configured roles (std::span over the config start() normalized) instead of copying them per connection, builds each "<role>_support" key on the stack, and embeds the support object with serialized(data, size), which copies it into the hello's JSON arena (the platform heap past its budget) rather than through operator new. The admission window of sendspin_alloc_tests now configures two application roles and stays at 0.
  • start() also refuses a support object nested past messaging.md "client/hello"'s 10-level cap, and a hello longer than its 16384 bytes, measured on a trial hello with the per-connection fields at their longest; that failure rolls back the roles it started (ClientLifecycle.OversizedHelloRollsBackStartedRoles, which fails without the rollback by finding the player's sync task still bound to the ring).
  • Role names are at most 64 bytes, a library limit, and exclude " and \. is_valid_utf8() lives in inline_text.h with its own table, which rejects a bad byte at every continuation position.
  • The integration guide says the library does not report which application roles a server activates, and that one listed in active_roles on a connection that is not playback-capable closes it.

…object

ArduinoJson accepts unquoted keys, single quotes and raw bytes it then writes back unescaped, so embedding the caller's text could put invalid JSON in client/hello.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues block the addition of configurable application roles to client hello messages.

No open issues 🎉

What changed in this PR

Adds a configuration hook for applications to advertise custom roles and optional support objects in client/hello, without changing the library’s built-in roles. This supports integrations such as Music Assistant local pairing.

Changes:

  • Adds SendspinApplicationRole and SendspinClientConfig::application_roles.
  • Validates role names, rejects duplicates, and normalizes support objects before startup.
  • Adds validation and hello-message tests, plus public API documentation.
File Description
tests/​test_record_store.cpp Tests startup rejection and configured roles in client hello messages.
tests/​test_protocol.cpp Tests role formatting, name validation, and support-object normalization.
tests/​CMakeLists.txt Documents private hello-builder access used by tests.
src/​protocol.cpp Serializes application roles and their support objects.
src/​protocol_messages.h Adds application roles to the internal hello message structure.
src/​client.cpp Validates configuration at startup and supplies roles to hello messages.
src/​application_role.h Implements role-name, UTF-8, and JSON normalization helpers.
include/​sendspin/​config.h Defines the public application-role configuration API.
docs/​integration-guide.md Documents configuration, examples, and validation behavior.

Review effort: Balanced

# Conflicts:
#	src/protocol.cpp
#	tests/test_protocol.cpp
…mits

- client/hello views the configured application roles instead of
  copying them for each connection, builds each "<role>_support" key on
  the stack, and embeds the normalized support object without a copy,
  so the admission window, now with application roles configured, stays
  at 0 allocations.
- start() refuses what messaging.md "client/hello" forbids: a support
  object nested past the hello's 10-level cap and a hello longer than
  16384 bytes, measured on a trial hello with the per-connection fields
  at their longest; the oversized path rolls the started roles back.
- Role names are at most 64 bytes (a library limit) and exclude `"`
  and `\`; is_valid_utf8() moves to inline_text.h with its own table.
- The integration guide says the library does not report which
  application roles a server activates, and that one listed on a
  connection that is not playback-capable closes it.
# Conflicts:
#	docs/internals.md
#	tests/test_allocations.cpp

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Duplicate keys can hide invalid support-object strings, while hello serialization adds avoidable allocations and its preflight check can fail despite sufficient reserved arena capacity.

6 open issues

Review effort: Max

Comment thread src/application_role.h Resolved
Comment thread src/protocol.cpp Resolved
Comment thread src/protocol.cpp Resolved
Comment thread src/protocol.cpp Resolved
Comment thread tests/test_client_lifecycle.cpp Resolved
Comment thread tests/test_inline_text.cpp Resolved
@kahrendt
kahrendt enabled auto-merge (squash) November 5, 2026 00:18
@kahrendt kahrendt added the enhancement New feature or request label Nov 5, 2026
@kahrendt
kahrendt merged commit 3a3722a into main Nov 5, 2026
16 checks passed
@kahrendt
kahrendt deleted the chrisuthe/task/advertise-application-specific-roles-and-support branch November 5, 2026 00:22
@kahrendt

kahrendt commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants