Skip to content

feat(settings): add the canonical contract manifest and validator - #473

Closed
Quick104 wants to merge 2 commits into
mainfrom
feat/settings-contract-manifest
Closed

Quick104 wants to merge 2 commits into
mainfrom
feat/settings-contract-manifest

Conversation

@Quick104

@Quick104 Quick104 commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

First implementation step for the settings contract (#477). Adds the artifact everything else depends on. Nothing reads it yet — no routes, no storage, no behavior change.

What changed

contracts/settings/v1/ — the artifact, at a stable path because clients vendor it and generate bindings from it

  • manifest.json — 38 definitions (35 remote, 3 contract-known client_local)
  • manifest.schema.json — the contract format
  • schemas/ — object value schemas for subtitle appearance, theme variable overrides, library page state
  • embed.go — a package containing nothing but the embed directive, because go:embed cannot reach outside its own directory

internal/settingscontract/ — loading, structural validation, value validation, RFC 8785 canonicalization, ETag, and a public projection that strips maintainer notes

What the inventory turned up

The manifest covers every key the legacy registry accepts, every key the extension bag was silently accepting, every unregistered device key Android writes, and the profile columns that become settings. Each non-obvious case is recorded in a notes field:

Finding Disposition
ui_theme, ui_text_scale, ui_text_weight, ui_high_contrast, ui_custom_theme_vars, ui_custom_css reached the server only via the unknown-key extension bag — untyped and unvalidated, with ui_custom_theme_vars storing arbitrary JSON Registered, typed, renamed to the dotted convention, moved to profile scope
player.match_frame_rate and player.sleep_timer_default_minutes are written by Android against a server that registers neither, so every write and every reset returns 400 today Registered
player.next_up_prompt_seconds is Android's alias for playback.next_up_prompt_seconds Not a definition; pinned as a migration alias in the test matrix
Android clamps playback speed to 4.0, the server to 3.0 Contract maximum is 3.0
subtitle_appearance is the only key with no domain prefix Renamed to playback.subtitle_appearance

Validation is stricter than the schema

The JSON Schema checks shape. The Go layer checks what actually causes bugs:

  • A resolution order must end in default and may only resolve scopes the definition allows
  • Every writable scope must actually be read — a setting cannot accept writes at a scope it will never honor, which is the "I changed it and nothing happened" failure mode
  • Defaults validate against their own value schema, so a default outside its own range or enum fails at load
  • Revision tags can never exceed the manifest revision, which is what makes revision-aware client filtering trustworthy
  • ceiling/floor policy constraints are rejected on unordered types, where capping would silently do nothing. This forced playback.preferred_quality's enum to be ordered ascending so its max_playback_quality ceiling has a defined direction

ValidateValue is the single validation path, so the mutation endpoint, the migration, and the manifest's own default checks cannot diverge later. Numbers decode through json.Number, so an integer setting rejects 30.5 instead of truncating, and object values validate against their referenced schema rather than accepting any JSON the way validateJSONSetting does today.

Verification

  • 124 tests across 16 cases pass — the inventory matrix, per-definition defaults and resolution orders, revision filtering in both directions, canonical-byte stability and idempotence, notes stripping, and a table of eleven malformed manifests that must be rejected
  • golangci-lint run ./internal/settingscontract/... ./contracts/... → 0 issues
  • make verify-local-paths passes; go build ./... clean
  • Two failures in internal/api/handlers reproduce unchanged on main and are unrelated (one needs ffmpeg, one is a temp-dir cleanup race)

Notes for review

  • Promotes santhosh-tekuri/jsonschema/v6 from indirect to direct
  • The three client_local definitions (downloads.wifi_only, downloads.keep_watched, subtitle.matches_device) are contract-owned because Apple and Android both implement them with shared semantics, but the value never leaves the device. Validation enforces exactly one client_local scope and no policy constraint
  • The renames are sanctioned by the design's non-goal of preserving accidental key names and are free during a breaking cutover, but they are judgment calls worth confirming
  • ui.theme carries a device override, added in the second commit — light theme on a phone in daylight, dark on a TV. ui.custom_theme_vars and ui.custom_css stay profile-wide, so custom tokens tuned against a dark theme will sit on top of a light one if a device overrides. Widening those later is an additive revision bump

Part of #376. Design: #477.

AI-use disclosure

Implemented with AI assistance (Claude Opus 5) under maintainer direction. The inventory was derived by reading the current server registry, web manifest, Android PlaybackSettingsKeys, and the profile/library/series preference stores; every drift claim is reproducible from those sources.

First implementation step for the cross-platform settings contract (#376).
Adds the artifact everything else depends on: the manifest, its JSON Schema,
the object value schemas, and a Go loader that validates the whole thing at
load time. No routes, no storage, no behavior change — nothing reads this yet.

contracts/settings/v1/ holds the artifact at a stable path because clients
vendor it and generate bindings from it. The embed directive has to sit beside
it (go:embed cannot reach outside its own directory), so that directory is a
tiny Go package containing nothing else; loading and validation live in
internal/settingscontract.

38 definitions: 35 remote, 3 contract-known client_local. That covers every key
the legacy registry accepts, every unregistered key the extension bag was
silently accepting from the web client, every unregistered device key Android
writes, and the profile preference columns that become settings.

Registering the previously-unregistered keys is where the drift shows up, and
the manifest records each case in a notes field:

- ui_theme, ui_text_scale, ui_text_weight, ui_high_contrast,
  ui_custom_theme_vars, and ui_custom_css reached the server only because
  keyUsesUserScope returns true for any unregistered key. They are now typed,
  renamed to the dotted convention every other key uses, and moved to profile
  scope per the design.
- player.match_frame_rate and player.sleep_timer_default_minutes are written by
  Android against a server that does not register them, so every write and reset
  is currently rejected. Registered.
- player.next_up_prompt_seconds is Android's alias for
  playback.next_up_prompt_seconds and does not become a definition; the test
  matrix pins it as a migration alias.
- player.playback_speed is capped at 3.0, matching the server rather than
  Android's 4.0.
- subtitle_appearance becomes playback.subtitle_appearance. Every other
  canonical key carries a domain prefix, and preserving accidental key names is
  an explicit non-goal of the design.

Validation is deliberately stricter than the schema can express. Beyond shape,
it enforces that a resolution order ends in "default", that it only resolves
scopes the definition allows, and — the one most likely to bite — that every
writable scope is actually read, so a setting cannot accept writes at a scope it
will never honor. Defaults are validated against their own value schema, so a
default that violates its own range or enum fails at load. Revision tags are
checked to never run ahead of the manifest revision, which is what makes
revision-aware client filtering trustworthy. Ceiling and floor policy
constraints are rejected on unordered types, where capping would silently do
nothing; playback.preferred_quality's enum is therefore ordered ascending.

ValidateValue is the single validation path, so the mutation endpoint, the
migration, and the manifest's own default checks cannot diverge later. Numbers
decode through json.Number so an integer setting rejects 30.5 rather than
truncating, and object values validate against their referenced JSON Schema
instead of accepting arbitrary JSON the way validateJSONSetting does today.

Canonicalization implements RFC 8785 over the value domain the contract uses:
sorted keys, no insignificant whitespace, ECMAScript number formatting. The
digest is the ETag, and PublicBytes strips maintainer notes so the served
manifest never carries internal commentary.

Promotes santhosh-tekuri/jsonschema/v6 from indirect to direct.

Verification: 124 tests pass across 16 cases; golangci-lint clean;
make verify-local-paths passes. Two failures in internal/api/handlers
(TestRemoveJellyfinCompatWebDisablesWebSetting, the playback v3 seek recovery
test) reproduce unchanged on main and are unrelated.

Part of #376.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 17a20ee9-9e67-4060-96df-16956ba32e66

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/settings-contract-manifest

Comment @coderabbitai help to get the list of available commands.

Theme joins text scale, text weight, and high contrast as a profile default
with an optional per-device override, resolving profile_device -> profile ->
default. The right theme is partly a function of the screen and the room — a
light theme on a phone in daylight, a dark one on a TV at night — which is the
same reasoning the other three appearance keys already used.

All four appearance settings now cascade consistently, which also means one
rule to explain in the UI rather than "these three follow the device, that one
does not".

ui.custom_theme_vars and ui.custom_css stay profile-wide. They are authored
styling rather than a contextual preference, so a profile's custom tokens still
apply on top of whichever theme a device resolves to. Recorded in the
definition notes because it is a visible consequence: vars tuned against a dark
theme will sit on top of a light one if a device overrides the theme. Widening
those to profile_device later is an additive revision bump if it turns out to
matter.

Part of #376.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@Quick104

Copy link
Copy Markdown
Contributor Author

Superseded by #479, which combines the design, the manifest, the ui.theme scope decision, and the web appearance cache fix into a single server PR. Same four commits, unchanged.

@Quick104 Quick104 closed this Jul 25, 2026
@Quick104
Quick104 deleted the feat/settings-contract-manifest branch July 25, 2026 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant