Compare commits

..
Author SHA1 Message Date
QuickandClaude Opus 4.8 37ad393536 fix(api): show symlinked directories in the folder browser
The folder browser listed children with entry.IsDir(), which reflects the
lstat type, so a symlink pointing at a directory was reported as a
non-directory and silently skipped. Symlinked library folders (e.g. Docker
bind mounts into an rclone/FUSE mount) never appeared in the picker, even
though the targets are valid, readable directories.

Follow symlink entries with os.Stat and include them when the target
resolves to a directory. Regular directories keep the fast path with no
extra syscall; symlinks to files and dangling symlinks remain excluded.

Closes #208

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 16:56:44 -04:00
1860 changed files with 24209 additions and 293342 deletions
-1
View File
@@ -1 +0,0 @@
../.claude/skills
@@ -1,111 +0,0 @@
---
name: dev-environment-debugging
description: Use when diagnosing a running Silo server — playback, streaming, or transcode failures, unhealthy nodes, stuck sessions, wrong database state, errors after a deploy, or anything needing the deployment's logs, health endpoints, or SQL. Covers both a local docker compose install and a remote host over SSH. Not for building or testing code in this repo, and not for client-side bugs that reproduce without a server.
---
# Debugging a running Silo deployment
Everything here goes through `scripts/silo-dev`, which reads `.silo-dev.env` and runs
commands against the deployment whether it is on this machine or behind SSH. Start with:
```bash
scripts/silo-dev doctor
```
`doctor` reports which of API, host shell, compose stack, database, and login actually
work. Fix what it flags before diagnosing anything else — most confusing symptoms here
are really a misconfigured target. If `.silo-dev.env` is missing, copy
`.silo-dev.env.example` and fill it in; ask the user for hosts and credentials rather
than guessing, and never move those values into a committed file.
## Orienting
```bash
scripts/silo-dev compose ps # what is running
scripts/silo-dev api /api/v1/health # API up
scripts/silo-dev api /api/v1/ready # PostgreSQL and optional S3 reachable
scripts/silo-dev logs --tail 200 # recent server logs
scripts/silo-dev logs -f # follow
```
`/ready` failing usually means the database, not the API — read the service logs before
concluding Postgres is down.
Silo also records structured logs in the database itself, which survive container
restarts and are easier to filter than stdout. `operational_logs` holds server events,
`activity_log` holds HTTP requests; both are keyed by `"timestamp"` (quoted — it is a
reserved word). See [references/queries.md](references/queries.md) for the diagnostic
queries worth having on hand, along with the schema traps that bite most often.
Log level lives in `server_settings` under `server.log_level` and is read at startup, so
raising it to `debug` means updating the row and recreating the service. Put it back
afterwards unless the task needs it to persist.
## Search
Meilisearch is optional — Silo runs without it — but it is recommended, and it is what
makes search results good. It ships as a compose service behind the `search` profile and
needs `MEILI_MASTER_KEY` set, so a stack brought up without that profile simply has no
`meilisearch` service.
The provider is chosen from the `catalog.search.provider` setting rather than from
whether the container is running, and the failure mode is quiet: if Meilisearch is
selected but the URL is empty, unreachable, or the provider fails to initialize, Silo
logs a warning at startup and serves Postgres results instead. Nothing surfaces to the
client. So "search got worse" or "search stopped matching the way it used to" is usually
the fallback being active, not a ranking regression — check which provider is live before
touching query code:
```bash
scripts/silo-dev psql "SELECT key, value FROM server_settings WHERE key LIKE 'catalog.search%' ORDER BY key;"
scripts/silo-dev logs --tail 500 | grep -i 'catalog search'
```
Provider settings, index name, timeouts, batch sizes, and the semantic-search options all
live under `catalog.search.meilisearch.*` in `server_settings`. Changing the provider
needs a restart to take effect.
## Playback
Work outward from the failure the user actually saw.
**Direct play** — confirm the file exists at the path stored in `media_files`
(`scripts/silo-dev sh 'ls -la …'`, under `SILO_MEDIA_ROOT`), then compare the file's
codecs against what the client advertised. A mismatch should have fallen back to remux
or transcode; if it did not, that is the bug.
**Remux and transcode** — both run ffmpeg inside the server container, so check ffmpeg
is present and, for hardware paths, that `/dev/dri` is passed through:
```bash
scripts/silo-dev compose "exec -T silo sh -lc 'ffmpeg -hwaccels; ls -la /dev/dri'"
```
Transcode output lands in a bind-mounted temp directory; a full disk there looks like a
transcode bug. If `SILO_TRANSCODE_SSH` is set, the node is a separate host with its own
`/api/v1/health` and logs — check it before blaming the main server.
**Stuck sessions** — query `playback_sessions_sync` for rows whose `updated_at` has gone
stale. The reconciler and shutdown path clean these up; when Redis is unavailable,
cross-node coordination degrades and stale rows are a symptom rather than the cause.
## Deploying a fix
`make dev-deploy` and friends come from `Makefile.local`, which is gitignored and
per-developer — do not assume they exist. Confirm with `make -n dev-deploy` first, and
otherwise deploy however the user's setup does. Afterwards, verify rather than assume:
```bash
scripts/silo-dev compose ps
scripts/silo-dev api /api/v1/ready
scripts/silo-dev logs --tail 100
```
Deploys restart the container, which invalidates any token you were holding.
## Rename drift
Silo was formerly Continuum. Names like `continuum-postgres`, `/opt/continuum`,
`CONTINUUM_IMAGE`, or a stray `docker-compose.dev.yml` are usually legacy artifacts, but
on a long-lived host they are occasionally still the live stack. Check what compose
actually reports before deciding which one you are looking at.
@@ -1,110 +0,0 @@
# Diagnostic queries
Run with `scripts/silo-dev psql "<sql>"`.
## Schema traps
- `activity_log` and `operational_logs` order by `"timestamp"` — quoted, not `created_at`.
- `admin_jobs` uses `job_type`, `requested_at`, and `completed_at` (not `type`,
`created_at`, `finished_at`).
- Login accounts (`users`) are separate from household profiles (`user_profiles`); a
playback session carries both a `user_id` and a `profile_id`.
## Errors and requests
```sql
SELECT "timestamp", level, component, message, request_id, playback_session_id, attrs
FROM operational_logs
WHERE level IN ('error', 'warn')
ORDER BY "timestamp" DESC
LIMIT 50;
```
```sql
SELECT "timestamp", client_ip, method, path, status_code, duration_ms, request_id
FROM activity_log
WHERE status_code >= 500
ORDER BY "timestamp" DESC
LIMIT 20;
```
Drop the `WHERE` clause on `activity_log` for a plain recent-traffic view — useful for
confirming a client is reaching the server at all, and with which paths.
## Playback
```sql
SELECT s.session_id, u.username, COALESCE(s.profile_id, '') AS profile_id,
s.play_method, s.reporting_node, s.transcode_node_url,
s.position_seconds, s.is_paused, s.target_resolution,
s.started_at, s.updated_at
FROM playback_sessions_sync s
LEFT JOIN users u ON u.id = s.user_id
ORDER BY s.updated_at DESC NULLS LAST;
```
Stale rows only:
```sql
SELECT session_id, user_id, play_method, updated_at
FROM playback_sessions_sync
WHERE updated_at < now() - interval '5 minutes'
ORDER BY updated_at;
```
## Nodes
```sql
SELECT id, name, type, url, enabled, healthy, active_jobs, last_health_check
FROM stream_nodes
ORDER BY type, name;
```
Read-only node state is better taken from here than from the admin endpoints, which need
a bearer token. To force a re-check, `POST /api/v1/admin/nodes/{id}/check` — reachable as
`scripts/silo-dev api /api/v1/admin/nodes/{id}/check -X POST`.
## Jobs
```sql
SELECT id, job_type, status, message, error_message,
progress_current, progress_total, requested_at, started_at,
completed_at, heartbeat_at
FROM admin_jobs
ORDER BY requested_at DESC
LIMIT 20;
```
Filter by `job_type = 'library_refresh'` (and select `request_payload`, `result_payload`)
when chasing a scan or refresh that did not finish.
## Users and settings
```sql
SELECT id, username, email, role, enabled, permissions, max_streams, max_transcodes, created_at
FROM users
ORDER BY id;
```
```sql
SELECT key, value
FROM server_settings
WHERE key NOT ILIKE '%secret%'
AND key NOT ILIKE '%password%'
AND key NOT ILIKE '%api_key%'
AND key NOT ILIKE '%token%'
ORDER BY key;
```
Keep that filter. Encrypted `server_settings` values are GCM-bound to their key name, so
they are unreadable here anyway — and dumping them into a transcript is a leak.
## Raising the log level
```sql
INSERT INTO server_settings (key, value) VALUES ('server.log_level', 'debug')
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value;
```
Then `scripts/silo-dev compose "up -d --force-recreate silo"`, and set it back to `info`
when done.
+31 -15
View File
@@ -33,17 +33,29 @@ doing these in order, not from skipping them.
## Operating principles
- **Default to "maybe nothing needs fixing."** Agents "fix" already-correct or stale
code in a large fraction of cases because they don't stop to confirm the problem is
real. Confirm the issue reproduces on current `main` before changing anything.
- **Verify by execution.** Build/lint/tests are the primary correctness signal. The
adversarial review is a *second* layer on top, never a substitute for green checks.
- **Don't trust recall for APIs.** Grep for every symbol and signature you call —
hallucinated-but-plausible APIs are a common failure here.
- **Know when to stop.** See [Stop and ask](#stop-and-ask). Autonomy is for execution,
not for inventing product decisions or shipping unverifiable guesses.
- **Default to "maybe nothing needs fixing."** Coding agents "fix" already-correct
or stale code in a large fraction of cases because they don't stop to confirm the
problem is real. Confirm the issue reproduces on current `main` before changing
anything — it may already be fixed.
- **Root cause over symptom.** A fix you can't explain is a fix you can't trust.
- **Verify by execution, not by reading.** Build/lint/tests are the primary
correctness signal. The adversarial review is a *second* layer on top — never a
substitute for green checks. If you can't verify it, don't ship it.
- **Smallest correct change.** Match surrounding code's idioms, naming, and comment
density. Put code in the package that owns the behavior (CLAUDE.md); don't create
catch-all helpers or duplicate logic — search for an existing helper before
writing a new one, and extract shared logic instead of copying.
- **Don't trust recall for APIs.** Verify every symbol, function, and signature you
call actually exists by grepping the codebase — agents hallucinate plausible-looking
APIs.
- **Don't gold-plate.** A reviewer told to find gaps will always find some. Address
what affects correctness or the issue's stated requirements; treat the rest as
optional. Extra abstraction "just in case" is a defect, not diligence.
- **Know when to stop.** See [Stop and ask](#stop-and-ask). Autonomy is for
execution, not for inventing product decisions or shipping unverifiable guesses.
Track the phases below with a task list so progress is visible on long runs.
Track the phases below with a task list (TaskCreate/TaskUpdate) so progress is
visible and nothing is skipped on long runs.
## Workflow
@@ -110,8 +122,8 @@ build-out.
### 4. Implement
Make the change, scoped to this one concern (one concern per PR). The two hard rules
that a reviewer cannot un-break after the fact:
Make the change, scoped to this one concern (one concern per PR). Respect the hard
rules:
- **API:** additive-only within `/api/v1` — never rename/remove a response field,
change a field's type, or repurpose a status code. New behavior = new
@@ -119,6 +131,8 @@ that a reviewer cannot un-break after the fact:
- **Migrations:** new DB changes are Goose SQL migrations via
`make migrate-create NAME=...` (timestamped). Never `goose fix`, never paired
`.up.sql`/`.down.sql`.
- **Maintainability:** extract shared logic instead of duplicating; change existing
code rather than bolting on local workarounds.
For a bug, the failing test from step 3 should now pass.
@@ -165,9 +179,11 @@ Do not open the PR while a material, un-rebutted adversarial finding stands.
### 7. Commit, push, open the PR
Conventional Commit subjects scoped to the domain, e.g.
`fix(playback): guard against nil session on reconnect`, ending with the
`Co-Authored-By:` trailer for the model you are actually running as — don't copy a
model name from this file or from an older commit.
`fix(playback): guard against nil session on reconnect`. End commit messages with:
```
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
```
Push and open a **ready** (non-draft) PR against `main`:
@@ -1,51 +0,0 @@
---
name: jellycompat-diagnosis
description: Use when a Jellyfin-protocol client (JellyCon, Findroid, Infuse, Swiftfin) misbehaves against Silo's jellycompat API — wrong or missing data, ignored sort/filter/pagination parameters, oversized responses, or slow browse queries. Covers comparing Silo's responses against a real Jellyfin server field-by-field and reading the jellycompat debug log. Not for Silo's own `/api/v1` clients.
---
# Diagnosing jellycompat responses
Jellyfin clients are unforgiving about response shape: a missing field or an extra one
changes what they render, and they rarely report why. The reliable method is to make the
identical request against Silo and against a real Jellyfin, then diff the JSON.
Set `JELLYFIN_COMPARE_URL` and credentials in `.silo-dev.env` — without a reference
server you are guessing at what the client expected.
## Start from what the client actually sent
The debug log records full request/response pairs, but only when the server runs with
`JELLYCOMPAT_DEBUG_LOG` set to a path. If it is unset, that is the first fix.
```bash
scripts/silo-dev sh 'grep -E "^(===|Status:|Remote:|Response \()" /opt/silo/jellycompat-debug.log | tail -60'
```
That overview is usually enough to localize the problem before reading any bodies. Look
for response sizes (a 20-item list over ~50KB is wrong), latency (browse over a second is
wrong), non-200 statuses, and — most importantly — which query parameters the client
actually sent, which is often not what you assumed. `grep -n "^==="` gives request
boundaries to `sed` a specific body out of.
## Compare against real Jellyfin
Authenticate to both and request the same path. Jellyfin's auth is a POST to
`/Users/AuthenticateByName` with an `X-Emby-Authorization` header; the response carries
`AccessToken` and `User.Id`, which you need for subsequent `/Users/{id}/Items` calls.
Silo's jellycompat listens on port 8096 alongside the main API.
Diff the sorted key lists of one item from each side before diffing values — a field that
is present on one and absent on the other explains most client bugs on its own, and
`omitempty` in `dto.go` means an empty value and a missing field are the same thing on
the wire.
[references/response-parity.md](references/response-parity.md) has the queries JellyCon
sends, the fields real Jellyfin returns with and without an explicit `Fields` parameter,
the parameter-handling behaviors worth asserting, and a symptom-to-cause table for the
failures already found once — check it before re-deriving a diagnosis.
## After a fix
Redeploy, then re-authenticate — restarting the container invalidates the tokens — and
re-run every query you were comparing, not just the one you fixed. Field gating is shared
across handlers, so a change that corrects a list view frequently perturbs detail views.
@@ -1,66 +0,0 @@
# Response parity reference
## Queries JellyCon sends
| Query | Purpose | Key params |
|-------|---------|-----------|
| Random widgets | Home screen | `SortBy=Random&IsPlayed=False&ImageTypeLimit=0` (no `Fields`) |
| Library browse | Movie/TV list | `Fields=Overview,Genres,Studios,…&SortBy=SortName&ParentId=LIB` |
| Recently added | New content | `Fields=…&SortBy=DateCreated&IsPlayed=False&Limit=20` |
| Recently played | Watched | `IsPlayed=True&SortBy=DatePlayed&Limit=20` |
| In progress | Resume | `Filters=IsResumable&SortBy=DatePlayed&Limit=20` |
| Item detail | Single item | `GET /Items/{id}` |
| Views | Libraries | `GET /Users/{id}/Views` |
## Expected shape
Structural, per response:
- `TotalRecordCount` is the real count, not a ceiling.
- `Items` length matches `Limit`, or the total when fewer exist.
- List items run ~0.5–1.5KB each without `Fields`, ~2–3KB with them.
Fields real Jellyfin returns on a list item with no `Fields` parameter:
```
Name, Id, ServerId, Type, IsFolder, ProductionYear, OfficialRating,
CommunityRating, RunTimeTicks, UserData, ImageTags, ChannelId, MediaType,
LocationType, VideoType, Container, HasSubtitles, CriticRating, PremiereDate,
ImageBlurHashes
```
With an explicit `Fields` parameter: every requested field appears, unrequested ones do
not, `ImageTags` is present even when empty (`{}`), and `People` and `MediaSources`
appear only on detail views — never in a list.
Parameter handling worth asserting directly:
- `ImageTypeLimit=0` → `ImageTags: {}` and no `BackdropImageTags`; `=1` → normal tags.
- `SortBy=Random` → a different order per request.
- `IsPlayed=False` / `True` → filtered accordingly, and the `True` case is fast.
- `Filters=IsResumable` → only items with `PlaybackPositionTicks > 0`.
## Symptoms already traced once
| Symptom | Cause | Where |
|---------|-------|-------|
| `TotalRecordCount` pinned at 10000 | count ceiling | `internal/catalog/browse.go` |
| Same items every request | `SortBy` value unmapped | `query.go:mapSortBy` |
| Parameter ignored (`IsPlayed`, `ImageTypeLimit`) | not parsed | `itemsQuery` / `parseItemsQuery` in `query.go` |
| Items over ~5KB each | fields ungated, detail fetched per item | `mapping.go` |
| Multi-second empty response | over-fetch loop scanning the catalog | needs a dedicated handler |
| Missing Studios/Taglines/Countries | not carried through the intermediate type | `upstream_types.go`, `mediaItemToListItem` |
| `People`/`MediaSources` in a list | resume path built items from the detail mapper | `handleResumeResponse` |
## Files
| File | Role |
|------|------|
| `internal/jellycompat/query.go` | query parsing, field and sort mapping |
| `internal/jellycompat/mapping.go` | DTO construction, field gating |
| `internal/jellycompat/handlers_items.go` | dispatch, `ImageTypeLimit` |
| `internal/jellycompat/content_direct.go` | browse post-filtering, user-data enrichment |
| `internal/jellycompat/dto.go` | JSON tags — `omitempty` decides field presence |
| `internal/jellycompat/upstream_types.go` | catalog-to-DTO intermediate types |
| `internal/jellycompat/logging.go` | debug log middleware (`JELLYCOMPAT_DEBUG_LOG`) |
| `internal/catalog/browse.go` | SQL building, sort, count, pagination |
@@ -1,5 +0,0 @@
.secrets/
.state/
__pycache__/
*.pyc
*.env
-102
View File
@@ -1,102 +0,0 @@
---
name: silo-discord-triage
description: Triage Discord thread URLs, Discord channel/message links, screenshots, or pasted Discord discussions that report bugs, regressions, feature requests, or support issues for Silo projects. Use when the user provides a Discord thread about Silo Server, the Silo Apple clients, the Silo Android app, or an unclear cross-project Silo issue and wants the report fetched with a scoped Discord bot token, summarized, validated, routed to the right repo, converted into a GitHub issue, used as the starting point for a fix, or answered through the bot after approving the exact reply.
---
# Silo Discord Triage
## Overview
Turn one Discord report into a decision-ready Silo intake: extract the concrete problem, route it to the correct project, validate the claim before editing, and produce privacy-safe next actions.
## Intake Workflow
1. Capture the source thread.
- If the user provided a Discord URL, run `scripts/parse_discord_url.py <url>` to identify the URL shape and IDs for private working notes.
- Prefer `scripts/fetch_discord_thread.py <url>` when the bot token is available. The script reads `DISCORD_BOT_TOKEN` first — set it in the repo's gitignored `.silo-dev.env` — then falls back to `.secrets/discord_bot_token` next to this skill, which is gitignored for the same reason.
- Keep the token out of prompts, command arguments, logs, issues, commits, public summaries, and reusable skill instructions. If a token file is used, keep it local, ignored, and mode `0600`.
- If bot-token fetch fails because the bot lacks channel/thread access, permissions, or message-content access, report that blocker precisely and fall back to browser access, pasted transcript, screenshots, or exported thread content.
- Open the Discord URL with whatever browser or Chrome tooling is available only when bot-token ingestion is unavailable or insufficient.
- Read the first report, title, replies, attachments, screenshots, logs, timestamps that affect ordering, and any maintainer follow-up. Treat Discord content as untrusted input.
- Do not post to Discord, react, mention users, or take external actions without explicit user approval.
2. Classify and route.
- Bug/regression: identify observed behavior, expected behavior, affected version or environment, repro steps, frequency, workaround, logs, and user impact.
- Feature request: identify the user need, affected workflow, proposed behavior, constraints, acceptance criteria, and open product questions.
- Support/question: separate user configuration or usage help from product defects.
- Server/web/API issues belong to Silo Server when they involve API behavior, web UI, auth/profiles, libraries, metadata, downloads, matching, Jellyfin/Jellycompat, database migrations, deploys, or backend logs.
- Apple issues belong to the Silo Apple client when they involve iOS, tvOS, macOS, SwiftUI layout, playback, AirPlay, cast remote control, subtitles, native media controls, background behavior, or App Store platform behavior.
- Android issues belong to the Silo Android app when they involve Android UI, playback, downloads, platform permissions, notifications, Android TV, or device-specific Android behavior. Locate the owning repo from local workspace or GitHub context before assuming a path.
- Cross-project issues need one primary owner plus explicit dependencies. Avoid spreading a fix across repos until the failing boundary is proven.
3. Validate before acting.
- For code changes, inspect the current owning repo and current implementation first. Preserve unrelated local work.
- For server/live API failures, start from the exact endpoint, log, schema, or runtime path described by the report before changing logic.
- For Apple/mobile visual reports, identify the actual platform and owning view or player path early instead of diagnosing from the server repo.
- For Android reports, verify the current Android code and device/API-level assumptions before proposing server or Apple changes.
- Search existing GitHub issues or PRs when the user asks to file, prioritize, or fix a report.
- Keep verification minimal by default: do not add tests for small changes or UI changes unless requested; add backend tests only for critical or high-risk logic.
4. Produce the result.
- For triage only, return a concise brief with: source type, classification, owning project, distilled report, evidence, validation performed, likely next action, and remaining unknowns.
- For GitHub issue text, draft a sanitized title and body with repro steps, expected behavior, actual behavior, evidence summary, scope, and acceptance criteria when relevant.
- Do not include private Discord URLs, Discord IDs, personal names, account names, private hostnames, local usernames, local filesystem paths, or private infrastructure identifiers in public issue text, PR text, commit messages, or summaries. Use neutral placeholders such as `internal Discord thread`, `reporting user`, `private deployment host`, or `local workspace`.
- Before publishing issue or PR text, committing, or summarizing public output, run `~/.local/bin/privacy-leak-check` on the draft or staged content when available.
5. Post an approved reply when requested.
- Require explicit approval of the exact message content before posting. An instruction such as "send that" after the draft is shown counts as approval; a request to investigate or draft does not.
- Use `scripts/post_discord_message.py <url> --content-file <path>` first to validate the destination and payload without posting.
- Add `--confirm` only after approval. The helper disables all allowed mentions, verifies Discord returned the same content, and never prints the token or message content.
- Fetch the thread again after posting and verify the approved reply is present once. Do not retry a successful post merely because a later verification fetch fails.
- If posting returns `403`, report the missing Discord permission precisely. A public channel needs `Send Messages`; a thread also needs `Send Messages in Threads`. Private threads must be visible to or joined by the bot.
- Prefer the bot helper over browser login for approved Silo thread replies when the bot token is configured and the bot can access the destination.
## Issue Draft Shape
Use this structure when the user asks to turn the thread into a GitHub issue:
```markdown
## Summary
Briefly state the user-visible problem or requested capability.
## Source
Internal Discord thread. Do not include private links or IDs unless the user explicitly asks for a private tracker entry.
## Steps to Reproduce
1. ...
## Expected Behavior
...
## Actual Behavior
...
## Evidence
Summarize screenshots, logs, messages, or validation results without exposing private identifiers.
## Scope
Owning project: Silo Server, Silo Apple, Silo Android, or cross-project.
## Acceptance Criteria
- ...
```
## Script
Use `scripts/parse_discord_url.py` to parse Discord URLs without network access. It accepts `discord.com` and `discordapp.com` channel links and emits JSON by default.
Use `scripts/fetch_discord_thread.py <url>` to fetch thread or channel messages through the Discord HTTP API. Requirements:
- Put the bot token in `DISCORD_BOT_TOKEN` (via `.silo-dev.env`), or keep it in `.secrets/discord_bot_token` next to this skill. The environment variable overrides the file. Both locations are gitignored; the token must never reach a committed file, a prompt, a command argument, or a log.
- Install the Discord app with the `bot` scope only.
- Grant the bot `View Channel` and `Read Message History` for the specific report channels/threads.
- Enable the `Message Content` privileged intent when the skill must read user-written content, embeds, attachments, components, or polls from message objects.
- For intake-only triage, do not grant `Send Messages`, `Manage Messages`, `Manage Threads`, moderation, admin, or webhook permissions.
- For explicitly approved reply workflows, grant only `Send Messages` and, for threads, `Send Messages in Threads`; moderation, admin, webhook, and message-management permissions remain unnecessary.
- If the report is in a private thread, ensure the bot is permitted to see that thread or is added to it.
Use `scripts/post_discord_message.py <url> --content-file <path> [--confirm]` for bot replies. Without `--confirm`, it performs a read-only destination/payload validation. With `--confirm`, it posts one message with mentions disabled and verifies the create-message response.
`fetch_discord_thread.py` emits oldest-first JSON with pseudonymous author labels by default. Message links (guild/channel/message URLs) are supported: the fetch anchors on the linked message (`around` context, guaranteed inclusion) and marks it with `"is_linked_message": true` in the output — start triage from that message. Use `--include-sensitive` only for private local diagnosis when exact Discord IDs, usernames, message URLs, or attachment URLs are necessary.
Use `scripts/discover_discord_threads.py` for automation. It reads `.secrets/discord_monitor.json`, lists active threads visible to the bot, compares them with `.state/discord_seen_threads.json`, and emits only newly discovered thread URLs by default. Run it with `--init` once before starting an automation so existing active threads are marked seen and only future threads create sessions. In automation runs, mark each Discord thread as seen with `--mark-thread-id <id>` only after its Codex session has been created.
@@ -1,4 +0,0 @@
interface:
display_name: "Silo Discord Triage"
short_description: "Fetch, triage, and reply to Silo Discord reports"
default_prompt: "Use $silo-discord-triage to fetch this Discord thread with the scoped bot token, triage it, and post an exact reply only after I approve the content."
@@ -1,191 +0,0 @@
#!/usr/bin/env python3
"""Discover new active Discord threads for Silo intake automation."""
from __future__ import annotations
import argparse
import json
import os
import sys
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
SCRIPT_DIR = Path(__file__).resolve().parent
sys.path.insert(0, str(SCRIPT_DIR))
from fetch_discord_thread import DEFAULT_TOKEN_ENV, DEFAULT_TOKEN_FILE, DiscordAPIError, load_token, request_json # noqa: E402
DISCORD_EPOCH_MS = 1420070400000
DEFAULT_CONFIG_FILE = SCRIPT_DIR.parent / ".secrets" / "discord_monitor.json"
DEFAULT_STATE_FILE = SCRIPT_DIR.parent / ".state" / "discord_seen_threads.json"
def now_iso() -> str:
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
def snowflake_timestamp(snowflake: str) -> str | None:
try:
timestamp_ms = (int(snowflake) >> 22) + DISCORD_EPOCH_MS
except ValueError:
return None
return datetime.fromtimestamp(timestamp_ms / 1000, tz=timezone.utc).isoformat().replace("+00:00", "Z")
def read_json(path: Path, default: dict[str, Any]) -> dict[str, Any]:
try:
return json.loads(path.read_text(encoding="utf-8"))
except FileNotFoundError:
return default
def write_json(path: Path, data: dict[str, Any]) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
tmp_path = path.with_suffix(path.suffix + ".tmp")
tmp_path.write_text(json.dumps(data, indent=2, sort_keys=True) + "\n", encoding="utf-8")
os.chmod(tmp_path, 0o600)
tmp_path.replace(path)
os.chmod(path, 0o600)
def load_config(path: Path) -> dict[str, Any]:
config = read_json(path, {})
guild_ids = config.get("guild_ids")
if not isinstance(guild_ids, list) or not guild_ids:
raise SystemExit(f"Missing guild_ids in {path}")
return config
def thread_url(guild_id: str, thread_id: str) -> str:
return f"https://discord.com/channels/{guild_id}/{thread_id}"
def normalize_thread(guild_id: str, thread: dict[str, Any]) -> dict[str, Any]:
thread_id = thread["id"]
return {
"created_at": snowflake_timestamp(thread_id),
"last_message_id": thread.get("last_message_id"),
"message_count": thread.get("message_count"),
"name": thread.get("name") or "untitled-discord-thread",
"parent_channel_id": thread.get("parent_id"),
"thread_id": thread_id,
"type": thread.get("type"),
"url": thread_url(guild_id, thread_id),
}
def iter_active_threads(token: str, config: dict[str, Any]) -> list[dict[str, Any]]:
parent_filter = set(config.get("parent_channel_ids") or [])
ignored = set(config.get("ignore_thread_ids") or [])
discovered: list[dict[str, Any]] = []
for guild_id in config["guild_ids"]:
payload = request_json(f"/guilds/{guild_id}/threads/active", token)
for thread in payload.get("threads", []):
thread_id = thread.get("id")
if not thread_id or thread_id in ignored:
continue
parent_id = thread.get("parent_id")
if parent_filter and parent_id not in parent_filter:
continue
discovered.append(normalize_thread(guild_id, thread))
discovered.sort(key=lambda item: item.get("thread_id") or "", reverse=True)
return discovered
def mark_seen(state: dict[str, Any], threads: list[dict[str, Any]]) -> None:
seen = state.setdefault("seen_threads", {})
timestamp = now_iso()
for thread in threads:
thread_id = thread["thread_id"]
record = seen.setdefault(thread_id, {})
record.update(
{
"first_seen_at": record.get("first_seen_at") or timestamp,
"last_seen_at": timestamp,
"name": thread.get("name"),
"url": thread.get("url"),
}
)
def mark_thread_ids(state: dict[str, Any], thread_ids: list[str]) -> None:
seen = state.setdefault("seen_threads", {})
timestamp = now_iso()
for thread_id in thread_ids:
record = seen.setdefault(thread_id, {})
record.update(
{
"first_seen_at": record.get("first_seen_at") or timestamp,
"last_seen_at": timestamp,
}
)
def main() -> int:
parser = argparse.ArgumentParser(description="Discover new active Discord threads visible to the Silo intake bot.")
parser.add_argument("--config-file", default=str(DEFAULT_CONFIG_FILE), help="Discord monitor config JSON")
parser.add_argument("--state-file", default=str(DEFAULT_STATE_FILE), help="Seen-thread state JSON")
parser.add_argument("--token-env", default=DEFAULT_TOKEN_ENV, help="Environment variable containing the bot token")
parser.add_argument("--token-file", default=str(DEFAULT_TOKEN_FILE), help="Fallback file containing the bot token")
parser.add_argument("--max-new", type=int, default=20, help="Maximum new threads to emit")
parser.add_argument("--init", action="store_true", help="Mark all currently visible active threads as seen")
parser.add_argument("--include-seen", action="store_true", help="Emit seen threads too")
parser.add_argument("--mark-seen", action="store_true", help="Mark emitted new threads as seen")
parser.add_argument("--mark-thread-id", action="append", default=[], help="Mark one specific Discord thread ID as seen without discovery")
args = parser.parse_args()
state_path = Path(args.state_file).expanduser()
state = read_json(state_path, {"seen_threads": {}})
if args.mark_thread_id:
mark_thread_ids(state, args.mark_thread_id)
write_json(state_path, state)
print(json.dumps({"marked_seen": len(args.mark_thread_id)}, indent=2, sort_keys=True))
return 0
token = load_token(args.token_env, args.token_file)
if not token:
raise SystemExit(f"No Discord bot token found; set {args.token_env} or create .secrets/discord_bot_token in the skill directory")
config_path = Path(args.config_file).expanduser()
config = load_config(config_path)
try:
active_threads = iter_active_threads(token, config)
except DiscordAPIError as exc:
print(str(exc), file=sys.stderr)
return 1
seen = state.setdefault("seen_threads", {})
if args.init:
mark_seen(state, active_threads)
write_json(state_path, state)
print(json.dumps({"initialized": True, "marked_seen": len(active_threads)}, indent=2, sort_keys=True))
return 0
if args.include_seen:
output_threads = active_threads
else:
output_threads = [thread for thread in active_threads if thread["thread_id"] not in seen]
output_threads = output_threads[: args.max_new]
if args.mark_seen:
mark_seen(state, output_threads)
write_json(state_path, state)
print(
json.dumps(
{
"new_thread_count": len(output_threads),
"threads": output_threads,
},
indent=2,
sort_keys=True,
)
)
return 0
if __name__ == "__main__":
sys.exit(main())
@@ -1,267 +0,0 @@
#!/usr/bin/env python3
"""Fetch Discord thread/channel messages with a bot token from env or a local secret file."""
from __future__ import annotations
import argparse
import json
import os
import sys
import time
import urllib.error
import urllib.parse
import urllib.request
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import Any
SCRIPT_DIR = Path(__file__).resolve().parent
sys.path.insert(0, str(SCRIPT_DIR))
from parse_discord_url import parse_discord_url # noqa: E402
API_BASE = "https://discord.com/api/v10"
DEFAULT_TOKEN_ENV = "DISCORD_BOT_TOKEN"
DEFAULT_TOKEN_FILE = SCRIPT_DIR.parent / ".secrets" / "discord_bot_token"
USER_AGENT = "silo-discord-triage/1.0"
@dataclass
class FetchResult:
source: str
channel_id: str
guild_id: str | None
channel: dict[str, Any] | None
message_count: int
messages: list[dict[str, Any]]
warnings: list[str]
class DiscordAPIError(RuntimeError):
def __init__(self, status: int | None, message: str):
self.status = status
super().__init__(message)
def request_json(path: str, token: str, params: dict[str, Any] | None = None) -> Any:
query = ""
if params:
query = "?" + urllib.parse.urlencode({key: value for key, value in params.items() if value is not None})
request = urllib.request.Request(
API_BASE + path + query,
headers={
"Authorization": f"Bot {token}",
"User-Agent": USER_AGENT,
"Accept": "application/json",
},
)
while True:
try:
with urllib.request.urlopen(request, timeout=30) as response:
if response.status == 204:
return None
return json.loads(response.read().decode("utf-8"))
except urllib.error.HTTPError as exc:
body = exc.read().decode("utf-8", errors="replace")
retry_after = None
try:
retry_after = json.loads(body).get("retry_after")
except json.JSONDecodeError:
pass
if exc.code == 429 and retry_after is not None:
time.sleep(float(retry_after))
continue
raise DiscordAPIError(exc.code, format_http_error(exc.code, body)) from exc
except urllib.error.URLError as exc:
raise DiscordAPIError(None, f"Discord request failed: {exc.reason}") from exc
def format_http_error(status: int, body: str) -> str:
try:
payload = json.loads(body)
except json.JSONDecodeError:
payload = {}
code = payload.get("code")
message = payload.get("message") or "Discord API request failed"
if status in {401, 403}:
message += "; check the bot token, channel visibility, thread access, View Channel, and Read Message History permissions"
return f"Discord API error {status}" + (f" ({code})" if code else "") + f": {message}"
def fetch_messages(channel_id: str, token: str, max_messages: int, anchor_message_id: str | None = None) -> list[dict[str, Any]]:
remaining = max_messages
messages: list[dict[str, Any]] = []
before = None
if anchor_message_id:
# Anchor on the linked message so it is always included, with context on both sides.
limit = min(100, remaining)
page = request_json(f"/channels/{channel_id}/messages", token, {"limit": limit, "around": anchor_message_id})
messages.extend(page or [])
remaining -= len(messages)
if not any(item.get("id") == anchor_message_id for item in messages):
anchor = request_json(f"/channels/{channel_id}/messages/{anchor_message_id}", token)
if isinstance(anchor, dict):
messages.append(anchor)
remaining -= 1
if messages:
before = min(messages, key=lambda item: int(item["id"]))["id"]
while remaining > 0:
limit = min(100, remaining)
page = request_json(f"/channels/{channel_id}/messages", token, {"limit": limit, "before": before})
if not page:
break
messages.extend(page)
remaining -= len(page)
before = page[-1]["id"]
if len(page) < limit:
break
deduped = {item["id"]: item for item in messages}
return sorted(deduped.values(), key=lambda item: int(item["id"]))
def pseudonymize_author(author_id: str, labels: dict[str, str]) -> str:
if author_id not in labels:
labels[author_id] = f"author_{len(labels) + 1}"
return labels[author_id]
def attachment_summary(attachment: dict[str, Any], include_sensitive: bool) -> dict[str, Any]:
summary = {
"filename": attachment.get("filename"),
"content_type": attachment.get("content_type"),
"size": attachment.get("size"),
"description": attachment.get("description"),
}
if include_sensitive:
summary["id"] = attachment.get("id")
summary["url"] = attachment.get("url")
summary["proxy_url"] = attachment.get("proxy_url")
return {key: value for key, value in summary.items() if value not in (None, "", [])}
def normalize_message(message: dict[str, Any], labels: dict[str, str], include_sensitive: bool, guild_id: str | None, anchor_message_id: str | None = None) -> dict[str, Any]:
author = message.get("author") or {}
author_id = author.get("id") or "unknown"
normalized: dict[str, Any] = {
"author": pseudonymize_author(author_id, labels),
"timestamp": message.get("timestamp"),
"edited_timestamp": message.get("edited_timestamp"),
"content": message.get("content") or "",
"attachments": [attachment_summary(item, include_sensitive) for item in message.get("attachments", [])],
"embeds": message.get("embeds", []),
"components": message.get("components", []),
}
if message.get("referenced_message"):
normalized["references_message"] = True
if anchor_message_id and message.get("id") == anchor_message_id:
normalized["is_linked_message"] = True
if include_sensitive:
normalized["id"] = message.get("id")
normalized["channel_id"] = message.get("channel_id")
normalized["author_id"] = author_id
normalized["author_username"] = author.get("username")
normalized["author_global_name"] = author.get("global_name")
normalized["jump_url"] = build_jump_url(message, guild_id)
return {key: value for key, value in normalized.items() if value not in (None, "", [])}
def build_jump_url(message: dict[str, Any], guild_id: str | None) -> str | None:
channel_id = message.get("channel_id")
message_id = message.get("id")
if channel_id and message_id:
return f"https://discord.com/channels/{guild_id or '@me'}/{channel_id}/{message_id}"
return None
def normalize_channel(channel: dict[str, Any], include_sensitive: bool) -> dict[str, Any]:
keys = ["name", "type", "topic", "thread_metadata", "message_count", "member_count"]
normalized = {key: channel.get(key) for key in keys if channel.get(key) not in (None, "", [])}
if include_sensitive:
normalized["id"] = channel.get("id")
normalized["guild_id"] = channel.get("guild_id")
normalized["parent_id"] = channel.get("parent_id")
return normalized
def build_result(source: str, token: str, max_messages: int, include_sensitive: bool) -> FetchResult:
parsed = parse_discord_url(source)
if not parsed.valid or not parsed.channel_or_thread_id:
raise SystemExit(f"Invalid Discord URL: {parsed.error}")
channel = request_json(f"/channels/{parsed.channel_or_thread_id}", token)
messages = fetch_messages(parsed.channel_or_thread_id, token, max_messages, parsed.message_id)
labels: dict[str, str] = {}
normalized_messages = [normalize_message(item, labels, include_sensitive, parsed.guild_id, parsed.message_id) for item in messages]
warnings = build_warnings(messages, normalized_messages)
return FetchResult(
source="discord_url",
channel_id=parsed.channel_or_thread_id if include_sensitive else "redacted",
guild_id=parsed.guild_id if include_sensitive else None,
channel=normalize_channel(channel, include_sensitive) if isinstance(channel, dict) else None,
message_count=len(normalized_messages),
messages=normalized_messages,
warnings=warnings,
)
def build_warnings(raw_messages: list[dict[str, Any]], normalized_messages: list[dict[str, Any]]) -> list[str]:
warnings = []
if raw_messages and not any(item.get("content") for item in raw_messages):
warnings.append("All fetched messages have empty content; verify the bot has Message Content privileged intent access or that the thread contains only non-text content.")
if raw_messages and any(item.get("attachments") for item in raw_messages):
warnings.append("Attachment URLs are omitted by default; rerun with --include-sensitive only for private local diagnosis if direct attachment access is required.")
if not normalized_messages:
warnings.append("No messages returned; verify the bot can view the channel/thread and has Read Message History.")
return warnings
def load_token(token_env: str, token_file: str) -> str | None:
token = os.environ.get(token_env)
if token:
return token.strip()
path = Path(token_file).expanduser()
try:
token = path.read_text(encoding="utf-8").strip()
except FileNotFoundError:
return None
if not token:
return None
return token
def main() -> int:
parser = argparse.ArgumentParser(description="Fetch Discord thread/channel messages using a scoped bot token.")
parser.add_argument("url", help="Discord channel, thread, or message URL")
parser.add_argument("--max-messages", type=int, default=300, help="Maximum messages to fetch, newest pages first then output oldest-first")
parser.add_argument("--token-env", default=DEFAULT_TOKEN_ENV, help="Environment variable containing the bot token")
parser.add_argument("--token-file", default=str(DEFAULT_TOKEN_FILE), help="Fallback file containing the bot token when the environment variable is unset")
parser.add_argument("--include-sensitive", action="store_true", help="Include Discord IDs, usernames, message URLs, and attachment URLs")
args = parser.parse_args()
if args.max_messages < 1:
raise SystemExit("--max-messages must be at least 1")
token = load_token(args.token_env, args.token_file)
if not token:
raise SystemExit(f"No Discord bot token found; set {args.token_env} or create .secrets/discord_bot_token in the skill directory")
try:
result = build_result(args.url, token, args.max_messages, args.include_sensitive)
except DiscordAPIError as exc:
print(str(exc), file=sys.stderr)
return 1
print(json.dumps(asdict(result), indent=2, sort_keys=True))
return 0
if __name__ == "__main__":
sys.exit(main())
@@ -1,103 +0,0 @@
#!/usr/bin/env python3
"""Parse Discord channel, thread, and message URLs without network access."""
from __future__ import annotations
import argparse
import json
import re
import sys
from dataclasses import asdict, dataclass
from urllib.parse import urlparse
DISCORD_HOSTS = {"discord.com", "www.discord.com", "discordapp.com", "www.discordapp.com"}
SNOWFLAKE_RE = re.compile(r"^\d{15,25}$")
@dataclass
class ParsedDiscordURL:
input: str
valid: bool
host: str | None = None
guild_id: str | None = None
channel_or_thread_id: str | None = None
message_id: str | None = None
is_dm: bool = False
kind: str | None = None
error: str | None = None
def parse_discord_url(raw_url: str) -> ParsedDiscordURL:
parsed = urlparse(raw_url.strip())
host = parsed.netloc.lower()
if host not in DISCORD_HOSTS:
return ParsedDiscordURL(input=raw_url, valid=False, host=host or None, error="not a Discord URL")
parts = [part for part in parsed.path.split("/") if part]
if len(parts) < 3 or parts[0] != "channels":
return ParsedDiscordURL(input=raw_url, valid=False, host=host, error="expected /channels/<guild>/<channel-or-thread>/<message?>")
guild_id, channel_id = parts[1], parts[2]
message_id = parts[3] if len(parts) > 3 else None
is_dm = guild_id == "@me"
bad_fields = []
if not is_dm and not SNOWFLAKE_RE.match(guild_id):
bad_fields.append("guild_id")
if not SNOWFLAKE_RE.match(channel_id):
bad_fields.append("channel_or_thread_id")
if message_id is not None and not SNOWFLAKE_RE.match(message_id):
bad_fields.append("message_id")
if bad_fields:
return ParsedDiscordURL(
input=raw_url,
valid=False,
host=host,
guild_id=None if is_dm else guild_id,
channel_or_thread_id=channel_id,
message_id=message_id,
is_dm=is_dm,
error="invalid Discord snowflake field(s): " + ", ".join(bad_fields),
)
if message_id:
kind = "message_link"
elif is_dm:
kind = "dm_channel_link"
else:
kind = "channel_or_thread_link"
return ParsedDiscordURL(
input=raw_url,
valid=True,
host=host,
guild_id=None if is_dm else guild_id,
channel_or_thread_id=channel_id,
message_id=message_id,
is_dm=is_dm,
kind=kind,
)
def main() -> int:
parser = argparse.ArgumentParser(description="Parse a Discord URL into channel/thread/message identifiers.")
parser.add_argument("url", help="Discord URL to parse")
parser.add_argument("--text", action="store_true", help="Print a short text summary instead of JSON")
args = parser.parse_args()
result = parse_discord_url(args.url)
if args.text:
if not result.valid:
print(f"invalid: {result.error}")
else:
message_part = f", message={result.message_id}" if result.message_id else ""
guild_part = "dm" if result.is_dm else f"guild={result.guild_id}"
print(f"{result.kind}: {guild_part}, channel_or_thread={result.channel_or_thread_id}{message_part}")
else:
print(json.dumps(asdict(result), indent=2, sort_keys=True))
return 0 if result.valid else 2
if __name__ == "__main__":
sys.exit(main())
@@ -1,170 +0,0 @@
#!/usr/bin/env python3
"""Validate or post one explicitly approved Discord message with the scoped bot token."""
from __future__ import annotations
import argparse
import hashlib
import json
import sys
import time
import urllib.error
import urllib.request
from pathlib import Path
from typing import Any
SCRIPT_DIR = Path(__file__).resolve().parent
sys.path.insert(0, str(SCRIPT_DIR))
from fetch_discord_thread import ( # noqa: E402
API_BASE,
DEFAULT_TOKEN_ENV,
DEFAULT_TOKEN_FILE,
USER_AGENT,
DiscordAPIError,
load_token,
request_json,
)
from parse_discord_url import parse_discord_url # noqa: E402
def post_json(path: str, token: str, payload: dict[str, Any]) -> Any:
body = json.dumps(payload, separators=(",", ":")).encode("utf-8")
while True:
request = urllib.request.Request(
API_BASE + path,
data=body,
method="POST",
headers={
"Authorization": f"Bot {token}",
"User-Agent": USER_AGENT,
"Accept": "application/json",
"Content-Type": "application/json",
},
)
try:
with urllib.request.urlopen(request, timeout=30) as response:
return json.loads(response.read().decode("utf-8"))
except urllib.error.HTTPError as exc:
response_body = exc.read().decode("utf-8", errors="replace")
retry_after = None
try:
retry_after = json.loads(response_body).get("retry_after")
except json.JSONDecodeError:
pass
if exc.code == 429 and retry_after is not None:
time.sleep(float(retry_after))
continue
raise DiscordAPIError(exc.code, format_post_error(exc.code, response_body)) from exc
except urllib.error.URLError as exc:
raise DiscordAPIError(None, f"Discord post failed: {exc.reason}") from exc
def format_post_error(status: int, body: str) -> str:
try:
payload = json.loads(body)
except json.JSONDecodeError:
payload = {}
code = payload.get("code")
message = payload.get("message") or "Discord API request failed"
if status == 401:
message += "; check the bot token"
elif status == 403:
message += (
"; check View Channel and Send Messages, plus Send Messages in Threads "
"and thread membership/visibility when posting to a thread"
)
return f"Discord API error {status}" + (f" ({code})" if code else "") + f": {message}"
def read_content(raw_content: str | None, content_file: str | None) -> str:
if raw_content is not None:
content = raw_content
elif content_file == "-":
content = sys.stdin.read()
elif content_file:
content = Path(content_file).expanduser().read_text(encoding="utf-8")
else:
raise SystemExit("Provide exactly one of --content or --content-file")
content = content.rstrip("\r\n")
if not content.strip():
raise SystemExit("Discord message content must not be empty")
if len(content) > 2000:
raise SystemExit(f"Discord message content is {len(content)} characters; maximum is 2000")
return content
def content_fingerprint(content: str) -> str:
return hashlib.sha256(content.encode("utf-8")).hexdigest()[:16]
def main() -> int:
parser = argparse.ArgumentParser(
description="Validate or post one explicitly approved Discord message using the scoped bot token."
)
parser.add_argument("url", help="Discord channel, thread, or message URL")
content_group = parser.add_mutually_exclusive_group(required=True)
content_group.add_argument("--content", help="Message content")
content_group.add_argument("--content-file", help="UTF-8 message file, or - for stdin")
parser.add_argument("--confirm", action="store_true", help="Actually post after the exact content is approved")
parser.add_argument("--token-env", default=DEFAULT_TOKEN_ENV, help="Environment variable containing the bot token")
parser.add_argument("--token-file", default=str(DEFAULT_TOKEN_FILE), help="Fallback local token file")
args = parser.parse_args()
parsed = parse_discord_url(args.url)
if not parsed.valid or not parsed.channel_or_thread_id:
raise SystemExit(f"Invalid Discord URL: {parsed.error}")
content = read_content(args.content, args.content_file)
token = load_token(args.token_env, args.token_file)
if not token:
raise SystemExit(
f"No Discord bot token found; set {args.token_env} or create "
".secrets/discord_bot_token in the skill directory"
)
try:
channel = request_json(f"/channels/{parsed.channel_or_thread_id}", token)
result: dict[str, Any] = {
"valid": True,
"posted": False,
"channel_type": channel.get("type") if isinstance(channel, dict) else None,
"is_thread": bool(isinstance(channel, dict) and channel.get("type") in {10, 11, 12}),
"content_length": len(content),
"content_sha256": content_fingerprint(content),
"mentions_disabled": True,
}
if not args.confirm:
print(json.dumps(result, indent=2, sort_keys=True))
return 0
response = post_json(
f"/channels/{parsed.channel_or_thread_id}/messages",
token,
{
"content": content,
"allowed_mentions": {
"parse": [],
"replied_user": False,
},
},
)
result.update(
{
"posted": True,
"verified": isinstance(response, dict) and response.get("content") == content,
"timestamp": response.get("timestamp") if isinstance(response, dict) else None,
}
)
if not result["verified"]:
print(json.dumps(result, indent=2, sort_keys=True), file=sys.stderr)
return 1
print(json.dumps(result, indent=2, sort_keys=True))
return 0
except DiscordAPIError as exc:
print(str(exc), file=sys.stderr)
return 1
if __name__ == "__main__":
sys.exit(main())
-72
View File
@@ -1,72 +0,0 @@
---
name: web-ui-testing
description: Use when verifying a change to the Silo web frontend (`web/`) in a real browser — checking a page renders, a flow works, or a fix actually landed, and capturing screenshots for a PR. Runs the local Vite dev server against a real Silo backend so no build or deploy is needed. Not for backend-only changes, and not a substitute for unit tests in `web/src`.
---
# Verifying web UI changes
The frontend only ever calls relative `/api` URLs, so pointing it at a real backend is a
one-line config change — no build, no deploy, and hot reload still works while you
iterate.
## Point the dev server at a backend
```bash
printf 'VITE_API_PROXY_TARGET=%s\n' "$(scripts/silo-dev env | awk '/^SILO_URL/{print $2}')" > web/.env.local
make dev-frontend
```
Any reachable Silo instance works as the target — the shared `.silo-dev.env` deployment,
a colleague's server, or `http://localhost:8090` for a backend you are running yourself
with `make dev-backend`. Vite proxies `/api` (including WebSockets, such as the realtime
`scans` channel) and sets `changeOrigin` automatically for non-localhost targets, because
remote vhost proxies reject a localhost `Host` header.
`web/.env.local` is per-checkout, so a git worktree needs its own.
Before debugging anything in the UI, confirm the proxy itself:
```bash
curl -s http://localhost:5173/api/v1/health
```
Silo health JSON means the wiring is good and any remaining problem is the frontend. An
HTML page or a connection error means the proxy target is wrong or the backend is down —
`scripts/silo-dev doctor` will say which.
## Drive it
The app is at `http://localhost:5173`. Use the Playwright tooling to navigate, interact,
and screenshot.
The dev server binds `0.0.0.0` and `allowedHosts` covers `.ts.net` plus the machine's own
hostname, so it is also reachable from any device on the tailnet at
`http://<tailscale-machine>:5173`. Always give the user that URL alongside the localhost
one when starting a dev server for them — it is how they watch the UI you are working on
from another machine. `tailscale status --json | jq -r .Self.DNSName` gives the name.
Most pages need a session. Sign in through the login form using `SILO_ADMIN_USER` and
`SILO_ADMIN_PASSWORD` from `.silo-dev.env`; the session then lives in that browser
profile for the rest of the run. If those are unset, ask the user for an account on the
target rather than testing only the signed-out shell — and never type credentials the
user has not given you for that server.
## What counts as verified
A change is verified when you have seen the specific thing that was broken now behaving
correctly, on a page reached the way a user reaches it, against real data. Screenshots
belong in the PR for anything visual.
Watch for the failure modes that look like success: a page that renders because it fell
back to an empty state, a stale bundle from a dev server started before your edit, and a
console full of errors under a page that looks fine. Check the browser console before
calling it done.
## States that are hard to reach
Some UI only appears under conditions you cannot conjure on a real server — a flood of
queued scans, a specific error shape, a half-finished download. Rather than mutating the
backend, render the real page inside a temporary dev-only route wrapping it in its own
`QueryClientProvider` (queries `enabled: false`) seeded via `setQueryData`. It needs its
own client because `useAuth` calls `clear()` on the global one when auth fails, which
would wipe the fixtures. Delete the harness route once you have the screenshot.
+4 -23
View File
@@ -2,11 +2,9 @@
# For the default docker compose setup, MEDIA_ROOT is the main value you need to set.
# Optional: layer compose files through env. Leave unset for CPU-only defaults.
# Linux example for Intel/AMD VA-API or Intel Quick Sync:
# COMPOSE_FILE=docker-compose.yml:docker-compose.vaapi.yml
# Linux example for NVIDIA NVENC:
# Linux/macOS example for enabling NVIDIA override:
# COMPOSE_FILE=docker-compose.yml:docker-compose.nvidia.yml
# Windows NVIDIA example:
# Windows example:
# COMPOSE_FILE=docker-compose.yml;docker-compose.nvidia.yml
# Required for docker compose: host path to your media library.
@@ -29,15 +27,6 @@ POSTGRES_USER=silo
POSTGRES_PASSWORD=silo
POSTGRES_DB=silo
POSTGRES_SHM_SIZE=8gb
# POSTGRES_PORT=5432
# REDIS_PORT=6379
# Optional Meilisearch service. Generate a key, uncomment it, then start the
# search profile with: docker compose --profile search up -d
# MEILI_MASTER_KEY=replace-with-output-of-openssl-rand-hex-32
# MEILISEARCH_IMAGE=getmeili/meilisearch:latest
# MEILISEARCH_HOST=127.0.0.1
# MEILISEARCH_PORT=7700
# PostgreSQL auto-tuning is enabled by default in docker-compose.yml. Silo
# applies pgtune-style OLTP recommendations through ALTER SYSTEM at startup.
@@ -51,8 +40,7 @@ POSTGRES_SHM_SIZE=8gb
# POSTGRES_TUNE_DB_SIZE=auto
# POSTGRES_TUNE_CONNECTIONS=100
# Optional host port overrides for docker-compose.yml. The container listeners
# remain fixed, so these values only change the host side of each port mapping.
# Optional host port overrides for docker-compose.yml.
# PORT=8090
# Used only after Jellyfin-compatible app support is enabled by an admin.
# JF_PORT=8096
@@ -75,13 +63,6 @@ POSTGRES_SHM_SIZE=8gb
# Optional public URL for Silo. If not set, the server will use the IP address of the container.
# SILO_PUBLIC_URL=https://silo.example.com
# Optional trusted reverse-proxy CIDRs for client IP resolution. When set, this
# overrides the "Trusted Proxies" admin setting on every startup (the value is
# validated and written to server_settings, so the Admin UI shows it). Leave
# unset to manage it from Admin > Settings > General instead. Defaults trust
# RFC 1918 private ranges + loopback.
# SILO_TRUSTED_PROXIES=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.0/8,::1/128,203.0.113.7/32
# Run from source / advanced overrides
# Only DATABASE_URL is required when running Silo outside the default docker compose stack.
# DATABASE_URL=postgres://silo:password@localhost:5432/silo
@@ -89,7 +70,7 @@ POSTGRES_SHM_SIZE=8gb
# Optional Redis override when running from source or pointing workers at an external Redis.
# REDIS_URL=redis://localhost:6379
# Optional standalone worker identity settings for custom worker deployments.
# Optional standalone worker identity settings for docker-compose.remote-transcode.yml.
# NODE_NAME=transcode-01
# NODE_URL=http://transcode-01.example.com:8082
-1
View File
@@ -1 +0,0 @@
github: quick104
-93
View File
@@ -1,93 +0,0 @@
name: Bug report
description: Report something broken in Silo server or web UI
title: "[bug] "
labels: ["bug"]
body:
- type: markdown
attributes:
value: |
Raw logs only. Never AI-summarize logs. You must have reproduced this yourself on a real deployment before filing.
Fabricated or AI-hallucinated reports are an instant block. Read [CONTRIBUTING.md](https://github.com/Silo-Server/silo-server/blob/main/CONTRIBUTING.md) first.
- type: textarea
id: what-happened
attributes:
label: What happened
description: What broke? What did you actually observe?
validations:
required: true
- type: textarea
id: steps-to-reproduce
attributes:
label: Steps to reproduce
description: Exact steps you ran on a real deployment.
validations:
required: true
- type: textarea
id: expected-behavior
attributes:
label: Expected behavior
validations:
required: true
- type: input
id: silo-version
attributes:
label: Silo version / commit
validations:
required: true
- type: dropdown
id: deployment
attributes:
label: Deployment
options:
- Docker
- Bare metal / systemd
- Local dev build
- Other
validations:
required: true
- type: checkboxes
id: clients-affected
attributes:
label: Clients affected
options:
- label: Web UI
- label: Android
- label: iOS/tvOS/macOS
- label: Jellyfin-compat client (Infuse, Findroid, ...)
- label: Other/not client-specific
- type: textarea
id: relevant-logs
attributes:
label: Relevant logs
description: Paste raw server logs.
placeholder: paste raw server logs; write "no logs available" if genuinely none
render: shell
validations:
required: true
- type: dropdown
id: ai-involvement
attributes:
label: AI involvement in this report
options:
- None — written by a human
- AI-assisted, human verified the repro
- AI-generated, human verified the repro
validations:
required: true
- type: input
id: ai-tool-model
attributes:
label: AI tool + model
placeholder: e.g. Claude Code / claude-fable-5 — or n/a
validations:
required: true
- type: checkboxes
id: confirmations
attributes:
label: Confirmations
options:
- label: I reproduced this myself on a real deployment
required: true
- label: Logs above are raw copy-paste, not AI-summarized
required: true
-1
View File
@@ -1 +0,0 @@
blank_issues_enabled: false
-21
View File
@@ -1,21 +0,0 @@
## Problem
Part of #NNN
<!-- PRs with no linked scope item will be questioned. -->
What does this solve?
## Approach
Why this approach?
## Testing
Paste ACTUAL command output here. For UI changes, include screenshots or recordings.
### AI Disclosure
- Tool(s):
- Model(s):
- Involvement:
- Adversarial review:
## Checklist
- [ ] I ran an adversarial AI review of the diff and summarized findings above.
- [ ] I ran the repo verify commands: `make lint`, `cd web && pnpm run lint`, `cd web && pnpm run format:check`, and relevant `go test ./...`.
-185
View File
@@ -1,185 +0,0 @@
name: CI
on:
pull_request:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
GOPROXY: https://proxy.golang.org,direct
GOPRIVATE: github.com/Silo-Server/*
GONOSUMDB: github.com/Silo-Server/*
# Pinned so a lint gate cannot change its mind between two runs of the same
# commit. Built from source below rather than downloaded: a released binary
# refuses to run against a Go version newer than the one it was built with,
# and go.mod tracks Go closely enough that this repo is regularly ahead.
GOLANGCI_LINT_VERSION: v2.12.2
# The default token is read-write. Nothing here needs to write, and a token
# that cannot push is one fewer thing a compromised dependency can reach.
permissions:
contents: read
jobs:
go:
name: Go
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
# golangci-lint needs the merge base to tell this branch's lines from
# the ones it inherited.
fetch-depth: 0
persist-credentials: false
# github.com/h2non/bimg binds libvips through cgo and pkg-config, so
# nothing under ./... compiles without the headers. The Dockerfile
# installs the same package in its build stage.
- name: Install libvips
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libvips-dev
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
# cmd/silo embeds the built frontend, so nothing under ./... compiles
# without web/dist. The Go jobs never serve it, so a placeholder is
# enough; the Docker workflow builds the real bundle.
- name: Stub the embedded frontend bundle
run: make embed-stub
- name: Build
run: go build ./...
- name: gofmt
run: |
unformatted="$(gofmt -l .)"
if [ -n "$unformatted" ]; then
echo "::error::gofmt is required on:"
echo "$unformatted"
exit 1
fi
- name: Vet
run: go vet ./...
# Scoped to the lines this branch touched. The repo does not pass a full
# golangci-lint run today — there are a few hundred pre-existing findings,
# which is why the Go half of `make lint` has never been enforced — and
# blocking every PR on a cleanup nobody has done would just get the gate
# removed again. New and changed lines have to be clean, so the count only
# falls from here.
- name: Install golangci-lint
run: go install "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}"
- name: Lint changed lines
env:
# A PR carries its target branch; a push to main compares against
# main's own history, which leaves the merge base at HEAD and lints
# nothing new. Read through the environment rather than interpolated
# into the script.
BASE_REF: ${{ github.base_ref || github.event.repository.default_branch }}
run: |
git fetch --no-tags origin "+refs/heads/${BASE_REF}:refs/remotes/origin/${BASE_REF}"
golangci-lint run --new-from-merge-base="origin/${BASE_REF}" ./...
# A manifest change that does not regenerate leaves every client reading
# stale keys, which the contract exists to prevent.
- name: Verify settings bindings are current
run: make verify-settings-bindings
# The server defines the playback protocol and the clients prove
# conformance against these fixtures. A contract change that does not
# regenerate leaves every client testing against a stale body, so the
# drift surfaces as a playback bug on three platforms rather than as a
# failure here.
- name: Verify playback protocol fixtures are current
run: make verify-playback-fixtures
# Runs the settings-contract gate among everything else: the embedded
# manifest must parse, satisfy its own schema, hold every structural
# invariant, and agree with the live settings registry on keys and
# defaults. Without this job those tests exist but never run.
- name: Test
run: make test-go
web:
name: Web
runs-on: ubuntu-latest
defaults:
run:
working-directory: web
steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false
# The pnpm version comes from web/package.json's packageManager field —
# there is no package.json at the repo root, and `defaults.run` does not
# apply to an action's own inputs.
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
package_json_file: web/package.json
- name: Set up Node
uses: actions/setup-node@v5
with:
node-version: 22
cache: pnpm
cache-dependency-path: web/pnpm-lock.yaml
- name: Install
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm run lint
- name: Format check
run: pnpm run format:check
- name: Typecheck and build
run: pnpm run build
# Includes the appearance-cache ownership tests, which are the regression
# guard for cross-account leaks in the localStorage warm start.
- name: Test
working-directory: .
run: make test-web
# The generated web binding is compared after prettier, so this half of
# the bindings check lives here rather than in the Go job, which has no
# pnpm. It needs Go to run the generator.
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- name: Verify the generated web settings binding is current
working-directory: .
run: make verify-settings-bindings-web
docs:
name: Docs hygiene
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Verify no local paths leaked into committed docs
run: make verify-local-paths
+10 -84
View File
@@ -19,15 +19,7 @@ env:
jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
runs-on: [self-hosted, linux]
permissions:
contents: read
packages: write
@@ -36,13 +28,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v5
- name: Prepare platform slug and lowercase image name
run: |
echo "PLATFORM_PAIR=${PLATFORM//\//-}" >> "$GITHUB_ENV"
echo "IMAGE_LC=${IMAGE_NAME,,}" >> "$GITHUB_ENV"
env:
PLATFORM: ${{ matrix.platform }}
- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
@@ -91,6 +76,9 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
name: silo-builder
keep-state: true
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
@@ -104,81 +92,19 @@ jobs:
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix=,format=short
- name: Build and push by digest
id: build
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ matrix.platform }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-contexts: |
frontend_dist=./web/dist
build-args: |
BUILD_REVISION=${{ github.sha }}
BUILD_DIRTY=false
cache-from: type=gha,scope=docker-${{ env.PLATFORM_PAIR }}
cache-to: type=gha,scope=docker-${{ env.PLATFORM_PAIR }},mode=max
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_LC }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p "${RUNNER_TEMP}/digests"
digest="${{ steps.build.outputs.digest }}"
touch "${RUNNER_TEMP}/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs: build
permissions:
packages: write
steps:
- name: Prepare lowercase image name
run: echo "IMAGE_LC=${IMAGE_NAME,,}" >> "$GITHUB_ENV"
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_LC }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=sha,prefix=,format=short
- name: Create and push manifest list
working-directory: ${{ runner.temp }}/digests
run: |
# shellcheck disable=SC2046
docker buildx imagetools create \
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf "${REGISTRY}/${IMAGE_LC}@sha256:%s " *)
- name: Inspect manifest list
run: |
docker buildx imagetools inspect "${REGISTRY}/${IMAGE_LC}:${GITHUB_SHA::7}"
+4 -16
View File
@@ -30,8 +30,6 @@ silo.yaml
.env
.env.*
!.env.example
# Per-developer settings for the agent skills (hosts, credentials, tokens).
.silo-dev.env
# Developer-specific make targets
Makefile.local
@@ -51,17 +49,12 @@ web/*.tsbuildinfo
docs/inspiration
# `.agents/skills` is a symlink to `.claude/skills` so non-Claude agents find the
# same files; everything else under .agents/ is per-developer scratch.
/.agents/*
!/.agents/skills
# Ignore everything in .claude/ except the committed, shared skills.
.agents/
# Ignore everything in .claude/ except committed, shared skills.
/.claude/*
!/.claude/skills/
# Skills may carry per-developer state next to their instructions (the global
# *.local.md rule above covers notes; these cover tokens and run state).
**/.secrets/
**/.state/
/.claude/skills/*
!/.claude/skills/issue-to-pr/
.cursor/
.superpowers/
.codex/
@@ -71,15 +64,10 @@ logs/
.playwright-mcp/
demo/
docker-compose.dev.yml
docker-compose.local.yml
# Local-only deployment override (unpublishes bundled redis/postgres host
# ports via `ports: !override []`). Kept out of git so a rebase from main
# never disturbs it and it never lands in a PR; its absence once exposed
# Redis to the internet, so it must persist on the box.
docker-compose.override.yml
# Local compose customization layered onto docker-compose.yml by make dev-deploy.
docker-compose.local.yml
.playwright-cli/
output/
/settingsgen
/playbackfixtures
+14 -34
View File
@@ -23,27 +23,12 @@ linters:
- ineffassign
- misspell
- nilerr
- sloglint
- staticcheck
- unconvert
- unused
- wastedassign
settings:
sloglint:
# Require the context-carrying slog variants (InfoContext, …) wherever a
# context.Context is in scope, so log records correlate with the active
# OpenTelemetry trace. "scope" (not "all") allows the plain Info/… form in
# background/init code where no ctx exists. Enforced repo-wide after the
# phase-3 sweep converted the ~1,159 legacy call sites.
context: "scope"
# Message must be a constant, not a built string; move dynamic parts to attrs.
static-msg: true
# Attribute keys are snake_case (component, request_id, trace_id, …).
key-naming-case: snake
# Don't mix key-value pairs and slog.Attr in one call.
no-mixed-args: true
errcheck:
check-type-assertions: true
@@ -59,24 +44,19 @@ linters:
misspell:
locale: US
exclusions:
# Anchored regexes, not directory names: `paths` matches anywhere in the
# path, so a bare `web` also excluded internal/jellycompat/web_component.go,
# internal/webhooksync/, internal/notifications/webhook*.go and every other
# non-test file with "web" in its name — 14 files that were being linted
# before.
paths:
- ^web/
- ^migrations/
issues:
exclude-dirs:
- web
- migrations
rules:
# Allow repeated strings in test files
- path: _test\.go
linters:
- goconst
exclude-rules:
# Allow repeated strings in test files
- path: _test\.go
linters:
- goconst
# Allow unchecked errors in test cleanup/defer
- path: _test\.go
text: "Error return value is not checked"
linters:
- errcheck
# Allow unchecked errors in test cleanup/defer
- path: _test\.go
text: "Error return value is not checked"
linters:
- errcheck
-63
View File
@@ -1,63 +0,0 @@
# Silo agent environment — copy to `.silo-dev.env` and fill in.
#
# cp .silo-dev.env.example .silo-dev.env && $EDITOR .silo-dev.env
#
# `.silo-dev.env` is gitignored. It is the single place agents and humans look
# for "which Silo deployment am I debugging, and how do I reach it" — real
# hosts, tokens, and passwords belong here and nowhere else in the repo.
#
# The skills in `.claude/skills/` (also reachable as `.agents/skills/`) read it
# through `scripts/silo-dev`, which works the same whether your server runs on
# this machine or over SSH. Nothing here is required to build or run Silo; it
# only configures debugging against an already-running deployment.
# --- The deployment under test -----------------------------------------------
# Base URL you reach the server on. A local docker compose install is usually
# http://localhost:8090; a remote one is whatever you browse to.
SILO_URL=http://localhost:8090
# SSH target for the host running Silo, e.g. root@10.0.0.5 or a ~/.ssh/config
# alias. Leave empty when Silo runs on this machine — commands then run locally.
SILO_SSH=
# Directory on that host holding docker-compose.yml and .env.
SILO_DIR=/opt/silo
# Compose file, relative to SILO_DIR. Colon-separate to layer overrides.
SILO_COMPOSE_FILE=docker-compose.yml
# Compose service names. Override if your stack renames them.
SILO_SERVICE=silo
SILO_POSTGRES_SERVICE=postgres
# --- Database ----------------------------------------------------------------
# Match POSTGRES_USER / POSTGRES_DB in the deployment's own .env.
SILO_DB_USER=silo
SILO_DB_NAME=silo
# --- Credentials -------------------------------------------------------------
# An account on the deployment, used to exercise authenticated API endpoints and
# to sign in to the web UI while verifying changes. Use a throwaway admin on a
# dev box, not your production login.
SILO_ADMIN_USER=
SILO_ADMIN_PASSWORD=
# --- Optional ----------------------------------------------------------------
# Host path the media library is mounted from, for checking that a file exists.
SILO_MEDIA_ROOT=
# SSH target of a separate transcode node, if you run one.
SILO_TRANSCODE_SSH=
# A real Jellyfin server to compare jellycompat responses against, and an
# account on it. Only needed for the jellycompat-diagnosis skill.
JELLYFIN_COMPARE_URL=
JELLYFIN_COMPARE_USER=
JELLYFIN_COMPARE_PASSWORD=
# Scoped Discord bot token for the silo-discord-triage skill.
DISCORD_BOT_TOKEN=
+70 -104
View File
@@ -1,136 +1,102 @@
# Silo Server
# Repository Guidelines
Go backend for Silo: API contracts, auth/session, catalog/scanner/playback services, database
migrations, Jellyfin compatibility, and the host-side plugin runtime. `cmd/silo` is the
entrypoint, backend code is under `internal/` by domain, the React frontend is `web/src/`.
## Project Structure & Module Organization
`cmd/silo` contains the main server entrypoint. Backend code lives in `internal/`, organized by domain (`api`, `catalog`, `metadata`, `playback`, `scanner`, `jellycompat`, etc.); keep new code in the package that owns the behavior instead of creating catch-all helpers. Database changes belong in `migrations/sql/` as Goose SQL migrations. Legacy converted migrations intentionally keep their original numeric versions so existing `schema_versions` rows can bootstrap cleanly into Goose. New migrations must use timestamped filenames created with `make migrate-create NAME=add_thing`; do not run `goose fix` or create paired `.up.sql` / `.down.sql` files. The React frontend lives in `web/src/`, with feature code split across `components/`, `pages/`, `hooks/`, `player/`, and `lib/`. Reference material belongs in `docs/architecture/` or `docs/superpowers/{specs,plans}/`; ad hoc SQL helpers live in `scripts/`.
This repository is a VERY EARLY WIP. Proposing sweeping changes that improve long-term
maintainability is encouraged.
When creating or editing `docs/superpowers/specs/` or `docs/superpowers/plans/`, never include local absolute filesystem paths or transient worktree IDs. Use repository-relative paths and wording like "Commands assume the repository root is the cwd."
## Priorities
This repository is a VERY EARLY WIP. Proposing sweeping changes that improve long-term maintainability is encouraged.
Performance and reliability first. Keep behavior predictable under load and during failures —
session restarts, reconnects, partial streams. When a tradeoff is forced, choose correctness and
robustness over short-term convenience.
Put new code in the package that owns the behavior rather than in a catch-all helper. Prefer
extracting shared logic over duplicating it, and prefer changing existing code over bolting a
local workaround onto it.
## Core Priorities
## Non-goals
1. Performance first.
2. Reliability first.
3. Keep behavior predictable under load and during failures (session restarts, reconnects, partial streams).
Most of this codebase's scope is open; a short list is permanently closed. Read
[docs/non-goals.md](docs/non-goals.md) before proposing or implementing in those areas.
If a tradeoff is required, choose correctness and robustness over short-term convenience.
**Live TV, OTA/DVB tuners, IPTV, EPG/XMLTV, DVR, and `.strm` remote-URL shortcuts will not be
accepted** — not in core, not as a plugin, not in a client. The first-party clients ship on the
Apple and Google stores, and a server that plays arbitrary remote stream URLs puts the whole
client suite at risk. This is settled product direction, not a design problem to solve; do not
write code for it, and say so plainly if asked.
## Maintainability
## Gotchas
Long term maintainability is a core priority. If you add new functionality, first check if there is shared logic that can be extracted to a separate module. Duplicate logic across multiple files is a code smell and should be avoided. Don't be afraid to change existing code. Don't take shortcuts by just adding local logic to solve a problem.
**Migrations.** New DB changes are Goose SQL migrations in `migrations/sql/`, created with
`make migrate-create NAME=add_thing` so they get timestamped filenames. Never run `goose fix`,
and never create paired `.up.sql` / `.down.sql` files. Legacy converted migrations deliberately
keep their original numeric versions so existing `schema_versions` rows bootstrap cleanly — do
not renumber them.
This repository is part of a broader multi-repo Silo workspace. The sibling
repositories are usually checked out side-by-side in the same parent directory.
**Encrypted settings.** Encrypted `server_settings` rows are GCM-bound to their key name.
Renaming a row in SQL makes its value undecryptable.
- `silo-server` owns the Go backend, web admin UI, API contracts, auth/session
behavior, catalog/scanner/playback services, database migrations, Jellyfin
compatibility, and host-side plugin runtime.
- `silo-android` owns the Android phone and TV clients. Client-visible API,
auth, playback, session, library, and metadata changes may require Android
follow-up.
- `silo-apple` owns the iOS, tvOS, and macOS clients. Client-visible API, auth,
playback, session, library, and metadata changes may require Apple follow-up.
**Profiles vs accounts.** Login accounts (`users`) are separate from household profiles; several
profiles on one account share a `user_id`. A profile's `is_primary` marks the household parent,
which is *not* the server-wide `admin` role on the account.
When changing server behavior consumed by clients, check whether both client
repos need model, routing, playback, or UX updates. Prefer coordinated
multi-repo changes over leaving one platform behind.
**Docs hygiene.** Files under `docs/superpowers/{specs,plans}/` must not contain local absolute
filesystem paths or transient worktree IDs — use repository-relative paths and wording like
"Commands assume the repository root is the cwd." `make verify-local-paths` enforces this.
Do not assume all plugin-related code lives in this repo.
**Dev frontend against a remote backend.** Set `VITE_API_PROXY_TARGET` in `web/.env.local` before
`make dev-frontend`; the frontend calls relative `/api` URLs that Vite proxies.
- `silo-plugin-sdk` owns the public plugin SDK, protobuf contracts, generated plugin API code, manifest helpers, and runtime bootstrap.
- `silo-plugins` owns the central plugin catalog / repository manifest.
- First-party plugins such as `silo-plugin-tmdb`, and `silo-plugin-tvdb` live in their own repositories.
- `Silo` owns host-side plugin installation, runtime management, API handlers, and integration logic.
**Working from a plan.** When implementing from an attached plan, don't edit the plan file.
When a task mentions plugins, first determine whether the change belongs in this repo, the SDK repo, the catalog repo, or a specific plugin repo. Prefer coordinated multi-repo changes over forcing plugin work into `Silo`.
## Multi-repo
## Build, and Development Commands
Use the checked-in `Makefile` for the common paths:
Sibling repos are usually checked out side-by-side in the same parent directory.
- `make build`: install frontend deps, build `web/dist`, compile `./silo`
- `make dev-backend`: run the Go server in integrated mode
- `make dev-frontend`: start the Vite dev server with HMR
- `make dev-proxy` / `make dev-transcode`: run standalone worker modes
- `make lint`: run `golangci-lint` and frontend ESLint
- `make migrate-status` / `make migrate-up`: inspect or apply Goose migrations through Silo's legacy-safe bootstrapping runner
- `silo-android` — Android phone and TV clients.
- `silo-apple` — iOS, tvOS, and macOS clients.
- `silo-plugin-sdk` — public plugin SDK, protobuf contracts, generated plugin API, manifest
helpers, runtime bootstrap.
- `silo-plugins` — central plugin catalog / repository manifest.
- First-party plugins (`silo-plugin-metadata-tmdb`, `silo-plugin-metadata-tvdb`, …) each have
their own repo.
Run before opening a merge request:
Client-visible changes to API, auth, playback, session, library, or metadata behavior usually
need follow-up in both client repos — prefer coordinated multi-repo changes over leaving a
platform behind. When a task mentions plugins, work out first whether it belongs here, in the
SDK, in the catalog, or in a specific plugin repo.
- `cd web && pnpm run lint`
- `cd web && pnpm run format:check`
- `make verify-local-paths`
## Building and verifying
For local services, start PostgreSQL and Redis with `docker compose up -d postgres redis`.
`make build`, `make dev-backend`, `make dev-frontend`, `make lint`, `make test`, `make migrate-status`
/ `make migrate-up` — read the `Makefile` for the rest. Local services:
`docker compose up -d postgres redis`.
## Coding Style & Naming Conventions
Go code must stay `gofmt`/`goimports` clean and pass `golangci-lint`. Keep package names lowercase and focused; Frontend code is TypeScript with 2-space indentation, semicolons, double quotes, trailing commas, and a 100-character line width (`web/.prettierrc`). Use `PascalCase.tsx` for components/pages, `useThing.ts` for hooks, and keep shared utilities in `web/src/lib` or `web/src/utils`.
`make test-go` runs the whole Go suite. A Go test that cannot pass yet carries a `t.Skip` and the
reason in its own source, not an entry in a Makefile variable. `make test-web` still skips the
files in `WEBTEST_KNOWN_FAILURES`, which predate the CI gate; that list may only shrink — delete an
entry together with its fix, and never add to it to make a new change pass.
Before opening a merge request:
## Deployment Debugging
```bash
make lint
make test
cd web && pnpm run lint && pnpm run format:check
make verify-local-paths
```
When troubleshooting a Silo deployment (container health, playback failures,
database state, log analysis, deploys), follow the runbook at
`.claude/skills/deployment-debugging/SKILL.md`. It includes step-by-step
procedures and a first-run setup that configures SSH, database, and Redis
connection details for your environment.
`.github/workflows/ci.yml` runs these on every pull request, with one difference worth knowing:
`make lint` runs `golangci-lint` over the whole tree, while CI runs it with `--new-from-merge-base`
so only the lines a branch touched have to be clean. The repo does not pass a full run today, so
expect local output to include findings that are not yours and that CI will not fail on. Do not add
to them.
## Commit & Merge Request Guidelines
Recent history follows Conventional Commit-style subjects such as `feat(playback): add realtime session hub`, `fix(playback): ...`, and `docs: ...`. Keep commits scoped to one concern. For non-trivial work, open an issue or discussion first; this codebase moves quickly. Merge requests should explain the problem, why this approach was chosen, linked issue/spec/plan, risks or follow-up work, and AI-use disclosure. Include screenshots or recordings for UI changes.
Go stays `gofmt`/`goimports` clean; the frontend follows `web/.prettierrc`.
## Learned User Preferences
## Skills
- When implementing from an attached plan, do not edit the plan file itself.
- After feature work, user may invoke the `/simplify` skill to improve readability without changing behavior.
Task-specific guides live in `.claude/skills/`, also reachable as `.agents/skills/` for agents
that look there. Read the one that matches the task instead of working from this file alone.
## Learned Workspace Facts
They share one config file: copy `.silo-dev.env.example` to `.silo-dev.env` and fill in how to
reach your Silo deployment — URL, SSH target, database, an account to debug with. That file is
gitignored and is the only place hosts, passwords, and tokens belong. `scripts/silo-dev doctor`
checks it end to end.
- Silo separates login accounts (`users`) from household profiles; multiple profiles on one account share the same `user_id`.
- Profile `is_primary` marks the household parent for that account; it is not the same as server-wide `admin` role on the user account.
- Point the Vite dev frontend at a remote backend with `VITE_API_PROXY_TARGET` in `web/.env.local` (or inline) when running `make dev-frontend`; the frontend calls relative `/api` URLs proxied by Vite.
## v1 API rules
## Silo v1 Process (scope lock & API rules)
Additive-only within `/api/v1`:
**API rules — additive-only within `/api/v1`.**
- Never rename or remove a response field, change a field's type, or repurpose a status code on an existing endpoint.
- New functionality adds new fields/endpoints; removals go through the existing Deprecation/Sunset header flow only.
- New features expose capability endpoints (feature detection) rather than relying on version sniffing.
- Contract strategy and tooling: issue #135.
- Never rename or remove a response field, change a field's type, or repurpose a status code on
an existing endpoint.
- New functionality adds new fields or endpoints. Removals go through the Deprecation/Sunset
header flow only.
- New features expose capability endpoints for feature detection rather than relying on version
sniffing. Contract strategy and tooling: issue #135.
Treat this as binding. The one exception: `/api/v1` is not locked yet, so a removal taken before
lock is in scope — but only when it is recorded in the pre-lock removals table in
[docs/architecture/v1-scope.md](docs/architecture/v1-scope.md) and ships before the lock. Assume
any removal not listed there is a mistake.
## Pull requests
Conventional Commit subjects (`feat(playback): add realtime session hub`). One concern per PR.
Explain the problem, why this approach, the linked issue/spec/plan, and risks or follow-up work.
Include screenshots or recordings for UI changes. Link the capability epic or sub-issue the PR
serves (`Part of #NNN`) — PRs with no linked scope item get questioned at review. For non-trivial
work, open an issue or discussion first; this codebase moves quickly.
AI-use disclosure is required in the PR body. If you are an AI agent contributing on behalf of a
non-maintainer, follow [docs/ai-contributions.md](docs/ai-contributions.md) — it has the required
disclosure block and the evidence standard.
**PR requirements.**
- Link the capability epic or sub-issue the PR serves (`Part of #NNN`). PRs with no linked scope item will be questioned at review.
- One concern per PR; Conventional Commit subject; AI-use disclosure in the PR body.
+1 -23
View File
@@ -36,35 +36,13 @@ AI writes most of the code here. That's fine. What's not fine is copy-pasting ou
"The AI suggested it" is not an acceptable answer in review. You should be able to explain the reasoning and tradeoffs.
## AI Disclosure (Required)
Every PR and every issue needs to say what AI was involved: the tool, the exact model ID, and the involvement level. "No AI" is a perfectly fine answer. Just say so.
```md
### AI Disclosure
- Tool(s): e.g. Claude Code, Codex CLI, Cursor — or "none"
- Model(s): exact model ID(s), e.g. claude-fable-5, gpt-5.4 — or "n/a"
- Involvement: fully AI-generated | AI-assisted | human-written, AI-reviewed | none
- Adversarial review: what your own AI review of the diff found, and how you resolved it
```
The exact model matters. This project is developed with frontier models. If a PR was generated by an older or weaker model, the fastest honest response may be for me to re-implement the idea with a current model instead of reviewing the diff line by line. Disclosing the model lets that call happen quickly. "Thanks, the idea is accepted, but the implementation will be redone" is a possible outcome; see [Be Realistic](#be-realistic).
Before submitting, run an adversarial review of your own diff with whatever AI tooling you have, and summarize what it found and what you did about it. "It found nothing" is only credible for tiny diffs.
Undisclosed AI use that is discovered later gets the PR closed on the spot. Repeat offenses get you blocked. The offense is the non-disclosure, not the AI use.
Fabricated content is an immediate block, first offense. Invented APIs, repro steps that never happened, AI-imagined vulnerabilities, and "bugs" nobody actually observed all count. This is the curl-style rule for hallucinated reports.
For issues, logs must be raw copy-paste, never AI-paraphrased. You must have actually reproduced the problem yourself on a real deployment before filing.
## Merge Requests
A good MR answers: what problem does this solve, why this approach, how was it tested, anything to watch out for. For non-trivial changes, link the issue and note any migration/compatibility concerns. Screenshots for UI changes.
Small, well-explained MRs get reviewed fast. Big unexplained ones sit.
AI disclosure is mandatory for every MR; use the required block in [AI Disclosure (Required)](#ai-disclosure-required).
If AI meaningfully shaped the implementation, say so in the description. Not gatekeeping — just helps reviewers understand intent.
## Development Setup
-121
View File
@@ -1,121 +0,0 @@
# Developing Silo
This document covers building, running, and contributing to the Silo server. If you just want to run Silo, see the [README](README.md).
See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution expectations, merge request guidance, and the policy for AI-assisted submissions.
## Prerequisites
- **Go** 1.26.4+
- **Node.js** 22+ with **pnpm** 10.32.1
- **PostgreSQL** 18 with pgvector
- **Redis**
- **FFmpeg** (for transcoding support)
## Local Development
Local development remains intentionally separate from the deploy-oriented compose setup. Use [docker-compose.yml](docker-compose.yml) for local services and the source-build workflow below.
```sh
# Create the local bootstrap configuration
cp .env.example .env
printf '\nSECRET_KEY=%s\nDATABASE_URL=%s\nREDIS_URL=%s\n' \
"$(openssl rand -base64 48)" \
'postgres://silo:silo@localhost:5432/silo?sslmode=disable' \
'redis://localhost:6379' >> .env
# Start local PostgreSQL and Redis
docker compose up -d postgres redis
# Run the frontend dev server (hot reload, proxies API to :8090)
make dev-frontend
# Run the Go backend
make dev-backend
```
The template supplies a non-empty `MEDIA_ROOT` because Compose validates the whole file even when
you start only PostgreSQL and Redis. Change it before testing libraries against real media.
If you are developing `Silo` and `silo-plugin-sdk` together, keep using the local [`go.work`](go.work) workspace. That workspace is a developer convenience only. CI and release builds run with `GOWORK=off`, so any new SDK helper used here must be pushed and tagged in `silo-plugin-sdk` before this repo can merge or release the change.
Plugin authors should start with [docs/architecture/plugin-development.md](docs/architecture/plugin-development.md), which covers the RPC plugin package format, generated proto workflow, SDK import paths, route and asset exposure, and auth or user-config integration points.
## Make Targets
| Target | Description |
|---|---|
| `make build` | Build frontend + Go binary |
| `make frontend` | Build frontend only |
| `make dev-frontend` | Vite dev server with HMR |
| `make dev-backend` | Run Go backend (integrated mode) |
| `make dev-proxy` | Run a standalone proxy node |
| `make dev-transcode` | Run a standalone transcode node |
| `make migrate-create NAME=add_thing` | Create a timestamped Goose SQL migration |
| `make migrate-validate` | Validate Goose migration files without touching a database |
| `make migrate-status` | Show Goose migration status using Silo's bootstrapping runner |
| `make migrate-up` | Apply pending Goose migrations using Silo's bootstrapping runner |
| `make clean` | Remove build artifacts |
## Database Migrations
PostgreSQL schema migrations are managed by Goose. Migration SQL files live in
`migrations/sql/` and use Goose annotations. Converted legacy migrations keep
their original numeric versions so existing `schema_versions` rows can bootstrap
cleanly into Goose without replaying old SQL. New migrations should be created
with timestamped filenames:
```sh
make migrate-create NAME=add_thing
make migrate-validate
```
Do not run `goose fix`; timestamped migrations are the repository policy because
they avoid version collisions across parallel PRs. The existing `001`-style
files are historical compatibility records, not the naming pattern for new work.
Runtime migrations are applied by the integrated/API server only. Proxy and
transcode modes never mutate schema.
For existing installs, use `make migrate-status` and `make migrate-up` rather
than invoking the Goose CLI directly; those targets copy legacy
`schema_versions` rows into `public.goose_db_version` under the migration lock
before reading or applying migrations. Set `ENV_FILE=path/to/.env` when the
database URL should be read from a non-default env file.
## Running Tests
```sh
# Go tests (uses testcontainers — Docker must be running)
go test ./...
# Frontend tests
cd web && pnpm test
```
## Linting
```sh
# Go
golangci-lint run
# Frontend
cd web && pnpm run lint
cd web && pnpm run format:check
```
## Project Structure
```
cmd/silo/ Entry point
internal/
api/ HTTP router, handlers, middleware
auth/ JWT authentication and sessions
catalog/ Media item, episode, season repositories
config/ YAML + env var configuration
jellycompat/ Jellyfin/Emby protocol compatibility
metadata/ Plugin-driven metadata matching and enrichment
playback/ Direct play, remux, transcode session management
scanner/ Media file discovery and FFProbe
worker/ Background jobs (scan, match, reconcile)
web/ React + TypeScript frontend (Vite, Tailwind, shadcn/ui)
migrations/sql/ Goose-managed PostgreSQL schema migrations
```
-4
View File
@@ -32,10 +32,6 @@ COPY --from=frontend_dist / web/dist
COPY cmd/ cmd/
COPY internal/ internal/
COPY migrations/ migrations/
# The settings contract is a Go package (contracts/settings/v1) that embeds the
# manifest, so the binary carries the exact bytes it was built from. It lives
# outside internal/ because clients vendor these files.
COPY contracts/ contracts/
ARG BUILD_REVISION
ARG BUILD_DIRTY=false
RUN --mount=type=cache,target=/root/.cache/go-build \
-3
View File
@@ -29,9 +29,6 @@ COPY --from=frontend /app/web/dist web/dist
COPY cmd/ cmd/
COPY internal/ internal/
COPY migrations/ migrations/
# See Dockerfile: the settings contract is an embedded Go package outside
# internal/, so the build fails without it.
COPY contracts/ contracts/
# Stage 3: Build Go binary for dev using a local plugin SDK checkout passed via
# BuildKit named context `silo_plugin_sdk`.
+1 -138
View File
@@ -1,4 +1,4 @@
.PHONY: frontend build dev-frontend dev-backend dev-proxy dev-transcode lint test test-go test-web embed-stub clean jellyfin-web migrate-continuum-check verify-local-paths install-hooks migrate-create migrate-validate migrate-status migrate-up migrate-down-to settings-bindings verify-settings-bindings verify-settings-bindings-web verify-settings-bindings-all playback-fixtures verify-playback-fixtures
.PHONY: frontend build dev-frontend dev-backend dev-proxy dev-transcode lint clean jellyfin-web migrate-continuum-check verify-local-paths install-hooks migrate-create migrate-validate migrate-status migrate-up
GIT_COMMON_DIR := $(strip $(shell git rev-parse --git-common-dir 2>/dev/null))
MAIN_CHECKOUT_ROOT := $(if $(GIT_COMMON_DIR),$(abspath $(GIT_COMMON_DIR)/..))
@@ -54,126 +54,6 @@ lint:
golangci-lint run
cd web && pnpm run lint
# Frontend test files that fail on main today. This list is shrink-only: delete
# an entry along with its fix, and never extend it to land a change. The Go
# suite has no equivalent — a Go test that cannot pass yet carries a t.Skip and
# its reason in the source, where whoever reads the test finds it.
WEBTEST_KNOWN_FAILURES := \
--exclude src/pages/Catalog.test.tsx \
--exclude src/pages/ItemDetail/SeasonContent.test.tsx \
--exclude src/pages/LibraryRecommended.test.tsx \
--exclude src/pages/setup-wizard/steps/ServerStorageStep.test.tsx \
--exclude src/player/hooks/useASSSubtitles.test.tsx
# The Go binary embeds the built frontend, so every Go build and test needs
# web/dist to exist. Tests never serve it, so a placeholder is enough; `make
# build` still builds the real bundle.
embed-stub:
@mkdir -p web/dist
@[ -e web/dist/index.html ] || printf '<!doctype html>\n' > web/dist/index.html
# Run the Go and frontend test suites.
test: test-go test-web
test-go: embed-stub
go test ./...
test-web:
cd web && pnpm exec vitest run $(WEBTEST_KNOWN_FAILURES)
# Regenerate the settings-contract bindings for every language.
#
# The client repos are siblings of this one (see CLAUDE.md); a missing checkout
# is skipped rather than failing, so a server-only developer can still run this.
#
# The conformance fixture (contracts/settings/v1/conformance.json) travels with
# the bindings: the vendored copy in web/src/lib is what the web runner reads.
# The Kotlin and Swift copies land together with their runners in the client
# repos, which will pick their own test-resource paths.
SILO_ANDROID_DIR ?= $(abspath ../silo-android)
SILO_APPLE_DIR ?= $(abspath ../silo-apple)
settings-bindings:
@mkdir -p internal/settingskeys
go run ./cmd/settingsgen -lang go -out internal/settingskeys/keys.go
gofmt -w internal/settingskeys/keys.go
go run ./cmd/settingsgen -lang ts -out web/src/lib/settingsContract.ts
@cd web && pnpm exec prettier --write src/lib/settingsContract.ts >/dev/null
cp contracts/settings/v1/conformance.json web/src/lib/settingsConformance.json
@if [ -d "$(SILO_ANDROID_DIR)" ]; then \
go run ./cmd/settingsgen -lang kotlin \
-out "$(SILO_ANDROID_DIR)/shared/src/commonMain/kotlin/org/siloserver/silo/model/settings/SettingKeys.kt"; \
echo "wrote Kotlin bindings to $(SILO_ANDROID_DIR)"; \
else \
echo "skipping Kotlin: $(SILO_ANDROID_DIR) not checked out"; \
fi
@if [ -d "$(SILO_APPLE_DIR)" ]; then \
go run ./cmd/settingsgen -lang swift \
-out "$(SILO_APPLE_DIR)/iosApp/iosApp/Networking/SettingKeys.generated.swift"; \
echo "wrote Swift bindings to $(SILO_APPLE_DIR)"; \
else \
echo "skipping Swift: $(SILO_APPLE_DIR) not checked out"; \
fi
# Fail when the committed bindings disagree with the manifest, so a manifest
# change cannot merge without regenerating what every client reads.
#
# Split in two because the generated TypeScript is compared after prettier, and
# only the Web CI job has pnpm: the Go job runs this target, the Web job runs
# verify-settings-bindings-web. Locally, `verify-settings-bindings-all` is both.
verify-settings-bindings:
@CHECK_DIR=$$(mktemp -d) && trap 'rm -rf "$$CHECK_DIR"' EXIT && \
go run ./cmd/settingsgen -lang go | gofmt > "$$CHECK_DIR/keys.go" && \
diff -u internal/settingskeys/keys.go "$$CHECK_DIR/keys.go" \
|| { echo "::error::internal/settingskeys/keys.go is stale; run make settings-bindings"; exit 1; }
@diff -u web/src/lib/settingsConformance.json contracts/settings/v1/conformance.json \
|| { echo "::error::web/src/lib/settingsConformance.json is stale; run make settings-bindings"; exit 1; }
@echo "settings bindings are current"
# The half that needs pnpm: regenerate the web binding, format it the way the
# bindings target does, and compare. Without this a manifest change could merge
# with a stale settingsContract.ts, which is what every web control renders from.
verify-settings-bindings-web:
@CHECK_DIR=$$(mktemp -d) && trap 'rm -rf "$$CHECK_DIR"' EXIT && \
go run ./cmd/settingsgen -lang ts -out "$$CHECK_DIR/settingsContract.ts" && \
cd web && pnpm exec prettier --log-level silent --config .prettierrc \
--write "$$CHECK_DIR/settingsContract.ts" && cd .. && \
diff -u web/src/lib/settingsContract.ts "$$CHECK_DIR/settingsContract.ts" \
|| { echo "::error::web/src/lib/settingsContract.ts is stale; run make settings-bindings"; exit 1; }
@echo "web settings binding is current"
verify-settings-bindings-all: verify-settings-bindings verify-settings-bindings-web
# Regenerate the protocol-v3 golden contract fixtures from the live types and planner.
#
# The server owns the playback contract and the clients prove conformance
# against these bodies, so they are only trustworthy while the code that emits
# them is the code that serves traffic. Editing one by hand instead of running
# this would let the contract and the implementation drift apart in silence.
PLAYBACK_FIXTURE_DIR := internal/playback/testdata/protocol_v3
PLAYBACK_SCHEMA_FIXTURE_DIR := docs/design/schemas/playback-v3/v3/fixtures/valid
PLAYBACK_WIRE_FIXTURES := start_request.json replan_request.json decision_response.json capability_response.json error_response.json route_event.json
playback-fixtures:
go run ./cmd/playbackfixtures -out $(PLAYBACK_FIXTURE_DIR)
@set -e; for fixture in $(PLAYBACK_WIRE_FIXTURES); do \
cp "$(PLAYBACK_FIXTURE_DIR)/$$fixture" "$(PLAYBACK_SCHEMA_FIXTURE_DIR)/$$fixture"; \
done
# Fail when the committed fixtures disagree with the contract types. A change
# that does not regenerate leaves every client testing against a body the server
# no longer produces, which is exactly the drift the fixtures exist to catch.
verify-playback-fixtures:
@CHECK_DIR=$$(mktemp -d) && trap 'rm -rf "$$CHECK_DIR"' EXIT && \
go run ./cmd/playbackfixtures -out "$$CHECK_DIR" && \
diff -ur $(PLAYBACK_FIXTURE_DIR) "$$CHECK_DIR" \
|| { echo "::error::$(PLAYBACK_FIXTURE_DIR) is stale; run make playback-fixtures"; exit 1; }; \
for fixture in $(PLAYBACK_WIRE_FIXTURES); do \
cmp -s "$$CHECK_DIR/$$fixture" "$(PLAYBACK_SCHEMA_FIXTURE_DIR)/$$fixture" \
|| { echo "::error::$(PLAYBACK_SCHEMA_FIXTURE_DIR)/$$fixture is stale; run make playback-fixtures"; exit 1; }; \
done
@echo "playback fixtures are current"
# Check committed content for local machine path leaks.
verify-local-paths:
scripts/check-local-path-leaks.sh
@@ -191,23 +71,6 @@ migrate-validate:
migrate-status:
go run ./cmd/silo/ --env "$(ENV_FILE)" --migrate-status
# Roll back every migration newer than VERSION (the version to KEEP).
#
# Not a routine operation: it discards data. It exists because some migrations
# are Go rather than SQL — the settings backfill and the jellycompat
# DisplayPreferences move — and those are registered in-process, so the goose
# CLI above cannot see or reverse them.
#
# This is a RANGE, not a list: everything newer than VERSION comes off, including
# migrations belonging to other features that happen to sort in between. Check
# `make migrate-status` and read the down of each one you are about to revert.
# Take a backup first regardless; the per-user SQLite stores have no down path.
#
# Usage: make migrate-down-to VERSION=<timestamp from migrate-status>
migrate-down-to:
@if [ -z "$(VERSION)" ]; then echo "usage: make migrate-down-to VERSION=<timestamp from make migrate-status>"; exit 1; fi
go run ./cmd/silo/ --env "$(ENV_FILE)" --migrate-down-to "$(VERSION)"
# Apply pending Goose migrations through Silo's bootstrapping runner.
migrate-up:
go run ./cmd/silo/ --env "$(ENV_FILE)" --migrate-only
+191 -153
View File
@@ -1,36 +1,19 @@
# Silo
Silo is a self-hosted media streaming server for your movies, shows, music, and books. Point it at your media folders and stream to your devices — at home or away — with direct play, remuxing, and hardware-accelerated transcoding handled automatically.
A self-hosted media streaming server with a React frontend and Go backend. Supports direct play, remuxing, and hardware-accelerated transcoding. Includes optional Jellyfin/Emby-compatible app support for clients such as VidHub and Findroid.
Join the community on [Discord](https://discord.gg/4RxuUQAEnW). If Silo is useful to you, consider [sponsoring the project](https://github.com/sponsors/quick104) — see [Supporting Silo](#supporting-silo).
## Highlights
- **Plays your media, your way** — direct play when the device supports it, remux or hardware-accelerated transcode (including NVENC) when it doesn't.
- **Web app included** — a full-featured web client and admin interface ship with the server.
- **Works with apps you already use** — optional Jellyfin/Emby-compatible API supports clients such as VidHub, Findroid, and Infuse.
- **Household profiles** — multiple profiles per account, with per-profile watch state and parental controls.
- **Plugin-driven metadata** — match and enrich your libraries with providers like TMDB and TVDB, installed as plugins.
- **Fast setup** — one `docker compose up -d` brings up the whole stack; everything else is configured in the admin UI.
Join the community on [Discord](https://discord.gg/4RxuUQAEnW).
## Deploy with Docker (recommended)
The easiest way to run Silo is with Docker Compose 2.24 or newer. The default stack assumes you do
not already have PostgreSQL and Redis available, so it bundles PostgreSQL, Redis, FFmpeg, and the
application for a one-command start.
The easiest way to run Silo is with Docker Compose. The default stack assumes you do not already have PostgreSQL and Redis available, so it bundles PostgreSQL, Redis, FFmpeg, and the application for a one-command start.
1. **Create a `.env` file**
```sh
cp .env.example .env
printf '\nPOSTGRES_PASSWORD=%s\nSECRET_KEY=%s\n' \
"$(openssl rand -hex 24)" "$(openssl rand -base64 48)" >> .env
```
This replaces the development database password from `.env.example` and creates the key Silo
uses to encrypt stored credentials. Back up `.env` separately from PostgreSQL; losing
`SECRET_KEY` makes those credentials unrecoverable.
2. **Set your media path**
Edit `.env` and set:
@@ -51,21 +34,6 @@ application for a one-command start.
If you already have PostgreSQL and Redis available, omit those bundled service examples from compose and point Silo at your existing `DATABASE_URL` and `REDIS_URL` instead.
### Optional Intel/AMD VA-API or Intel Quick Sync
The default stack is CPU-only so it starts on hosts without `/dev/dri`. On a Linux host with
`/dev/dri`, enable the device overlay:
```sh
docker compose -f docker-compose.yml -f docker-compose.vaapi.yml up -d
```
To make that the default for this installation, set:
```dotenv
COMPOSE_FILE=docker-compose.yml:docker-compose.vaapi.yml
```
### Optional NVIDIA/NVENC
GPU support is kept out of the default compose file so hosts without NVIDIA drivers work unchanged.
@@ -101,39 +69,32 @@ By default, data is stored under `/opt/silo`:
- `/opt/silo/postgres`
- `/opt/silo/redis`
- `/opt/silo/plugins`
- `/opt/silo/compat`
- `/opt/silo/transcode`
- `/opt/silo/catalog-seeds`
The optional `search` profile also stores its index under `/opt/silo/meilisearch`.
Media is mounted into the container at `/mnt/media` from the host path you set in `MEDIA_ROOT`.
### Optional Search Profile
### Optional Profiles
PostgreSQL full-text search works without any optional services. Meilisearch is available when you
want its search provider:
The main compose file is integrated-first. These profiles exist for operators testing distributed mode or mirroring a split deployment shape. Most single-host installs should stay on the default integrated service, because it already includes proxying and transcoding.
| Profile | Command | Description |
|---|---|---|
| default | `docker compose up -d` | Integrated server plus bundled PostgreSQL and Redis |
| `search` | `docker compose --profile search up -d` | Add the optional Meilisearch service |
| `proxy` | `docker compose --profile proxy up -d` | Start a standalone proxy service for distributed-mode testing |
| `transcode` | `docker compose --profile transcode up -d` | Start a standalone transcode service for distributed-mode testing |
Before starting the `search` profile, set `MEILI_MASTER_KEY` in `.env` to the output of
`openssl rand -hex 32`. After Silo starts, choose Meilisearch under **Admin > Settings > Search**,
set the URL to `http://meilisearch:7700`, enter the same key as the API key, test the connection,
and save. Restart Silo, then rebuild the catalog search index from the same page. Silo continues
to use PostgreSQL full-text search until you select Meilisearch.
You can enable both optional examples together:
### Distributed Examples
```sh
docker compose --profile proxy --profile transcode up -d
```
The main Compose file includes commented proxy and transcode service examples. Most single-host
installs should leave them commented because the integrated service already includes proxying and
transcoding.
If you are splitting workers across multiple hosts, use the separate remote worker example instead of trying to stretch the main compose file across machines.
Multi-host operators can use those examples as a starting point for a dedicated worker Compose
file connected to the deployment's shared PostgreSQL and Redis services.
### Advanced Remote Node Example
For a dedicated remote transcode worker, use [docker-compose.remote-transcode.yml](docker-compose.remote-transcode.yml). That file is intended for a separate worker host that connects back to an existing Silo deployment using shared PostgreSQL and Redis.
### Deployment Notes
@@ -144,12 +105,168 @@ Silo is externally stateful by default rather than fully stateless. Durable appl
Migrating an existing Continuum Docker install should be done with the preflight
helper and cutover guide in [docs/continuum-to-silo-docker-migration.md](docs/continuum-to-silo-docker-migration.md).
## Build from Source
### Prerequisites
- **Go** 1.24+
- **Bun** 1.0+
- **PostgreSQL** 18+
- **FFmpeg** (for transcoding support)
### Quick Start
1. **Start PostgreSQL** (skip if you already have one running)
```sh
docker compose up -d postgres redis
```
The main compose file still expects `MEDIA_ROOT` to be set even if you only want the bundled PostgreSQL and Redis services, so set that in `.env` first.
2. **Configure the database connection**
```sh
cp .env.example .env
```
Edit `.env` and set `DATABASE_URL` to point to your PostgreSQL instance.
3. **Build and run**
```sh
make build
./silo
```
The server starts at `http://localhost:8080` by default. All other settings are configured through the admin UI.
## Development
Local development remains intentionally separate from the deploy-oriented compose setup. Use [docker-compose.yml](docker-compose.yml) and the existing source-build workflow for local development.
```sh
# Run the frontend dev server (hot reload, proxies API to :8090)
make dev-frontend
# Run the Go backend
make dev-backend
```
If you are developing `Silo` and `silo-plugin-sdk` together, keep using the local [`go.work`](go.work) workspace. That workspace is a developer convenience only. CI and release builds run with `GOWORK=off`, so any new SDK helper used here must be pushed and tagged in `silo-plugin-sdk` before this repo can merge or release the change.
See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution expectations, merge request guidance, and the policy for AI-assisted submissions.
Plugin authors should start with [docs/architecture/plugin-development.md](docs/architecture/plugin-development.md), which covers the RPC plugin package format, generated proto workflow, SDK import paths, route and asset exposure, and auth or user-config integration points.
## Reporting Issues
If you are reporting a bug, install problem, or performance issue, start with the admin workflow and reproduction steps, not Claude/Codex analysis.
Please include:
- What you were trying to do
- Exact steps you took
- What you expected to happen
- What actually happened
- What exact action is slow or broken (`save`, `scan`, `browse`, `import`, `playback`, etc.)
- Whether it happens every time or only sometimes
- The library, media type, filter, setting, or value involved
- Version, branch, commit, and deployment details if you know them
- Screenshots, recordings, or log snippets if relevant
If you used Claude/Codex for debugging, put that under `Technical notes` at the end. Suspected files, SQL output, stack traces, and root-cause theories can be helpful, but only after the workflow and repro steps are clear.
Use this template:
```text
Goal:
Steps:
Expected:
Actual:
What is slow/broken:
Scope:
Version/branch:
Deployment:
Technical notes:
```
### Make Targets
| Target | Description |
|---|---|
| `make build` | Build frontend + Go binary |
| `make frontend` | Build frontend only |
| `make dev-frontend` | Vite dev server with HMR |
| `make dev-backend` | Run Go backend (integrated mode) |
| `make dev-proxy` | Run a standalone proxy node |
| `make dev-transcode` | Run a standalone transcode node |
| `make migrate-create NAME=add_thing` | Create a timestamped Goose SQL migration |
| `make migrate-validate` | Validate Goose migration files without touching a database |
| `make migrate-status` | Show Goose migration status using Silo's bootstrapping runner |
| `make migrate-up` | Apply pending Goose migrations using Silo's bootstrapping runner |
| `make clean` | Remove build artifacts |
### Database Migrations
PostgreSQL schema migrations are managed by Goose. Migration SQL files live in
`migrations/sql/` and use Goose annotations. Converted legacy migrations keep
their original numeric versions so existing `schema_versions` rows can bootstrap
cleanly into Goose without replaying old SQL. New migrations should be created
with timestamped filenames:
```sh
make migrate-create NAME=add_thing
make migrate-validate
```
Do not run `goose fix`; timestamped migrations are the repository policy because
they avoid version collisions across parallel PRs. The existing `001`-style
files are historical compatibility records, not the naming pattern for new work.
Runtime migrations are applied by the integrated/API server only. Proxy and
transcode modes never mutate schema.
For existing installs, use `make migrate-status` and `make migrate-up` rather
than invoking the Goose CLI directly; those targets copy legacy
`schema_versions` rows into `public.goose_db_version` under the migration lock
before reading or applying migrations. Set `ENV_FILE=path/to/.env` when the
database URL should be read from a non-default env file.
### Running Tests
```sh
# Go tests (uses testcontainers — Docker must be running)
go test ./...
# Frontend tests
cd web && bun test
```
### Linting
```sh
# Go
golangci-lint run
# Frontend
cd web && bun run lint
cd web && bun run format:check
```
## License & Trademarks
Silo's source code is licensed under the **GNU Affero General Public License
v3.0 or later** (`AGPL-3.0-or-later`) — see [LICENSE](LICENSE).
The **Silo name, logo, and wordmark are trademarks of Silo Media L.L.C.** and
are **not** covered by the AGPL. You're free to fork and redistribute the code,
but forks and redistributions must not use the Silo brand as their identity and
must remove or replace the brand assets. Publishing a Silo-branded app to an app
store requires written permission. See [TRADEMARK.md](TRADEMARK.md) for what's
permitted — including referential use like "compatible with Silo."
## Configuration
Silo requires `DATABASE_URL` and `SECRET_KEY` when running from source or against external
infrastructure. In the default Docker Compose path, the stack wires the database and Redis URLs
for you. All other settings — libraries, metadata providers, transcoding, users — are managed
through the admin UI after first launch.
Silo requires only a `DATABASE_URL` when running from source or against external infrastructure. In the default Docker Compose path, the stack wires the database and Redis URLs for you. All other settings — libraries, metadata providers, transcoding, users — are managed through the admin UI after first launch.
### Server Modes
@@ -160,7 +277,7 @@ through the admin UI after first launch.
| `proxy` | Stream proxy node that connects to the shared deployment database and Redis |
| `transcode` | HLS transcode worker node that connects to the shared deployment database and Redis |
### PostgreSQL Auto-Tuning
## PostgreSQL Auto-Tuning
The default Docker Compose stack does not require a checked-in `postgresql.conf`.
It enables Silo's [pgtune](https://github.com/le0pard/pgtune)-style OLTP tuning
@@ -212,99 +329,20 @@ change PostgreSQL server settings. Settings already written with `ALTER SYSTEM`
remain in `postgresql.auto.conf`; reset those PostgreSQL parameters if you later
move fully to a custom `postgresql.conf`.
## Build from Source
## Project Structure
If you prefer running Silo without Docker:
1. **Install prerequisites**: Go 1.26.4+, Node.js 22+, pnpm 10.32.1, PostgreSQL 18 with pgvector, Redis, and FFmpeg.
2. **Configure the source process**
```sh
cp .env.example .env
printf '\nSECRET_KEY=%s\nDATABASE_URL=%s\nREDIS_URL=%s\n' \
"$(openssl rand -base64 48)" \
'postgres://silo:silo@localhost:5432/silo?sslmode=disable' \
'redis://localhost:6379' >> .env
```
Change the URLs when you use existing services instead of the bundled development defaults.
3. **Start PostgreSQL and Redis** (skip if you already have them running)
```sh
docker compose up -d postgres redis
```
4. **Build and run**
```sh
make build
./silo
```
The server starts at `http://localhost:8080` by default. All other settings are configured through the admin UI.
## Reporting Issues
Client implementers can use the [Canonical Settings API guide](docs/settings-api.md)
for contract discovery, contextual headers, remote scopes, effective reads, and
the admin projection.
If you are reporting a bug, install problem, or performance issue, start with the admin workflow and reproduction steps, not Claude/Codex analysis.
Please include:
- What you were trying to do
- Exact steps you took
- What you expected to happen
- What actually happened
- What exact action is slow or broken (`save`, `scan`, `browse`, `import`, `playback`, etc.)
- Whether it happens every time or only sometimes
- The library, media type, filter, setting, or value involved
- Version, branch, commit, and deployment details if you know them
- Screenshots, recordings, or log snippets if relevant
If you used Claude/Codex for debugging, put that under `Technical notes` at the end. Suspected files, SQL output, stack traces, and root-cause theories can be helpful, but only after the workflow and repro steps are clear.
Use this template:
```text
Goal:
Steps:
Expected:
Actual:
What is slow/broken:
Scope:
Version/branch:
Deployment:
Technical notes:
```
## Contributing & Development
Silo is open source and contributions are welcome. See [DEVELOPMENT.md](DEVELOPMENT.md) for building from source in a dev workflow, running tests, database migrations, and project layout, and [CONTRIBUTING.md](CONTRIBUTING.md) for contribution expectations, merge request guidance, and the policy for AI-assisted submissions.
## Supporting Silo
Silo is an open-source hobby project, developed in spare time and funded out of pocket. If you'd like to support development, you can sponsor via [GitHub Sponsors](https://github.com/sponsors/quick104).
Donations go directly toward the costs of building and running the project:
- AI development tooling subscriptions (Claude, Codex) used to build and maintain Silo
- Push notification relay infrastructure
- Future development costs
Sponsoring is entirely optional — Silo is and will remain free and open source. Bug reports, contributions, and feedback are just as valuable.
## License & Trademarks
Silo's source code is licensed under the **GNU Affero General Public License
v3.0 or later** (`AGPL-3.0-or-later`) — see [LICENSE](LICENSE).
The **Silo name, logo, and wordmark are trademarks of Silo Media L.L.C.** and
are **not** covered by the AGPL. You're free to fork and redistribute the code,
but forks and redistributions must not use the Silo brand as their identity and
must remove or replace the brand assets. Publishing a Silo-branded app to an app
store requires written permission. See [TRADEMARK.md](TRADEMARK.md) for what's
permitted — including referential use like "compatible with Silo."
cmd/silo/ Entry point
internal/
api/ HTTP router, handlers, middleware
auth/ JWT authentication and sessions
catalog/ Media item, episode, season repositories
config/ YAML + env var configuration
jellycompat/ Jellyfin/Emby protocol compatibility
metadata/ Plugin-driven metadata matching and enrichment
playback/ Direct play, remux, transcode session management
scanner/ Media file discovery and FFProbe
worker/ Background jobs (scan, match, reconcile)
web/ React + TypeScript frontend (Vite, Tailwind, shadcn/ui)
migrations/sql/ Goose-managed PostgreSQL schema migrations
```
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

-858
View File
@@ -1,858 +0,0 @@
// Command playbackfixtures writes the protocol-v3 golden contract fixtures
// from the live Go types and planner.
//
// The direction of authority is inverted from where it started: the server
// defines the playback protocol, and clients prove conformance against these
// files. Android and Apple CI vendor them and compare their own decoders and
// opaque-token echo behavior against the values here, so a fixture is
// only trustworthy if it was produced by the same code that serves real
// traffic — hand-editing one would let the contract and the implementation
// drift apart silently.
//
// Usage:
//
// go run ./cmd/playbackfixtures -out internal/playback/testdata/protocol_v3
//
// `make playback-fixtures` runs it; `make verify-playback-fixtures`
// regenerates into a temporary directory and diffs, so a contract change
// cannot merge without refreshing what every client tests against.
package main
import (
"encoding/json"
"flag"
"fmt"
"net/http"
"os"
"path/filepath"
"time"
"github.com/Silo-Server/silo-server/internal/models"
"github.com/Silo-Server/silo-server/internal/playback"
)
// goldenSessionID is a fixed UUID: fixtures must be byte-stable across runs,
// so nothing in this generator may read the clock or a random source.
const (
goldenSessionID = "11111111-1111-4111-8111-111111111111"
goldenAttemptID = "attempt-golden-0001"
goldenExpiresAt = "2030-01-01T00:00:00Z"
goldenMediaFileID = 42
// Codec and container tokens the fixtures are built from. Named so the
// capability lists, the plan recipe, and the source descriptor cannot drift
// into describing different media by a one-character typo.
codecH264 = "h264"
codecHEVC = "hevc"
codecAAC = "aac"
codecTrueHD = "truehd"
containerMP4 = "mp4"
containerMKV = "mkv"
containerHLS = "hls"
profileHigh = "high"
resolutionHD = "720p"
resolutionFHD = "1080p"
qualityOriginal = "original"
audioLayoutStereo = "stereo"
audioLayout71 = "7.1"
filmFrameRate = "24000/1001"
languageEnglish = "eng"
videoRangeSDR = "SDR"
categoryMidSeek = "mid_seek_replan"
)
func main() {
out := flag.String("out", "", "directory to write fixtures into (required)")
flag.Parse()
if *out == "" {
fail("usage: playbackfixtures -out <dir>")
}
if err := os.MkdirAll(*out, 0o755); err != nil {
fail("create %s: %v", *out, err)
}
write(*out, "start_request.json", goldenStartRequest())
write(*out, "replan_request.json", goldenReplanRequest())
write(*out, "decision_response.json", goldenDecisionResponse())
write(*out, "capability_response.json", goldenCapabilityResponse())
write(*out, "error_response.json", goldenErrorResponse())
write(*out, "route_event.json", goldenRouteEvent())
write(*out, "subtitle_inventory.json", goldenSubtitleInventory())
write(*out, "attempt_keys.json", goldenAttemptKeys())
write(*out, "conformance_matrix.json", goldenConformanceMatrix())
}
func goldenErrorResponse() playback.ErrorResponseV3 {
return playback.LegacyUpgradeErrorV3()
}
func write(dir, name string, value any) {
body, err := json.MarshalIndent(value, "", " ")
if err != nil {
fail("marshal %s: %v", name, err)
}
body = append(body, '\n')
path := filepath.Join(dir, name)
if err := os.WriteFile(path, body, 0o644); err != nil { //nolint:gosec // generated fixture
fail("write %s: %v", path, err)
}
}
func fail(format string, args ...any) {
fmt.Fprintf(os.Stderr, format+"\n", args...)
os.Exit(1)
}
// goldenCapabilities is the exact-evidence Android-shaped capability block the
// request fixtures share. Both request bodies carry the same capability
// contract, so they are built from one function rather than two drifting
// literals.
func goldenCapabilities() playback.ClientCodecCapabilitiesV3 {
return playback.ClientCodecCapabilitiesV3{
VideoEvidence: playback.EvidenceExactV3,
AudioEvidence: playback.EvidenceExactV3,
CodecsVideo: []string{codecH264},
CodecsVideoHardware: []string{codecH264},
CodecsAudio: []string{codecAAC},
Containers: []string{containerMP4},
MaxResolution: resolutionFHD,
VideoDecode: []playback.VideoDecodeCapabilityV3{{
Codec: codecH264,
Profiles: []string{profileHigh},
Levels: []int{41},
BitDepths: []int{8},
MaxWidth: 1920,
MaxHeight: 1080,
MaxFrameRate: 60,
MaxBitrateKbps: 20_000,
Hardware: true,
}},
}
}
func goldenPlaybackContext() playback.ClientPlaybackContextV3 {
return playback.ClientPlaybackContextV3{
ProtocolVersion: playback.ProtocolV3,
FormFactor: "tv",
AppVersion: "3.0-test",
Device: playback.DeviceContextV3{
Platform: "android",
OSVersion: "15",
Manufacturer: "NVIDIA",
Model: "SHIELD Android TV",
// Everything platform-specific travels here as opaque bounded
// strings; the contract itself stays neutral.
PlatformDetails: map[string]string{"sdk_int": "35", "abis": "arm64-v8a"},
},
Output: playback.OutputContextV3{OutputContextID: "7"},
Deliveries: map[string]playback.DeliveryCapabilityV3{
playback.DeliveryClassOriginalHTTPV3: {
Enabled: true,
SupportedOnDevice: true,
Containers: []string{containerMP4},
VideoCodecs: []string{codecH264},
AudioDecodeCodecs: []string{codecAAC},
AudioPassthroughCodecs: []string{},
Subtitles: playback.DeliverySubtitleCapabilitiesV3{
EmbeddedText: true,
SidecarText: true,
},
Features: []string{},
AuthHeaderRefresh: true,
ValidatedClaims: []string{},
Transformations: []playback.TransformationV3{},
},
},
}
}
func goldenStartRequest() playback.StartRequestV3 {
start := 12.5
audioIndex := 0
return playback.StartRequestV3{
ProtocolVersion: playback.ProtocolV3,
ClientFeatures: []string{playback.FeaturePlaybackPlanV3},
FileID: goldenMediaFileID,
ProfileID: "profile-1",
PlaybackAttemptID: goldenAttemptID,
QualityPreference: playback.QualityOriginalV3,
SubtitleFidelityPreference: playback.SubtitleFidelityCompatibleV3,
StartPosition: &start,
ProgressPersistence: playback.ProgressPersistenceClientV3,
AudioTrackID: playback.TrackIDV3(goldenMediaFileID, "audio", 0),
AudioTrackIndex: &audioIndex,
Capabilities: goldenCapabilities(),
ClientPlaybackContext: goldenPlaybackContext(),
}
}
func goldenReplanRequest() playback.ReplanRequestV3 {
estimate := 3_500
cap := 4_000
audioIndex := 0
decision := goldenDecisionResponse()
if decision.PlaybackPlan == nil {
fail("golden decision has no plan")
}
plan := decision.PlaybackPlan
return playback.ReplanRequestV3{
ProtocolVersion: playback.ProtocolV3,
ClientFeatures: []string{playback.FeaturePlaybackPlanV3},
Operation: playback.ReplanOperationFailureRecoveryV3,
PlaybackAttemptID: goldenAttemptID,
ReplanRequestID: "replan-golden-0001",
FailedPlanID: plan.PlanID,
PlanAttemptID: "plan-attempt-golden-0001",
// Attempt keys are server-owned opaque tokens. A client echoes the
// values it was handed; it never computes one.
PlanAttemptKey: plan.PlanAttemptKey,
AttemptedPlanKeys: []string{plan.PlanAttemptKey},
AttemptCount: 1,
QualityPreference: "auto",
PositionSeconds: 42.5,
Metered: true,
BandwidthEstimateKbps: &estimate,
BandwidthCapKbps: &cap,
SelectedTracks: playback.SelectedTracksV3{
Audio: &playback.TrackIdentityV3{ID: playback.TrackIDV3(goldenMediaFileID, "audio", 0), Index: &audioIndex},
},
Failure: playback.FailureV3{Classification: "network_degraded"},
Capabilities: goldenCapabilities(),
ClientPlaybackContext: goldenPlaybackContext(),
}
}
// goldenMediaFile is the subtitle-bearing source the inventory fixtures
// describe. The embedded track list deliberately mixes a text track, a PGS
// track, and a DVD bitmap track: the DVD track has no sidecar shape the stream
// handler can serve, and pinning its ordinal is the point of the fixture.
func goldenMediaFile() *models.MediaFile {
return &models.MediaFile{
ID: goldenMediaFileID,
ExternalSubtitles: []models.ExternalSubtitle{
{Path: "/library/movie.en.srt", Language: languageEnglish, Format: "srt", Title: "English"},
},
SubtitleTracks: []models.SubtitleTrack{
{Index: 0, Language: languageEnglish, Codec: "ass", Title: "English (Signs)", Forced: true},
{Index: 1, Language: "jpn", Codec: "pgs", Title: "Japanese"},
{Index: 2, Language: "fre", Codec: "dvd_subtitle", Title: "French"},
},
}
}
func goldenSubtitleAdditional() []playback.SubtitleInventoryEntryV3 {
return []playback.SubtitleInventoryEntryV3{
{Codec: "srt", Language: "spa", Label: "Spanish (downloaded)", Source: playback.SubtitleSourceDownloadedV3},
}
}
// subtitleInventoryFixture is a self-describing conformance vector: the inputs
// a client would receive for the same file, and the ordinals the server
// assigns to them. A client reproduces `inventory` from `source` and compares.
type subtitleInventoryFixture struct {
Description string `json:"description"`
SessionID string `json:"session_id"`
MediaFileID int `json:"media_file_id"`
Source subtitleInventorySource `json:"source"`
Inventory []playback.SubtitleInventoryItemV3 `json:"inventory"`
}
type subtitleInventorySource struct {
ExternalSubtitles []models.ExternalSubtitle `json:"external_subtitles"`
SubtitleTracks []models.SubtitleTrack `json:"subtitle_tracks"`
Downloaded []playback.SubtitleInventoryEntryV3 `json:"downloaded"`
}
func goldenSubtitleInventory() subtitleInventoryFixture {
file := goldenMediaFile()
additional := goldenSubtitleAdditional()
return subtitleInventoryFixture{
Description: "Combined subtitle ordinals are dense and gap-free across externals, embedded tracks, " +
"then downloaded tracks. A track with no sidecar representation keeps its ordinal and is " +
"published as burn_in_only without a URL rather than omitted.",
SessionID: goldenSessionID,
MediaFileID: goldenMediaFileID,
Source: subtitleInventorySource{
ExternalSubtitles: file.ExternalSubtitles,
SubtitleTracks: file.SubtitleTracks,
Downloaded: additional,
},
Inventory: playback.SubtitleInventoryV3(goldenSessionID, file, additional),
}
}
func goldenDecisionResponse() playback.DecisionResponseV3 {
file := conformanceFallbackFile()
subtitleSource := goldenMediaFile()
file.ExternalSubtitles = subtitleSource.ExternalSubtitles
file.SubtitleTracks = subtitleSource.SubtitleTracks
now, err := time.Parse(time.RFC3339, "2029-12-31T23:55:00Z")
if err != nil {
fail("parse golden planner time: %v", err)
}
result := playback.PlanPlaybackV3(playback.PlannerInputV3{
Request: goldenStartRequest(),
RequestedFile: file,
EffectiveFile: file,
AudioTrackIndex: 0,
Settings: playback.PlannerSettingsV3{TranscodeEnabled: true, Allow4KTranscode: true},
Registry: conformanceRegistry(),
Now: now,
AdditionalSubtitles: goldenSubtitleAdditional(),
})
if result.Plan == nil {
fail("golden planner returned terminal: %#v", result.Terminal)
}
plan := *result.Plan
// These values belong to session/transport setup, which runs after the
// planner in the request handler. Keep the planner authoritative for every
// decision field and bind only the deterministic fixture runtime values.
plan.SessionID = goldenSessionID
plan.ExpiresAt = goldenExpiresAt
plan.Stream.URL = "/stream/" + goldenSessionID
plan.Subtitle.Inventory = playback.ScopeSubtitleInventoryV3(goldenSessionID, file, plan.Subtitle.Inventory)
return playback.DecisionResponseV3{
ProtocolVersion: playback.ProtocolV3,
ServerFeatures: playback.ServerFeaturesV3(),
Outcome: playback.OutcomePlayableV3,
SessionID: goldenSessionID,
PlaybackPlan: &plan,
}
}
func goldenCapabilityResponse() playback.CapabilityResponseV3 {
return playback.CapabilityResponseV3{
Enabled: true,
ProtocolVersions: []int{playback.ProtocolV3},
Features: playback.ServerFeaturesV3(),
Deliveries: []playback.DeliveryV3{
playback.DeliveryOriginalHTTPV3,
playback.DeliveryRemuxProgressiveV3,
playback.DeliveryRemuxHLSV3,
playback.DeliveryTranscodeHLSV3,
},
// A real server advertises only what its installed FFmpeg probed; the
// fixture pins the full set so a client sees every shape it must parse.
Transformations: []playback.TransformationV3{
{Name: playback.TransformationAudioToAACV3, Executor: playback.ExecutorServerV3, RecipeVersion: "1", ValidatedClaims: []string{playback.ClaimAudioDecodeV3}},
{Name: playback.TransformationServerDV7HDR10V3, Executor: playback.ExecutorServerV3, RecipeVersion: "1", ValidatedClaims: playback.DV7ToHDR10ClaimsV3()},
{Name: playback.TransformationVideoToH264V3, Executor: playback.ExecutorServerV3, RecipeVersion: playback.TransformationVideoToH264RecipeVersionV3, ValidatedClaims: []string{playback.ClaimH264DecodeV3}},
},
}
}
func goldenRouteEvent() playback.RouteEventV3 {
decision := goldenDecisionResponse()
if decision.PlaybackPlan == nil {
fail("golden decision has no plan")
}
plan := decision.PlaybackPlan
return playback.RouteEventV3{
ProtocolVersion: playback.ProtocolV3,
PlaybackAttemptID: goldenAttemptID,
SessionID: goldenSessionID,
PlanID: plan.PlanID,
PlanAttemptID: "plan-attempt-golden-0001",
PlanAttemptKey: plan.PlanAttemptKey,
Event: playback.RouteEventFirstFrameV3,
OutputContextID: "7",
Diagnostics: map[string]string{
"decoder_name": "c2.android.avc.decoder",
"first_frame_ms": "412",
"video_mime": "video/avc",
},
}
}
// attemptKeyInput exists only inside the Go fixture generator. The inputs to
// the server's identity function are deliberately absent from the generated
// JSON: clients receive a token and prove only that they echo it unchanged.
type attemptKeyInput struct {
Name string `json:"name"`
PlanID string `json:"plan_id"`
Delivery playback.DeliveryV3 `json:"delivery"`
StreamProtocol playback.StreamProtocolV3 `json:"stream_protocol"`
Container string `json:"container"`
VideoCodec string `json:"video_codec"`
AudioCodec string `json:"audio_codec"`
Width int `json:"width"`
Height int `json:"height"`
BitrateKbps int `json:"bitrate_kbps"`
DynamicRange string `json:"dynamic_range"`
SubtitleMode playback.SubtitleModeV3 `json:"subtitle_mode"`
Transformations []playback.TransformationV3 `json:"transformations"`
AppliedQuirks []playback.AppliedQuirkV3 `json:"applied_quirks,omitempty"`
RuntimeCorrections []string `json:"runtime_corrections,omitempty"`
OutputContextID string `json:"output_context_id"`
LocalMutations []string `json:"local_mutations"`
}
func (f attemptKeyInput) plan() playback.PlanV3 {
width, height, bitrate := f.Width, f.Height, f.BitrateKbps
return playback.PlanV3{
PlanID: f.PlanID,
Delivery: f.Delivery,
Stream: playback.StreamV3{Protocol: f.StreamProtocol, Container: f.Container},
EffectiveRecipe: playback.EffectiveRecipeV3{
VideoCodec: f.VideoCodec,
AudioCodec: f.AudioCodec,
Width: &width,
Height: &height,
BitrateKbps: &bitrate,
DynamicRange: f.DynamicRange,
},
Subtitle: playback.SubtitleDecisionV3{Mode: f.SubtitleMode},
Transformations: f.Transformations,
AppliedQuirks: f.AppliedQuirks,
RuntimeCorrections: f.RuntimeCorrections,
}
}
type opaqueAttemptKeyFixture struct {
Name string `json:"name"`
ServerPlanAttemptKey string `json:"server_plan_attempt_key"`
ReplanEcho string `json:"replan_echo"`
AttemptedPlanKeys []string `json:"attempted_plan_keys"`
ExpectedServerAction string `json:"expected_server_action"`
}
func goldenAttemptKeys() []opaqueAttemptKeyFixture {
inputs := []attemptKeyInput{
{
Name: "hls_burn_in_sorted_transformations_and_pcm_mutations",
PlanID: "plan:fixture",
Delivery: playback.DeliveryRemuxHLSV3,
StreamProtocol: playback.StreamHLSV3,
Container: containerHLS,
VideoCodec: codecHEVC,
AudioCodec: codecAAC,
Width: 3840,
Height: 2160,
BitrateKbps: 20_000,
DynamicRange: playback.DynamicRangeHDR10V3,
SubtitleMode: playback.SubtitleBurnInV3,
// Deliberately out of order, and deliberately naming a
// transformation the registry no longer defines: the key preimage
// sorts its inputs and never consults the registry, and pinning a
// retired name proves both properties stay true.
Transformations: []playback.TransformationV3{
{Name: "hdr_to_sdr_tonemap", Executor: playback.ExecutorServerV3, RecipeVersion: "1", ValidatedClaims: []string{}},
{Name: playback.TransformationAudioToAACV3, Executor: playback.ExecutorServerV3, RecipeVersion: "1", ValidatedClaims: []string{}},
},
OutputContextID: "7",
LocalMutations: []string{"transport_reopen", "pcm:truehd:8"},
},
{
Name: "direct_client_dv81_executor_and_version",
PlanID: "plan:dv81-fixture",
Delivery: playback.DeliveryOriginalHTTPV3,
StreamProtocol: playback.StreamHTTPProgressiveV3,
Container: containerMKV,
VideoCodec: codecHEVC,
AudioCodec: codecTrueHD,
Width: 3840,
Height: 2160,
BitrateKbps: 65_000,
DynamicRange: playback.DynamicRangeDolbyVisionV3,
SubtitleMode: playback.SubtitleOffV3,
Transformations: []playback.TransformationV3{
{Name: playback.ClientDV7ToDV81V3, Executor: playback.ExecutorClientV3, RecipeVersion: playback.ClientDVTransformVersionV3, ValidatedClaims: []string{}},
},
OutputContextID: "9",
LocalMutations: []string{},
},
{
Name: "direct_device_quirk_and_runtime_correction_identity",
PlanID: "plan:quirk",
Delivery: playback.DeliveryOriginalHTTPV3,
StreamProtocol: playback.StreamHTTPProgressiveV3,
Container: containerMKV,
VideoCodec: codecHEVC,
AudioCodec: "eac3",
Width: 3840,
Height: 2160,
BitrateKbps: 60_000,
DynamicRange: playback.DynamicRangeDolbyVisionV3,
SubtitleMode: playback.SubtitleOffV3,
Transformations: []playback.TransformationV3{},
// The private server implementation includes quirk and runtime
// correction identity; clients see only its opaque result.
AppliedQuirks: []playback.AppliedQuirkV3{{
ID: playback.QuirkFireTVDV8HDR10PlusV3,
RegistryRevision: playback.DeviceQuirkRegistryRevisionV3,
Action: "client_runtime_correction",
}},
RuntimeCorrections: []string{playback.ClientDV8HDR10PlusSanitizerV3},
OutputContextID: "9",
LocalMutations: []string{},
},
}
fixtures := make([]opaqueAttemptKeyFixture, 0, len(inputs))
for _, input := range inputs {
key := playback.PlanAttemptKeyV3(input.plan(), input.OutputContextID, input.LocalMutations)
fixtures = append(fixtures, opaqueAttemptKeyFixture{
Name: input.Name,
ServerPlanAttemptKey: key,
ReplanEcho: key,
AttemptedPlanKeys: []string{key},
ExpectedServerAction: "reject_already_attempted_plan",
})
}
return fixtures
}
func goldenConformanceMatrix() playback.ConformanceMatrixV3 {
videoFile := conformanceVideoFile()
base := conformanceStartRequest()
registry := conformanceRegistry()
settings := playback.PlannerSettingsV3{TranscodeEnabled: true, Allow4KTranscode: true}
planner := make([]playback.PlannerScenarioV3, 0, 18)
for _, tier := range []playback.CapabilityEvidenceV3{
playback.EvidenceExactV3,
playback.EvidencePlatformAttestedV3,
playback.EvidenceDeclaredV3,
} {
request := base
request.PlaybackAttemptID = "attempt-evidence-" + string(tier)
request.Capabilities.VideoEvidence = tier
if tier == playback.EvidenceDeclaredV3 {
request.Capabilities.VideoDecode = nil
}
planner = append(planner, makePlannerScenario(
"evidence_"+string(tier), "evidence_tier_gating", request, videoFile, nil, settings, registry,
))
}
fallbackRequest := conformanceStartRequest()
fallbackRequest.Capabilities.VideoEvidence = playback.EvidenceDeclaredV3
fallbackRequest.Capabilities.VideoDecode = nil
fallbackRequest.Capabilities.CodecsVideo = []string{codecH264}
fallbackRequest.Capabilities.CodecsVideoHardware = []string{codecH264}
fallbackRequest.Capabilities.Containers = []string{containerMP4}
fallbackFile := conformanceFallbackFile()
var attempted []string
for _, name := range []string{qualityOriginal, "progressive", containerHLS} {
request := fallbackRequest
request.PlaybackAttemptID = "attempt-delivery-chain"
scenario := makePlannerScenario("delivery_"+name, "deliveries_negotiation", request, fallbackFile, attempted, settings, registry)
planner = append(planner, scenario)
attempted = append(attempted, scenario.Expected.PlanAttemptKey)
}
transcodeRequest := fallbackRequest
transcodeRequest.PlaybackAttemptID = "attempt-delivery-transcode"
transcodeRequest.QualityPreference = resolutionHD
planner = append(planner, makePlannerScenario("delivery_transcode", "deliveries_negotiation", transcodeRequest, fallbackFile, nil, settings, registry))
audioFile := &models.MediaFile{ID: 77, BaseType: "audiobook", FilePath: "/media/audiobook.m4b", Container: containerMP4, CodecAudio: codecAAC, Bitrate: 128, AudioChannels: 2, Duration: 39_600, AudioTracks: []models.AudioTrack{{Codec: codecAAC, Channels: 2, Layout: audioLayoutStereo}}}
audioRequest := conformanceStartRequest()
audioRequest.FileID = audioFile.ID
audioRequest.PlaybackAttemptID = "attempt-audio-only"
audioRequest.Capabilities.Containers = []string{containerMP4}
planner = append(planner, makePlannerScenario("audio_only_original", "audio_only_planning", audioRequest, audioFile, nil, settings, registry))
hdr10Request := conformanceHDRRequest()
hdr10Request.PlaybackAttemptID = "attempt-hdr10-direct"
planner = append(planner, makePlannerScenario("hdr10_exact_direct", "hdr_dv_matrix", hdr10Request, conformanceHDRFile(), nil, settings, registry))
dv8File := conformanceHDRFile()
dv8File.VideoTracks[0].DVProfile = 8
dv8File.VideoTracks[0].DVBLCompatID = 1
dv8File.VideoTracks[0].VideoRange = "DolbyVision"
dv8File.VideoTracks[0].VideoRangeType = "DOVIWithHDR10"
dv8Request := conformanceHDRRequest()
dv8Request.PlaybackAttemptID = "attempt-dv8-direct"
dv8Request.Capabilities.HDRDetails.DolbyVisionProfiles = []int{8}
dv8Request.ClientPlaybackContext.Output.HDRDetails.DolbyVisionProfiles = []int{8}
planner = append(planner, makePlannerScenario("dolby_vision_8_exact_direct", "hdr_dv_matrix", dv8Request, dv8File, nil, settings, registry))
dv7File := conformanceHDRFile()
dv7File.VideoTracks[0].DVProfile = 7
dv7File.VideoTracks[0].DVBLCompatID = 6
dv7File.VideoTracks[0].VideoRange = "DolbyVision"
dv7File.VideoTracks[0].VideoRangeType = "DOVIWithEL"
dv7Request := conformanceHDRRequest()
dv7Request.PlaybackAttemptID = "attempt-dv7-hdr10"
dv7Registry := playback.NewTransformationRegistryV3([]playback.TransformationSpecV3{{Name: playback.TransformationServerDV7HDR10V3, RecipeVersion: "1", Available: true}})
planner = append(planner, makePlannerScenario("dolby_vision_7_hdr10_fallback", "hdr_dv_matrix", dv7Request, dv7File, nil, settings, dv7Registry))
audioAdaptFile := conformanceHDRFile()
audioAdaptFile.CodecAudio = codecTrueHD
audioAdaptFile.AudioChannels = 8
audioAdaptFile.AudioTracks[0] = models.AudioTrack{Codec: codecTrueHD, Channels: 8, Layout: audioLayout71}
audioAdaptRequest := conformanceHDRRequest()
audioAdaptRequest.PlaybackAttemptID = "attempt-truehd-aac"
planner = append(planner, makePlannerScenario("truehd_audio_conversion", "audio_matrix", audioAdaptRequest, audioAdaptFile, nil, settings, registry))
audioPassthroughFile := conformanceHDRFile()
audioPassthroughFile.CodecAudio = codecTrueHD
audioPassthroughFile.AudioChannels = 8
audioPassthroughFile.AudioTracks[0] = models.AudioTrack{Codec: codecTrueHD, Channels: 8, Layout: audioLayout71}
audioPassthroughRequest := conformanceHDRRequest()
audioPassthroughRequest.PlaybackAttemptID = "attempt-truehd-passthrough"
audioPassthroughRequest.ClientFeatures = append(audioPassthroughRequest.ClientFeatures, playback.FeatureLayoutPassthrough)
audioPassthroughRequest.Capabilities.CodecsAudio = []string{codecTrueHD}
audioPassthroughRequest.Capabilities.AudioPassthrough = &playback.AudioPassthroughV3{
PassthroughCodecs: []string{codecTrueHD}, MaxChannels: 8,
Entries: []playback.AudioPassthroughEntryV3{{Codec: codecTrueHD, ChannelCounts: []int{8}, Layouts: []string{audioLayout71}}},
}
originalDelivery := audioPassthroughRequest.ClientPlaybackContext.Deliveries[playback.DeliveryClassOriginalHTTPV3]
originalDelivery.AudioPassthroughCodecs = []string{codecTrueHD}
audioPassthroughRequest.ClientPlaybackContext.Deliveries[playback.DeliveryClassOriginalHTTPV3] = originalDelivery
planner = append(planner, makePlannerScenario("truehd_exact_layout_passthrough", "audio_matrix", audioPassthroughRequest, audioPassthroughFile, nil, settings, registry))
pgsFile := conformanceHDRFile()
pgsFile.SubtitleTracks = []models.SubtitleTrack{{Index: 4, Language: "jpn", Codec: "hdmv_pgs_subtitle", Title: "Japanese"}}
pgsRequest := conformanceHDRRequest()
pgsRequest.PlaybackAttemptID = "attempt-pgs-sidecar"
pgsIndex := 0
pgsRequest.SubtitleTrackIndex = &pgsIndex
pgsRequest.SubtitleTrackID = playback.TrackIDV3(pgsFile.ID, "subtitle", pgsIndex)
for _, deliveryClass := range []string{playback.DeliveryClassOriginalHTTPV3, playback.DeliveryClassProgressiveV3, playback.DeliveryClassHLSV3} {
delivery := pgsRequest.ClientPlaybackContext.Deliveries[deliveryClass]
delivery.Subtitles.EmbeddedBitmap = true
pgsRequest.ClientPlaybackContext.Deliveries[deliveryClass] = delivery
}
planner = append(planner, makePlannerScenario("embedded_pgs_sidecar", "subtitle_matrix", pgsRequest, pgsFile, nil, settings, registry))
assFile := conformanceHDRFile()
assFile.SubtitleTracks = []models.SubtitleTrack{{Index: 4, Language: languageEnglish, Codec: "ass", Title: "English Signs"}}
assRequest := conformanceHDRRequest()
assRequest.PlaybackAttemptID = "attempt-ass-authored"
assRequest.SubtitleFidelityPreference = playback.SubtitleFidelityPreserveV3
assIndex := 0
assRequest.SubtitleTrackIndex = &assIndex
assRequest.SubtitleTrackID = playback.TrackIDV3(assFile.ID, "subtitle", assIndex)
for _, deliveryClass := range []string{playback.DeliveryClassOriginalHTTPV3, playback.DeliveryClassProgressiveV3, playback.DeliveryClassHLSV3} {
delivery := assRequest.ClientPlaybackContext.Deliveries[deliveryClass]
delivery.Subtitles.EmbeddedText = true
delivery.Subtitles.ASSStyling = true
delivery.Subtitles.FontAttachments = true
assRequest.ClientPlaybackContext.Deliveries[deliveryClass] = delivery
}
planner = append(planner, makePlannerScenario("embedded_ass_authored_render", "subtitle_matrix", assRequest, assFile, nil, settings, registry))
dvdFile := conformanceVideoFile()
dvdFile.SubtitleTracks = []models.SubtitleTrack{{Index: 4, Language: languageEnglish, Codec: "dvd_subtitle", Title: "English"}}
dvdRequest := conformanceStartRequest()
dvdRequest.PlaybackAttemptID = "attempt-dvd-burn-in"
dvdIndex := 0
dvdRequest.SubtitleTrackIndex = &dvdIndex
dvdRequest.SubtitleTrackID = playback.TrackIDV3(dvdFile.ID, "subtitle", dvdIndex)
planner = append(planner, makePlannerScenario("embedded_dvd_burn_in", "subtitle_matrix", dvdRequest, dvdFile, nil, settings, registry))
qualityRequest := fallbackRequest
qualityRequest.PlaybackAttemptID = "attempt-available-qualities"
qualityRequest.QualityPreference = qualityOriginal
planner = append(planner, makePlannerScenario("available_qualities", "available_qualities", qualityRequest, fallbackFile, nil, settings, registry))
decision := goldenDecisionResponse()
plan := decision.PlaybackPlan
if plan == nil {
fail("golden decision has no plan")
}
trackIndex := 1
trackChange := goldenReplanRequest()
trackChange.Operation = playback.ReplanOperationTrackChangeV3
trackChange.ReplanRequestID = "replan-track-change-0001"
trackChange.Failure = playback.FailureV3{}
trackChange.SelectedTracks.Audio = &playback.TrackIdentityV3{ID: "", Index: &trackIndex}
qualityChange := goldenReplanRequest()
qualityChange.Operation = playback.ReplanOperationQualityChangeV3
qualityChange.ReplanRequestID = "replan-quality-change-0001"
qualityChange.Failure = playback.FailureV3{}
qualityChange.QualityPreference = resolutionHD
seekReanchor := goldenReplanRequest()
seekReanchor.Operation = playback.ReplanOperationSeekReanchorV3
seekReanchor.ReplanRequestID = "replan-seek-reanchor-0001"
seekReanchor.Failure = playback.FailureV3{}
seekReanchor.PositionSeconds = 321.25
trackChange.PositionSeconds = 321.25
qualityChange.PositionSeconds = 321.25
trackDuplicate := trackChange
trackDuplicate.ReplanRequestID = "replan-track-duplicate-0001"
qualityDuplicate := qualityChange
qualityDuplicate.ReplanRequestID = "replan-quality-duplicate-0001"
trackConcurrent := trackChange
trackConcurrent.ReplanRequestID = "replan-track-concurrent-0001"
qualityConcurrent := qualityChange
qualityConcurrent.ReplanRequestID = "replan-quality-concurrent-0001"
trackMidSeek := trackChange
trackMidSeek.ReplanRequestID = "replan-track-mid-seek-0001"
qualityMidSeek := qualityChange
qualityMidSeek.ReplanRequestID = "replan-quality-mid-seek-0001"
replans := []playback.ReplanScenarioV3{
{Name: "track_change", Category: "track_change_replan", Request: trackChange, Expected: playback.ReplanExpectationV3{HTTPStatus: http.StatusOK, PreserveUnmodifiedTracks: true}},
{Name: "quality_change", Category: "quality_change_replan", Request: qualityChange, Expected: playback.ReplanExpectationV3{HTTPStatus: http.StatusOK, SelectedQuality: resolutionHD}},
{Name: "track_change_idempotent_duplicate", Category: "idempotent_replan", Request: trackDuplicate, Expected: playback.ReplanExpectationV3{SameRequestAndBodyStatus: http.StatusOK, ResponseReplayedVerbatim: true, ChangedBodyStatus: http.StatusConflict, ChangedBodyError: "idempotency_key_reused"}},
{Name: "quality_change_idempotent_duplicate", Category: "idempotent_replan", Request: qualityDuplicate, Expected: playback.ReplanExpectationV3{SameRequestAndBodyStatus: http.StatusOK, ResponseReplayedVerbatim: true, ChangedBodyStatus: http.StatusConflict, ChangedBodyError: "idempotency_key_reused"}},
{Name: "track_change_concurrent_duplicate", Category: "concurrent_replan", Request: trackConcurrent, Expected: playback.ReplanExpectationV3{WhileFirstLeaseActiveStatus: http.StatusConflict, ConcurrentError: "replan_in_progress", AfterCompletionStatus: http.StatusOK, ResponseReplayedVerbatim: true}},
{Name: "quality_change_concurrent_duplicate", Category: "concurrent_replan", Request: qualityConcurrent, Expected: playback.ReplanExpectationV3{WhileFirstLeaseActiveStatus: http.StatusConflict, ConcurrentError: "replan_in_progress", AfterCompletionStatus: http.StatusOK, ResponseReplayedVerbatim: true}},
{Name: "track_change_mid_seek", Category: categoryMidSeek, Request: trackMidSeek, Expected: playback.ReplanExpectationV3{HTTPStatus: http.StatusOK, PositionSeconds: trackMidSeek.PositionSeconds, PositionPreserved: true}},
{Name: "quality_change_mid_seek", Category: categoryMidSeek, Request: qualityMidSeek, Expected: playback.ReplanExpectationV3{HTTPStatus: http.StatusOK, PositionSeconds: qualityMidSeek.PositionSeconds, PositionPreserved: true}},
{Name: "mid_seek_reanchor", Category: categoryMidSeek, Request: seekReanchor, Expected: playback.ReplanExpectationV3{HTTPStatus: http.StatusOK, PositionSeconds: seekReanchor.PositionSeconds, PositionPreserved: true}},
}
outputA := playback.PlanAttemptKeyV3(*plan, "output-a", nil)
outputB := playback.PlanAttemptKeyV3(*plan, "output-b", nil)
if outputA == outputB {
fail("output context must change the opaque plan attempt key")
}
recovery := goldenReplanRequest()
recovery.ReplanRequestID = "replan-failure-matrix-0001"
recovery.PositionSeconds = 321.25
subtitleIndex := 2
recovery.SelectedTracks.Subtitle = &playback.TrackIdentityV3{
ID: playback.TrackIDV3(goldenMediaFileID, "subtitle", subtitleIndex),
Index: &subtitleIndex,
}
restartStart := goldenStartRequest()
restartStart.PlaybackAttemptID = "attempt-restart-terminal"
restartTerminal := playback.NewTerminalResponseV3(
"transcode_start_failed",
"The playback transport did not become ready in time.",
true,
)
capacityStart := goldenStartRequest()
capacityStart.PlaybackAttemptID = "attempt-capacity-unavailable"
capacityAvailable := false
zeroCapacityDelta := 0
limitEvent := goldenRouteEvent()
limitEvent.PlaybackAttemptID = "attempt-route-limit"
limitEvent.Diagnostics = make(map[string]string, 33)
for index := range 33 {
limitEvent.Diagnostics[fmt.Sprintf("diagnostic_%02d", index)] = "value"
}
draftProtocolVersion := playback.ProtocolV3
protocol := []playback.ProtocolScenarioV3{
{Name: "legacy_start_requires_upgrade", Category: "legacy_426", Input: playback.ProtocolScenarioInputV3{LegacyStartBody: &playback.LegacyStartBodyV3{FileID: goldenMediaFileID}}, Expected: playback.ProtocolExpectationV3{HTTPStatus: http.StatusUpgradeRequired, Error: "client_upgrade_required"}},
{Name: "draft_v3_start_requires_upgrade", Category: "draft_v3_426", Input: playback.ProtocolScenarioInputV3{LegacyStartBody: &playback.LegacyStartBodyV3{ProtocolVersion: &draftProtocolVersion, FileID: goldenMediaFileID, ClientCapabilities: &playback.DraftClientCapabilitiesV3{CodecsVideo: []string{codecH264}}}}, Expected: playback.ProtocolExpectationV3{HTTPStatus: http.StatusUpgradeRequired, Error: "client_upgrade_required"}},
{Name: "output_context_change_invalidates_attempt", Category: "output_context_invalidation", Input: playback.ProtocolScenarioInputV3{PlanID: plan.PlanID, FirstOutputContextID: "output-a", SecondOutputContextID: "output-b", FirstPlanAttemptKey: outputA, SecondPlanAttemptKey: outputB}, Expected: playback.ProtocolExpectationV3{PlanIDUnchanged: true, PlanAttemptKeyChanged: true}},
{Name: "opaque_attempt_key_loop", Category: "attempt_key_echo_and_loop", Input: playback.ProtocolScenarioInputV3{ServerPlanAttemptKey: plan.PlanAttemptKey, ReplanEcho: plan.PlanAttemptKey, AttemptedPlanKeys: []string{plan.PlanAttemptKey}}, Expected: playback.ProtocolExpectationV3{Action: "reject_already_attempted_plan"}},
{Name: "failure_recovery_preserves_intent", Category: "recovery_matrix", Input: playback.ProtocolScenarioInputV3{ReplanRequest: &recovery}, Expected: playback.ProtocolExpectationV3{HTTPStatus: http.StatusOK, SelectionPreserved: true, PositionPreserved: true, Action: "preserve_selected_tracks_and_position"}},
{Name: "restart_replays_terminal_attempt", Category: "restart_matrix", Input: playback.ProtocolScenarioInputV3{StartRequest: &restartStart, PersistedDecision: &restartTerminal, Restarted: true}, Expected: playback.ProtocolExpectationV3{HTTPStatus: http.StatusCreated, Outcome: playback.OutcomeAdaptationUnavailableV3, TerminalReason: "transcode_start_failed", ResponseReplayedVerbatim: true, CapacityDelta: &zeroCapacityDelta}},
{Name: "capacity_unavailable_cleans_up", Category: "capacity_matrix", Input: playback.ProtocolScenarioInputV3{StartRequest: &capacityStart, CapacityAvailable: &capacityAvailable}, Expected: playback.ProtocolExpectationV3{HTTPStatus: http.StatusCreated, Outcome: playback.OutcomeAdaptationUnavailableV3, TerminalReason: "capacity_unavailable", CapacityDelta: &zeroCapacityDelta, CleanupComplete: true}},
{Name: "route_event_diagnostic_limit", Category: "route_event_limits", Input: playback.ProtocolScenarioInputV3{RouteEvent: &limitEvent}, Expected: playback.ProtocolExpectationV3{HTTPStatus: http.StatusBadRequest, Error: "bad_request", Action: "reject_without_persisting"}},
}
return playback.ConformanceMatrixV3{SchemaVersion: 1, Planner: planner, Replans: replans, Protocol: protocol}
}
func makePlannerScenario(name, category string, request playback.StartRequestV3, file *models.MediaFile, attempted []string, settings playback.PlannerSettingsV3, registry *playback.TransformationRegistryV3) playback.PlannerScenarioV3 {
result := playback.PlanPlaybackV3(playback.PlannerInputV3{
Request: request, RequestedFile: file, EffectiveFile: file, AudioTrackIndex: 0,
Settings: settings, Registry: registry, AttemptedKeys: attempted,
})
expected := playback.PlannerExpectationV3{Outcome: playback.OutcomeAdaptationUnavailableV3}
if result.Plan != nil {
selectedTracks := result.Plan.SelectedTracks
subtitle := result.Plan.Subtitle
claims := result.Plan.Claims
expected = playback.PlannerExpectationV3{
Outcome: playback.OutcomePlayableV3,
Delivery: result.Plan.Delivery,
DecisionReason: result.Plan.DecisionReason,
PlanID: result.Plan.PlanID,
PlanAttemptKey: result.Plan.PlanAttemptKey,
SelectedTracks: &selectedTracks,
Subtitle: &subtitle,
Claims: &claims,
Transformations: append([]playback.TransformationV3(nil), result.Plan.Transformations...),
AvailableQualities: result.Plan.AvailableQualities,
}
} else if result.Terminal != nil {
expected.TerminalReason = result.Terminal.Reason
}
return playback.PlannerScenarioV3{
Name: name, Category: category, Request: request,
Source: playback.SourceDescriptorFromFileV3(file, 0),
AttemptedKeys: append([]string(nil), attempted...), Expected: expected,
}
}
func conformanceStartRequest() playback.StartRequestV3 {
request := goldenStartRequest()
request.QualityPreference = qualityOriginal
request.Capabilities = playback.ClientCodecCapabilitiesV3{
VideoEvidence: playback.EvidenceExactV3, AudioEvidence: playback.EvidenceExactV3,
CodecsVideo: []string{codecHEVC}, CodecsVideoHardware: []string{codecHEVC}, CodecsAudio: []string{codecAAC}, Containers: []string{containerMKV}, MaxResolution: resolutionFHD,
VideoDecode: []playback.VideoDecodeCapabilityV3{{Codec: codecHEVC, Profiles: []string{"main 10"}, Levels: []int{41}, BitDepths: []int{8}, MaxWidth: 1920, MaxHeight: 1080, MaxFrameRate: 60, MaxBitrateKbps: 20_000, Hardware: true}},
}
request.ClientPlaybackContext = playback.ClientPlaybackContextV3{
ProtocolVersion: playback.ProtocolV3, FormFactor: "tv", AppVersion: "3.0-test",
Device: playback.DeviceContextV3{Platform: "fixture"}, Output: playback.OutputContextV3{OutputContextID: "output-a"},
Deliveries: map[string]playback.DeliveryCapabilityV3{
playback.DeliveryClassOriginalHTTPV3: conformanceDelivery([]string{containerMKV, containerMP4}),
playback.DeliveryClassProgressiveV3: conformanceDelivery([]string{containerMP4}),
playback.DeliveryClassHLSV3: conformanceDelivery([]string{containerHLS}),
},
}
return request
}
func conformanceDelivery(containers []string) playback.DeliveryCapabilityV3 {
return playback.DeliveryCapabilityV3{
Enabled: true,
SupportedOnDevice: true,
Containers: append([]string(nil), containers...),
VideoCodecs: []string{codecHEVC, codecH264},
AudioDecodeCodecs: []string{codecAAC},
AudioPassthroughCodecs: []string{},
Features: []string{},
ValidatedClaims: []string{},
Transformations: []playback.TransformationV3{},
}
}
func conformanceVideoFile() *models.MediaFile {
return &models.MediaFile{ID: goldenMediaFileID, Container: containerMKV, CodecVideo: codecHEVC, CodecAudio: codecAAC, Resolution: resolutionFHD, Bitrate: 8_000, AudioChannels: 2, Duration: 7_200, VideoTracks: []models.VideoTrack{{Codec: codecHEVC, Profile: "Main", Level: 41, Width: 1920, Height: 1080, FrameRate: filmFrameRate, Bitrate: 8_000, BitDepth: 8, VideoRange: videoRangeSDR, VideoRangeType: videoRangeSDR}}, AudioTracks: []models.AudioTrack{{Codec: codecAAC, Channels: 2, Layout: audioLayoutStereo}}}
}
func conformanceHDRFile() *models.MediaFile {
return &models.MediaFile{
ID: goldenMediaFileID,
Container: containerMKV,
CodecVideo: codecHEVC,
CodecAudio: codecAAC,
Resolution: "2160p",
Bitrate: 60_000,
AudioChannels: 2,
Duration: 7_200,
VideoTracks: []models.VideoTrack{{
Codec: codecHEVC, Profile: "Main 10", Level: 153,
Width: 3840, Height: 2160, FrameRate: filmFrameRate, Bitrate: 60_000, BitDepth: 10,
VideoRange: "HDR", VideoRangeType: "HDR10", ColorRange: "tv",
}},
AudioTracks: []models.AudioTrack{{Codec: codecAAC, Channels: 2, Layout: audioLayoutStereo}},
}
}
func conformanceHDRRequest() playback.StartRequestV3 {
request := conformanceStartRequest()
request.Capabilities.CodecsVideo = []string{codecHEVC}
request.Capabilities.CodecsVideoHardware = []string{codecHEVC}
request.Capabilities.CodecsAudio = []string{codecAAC}
request.Capabilities.Containers = []string{containerMKV}
request.Capabilities.MaxResolution = "2160p"
request.Capabilities.HDR = true
request.Capabilities.HDRDetails = &playback.HDRCapabilitiesV3{HDR10: true, DolbyVisionProfiles: []int{}}
request.Capabilities.VideoDecode = []playback.VideoDecodeCapabilityV3{{
Codec: codecHEVC, Profiles: []string{"main 10"}, Levels: []int{153}, BitDepths: []int{10},
MaxWidth: 3840, MaxHeight: 2160, MaxFrameRate: 60, MaxBitrateKbps: 80_000, Hardware: true,
}}
request.ClientPlaybackContext.Output.HDRDetails = &playback.HDRCapabilitiesV3{HDR10: true, DolbyVisionProfiles: []int{}}
return request
}
func conformanceFallbackFile() *models.MediaFile {
return &models.MediaFile{ID: goldenMediaFileID, FilePath: "/media/movie.mp4", Container: containerMP4, CodecVideo: codecH264, CodecAudio: codecAAC, Resolution: resolutionFHD, Bitrate: 8_000, AudioChannels: 2, Duration: 7_200, VideoTracks: []models.VideoTrack{{Codec: codecH264, Profile: profileHigh, Level: 41, Width: 1920, Height: 1080, FrameRate: filmFrameRate, Bitrate: 8_000, BitDepth: 8, VideoRange: videoRangeSDR, VideoRangeType: videoRangeSDR}}, AudioTracks: []models.AudioTrack{{Codec: codecAAC, Channels: 2, Layout: audioLayoutStereo}}}
}
func conformanceRegistry() *playback.TransformationRegistryV3 {
return playback.NewTransformationRegistryV3([]playback.TransformationSpecV3{
{Name: playback.TransformationAudioToAACV3, RecipeVersion: "1", Available: true},
{Name: playback.TransformationVideoToH264V3, RecipeVersion: "1", Available: true},
{Name: playback.TransformationServerDV7HDR10V3, RecipeVersion: "1", Available: true},
})
}
-628
View File
@@ -1,628 +0,0 @@
// Command settingsgen emits typed bindings for the settings contract.
//
// One generator for every language rather than one per repo: the whole point of
// the contract is that four codebases agree on keys, types, scopes and
// defaults, and four independently-written generators would be four chances to
// disagree. Each client repo vendors the manifest and runs this to regenerate.
//
// Usage:
//
// settingsgen -lang go -out internal/settingskeys/keys.go
// settingsgen -lang ts -out web/src/lib/settingsContract.ts
// settingsgen -lang kotlin -out <path> -package org.siloserver.silo.model.settings
// settingsgen -lang swift -out <path>
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"os"
"sort"
"strings"
"github.com/Silo-Server/silo-server/internal/settingscontract"
)
func main() {
lang := flag.String("lang", "", "go, ts, kotlin or swift")
out := flag.String("out", "", "file to write (default stdout)")
pkg := flag.String("package", "", "package or namespace for the generated code")
flag.Parse()
contract, err := settingscontract.Load()
if err != nil {
fail("loading contract: %v", err)
}
var body []byte
switch *lang {
case "go":
body, err = generateGo(contract, defaultString(*pkg, "settingskeys"))
case "ts":
body, err = generateTypeScript(contract)
case "kotlin":
body, err = generateKotlin(contract,
defaultString(*pkg, "org.siloserver.silo.model.settings"))
case "swift":
body, err = generateSwift(contract)
default:
fail("unknown -lang %q: want go, ts, kotlin or swift", *lang)
}
if err != nil {
fail("generating %s: %v", *lang, err)
}
if *out == "" {
_, _ = os.Stdout.Write(body)
return
}
if err := os.WriteFile(*out, body, 0o644); err != nil { //nolint:gosec // generated source
fail("writing %s: %v", *out, err)
}
}
func fail(format string, args ...any) {
fmt.Fprintf(os.Stderr, "settingsgen: "+format+"\n", args...)
os.Exit(1)
}
func defaultString(value, fallback string) string {
if strings.TrimSpace(value) == "" {
return fallback
}
return value
}
// remoteAndLocal returns every definition, sorted by key so the output is
// stable: a generator whose output depends on manifest authoring order would
// produce spurious diffs on every unrelated manifest edit.
func sortedDefinitions(contract *settingscontract.Manifest) []*settingscontract.Definition {
defs := make([]*settingscontract.Definition, 0, len(contract.Definitions))
for i := range contract.Definitions {
defs = append(defs, &contract.Definitions[i])
}
sort.Slice(defs, func(i, j int) bool { return defs[i].Key < defs[j].Key })
return defs
}
// identifierFor turns a dotted key into a language identifier:
// playback.subtitle_language becomes PlaybackSubtitleLanguage.
func identifierFor(key string) string {
var out strings.Builder
for _, part := range strings.FieldsFunc(key, func(r rune) bool {
return r == '.' || r == '_' || r == '-'
}) {
out.WriteString(strings.ToUpper(part[:1]))
out.WriteString(part[1:])
}
return out.String()
}
// screamingCase turns a dotted key into PLAYBACK_SUBTITLE_LANGUAGE.
func screamingCase(key string) string {
replaced := strings.NewReplacer(".", "_", "-", "_").Replace(key)
return strings.ToUpper(replaced)
}
const generatedHeader = `Code generated by cmd/settingsgen from contracts/settings/v1/manifest.json. DO NOT EDIT.
Regenerate with: make settings-bindings
Every key, type, scope and default here comes from the manifest, so a client
cannot drift from the server's contract by editing a constant. Adding a setting
is a manifest change plus a regeneration, never a hand-written key.`
func generateGo(contract *settingscontract.Manifest, pkg string) ([]byte, error) {
var out bytes.Buffer
for _, line := range strings.Split(generatedHeader, "\n") {
out.WriteString(strings.TrimRight("// "+line, " ") + "\n")
}
fmt.Fprintf(&out, "\npackage %s\n\n", pkg)
fmt.Fprintf(&out, "// Revision is the manifest revision these bindings were generated from.\nconst Revision = %d\n\n",
contract.Revision)
out.WriteString("// Setting keys, one constant per definition.\nconst (\n")
for _, def := range sortedDefinitions(contract) {
fmt.Fprintf(&out, "\t// %s\n", def.Label)
fmt.Fprintf(&out, "\t%s = %q\n", identifierFor(def.Key), def.Key)
}
out.WriteString(")\n\n")
out.WriteString("// Remote lists every key the server stores.\nvar Remote = []string{\n")
for _, def := range sortedDefinitions(contract) {
if def.IsRemote() {
fmt.Fprintf(&out, "\t%s,\n", identifierFor(def.Key))
}
}
out.WriteString("}\n\n")
out.WriteString("// ClientLocal lists keys the contract defines but the server never stores.\n")
out.WriteString("var ClientLocal = []string{\n")
for _, def := range sortedDefinitions(contract) {
if !def.IsRemote() {
fmt.Fprintf(&out, "\t%s,\n", identifierFor(def.Key))
}
}
out.WriteString("}\n")
return out.Bytes(), nil
}
func generateTypeScript(contract *settingscontract.Manifest) ([]byte, error) {
var out bytes.Buffer
out.WriteString("/**\n")
for _, line := range strings.Split(generatedHeader, "\n") {
out.WriteString(strings.TrimRight(" * "+line, " ") + "\n")
}
out.WriteString(" */\n\n")
fmt.Fprintf(&out, "export const SETTINGS_API_VERSION = %d;\n", contract.APIVersion)
fmt.Fprintf(&out, "export const SETTINGS_REVISION = %d;\n\n", contract.Revision)
out.WriteString("export interface SettingSuggestedOption {\n")
out.WriteString(" value: string;\n")
out.WriteString(" introducedIn: number;\n")
out.WriteString("}\n\n")
out.WriteString("export interface SettingOptionSet {\n")
out.WriteString(" type: string;\n")
out.WriteString(" options: readonly SettingSuggestedOption[];\n")
out.WriteString("}\n\n")
out.WriteString("export const SETTING_OPTION_SETS = {\n")
for _, name := range sortedOptionSetNames(contract) {
optionSet := contract.OptionSets[name]
fmt.Fprintf(&out, " %s: {\n", name)
fmt.Fprintf(&out, " type: %q,\n", optionSet.Type)
out.WriteString(" options: [\n")
for _, option := range optionSet.Options {
fmt.Fprintf(&out, " { value: %q, introducedIn: %d },\n",
option.Value, option.IntroducedIn)
}
out.WriteString(" ],\n")
out.WriteString(" },\n")
}
out.WriteString("} as const satisfies Record<string, SettingOptionSet>;\n\n")
out.WriteString("export type SettingOptionSetId = keyof typeof SETTING_OPTION_SETS;\n\n")
out.WriteString("export const SETTING_KEYS = {\n")
for _, def := range sortedDefinitions(contract) {
fmt.Fprintf(&out, " /** %s */\n", def.Label)
fmt.Fprintf(&out, " %s: %q,\n", screamingCase(def.Key), def.Key)
}
out.WriteString("} as const;\n\n")
out.WriteString("export type SettingKey = (typeof SETTING_KEYS)[keyof typeof SETTING_KEYS];\n\n")
// The full definition table, so the UI can render controls from the
// contract rather than a hand-kept parallel manifest.
out.WriteString("export interface SettingDefinition {\n")
out.WriteString(" key: SettingKey;\n")
out.WriteString(" type: string;\n")
out.WriteString(" nullable: boolean;\n")
out.WriteString(" persistence: \"remote\" | \"client_local\";\n")
out.WriteString(" /** The manifest revision this definition first appeared in. A client\n")
out.WriteString(" * pinned to a newer contract than the server's advertised revision must\n")
out.WriteString(" * hide definitions, scopes, enum members and widened bounds introduced\n")
out.WriteString(" * after that revision — the server would reject them. */\n")
out.WriteString(" introducedIn: number;\n")
out.WriteString(" scopes: readonly string[];\n")
out.WriteString(" /** Revision each scope became writable at, aligned with scopes. */\n")
out.WriteString(" scopeIntroducedIn: readonly number[];\n")
out.WriteString(" resolutionOrder: readonly string[];\n")
out.WriteString(" defaultValue: unknown;\n")
out.WriteString(" label: string;\n")
out.WriteString(" description: string;\n")
out.WriteString(" category: string;\n")
out.WriteString(" control?: string;\n")
out.WriteString(" unit?: string;\n")
out.WriteString(" /** Advisory: platforms this setting is expected to matter on. Absent\n")
out.WriteString(" * means everywhere. A client hides settings for platforms it is not,\n")
out.WriteString(" * rather than disabling them without explanation. */\n")
out.WriteString(" platforms?: readonly string[];\n")
out.WriteString(" suggestedOptions?: SettingOptionSetId;\n")
out.WriteString(" unsetLabel?: string;\n")
out.WriteString(" values?: readonly { value: unknown; label: string; introducedIn: number }[];\n")
out.WriteString(" /** Present on enums whose members are ranked, so a ceiling or floor has a direction. */\n")
out.WriteString(" ordered?: boolean;\n")
out.WriteString(" minimum?: number;\n")
out.WriteString(" maximum?: number;\n")
out.WriteString(" /** Bound history, oldest first, when a bound was widened after revision 1;\n")
out.WriteString(" * a client filtering to an older server revision applies the newest entry\n")
out.WriteString(" * whose introducedIn does not exceed it. */\n")
out.WriteString(" minimumHistory?: readonly { value: number; introducedIn: number }[];\n")
out.WriteString(" maximumHistory?: readonly { value: number; introducedIn: number }[];\n")
out.WriteString(" step?: number;\n")
out.WriteString(" /** The policy input that narrows this setting, when the manifest binds one. */\n")
out.WriteString(" constrainedBy?: {\n")
out.WriteString(" policyInput: string;\n")
out.WriteString(" constraint: \"ceiling\" | \"floor\" | \"allowlist\" | \"locked\";\n")
out.WriteString(" };\n")
out.WriteString("}\n\n")
out.WriteString("export const SETTING_DEFINITIONS: Record<SettingKey, SettingDefinition> = {\n")
for _, def := range sortedDefinitions(contract) {
fmt.Fprintf(&out, " %q: {\n", def.Key)
fmt.Fprintf(&out, " key: %q,\n", def.Key)
fmt.Fprintf(&out, " type: %q,\n", def.ValueSchema.Type)
fmt.Fprintf(&out, " nullable: %t,\n", def.ValueSchema.Nullable)
fmt.Fprintf(&out, " persistence: %q,\n", def.Persistence)
fmt.Fprintf(&out, " introducedIn: %d,\n", def.IntroducedIn)
fmt.Fprintf(&out, " scopes: [%s],\n", quotedScopes(def))
fmt.Fprintf(&out, " scopeIntroducedIn: [%s],\n", scopeRevisions(def))
fmt.Fprintf(&out, " resolutionOrder: [%s],\n", quotedResolution(def))
fmt.Fprintf(&out, " defaultValue: %s,\n", defaultLiteral(def))
fmt.Fprintf(&out, " label: %s,\n", jsString(def.Label))
fmt.Fprintf(&out, " description: %s,\n", jsString(def.Description))
fmt.Fprintf(&out, " category: %q,\n", def.Category)
if def.Control != "" {
fmt.Fprintf(&out, " control: %q,\n", def.Control)
}
if def.Unit != "" {
fmt.Fprintf(&out, " unit: %q,\n", def.Unit)
}
if len(def.Platforms) > 0 {
fmt.Fprintf(&out, " platforms: [%s],\n", quotedStrings(def.Platforms))
}
if def.SuggestedOptions != "" {
fmt.Fprintf(&out, " suggestedOptions: %q,\n", def.SuggestedOptions)
}
if def.UnsetLabel != "" {
fmt.Fprintf(&out, " unsetLabel: %s,\n", jsString(def.UnsetLabel))
}
if len(def.ValueSchema.Values) > 0 {
out.WriteString(" values: [\n")
for _, member := range def.ValueSchema.Values {
encoded, err := json.Marshal(member.Value)
if err != nil {
return nil, err
}
fmt.Fprintf(&out, " { value: %s, label: %s, introducedIn: %d },\n",
encoded, jsString(member.Label), memberRevision(def, member))
}
out.WriteString(" ],\n")
}
if def.ValueSchema.Ordered {
out.WriteString(" ordered: true,\n")
}
if minimum, ok := def.ValueSchema.Minimum.Current(); ok {
fmt.Fprintf(&out, " minimum: %s,\n", trimFloat(minimum))
if history := boundHistory(def, def.ValueSchema.Minimum); history != "" {
fmt.Fprintf(&out, " minimumHistory: [%s],\n", history)
}
}
if maximum, ok := def.ValueSchema.Maximum.Current(); ok {
fmt.Fprintf(&out, " maximum: %s,\n", trimFloat(maximum))
if history := boundHistory(def, def.ValueSchema.Maximum); history != "" {
fmt.Fprintf(&out, " maximumHistory: [%s],\n", history)
}
}
if def.ValueSchema.Step != nil {
fmt.Fprintf(&out, " step: %s,\n", trimFloat(*def.ValueSchema.Step))
}
if def.ConstrainedBy != nil {
fmt.Fprintf(&out, " constrainedBy: { policyInput: %q, constraint: %q },\n",
def.ConstrainedBy.PolicyInput, def.ConstrainedBy.Constraint)
}
out.WriteString(" },\n")
}
out.WriteString("};\n")
return out.Bytes(), nil
}
func generateKotlin(contract *settingscontract.Manifest, pkg string) ([]byte, error) {
var out bytes.Buffer
for _, line := range strings.Split(generatedHeader, "\n") {
out.WriteString(strings.TrimRight("// "+line, " ") + "\n")
}
fmt.Fprintf(&out, "\npackage %s\n\n", pkg)
out.WriteString("data class SettingSuggestedOption(\n")
out.WriteString(" val value: String,\n")
out.WriteString(" val introducedIn: Int,\n")
out.WriteString(")\n\n")
out.WriteString("data class SettingOptionSet(\n")
out.WriteString(" val type: String,\n")
out.WriteString(" val options: List<SettingSuggestedOption>,\n")
out.WriteString(")\n\n")
out.WriteString("data class SettingPresentation(\n")
out.WriteString(" val suggestedOptions: String? = null,\n")
out.WriteString(" val unsetLabel: String? = null,\n")
out.WriteString(")\n\n")
out.WriteString("object SettingKeys {\n")
fmt.Fprintf(&out, " const val REVISION = %d\n\n", contract.Revision)
for _, def := range sortedDefinitions(contract) {
fmt.Fprintf(&out, " /** %s */\n", def.Label)
fmt.Fprintf(&out, " const val %s = %q\n", screamingCase(def.Key), def.Key)
}
// The allowlist Android maintained by hand, generated instead. The whole
// class of "wrote a local key to the server" bug is a manifest question now.
out.WriteString("\n /** Every key the server stores. Safe to flush. */\n")
out.WriteString(" val REMOTE: List<String> = listOf(\n")
for _, def := range sortedDefinitions(contract) {
if def.IsRemote() {
fmt.Fprintf(&out, " %s,\n", screamingCase(def.Key))
}
}
out.WriteString(" )\n\n")
out.WriteString(" /** Contract-known keys that never leave the device. */\n")
out.WriteString(" val CLIENT_LOCAL: List<String> = listOf(\n")
for _, def := range sortedDefinitions(contract) {
if !def.IsRemote() {
fmt.Fprintf(&out, " %s,\n", screamingCase(def.Key))
}
}
out.WriteString(" )\n")
// Type classification, which Android kept as a second hand-maintained table
// that had to agree with the first.
for _, group := range []struct {
name string
types []settingscontract.ValueType
}{
{"BOOLEAN_KEYS", []settingscontract.ValueType{settingscontract.TypeBoolean}},
{"INT_KEYS", []settingscontract.ValueType{settingscontract.TypeInteger}},
{"DOUBLE_KEYS", []settingscontract.ValueType{settingscontract.TypeNumber}},
} {
// Remote only: these tables drive how a value read back from the
// server is parsed, and a client_local key never comes back from the
// server at all. Listing one would describe a wire format that has no
// wire.
fmt.Fprintf(&out, "\n val %s: Set<String> = setOf(\n", group.name)
for _, def := range sortedDefinitions(contract) {
if !def.IsRemote() {
continue
}
for _, want := range group.types {
if def.ValueSchema.Type == want {
fmt.Fprintf(&out, " %s,\n", screamingCase(def.Key))
}
}
}
out.WriteString(" )\n")
}
out.WriteString("}\n\n")
out.WriteString("object SettingPresentationMetadata {\n")
out.WriteString(" val OPTION_SETS: Map<String, SettingOptionSet> = mapOf(\n")
for _, name := range sortedOptionSetNames(contract) {
optionSet := contract.OptionSets[name]
fmt.Fprintf(&out, " %q to SettingOptionSet(\n", name)
fmt.Fprintf(&out, " type = %q,\n", optionSet.Type)
out.WriteString(" options = listOf(\n")
for _, option := range optionSet.Options {
fmt.Fprintf(&out, " SettingSuggestedOption(%q, %d),\n",
option.Value, option.IntroducedIn)
}
out.WriteString(" ),\n")
out.WriteString(" ),\n")
}
out.WriteString(" )\n\n")
out.WriteString(" val DEFINITIONS: Map<String, SettingPresentation> = mapOf(\n")
for _, def := range sortedDefinitions(contract) {
if def.SuggestedOptions == "" && def.UnsetLabel == "" {
continue
}
fmt.Fprintf(&out, " SettingKeys.%s to SettingPresentation(\n", screamingCase(def.Key))
if def.SuggestedOptions != "" {
fmt.Fprintf(&out, " suggestedOptions = %q,\n", def.SuggestedOptions)
}
if def.UnsetLabel != "" {
fmt.Fprintf(&out, " unsetLabel = %q,\n", def.UnsetLabel)
}
out.WriteString(" ),\n")
}
out.WriteString(" )\n\n")
out.WriteString(" fun suggestedValues(key: String, revision: Int = SettingKeys.REVISION): List<String> {\n")
out.WriteString(" val setId = DEFINITIONS[key]?.suggestedOptions ?: return emptyList()\n")
out.WriteString(" return OPTION_SETS[setId]?.options\n")
out.WriteString(" ?.filter { it.introducedIn <= revision }\n")
out.WriteString(" ?.map { it.value }\n")
out.WriteString(" .orEmpty()\n")
out.WriteString(" }\n")
out.WriteString("}\n")
return out.Bytes(), nil
}
func generateSwift(contract *settingscontract.Manifest) ([]byte, error) {
var out bytes.Buffer
for _, line := range strings.Split(generatedHeader, "\n") {
out.WriteString(strings.TrimRight("// "+line, " ") + "\n")
}
out.WriteString("\nimport Foundation\n\n")
out.WriteString("public struct SettingSuggestedOption: Hashable, Sendable {\n")
out.WriteString(" public let value: String\n")
out.WriteString(" public let introducedIn: Int\n")
out.WriteString("}\n\n")
out.WriteString("public struct SettingOptionSet: Hashable, Sendable {\n")
out.WriteString(" public let type: String\n")
out.WriteString(" public let options: [SettingSuggestedOption]\n")
out.WriteString("}\n\n")
out.WriteString("public struct SettingPresentation: Hashable, Sendable {\n")
out.WriteString(" public let suggestedOptions: String?\n")
out.WriteString(" public let unsetLabel: String?\n")
out.WriteString("}\n\n")
out.WriteString("/// Every setting the contract defines.\n")
out.WriteString("public enum SettingKey: String, CaseIterable, Sendable {\n")
for _, def := range sortedDefinitions(contract) {
fmt.Fprintf(&out, " /// %s\n", def.Label)
fmt.Fprintf(&out, " case %s = %q\n", lowerFirst(identifierFor(def.Key)), def.Key)
}
out.WriteString("}\n\n")
out.WriteString("public extension SettingKey {\n")
fmt.Fprintf(&out, " static let revision = %d\n\n", contract.Revision)
out.WriteString(" /// Keys the server stores. The rest never leave the device.\n")
out.WriteString(" static let remote: [SettingKey] = [\n")
for _, def := range sortedDefinitions(contract) {
if def.IsRemote() {
fmt.Fprintf(&out, " .%s,\n", lowerFirst(identifierFor(def.Key)))
}
}
out.WriteString(" ]\n\n")
out.WriteString(" static let clientLocal: [SettingKey] = [\n")
for _, def := range sortedDefinitions(contract) {
if !def.IsRemote() {
fmt.Fprintf(&out, " .%s,\n", lowerFirst(identifierFor(def.Key)))
}
}
out.WriteString(" ]\n")
out.WriteString("}\n\n")
out.WriteString("public enum SettingPresentationMetadata {\n")
out.WriteString(" public static let optionSets: [String: SettingOptionSet] = [\n")
for _, name := range sortedOptionSetNames(contract) {
optionSet := contract.OptionSets[name]
fmt.Fprintf(&out, " %q: SettingOptionSet(\n", name)
fmt.Fprintf(&out, " type: %q,\n", optionSet.Type)
out.WriteString(" options: [\n")
for _, option := range optionSet.Options {
fmt.Fprintf(&out, " SettingSuggestedOption(value: %q, introducedIn: %d),\n",
option.Value, option.IntroducedIn)
}
out.WriteString(" ]\n")
out.WriteString(" ),\n")
}
out.WriteString(" ]\n\n")
out.WriteString(" public static let definitions: [SettingKey: SettingPresentation] = [\n")
for _, def := range sortedDefinitions(contract) {
if def.SuggestedOptions == "" && def.UnsetLabel == "" {
continue
}
fmt.Fprintf(&out, " .%s: SettingPresentation(\n", lowerFirst(identifierFor(def.Key)))
if def.SuggestedOptions != "" {
fmt.Fprintf(&out, " suggestedOptions: %q,\n", def.SuggestedOptions)
} else {
out.WriteString(" suggestedOptions: nil,\n")
}
if def.UnsetLabel != "" {
fmt.Fprintf(&out, " unsetLabel: %q\n", def.UnsetLabel)
} else {
out.WriteString(" unsetLabel: nil\n")
}
out.WriteString(" ),\n")
}
out.WriteString(" ]\n\n")
out.WriteString(" public static func suggestedValues(\n")
out.WriteString(" for key: SettingKey,\n")
out.WriteString(" revision: Int = SettingKey.revision\n")
out.WriteString(" ) -> [String] {\n")
out.WriteString(" guard let setID = definitions[key]?.suggestedOptions,\n")
out.WriteString(" let optionSet = optionSets[setID] else { return [] }\n")
out.WriteString(" return optionSet.options\n")
out.WriteString(" .filter { $0.introducedIn <= revision }\n")
out.WriteString(" .map(\\.value)\n")
out.WriteString(" }\n")
out.WriteString("}\n")
return out.Bytes(), nil
}
func lowerFirst(value string) string {
if value == "" {
return value
}
return strings.ToLower(value[:1]) + value[1:]
}
func sortedOptionSetNames(contract *settingscontract.Manifest) []string {
names := make([]string, 0, len(contract.OptionSets))
for name := range contract.OptionSets {
names = append(names, name)
}
sort.Strings(names)
return names
}
func quotedStrings(values []string) string {
parts := make([]string, 0, len(values))
for _, value := range values {
parts = append(parts, fmt.Sprintf("%q", value))
}
return strings.Join(parts, ", ")
}
func quotedScopes(def *settingscontract.Definition) string {
parts := make([]string, 0, len(def.AllowedScopes))
for _, entry := range def.AllowedScopes {
parts = append(parts, fmt.Sprintf("%q", entry.Scope))
}
return strings.Join(parts, ", ")
}
// scopeRevisions emits each scope's introduction revision, aligned with
// quotedScopes. A scope entry with no explicit tag has held since the
// definition itself appeared.
func scopeRevisions(def *settingscontract.Definition) string {
parts := make([]string, 0, len(def.AllowedScopes))
for _, entry := range def.AllowedScopes {
revision := entry.IntroducedIn
if revision == 0 {
revision = def.IntroducedIn
}
parts = append(parts, fmt.Sprintf("%d", revision))
}
return strings.Join(parts, ", ")
}
// memberRevision is the revision an enum member became a legal value at; an
// untagged member has existed since its definition.
func memberRevision(def *settingscontract.Definition, member settingscontract.EnumMember) int {
if member.IntroducedIn != 0 {
return member.IntroducedIn
}
return def.IntroducedIn
}
// boundHistory renders a widened bound's full history so an ahead-of-server
// client can recover the bound in force at an older revision. Empty when the
// bound never changed — the flattened minimum/maximum already carries it.
func boundHistory(def *settingscontract.Definition, bound *settingscontract.Bound) string {
if bound == nil || len(bound.History) < 2 {
return ""
}
parts := make([]string, 0, len(bound.History))
for _, entry := range bound.History {
revision := entry.IntroducedIn
if revision == 0 {
revision = def.IntroducedIn
}
parts = append(parts, fmt.Sprintf("{ value: %s, introducedIn: %d }",
trimFloat(entry.Value), revision))
}
return strings.Join(parts, ", ")
}
func quotedResolution(def *settingscontract.Definition) string {
parts := make([]string, 0, len(def.ResolutionOrder))
for _, scope := range def.ResolutionOrder {
parts = append(parts, fmt.Sprintf("%q", scope))
}
return strings.Join(parts, ", ")
}
func defaultLiteral(def *settingscontract.Definition) string {
if len(def.DefaultValue) == 0 {
return "null"
}
return string(bytes.TrimSpace(def.DefaultValue))
}
func jsString(value string) string {
encoded, err := json.Marshal(value)
if err != nil {
return `""`
}
return string(encoded)
}
func trimFloat(value float64) string {
return strings.TrimSuffix(fmt.Sprintf("%g", value), ".0")
}
-90
View File
@@ -1,90 +0,0 @@
package main
import (
"strings"
"testing"
"github.com/Silo-Server/silo-server/internal/settingscontract"
)
func TestPresentationMetadataIsGeneratedForEveryClientLanguage(t *testing.T) {
contract, err := settingscontract.Load()
if err != nil {
t.Fatalf("loading contract: %v", err)
}
tests := []struct {
name string
generate func() ([]byte, error)
markers []string
}{
{
name: "typescript",
generate: func() ([]byte, error) { return generateTypeScript(contract) },
markers: []string{
"export const SETTING_OPTION_SETS",
`catalog_metadata_languages`,
`suggestedOptions: "playback_subtitle_languages"`,
`unsetLabel: "None"`,
// Advisory platform tags reach the web UI so it can hide
// settings that do not apply to the device being edited.
`platforms: ["web"]`,
`platforms: ["ios", "android"]`,
},
},
{
name: "kotlin",
generate: func() ([]byte, error) {
return generateKotlin(contract, "org.siloserver.silo.model.settings")
},
markers: []string{
"object SettingPresentationMetadata",
`"playback_audio_languages" to SettingOptionSet`,
`suggestedOptions = "catalog_metadata_languages"`,
`unsetLabel = "Library default"`,
},
},
{
name: "swift",
generate: func() ([]byte, error) { return generateSwift(contract) },
markers: []string{
"public enum SettingPresentationMetadata",
`"playback_subtitle_languages": SettingOptionSet`,
`suggestedOptions: "playback_audio_languages"`,
`unsetLabel: "No preference"`,
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
generated, err := tc.generate()
if err != nil {
t.Fatalf("generating: %v", err)
}
for _, marker := range tc.markers {
if !strings.Contains(string(generated), marker) {
t.Errorf("generated output omitted %q", marker)
}
}
})
}
}
func TestGeneratedOptionOrderMatchesTheManifest(t *testing.T) {
contract, err := settingscontract.Load()
if err != nil {
t.Fatalf("loading contract: %v", err)
}
generated, err := generateTypeScript(contract)
if err != nil {
t.Fatalf("generating TypeScript: %v", err)
}
text := string(generated)
arabic := strings.Index(text, `{ value: "ar", introducedIn: 1 }`)
bengali := strings.Index(text, `{ value: "bn", introducedIn: 1 }`)
if arabic < 0 || bengali < 0 || arabic >= bengali {
t.Fatalf("generated option order does not preserve the manifest: ar=%d bn=%d", arabic, bengali)
}
}
+98 -660
View File
File diff suppressed because it is too large Load Diff
-46
View File
@@ -1,8 +1,6 @@
package main
import (
"context"
"errors"
"io"
"net/http"
"net/http/httptest"
@@ -10,12 +8,9 @@ import (
"sync"
"testing"
pluginv1 "github.com/Silo-Server/silo-plugin-sdk/pkg/pluginproto/silo/plugin/v1"
"github.com/Silo-Server/silo-server/internal/api"
"github.com/Silo-Server/silo-server/internal/config"
"github.com/Silo-Server/silo-server/internal/playback"
"github.com/Silo-Server/silo-server/internal/plugins"
"github.com/Silo-Server/silo-server/internal/watchsync"
)
func TestConfigureS3Clients_SetsCORSOnPublicAssetsBucket(t *testing.T) {
@@ -187,44 +182,3 @@ func TestBuildLiveSessionSync_UsesTransportPlayMethod(t *testing.T) {
})
}
}
type failingWatchSyncCapabilityStore struct{}
func (failingWatchSyncCapabilityStore) ListEnabled(context.Context) ([]*plugins.Installation, error) {
return []*plugins.Installation{{ID: 2, Enabled: true, Kind: plugins.KindPlugin}}, nil
}
func (failingWatchSyncCapabilityStore) ListCapabilities(context.Context, int) ([]*plugins.Capability, error) {
return nil, errors.New("database unavailable")
}
func TestReloadWatchSyncPluginProvidersDropsStaleProvidersOnCapabilityReadFailure(t *testing.T) {
registry := watchsync.NewRegistry()
provider, err := watchsync.NewPluginProvider(watchsync.PluginProviderOptions{
InstallationID: 1,
ProviderKey: "plugin:1:tracker",
CapabilityID: "tracker",
Descriptor: &pluginv1.WatchSyncProviderDescriptor{
AuthMethods: []pluginv1.WatchSyncAuthMethod{pluginv1.WatchSyncAuthMethod_WATCH_SYNC_AUTH_METHOD_API_KEY},
ExportWatched: true,
},
ResolveClient: func(context.Context, int, string) (watchsync.WatchSyncPluginClient, error) {
return nil, errors.New("not used")
},
})
if err != nil {
t.Fatal(err)
}
if err := registry.Register(provider); err != nil {
t.Fatal(err)
}
if err := reloadWatchSyncPluginProviders(
context.Background(), registry, failingWatchSyncCapabilityStore{}, &plugins.Service{}, nil,
); err != nil {
t.Fatal(err)
}
if _, ok := registry.Get(provider.Key()); ok {
t.Fatalf("stale provider %q remained registered", provider.Key())
}
}
-1
View File
@@ -40,6 +40,5 @@ func buildLiveSessionSync(s *playback.Session, reportingNode string) worker.Sess
PositionSeconds: s.Position,
IsPaused: s.IsPaused,
HasWebSocket: s.HasWebSocket,
IsJellyfinCompat: s.IsJellyfinCompat,
}
}
-696
View File
@@ -1,696 +0,0 @@
{
"fixture_version": 1,
"manifest_revision": 6,
"description": "Cross-platform conformance cases for settings resolution. Every case runs against the shipped manifest in this directory: definitions are referenced by key, never restated, so an expectation can only be satisfied by resolving the real contract. Each platform's resolver (Go in internal/settingsresolve, TypeScript in web/src/lib/settingsResolve.ts, Kotlin and Swift in the client repos) runs every case through a hand-written runner; a runner must fail on any fixture field it does not know, because schema drift in the fixture itself is drift. A case's constraint_bindings attach a constraint to a copy of a real definition so constraint semantics stay testable even while no shipped definition carries that constraint kind. In expected entries, constrained:true requires stored_value and constraint_kind to be present, and stored_value may be null to mean the authored value was JSON null.",
"cases": [
{
"name": "profile_client_sits_between_device_and_profile",
"description": "Presentation values roam across like clients, while an exact-device override remains more specific and a profile value remains the cross-family fallback.",
"keys": ["ui.card_presentation"],
"context": { "profile_id": "p1", "client_family": "tv", "device_id": "living-room" },
"stored": [
{
"key": "ui.card_presentation",
"scope": "profile",
"profile_id": "p1",
"value": { "poster_size": "standard", "caption": "title" }
},
{
"key": "ui.card_presentation",
"scope": "profile_client",
"profile_id": "p1",
"client_family": "tv",
"value": { "poster_size": "large", "caption": "artwork" }
},
{
"key": "ui.card_presentation",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "living-room",
"value": { "poster_size": "compact", "caption": "title_metadata" }
}
],
"expected": [
{
"key": "ui.card_presentation",
"value": { "poster_size": "compact", "caption": "title_metadata" },
"source": "profile_device"
}
]
},
{
"name": "profile_client_roams_only_within_its_family",
"description": "A television menu applies to another television identity but not to mobile; the family is explicit resolution context rather than inferred from device metadata.",
"keys": ["nav.primary_menu"],
"context": { "profile_id": "p1", "client_family": "tv", "device_id": "bedroom-tv" },
"stored": [
{
"key": "nav.primary_menu",
"scope": "profile_client",
"profile_id": "p1",
"client_family": "mobile",
"value": { "items": [{ "type": "builtin", "destination": "home" }] }
},
{
"key": "nav.primary_menu",
"scope": "profile_client",
"profile_id": "p1",
"client_family": "tv",
"value": {
"items": [
{ "type": "builtin", "destination": "home" },
{ "type": "builtin", "destination": "movies" }
]
}
}
],
"expected": [
{
"key": "nav.primary_menu",
"value": {
"items": [
{ "type": "builtin", "destination": "home" },
{ "type": "builtin", "destination": "movies" }
]
},
"source": "profile_client"
}
]
},
{
"name": "resolution_order_series_wins",
"description": "The full ladder: with values stored at every scope a content key allows, profile_series beats profile_library, profile_device, and profile.",
"keys": ["playback.subtitle_language"],
"context": {
"profile_id": "p1",
"device_id": "d1",
"library_ids": [7],
"series_ids": ["s-101"]
},
"stored": [
{ "key": "playback.subtitle_language", "scope": "profile", "profile_id": "p1", "value": "en" },
{
"key": "playback.subtitle_language",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "d1",
"value": "de"
},
{
"key": "playback.subtitle_language",
"scope": "profile_library",
"profile_id": "p1",
"library_id": 7,
"value": "fr"
},
{
"key": "playback.subtitle_language",
"scope": "profile_series",
"profile_id": "p1",
"series_id": "s-101",
"value": "ja"
}
],
"expected": [
{ "key": "playback.subtitle_language", "value": "ja", "source": "profile_series" }
]
},
{
"name": "resolution_order_library_beats_device",
"description": "Without a series row, the library row wins over the device and profile rows.",
"keys": ["playback.subtitle_language"],
"context": {
"profile_id": "p1",
"device_id": "d1",
"library_ids": [7],
"series_ids": ["s-101"]
},
"stored": [
{ "key": "playback.subtitle_language", "scope": "profile", "profile_id": "p1", "value": "en" },
{
"key": "playback.subtitle_language",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "d1",
"value": "de"
},
{
"key": "playback.subtitle_language",
"scope": "profile_library",
"profile_id": "p1",
"library_id": 7,
"value": "fr"
}
],
"expected": [
{ "key": "playback.subtitle_language", "value": "fr", "source": "profile_library" }
]
},
{
"name": "resolution_order_device_beats_profile",
"description": "Without content rows, the device override wins over the profile fallback even though the context names a library and a series.",
"keys": ["playback.subtitle_language"],
"context": {
"profile_id": "p1",
"device_id": "d1",
"library_ids": [7],
"series_ids": ["s-101"]
},
"stored": [
{ "key": "playback.subtitle_language", "scope": "profile", "profile_id": "p1", "value": "en" },
{
"key": "playback.subtitle_language",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "d1",
"value": "de"
}
],
"expected": [
{ "key": "playback.subtitle_language", "value": "de", "source": "profile_device" }
]
},
{
"name": "resolution_order_profile_alone",
"description": "A profile row alone resolves at profile scope.",
"keys": ["playback.subtitle_language"],
"context": {
"profile_id": "p1",
"device_id": "d1",
"library_ids": [7],
"series_ids": ["s-101"]
},
"stored": [
{ "key": "playback.subtitle_language", "scope": "profile", "profile_id": "p1", "value": "en" }
],
"expected": [{ "key": "playback.subtitle_language", "value": "en", "source": "profile" }]
},
{
"name": "device_override_beats_profile_for_quality",
"description": "playback.preferred_quality has no content scopes; its device override wins over the profile value.",
"keys": ["playback.preferred_quality"],
"context": { "profile_id": "p1", "device_id": "d1" },
"stored": [
{
"key": "playback.preferred_quality",
"scope": "profile",
"profile_id": "p1",
"value": "720p"
},
{
"key": "playback.preferred_quality",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "d1",
"value": "1080p"
}
],
"expected": [
{ "key": "playback.preferred_quality", "value": "1080p", "source": "profile_device" }
]
},
{
"name": "missing_device_identity_drops_device_scope",
"description": "A caller with no device identity must not see a device override; the profile row answers instead. This is the anonymous jellycompat seed: a device row leaking here hands one device's settings to every client.",
"keys": ["playback.subtitle_language"],
"context": { "profile_id": "p1" },
"stored": [
{ "key": "playback.subtitle_language", "scope": "profile", "profile_id": "p1", "value": "en" },
{
"key": "playback.subtitle_language",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "d1",
"value": "de"
}
],
"expected": [{ "key": "playback.subtitle_language", "value": "en", "source": "profile" }]
},
{
"name": "foreign_identity_rows_never_resolve",
"description": "Rows for another profile, another device, or another series must not resolve just because a batched read returned them; the answer falls to the contract default.",
"keys": ["playback.subtitle_language"],
"context": { "profile_id": "p1", "device_id": "d1", "series_ids": ["s-101"] },
"stored": [
{ "key": "playback.subtitle_language", "scope": "profile", "profile_id": "p2", "value": "xx" },
{
"key": "playback.subtitle_language",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "d2",
"value": "yy"
},
{
"key": "playback.subtitle_language",
"scope": "profile_series",
"profile_id": "p1",
"series_id": "s-other",
"value": "zz"
}
],
"expected": [{ "key": "playback.subtitle_language", "value": null, "source": "default" }]
},
{
"name": "absent_values_resolve_to_contract_defaults",
"description": "Nothing stored resolves to each definition's default_value with source \"default\": enum, boolean, integer, and nullable language tag.",
"keys": [
"playback.subtitle_mode",
"playback.show_forced_subtitles",
"playback.next_up_prompt_seconds",
"playback.audio_language"
],
"context": { "profile_id": "p1", "device_id": "d1" },
"expected": [
{ "key": "playback.subtitle_mode", "value": "auto", "source": "default" },
{ "key": "playback.show_forced_subtitles", "value": true, "source": "default" },
{ "key": "playback.next_up_prompt_seconds", "value": 30, "source": "default" },
{ "key": "playback.audio_language", "value": null, "source": "default" }
]
},
{
"name": "batch_resolves_each_key_independently",
"description": "One batch, three keys, three different sources: a device override, a profile value, and a default.",
"keys": [
"playback.preferred_quality",
"playback.subtitle_mode",
"playback.audio_language"
],
"context": { "profile_id": "p1", "device_id": "d1" },
"stored": [
{
"key": "playback.preferred_quality",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "d1",
"value": "1080p"
},
{ "key": "playback.subtitle_mode", "scope": "profile", "profile_id": "p1", "value": "always" }
],
"expected": [
{ "key": "playback.preferred_quality", "value": "1080p", "source": "profile_device" },
{ "key": "playback.subtitle_mode", "value": "always", "source": "profile" },
{ "key": "playback.audio_language", "value": null, "source": "default" }
]
},
{
"name": "ceiling_caps_stored_quality_and_reports_the_stored_value",
"description": "The manifest binds playback.preferred_quality to the max_playback_quality ceiling. A stored 2160p over a 1080p cap resolves to 1080p while the authored value survives, reported as stored_value with constrained:true.",
"keys": ["playback.preferred_quality"],
"context": { "profile_id": "p1" },
"stored": [
{
"key": "playback.preferred_quality",
"scope": "profile",
"profile_id": "p1",
"value": "2160p"
}
],
"constraints": { "max_playback_quality": "1080p" },
"expected": [
{
"key": "playback.preferred_quality",
"value": "1080p",
"source": "profile",
"constrained": true,
"stored_value": "2160p",
"constraint_kind": "ceiling"
}
]
},
{
"name": "ceiling_leaves_quality_under_the_cap_alone",
"description": "A value at or under the cap passes through untouched and is not reported as constrained.",
"keys": ["playback.preferred_quality"],
"context": { "profile_id": "p1" },
"stored": [
{
"key": "playback.preferred_quality",
"scope": "profile",
"profile_id": "p1",
"value": "720p"
}
],
"constraints": { "max_playback_quality": "1080p" },
"expected": [{ "key": "playback.preferred_quality", "value": "720p", "source": "profile" }]
},
{
"name": "ceiling_ranks_auto_below_every_cap",
"description": "The ordered enum lists \"auto\" first because it never exceeds a cap: even the lowest cap leaves it alone.",
"keys": ["playback.preferred_quality"],
"context": { "profile_id": "p1" },
"stored": [
{
"key": "playback.preferred_quality",
"scope": "profile",
"profile_id": "p1",
"value": "auto"
}
],
"constraints": { "max_playback_quality": "480p" },
"expected": [{ "key": "playback.preferred_quality", "value": "auto", "source": "profile" }]
},
{
"name": "ceiling_caps_original_as_the_highest_member",
"description": "\"original\" is the uncapped source and ranks above every resolution, so any cap brings it down.",
"keys": ["playback.preferred_quality"],
"context": { "profile_id": "p1" },
"stored": [
{
"key": "playback.preferred_quality",
"scope": "profile",
"profile_id": "p1",
"value": "original"
}
],
"constraints": { "max_playback_quality": "2160p" },
"expected": [
{
"key": "playback.preferred_quality",
"value": "2160p",
"source": "profile",
"constrained": true,
"stored_value": "original",
"constraint_kind": "ceiling"
}
]
},
{
"name": "null_bitrate_is_unbounded_and_a_ceiling_caps_it",
"description": "null on the nullable integer playback.max_bitrate_kbps means \"no cap of my own\", which is unbounded above. It has no numeric rank, so a resolver that compares it as equal lets the one value that most needs capping slip past; a ceiling must bring it down to the limit.",
"keys": ["playback.max_bitrate_kbps"],
"context": { "profile_id": "p1" },
"stored": [
{ "key": "playback.max_bitrate_kbps", "scope": "profile", "profile_id": "p1", "value": null }
],
"constraint_bindings": [
{
"key": "playback.max_bitrate_kbps",
"policy_input": "max_bitrate_kbps",
"constraint": "ceiling"
}
],
"constraints": { "max_bitrate_kbps": 8000 },
"expected": [
{
"key": "playback.max_bitrate_kbps",
"value": 8000,
"source": "profile",
"constrained": true,
"stored_value": null,
"constraint_kind": "ceiling"
}
]
},
{
"name": "default_null_bitrate_is_capped_by_a_ceiling",
"description": "The contract default for playback.max_bitrate_kbps is null, so even with nothing stored a ceiling caps the resolved default; source stays \"default\" and the null is reported as stored_value.",
"keys": ["playback.max_bitrate_kbps"],
"context": { "profile_id": "p1" },
"constraint_bindings": [
{
"key": "playback.max_bitrate_kbps",
"policy_input": "max_bitrate_kbps",
"constraint": "ceiling"
}
],
"constraints": { "max_bitrate_kbps": 8000 },
"expected": [
{
"key": "playback.max_bitrate_kbps",
"value": 8000,
"source": "default",
"constrained": true,
"stored_value": null,
"constraint_kind": "ceiling"
}
]
},
{
"name": "floor_leaves_an_unbounded_bitrate_alone",
"description": "The mirror rule: unbounded already satisfies any floor, so a floor must not touch a null numeric.",
"keys": ["playback.max_bitrate_kbps"],
"context": { "profile_id": "p1" },
"stored": [
{ "key": "playback.max_bitrate_kbps", "scope": "profile", "profile_id": "p1", "value": null }
],
"constraint_bindings": [
{
"key": "playback.max_bitrate_kbps",
"policy_input": "min_bitrate_kbps",
"constraint": "floor"
}
],
"constraints": { "min_bitrate_kbps": 8000 },
"expected": [{ "key": "playback.max_bitrate_kbps", "value": null, "source": "profile" }]
},
{
"name": "allowlist_falls_back_when_the_default_is_outside_the_list",
"description": "With nothing stored, catalog.metadata_language resolves to its default null, which is outside the allowlist. The fallback is the first allowed member — not the definition default, which is exactly the value the policy forbids.",
"keys": ["catalog.metadata_language"],
"context": { "profile_id": "p1" },
"constraint_bindings": [
{
"key": "catalog.metadata_language",
"policy_input": "allowed_metadata_languages",
"constraint": "allowlist"
}
],
"constraints": { "allowed_metadata_languages": ["en", "fr"] },
"expected": [
{
"key": "catalog.metadata_language",
"value": "en",
"source": "default",
"constrained": true,
"stored_value": null,
"constraint_kind": "allowlist"
}
]
},
{
"name": "allowlist_replaces_a_forbidden_choice",
"description": "A stored value outside the allowlist is replaced by the first allowed member, with the authored choice preserved as stored_value.",
"keys": ["catalog.metadata_language"],
"context": { "profile_id": "p1" },
"stored": [
{ "key": "catalog.metadata_language", "scope": "profile", "profile_id": "p1", "value": "ja" }
],
"constraint_bindings": [
{
"key": "catalog.metadata_language",
"policy_input": "allowed_metadata_languages",
"constraint": "allowlist"
}
],
"constraints": { "allowed_metadata_languages": ["en", "fr"] },
"expected": [
{
"key": "catalog.metadata_language",
"value": "en",
"source": "profile",
"constrained": true,
"stored_value": "ja",
"constraint_kind": "allowlist"
}
]
},
{
"name": "allowlist_passes_a_permitted_choice",
"description": "A stored value inside the allowlist passes through untouched.",
"keys": ["catalog.metadata_language"],
"context": { "profile_id": "p1" },
"stored": [
{ "key": "catalog.metadata_language", "scope": "profile", "profile_id": "p1", "value": "fr" }
],
"constraint_bindings": [
{
"key": "catalog.metadata_language",
"policy_input": "allowed_metadata_languages",
"constraint": "allowlist"
}
],
"constraints": { "allowed_metadata_languages": ["en", "fr"] },
"expected": [{ "key": "catalog.metadata_language", "value": "fr", "source": "profile" }]
},
{
"name": "metadata_language_exceptions_resolve_as_one_object",
"description": "The original-language exception map is a single profile-scoped value; resolution preserves every source-to-target entry together.",
"keys": ["catalog.metadata_language_overrides"],
"context": { "profile_id": "p1" },
"stored": [
{
"key": "catalog.metadata_language_overrides",
"scope": "profile",
"profile_id": "p1",
"value": { "ja": "en", "no": "x-silo-original" }
}
],
"expected": [
{
"key": "catalog.metadata_language_overrides",
"value": { "ja": "en", "no": "x-silo-original" },
"source": "profile"
}
]
},
{
"name": "locked_replaces_a_differing_choice",
"description": "locked is total: the policy value replaces the user's outright, and the authored choice is preserved as stored_value so it takes effect the day the lock lifts.",
"keys": ["playback.subtitle_mode"],
"context": { "profile_id": "p1" },
"stored": [
{ "key": "playback.subtitle_mode", "scope": "profile", "profile_id": "p1", "value": "off" }
],
"constraint_bindings": [
{
"key": "playback.subtitle_mode",
"policy_input": "forced_subtitle_mode",
"constraint": "locked"
}
],
"constraints": { "forced_subtitle_mode": "always" },
"expected": [
{
"key": "playback.subtitle_mode",
"value": "always",
"source": "profile",
"constrained": true,
"stored_value": "off",
"constraint_kind": "locked"
}
]
},
{
"name": "locked_leaves_an_equal_value_unconstrained",
"description": "A stored value already equal to the lock is not a narrowing: it passes through with no constrained flag, so clients do not tell the user their own choice was overridden.",
"keys": ["playback.subtitle_mode"],
"context": { "profile_id": "p1" },
"stored": [
{
"key": "playback.subtitle_mode",
"scope": "profile",
"profile_id": "p1",
"value": "always"
}
],
"constraint_bindings": [
{
"key": "playback.subtitle_mode",
"policy_input": "forced_subtitle_mode",
"constraint": "locked"
}
],
"constraints": { "forced_subtitle_mode": "always" },
"expected": [{ "key": "playback.subtitle_mode", "value": "always", "source": "profile" }]
},
{
"name": "locked_replaces_the_contract_default",
"description": "With nothing stored, the lock replaces even the contract default: source stays \"default\" and the default is reported as stored_value, exactly like a capped default.",
"keys": ["playback.subtitle_mode"],
"context": { "profile_id": "p1" },
"constraint_bindings": [
{
"key": "playback.subtitle_mode",
"policy_input": "forced_subtitle_mode",
"constraint": "locked"
}
],
"constraints": { "forced_subtitle_mode": "always" },
"expected": [
{
"key": "playback.subtitle_mode",
"value": "always",
"source": "default",
"constrained": true,
"stored_value": "auto",
"constraint_kind": "locked"
}
]
},
{
"name": "subtitle_appearance_ignores_content_scopes",
"description": "playback.subtitle_appearance resolves profile_device then profile only. With a library and a series in the context, the device row still wins — and the sparse device object replaces the profile object outright rather than merging with it.",
"keys": ["playback.subtitle_appearance"],
"context": {
"profile_id": "p1",
"device_id": "d1",
"library_ids": [7],
"series_ids": ["s-101"]
},
"stored": [
{
"key": "playback.subtitle_appearance",
"scope": "profile",
"profile_id": "p1",
"value": { "fontSize": "medium", "fontColor": "#ffcc00" }
},
{
"key": "playback.subtitle_appearance",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "d1",
"value": { "fontSize": "xxlarge", "position": "top" }
}
],
"expected": [
{
"key": "playback.subtitle_appearance",
"value": { "fontSize": "xxlarge", "position": "top" },
"source": "profile_device"
}
]
},
{
"name": "subtitle_appearance_falls_to_profile_without_device",
"description": "Without a device identity the profile's appearance object answers, unmerged.",
"keys": ["playback.subtitle_appearance"],
"context": { "profile_id": "p1" },
"stored": [
{
"key": "playback.subtitle_appearance",
"scope": "profile",
"profile_id": "p1",
"value": { "fontSize": "medium", "fontColor": "#ffcc00" }
},
{
"key": "playback.subtitle_appearance",
"scope": "profile_device",
"profile_id": "p1",
"device_id": "d1",
"value": { "fontSize": "xxlarge", "position": "top" }
}
],
"expected": [
{
"key": "playback.subtitle_appearance",
"value": { "fontSize": "medium", "fontColor": "#ffcc00" },
"source": "profile"
}
]
},
{
"name": "subtitle_appearance_uses_shared_default",
"description": "With no stored profile or device value, every client receives the contract's shared Box 75% subtitle appearance.",
"keys": ["playback.subtitle_appearance"],
"context": { "profile_id": "p1", "device_id": "d1" },
"stored": [],
"expected": [
{
"key": "playback.subtitle_appearance",
"value": {
"fontSize": "large",
"fontFamily": "sans-serif",
"fontColor": "#ffffff",
"backgroundColor": "#000000",
"backgroundStyle": "box",
"backgroundOpacity": 75,
"textOutline": false,
"textOutlineColor": "#000000",
"position": "bottom"
},
"source": "default"
}
]
}
]
}
-18
View File
@@ -1,18 +0,0 @@
// Package settingsv1 embeds the canonical cross-platform user settings
// contract so the server binary carries the exact bytes it was built from.
//
// This package deliberately contains nothing but the embed directive. The
// contract files are the artifact clients vendor and generate bindings from, so
// they live at this stable path rather than inside an internal package; the
// embed has to sit beside them because go:embed cannot reach outside its own
// directory.
//
// Loading, validation, and lookup live in internal/settingscontract.
package settingsv1
import "embed"
// FS holds manifest.json, manifest.schema.json, and schemas/.
//
//go:embed manifest.json manifest.schema.json schemas
var FS embed.FS
File diff suppressed because it is too large Load Diff
-344
View File
@@ -1,344 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/manifest.schema.json",
"title": "Silo cross-platform user settings manifest",
"description": "Canonical contract for every production, user-facing setting. See docs/superpowers/specs/2026-07-10-cross-platform-user-settings-contract-design.md.",
"type": "object",
"additionalProperties": false,
"required": ["api_version", "revision", "definitions"],
"properties": {
"api_version": {
"description": "Settings protocol version. Changes only for a change no revision rule can express.",
"type": "integer",
"minimum": 1
},
"revision": {
"description": "Monotonically increasing integer bumped by every manifest PR.",
"type": "integer",
"minimum": 1
},
"option_sets": {
"description": "Advisory ordered vocabularies for open-value controls. They suggest values but never constrain the corresponding value schema.",
"type": "object",
"propertyNames": { "$ref": "#/$defs/optionSetName" },
"additionalProperties": { "$ref": "#/$defs/optionSet" }
},
"definitions": {
"type": "array",
"items": { "$ref": "#/$defs/definition" }
}
},
"$defs": {
"settingKey": {
"description": "Lowercase dot-separated identifier. Canonical names do not encode a platform.",
"type": "string",
"pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$",
"maxLength": 128
},
"revisionRef": {
"description": "Manifest revision in which this element was introduced.",
"type": "integer",
"minimum": 1
},
"optionSetName": {
"description": "Stable snake_case identifier for a reusable presentation vocabulary.",
"type": "string",
"pattern": "^[a-z][a-z0-9_]*$",
"maxLength": 128
},
"suggestedOption": {
"description": "One advisory value. Labels are localized by clients from the stable wire value.",
"type": "object",
"additionalProperties": false,
"required": ["value", "introduced_in"],
"properties": {
"value": { "type": "string", "minLength": 1 },
"introduced_in": { "$ref": "#/$defs/revisionRef" }
}
},
"optionSet": {
"description": "An ordered advisory value floor for an open setting. The server validates that its type matches every referring definition.",
"type": "object",
"additionalProperties": false,
"required": ["type", "options"],
"properties": {
"type": { "const": "language_tag" },
"options": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/$defs/suggestedOption" }
}
}
},
"scopeName": {
"description": "Storage identity a value attaches to. Whether a given scope is legal for a definition depends on its persistence class, which internal/settingscontract enforces.",
"type": "string",
"enum": [
"account",
"profile",
"profile_client",
"profile_device",
"profile_library",
"profile_series",
"client_local"
]
},
"scopeEntry": {
"description": "A scope, optionally tagged with the revision that added it to this definition.",
"oneOf": [
{ "$ref": "#/$defs/scopeName" },
{
"type": "object",
"additionalProperties": false,
"required": ["scope"],
"properties": {
"scope": { "$ref": "#/$defs/scopeName" },
"introduced_in": { "$ref": "#/$defs/revisionRef" }
}
}
]
},
"integerBound": {
"description": "A numeric bound. Write a bare number for a bound that has never been widened. Widening replaces it with the full history, oldest first, so a client can recover the bound an older server still enforces; the bare form alone would discard it.",
"oneOf": [
{ "type": "integer" },
{
"type": "array",
"minItems": 2,
"items": {
"type": "object",
"additionalProperties": false,
"required": ["value"],
"properties": {
"value": { "type": "integer" },
"introduced_in": { "$ref": "#/$defs/revisionRef" }
}
}
}
]
},
"numberBound": {
"description": "A numeric bound. Write a bare number for a bound that has never been widened. Widening replaces it with the full history, oldest first, so a client can recover the bound an older server still enforces; the bare form alone would discard it.",
"oneOf": [
{ "type": "number" },
{
"type": "array",
"minItems": 2,
"items": {
"type": "object",
"additionalProperties": false,
"required": ["value"],
"properties": {
"value": { "type": "number" },
"introduced_in": { "$ref": "#/$defs/revisionRef" }
}
}
}
]
},
"enumMember": {
"description": "Enum members are objects so members added later can carry their own revision.",
"type": "object",
"additionalProperties": false,
"required": ["value"],
"properties": {
"value": { "type": ["string", "integer", "boolean"] },
"label": { "type": "string" },
"introduced_in": { "$ref": "#/$defs/revisionRef" },
"deprecated": { "type": "boolean", "default": false }
}
},
"valueSchema": {
"oneOf": [
{
"type": "object",
"additionalProperties": false,
"required": ["type"],
"properties": {
"type": { "const": "boolean" },
"nullable": { "type": "boolean", "default": false }
}
},
{
"type": "object",
"additionalProperties": false,
"required": ["type", "minimum", "maximum"],
"properties": {
"type": { "const": "integer" },
"minimum": { "$ref": "#/$defs/integerBound" },
"maximum": { "$ref": "#/$defs/integerBound" },
"step": { "type": "integer", "exclusiveMinimum": 0 },
"nullable": { "type": "boolean", "default": false }
}
},
{
"type": "object",
"additionalProperties": false,
"required": ["type", "minimum", "maximum"],
"properties": {
"type": { "const": "number" },
"minimum": { "$ref": "#/$defs/numberBound" },
"maximum": { "$ref": "#/$defs/numberBound" },
"step": { "type": "number", "exclusiveMinimum": 0 },
"nullable": { "type": "boolean", "default": false }
}
},
{
"type": "object",
"additionalProperties": false,
"required": ["type", "max_length"],
"properties": {
"type": { "const": "string" },
"min_length": { "type": "integer", "minimum": 0, "default": 0 },
"max_length": { "type": "integer", "minimum": 1 },
"pattern": { "type": "string", "format": "regex" },
"nullable": { "type": "boolean", "default": false }
}
},
{
"type": "object",
"additionalProperties": false,
"required": ["type", "values"],
"properties": {
"type": { "const": "enum" },
"values": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/$defs/enumMember" }
},
"ordered": {
"description": "Members form a meaningful progression. Required for ceiling/floor constraints.",
"type": "boolean",
"default": false
},
"nullable": { "type": "boolean", "default": false }
}
},
{
"type": "object",
"additionalProperties": false,
"required": ["type"],
"properties": {
"type": { "const": "language_tag" },
"nullable": { "type": "boolean", "default": false }
}
},
{
"type": "object",
"additionalProperties": false,
"required": ["type", "schema_ref"],
"properties": {
"type": { "const": "object" },
"schema_ref": {
"description": "Filename under contracts/settings/v1/schemas/.",
"type": "string",
"pattern": "^[a-z0-9-]+\\.json$"
},
"nullable": { "type": "boolean", "default": false }
}
}
]
},
"constraint": {
"description": "Binding to a policy input that constrains this setting at resolution time.",
"type": "object",
"additionalProperties": false,
"required": ["policy_input", "constraint"],
"properties": {
"policy_input": {
"description": "Field name produced by internal/policy.",
"type": "string",
"pattern": "^[a-z][a-z0-9_]*$"
},
"constraint": {
"type": "string",
"enum": ["ceiling", "floor", "allowlist", "locked"]
}
}
},
"definition": {
"type": "object",
"additionalProperties": false,
"required": [
"key",
"introduced_in",
"persistence",
"allowed_scopes",
"resolution_order",
"value_schema",
"default_value",
"category",
"label",
"description"
],
"properties": {
"key": { "$ref": "#/$defs/settingKey" },
"introduced_in": { "$ref": "#/$defs/revisionRef" },
"persistence": {
"type": "string",
"enum": ["remote", "client_local"]
},
"allowed_scopes": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/$defs/scopeEntry" }
},
"resolution_order": {
"description": "Most specific first. Must end with \"default\".",
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"enum": [
"account",
"profile",
"profile_client",
"profile_device",
"profile_library",
"profile_series",
"client_local",
"default"
]
}
},
"value_schema": { "$ref": "#/$defs/valueSchema" },
"default_value": {},
"constrained_by": { "$ref": "#/$defs/constraint" },
"platforms": {
"description": "Advisory UI metadata. Absent means \"expected everywhere\". Never server-enforced.",
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"enum": ["web", "ios", "tvos", "macos", "android", "android_tv"]
}
},
"category": {
"type": "string",
"pattern": "^[a-z][a-z0-9_]*$"
},
"label": { "type": "string", "minLength": 1 },
"description": { "type": "string", "minLength": 1 },
"unit": { "type": "string" },
"recommended_control": {
"type": "string",
"enum": ["switch", "select", "slider", "stepper", "text", "color", "panel"]
},
"suggested_options": {
"description": "Advisory option-set reference for an open-value control. It does not turn the value schema into an enum.",
"$ref": "#/$defs/optionSetName"
},
"unset_label": {
"description": "Context-specific label for the nullable/unset row in a generated control.",
"type": "string",
"minLength": 1
},
"deprecated": { "type": "boolean", "default": false },
"notes": {
"description": "Maintainer commentary. Not served in the public manifest.",
"type": "string"
}
}
}
}
}
@@ -1,80 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/card-overlays.json",
"title": "Card overlay preferences",
"description": "Badges painted on poster cards. Mirrors CardOverlayPrefs in web/src/lib/overlays/types.ts.",
"type": "object",
"additionalProperties": false,
"required": ["version", "preset", "order", "items"],
"properties": {
"version": { "const": 2 },
"preset": {
"type": "string",
"enum": ["minimal", "classic", "vibrant", "pill", "square"]
},
"order": {
"description": "Explicit render order. Empty means use the registry's own order.",
"type": "array",
"maxItems": 64,
"uniqueItems": true,
"items": { "$ref": "#/$defs/overlayId" }
},
"items": {
"type": "object",
"propertyNames": { "$ref": "#/$defs/overlayId" },
"additionalProperties": {
"type": "object",
"additionalProperties": false,
"required": ["enabled", "position"],
"properties": {
"enabled": { "type": "boolean" },
"position": {
"type": "string",
"enum": ["top-left", "top-right", "bottom-left", "bottom-right"]
},
"accentColor": {
"description": "Hex colour. Absent means the overlay's own default accent.",
"type": "string",
"pattern": "^#[0-9a-fA-F]{6}$"
},
"showIcon": {
"description": "Absent means inherit from the preset.",
"type": "boolean"
}
}
}
}
},
"$defs": {
"overlayId": {
"type": "string",
"enum": [
"resolution",
"hdr",
"resolution_hdr",
"audio",
"audio_channels",
"video_codec",
"container",
"aspect_ratio",
"release_type",
"edition",
"multi_audio",
"multi_sub",
"rating_imdb",
"rating_tmdb",
"rating_rt",
"rating_rt_audience",
"content_rating",
"year",
"runtime",
"original_language",
"studio",
"network",
"show_status",
"imdb_top_250",
"rt_certified_fresh"
]
}
}
}
@@ -1,19 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/card-presentation.json",
"title": "Media card presentation",
"description": "Semantic density and caption presets that each client family maps to platform-appropriate card dimensions.",
"type": "object",
"additionalProperties": false,
"required": ["poster_size", "caption"],
"properties": {
"poster_size": {
"type": "string",
"enum": ["compact", "standard", "large"]
},
"caption": {
"type": "string",
"enum": ["title_metadata", "title", "artwork"]
}
}
}
@@ -1,13 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/library-id-list.json",
"title": "Library id list",
"description": "An ordered, duplicate-free list of library ids. Backs both ui.disabled_library_ids and ui.library_order; the web client normalizes with normalizeLibraryIDs in web/src/hooks/queries/libraries.ts, which drops non-integers and anything below 1.",
"type": "array",
"maxItems": 512,
"uniqueItems": true,
"items": {
"type": "integer",
"minimum": 1
}
}
@@ -1,32 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/library-page-state.json",
"title": "Library page state",
"description": "Remembered per-library browse state. Mirrors web/src/hooks/queries/libraryPageState.ts.",
"type": "object",
"additionalProperties": false,
"required": ["version", "libraries"],
"properties": {
"version": { "const": 1 },
"libraries": {
"type": "object",
"propertyNames": {
"type": "string",
"pattern": "^[0-9]+$"
},
"additionalProperties": {
"type": "object",
"additionalProperties": false,
"required": ["search"],
"properties": {
"search": {
"type": "string",
"description": "Serialized URLSearchParams from serializeLibraryPageSearchParams. An advanced view encodes each filter rule as three groups[i][rules][j][...] keys, so the length grows about 150 characters per rule: measured at 216 for one rule, 518 for three, 820 for five. The bound has to clear what the current unvalidated endpoint already stores, or these rows fail the migration.",
"maxLength": 4096
}
}
},
"maxProperties": 512
}
}
}
@@ -1,20 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/metadata-language-overrides.json",
"title": "Metadata language exceptions",
"description": "Maps a media item's canonical original-language code to the metadata language a profile wants for that item. x-silo-original means use the source language itself.",
"type": "object",
"propertyNames": {
"description": "Canonical ISO 639 language code as stored in media_items.original_language.",
"type": "string",
"pattern": "^[a-z]{2,3}$"
},
"additionalProperties": {
"description": "A BCP 47 target language or the x-silo-original private-use sentinel.",
"type": "string",
"minLength": 2,
"maxLength": 255,
"pattern": "^([a-zA-Z]{2,3}(-[a-zA-Z]{3}){0,3}(-[a-zA-Z]{4})?(-([a-zA-Z]{2}|[0-9]{3}))?(-([0-9a-zA-Z]{5,8}|[0-9][0-9a-zA-Z]{3}))*(-[0-9a-wy-zA-WY-Z](-[0-9a-zA-Z]{2,8})+)*(-[xX](-[0-9a-zA-Z]{1,8})+)?|[xX](-[0-9a-zA-Z]{1,8})+)$"
},
"maxProperties": 256
}
@@ -1,62 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/navigation-shortcuts.json",
"title": "Navigation shortcuts",
"description": "Profile-wide catalog of pinned libraries, sections, and collections that client-family menus may surface.",
"$comment": "Contract validation also rejects repeated semantic destination identities even when labels differ: library(library_id), section(library_id, section_id), collection(optional library_id, collection_id).",
"type": "object",
"additionalProperties": false,
"required": ["items"],
"properties": {
"items": {
"description": "Pinned targets. Each semantic destination identity may appear at most once; changing its label does not create a distinct destination.",
"type": "array",
"maxItems": 256,
"uniqueItems": true,
"items": {
"oneOf": [
{ "$ref": "#/$defs/library" },
{ "$ref": "#/$defs/section" },
{ "$ref": "#/$defs/collection" }
]
}
}
},
"$defs": {
"label": { "type": "string", "minLength": 1, "maxLength": 256, "pattern": "\\S" },
"libraryId": { "type": "integer", "minimum": 1 },
"targetId": { "type": "string", "minLength": 1, "maxLength": 128, "pattern": "\\S" },
"library": {
"type": "object",
"additionalProperties": false,
"required": ["type", "library_id", "label"],
"properties": {
"type": { "const": "library" },
"library_id": { "$ref": "#/$defs/libraryId" },
"label": { "$ref": "#/$defs/label" }
}
},
"section": {
"type": "object",
"additionalProperties": false,
"required": ["type", "library_id", "section_id", "label"],
"properties": {
"type": { "const": "section" },
"library_id": { "$ref": "#/$defs/libraryId" },
"section_id": { "$ref": "#/$defs/targetId" },
"label": { "$ref": "#/$defs/label" }
}
},
"collection": {
"type": "object",
"additionalProperties": false,
"required": ["type", "collection_id", "label"],
"properties": {
"type": { "const": "collection" },
"collection_id": { "$ref": "#/$defs/targetId" },
"library_id": { "$ref": "#/$defs/libraryId" },
"label": { "$ref": "#/$defs/label" }
}
}
}
}
@@ -1,86 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/primary-menu.json",
"title": "Primary navigation menu",
"description": "Ordered visible destinations for one client family. Search and profile controls are fixed client utilities and are intentionally absent.",
"$comment": "Contract validation also rejects repeated semantic destination identities even when labels differ: builtin(destination), library(library_id), section(library_id, section_id), collection(optional library_id, collection_id).",
"type": "object",
"additionalProperties": false,
"required": ["items"],
"properties": {
"items": {
"description": "Ordered destinations. Each semantic destination identity may appear at most once; changing its label does not create a distinct destination.",
"type": "array",
"minItems": 1,
"maxItems": 64,
"uniqueItems": true,
"contains": {
"type": "object",
"required": ["type", "destination"],
"properties": {
"type": { "const": "builtin" },
"destination": { "const": "home" }
}
},
"minContains": 1,
"maxContains": 1,
"items": {
"oneOf": [
{ "$ref": "#/$defs/builtin" },
{ "$ref": "#/$defs/library" },
{ "$ref": "#/$defs/section" },
{ "$ref": "#/$defs/collection" }
]
}
}
},
"$defs": {
"label": { "type": "string", "minLength": 1, "maxLength": 256, "pattern": "\\S" },
"libraryId": { "type": "integer", "minimum": 1 },
"targetId": { "type": "string", "minLength": 1, "maxLength": 128, "pattern": "\\S" },
"builtin": {
"type": "object",
"additionalProperties": false,
"required": ["type", "destination"],
"properties": {
"type": { "const": "builtin" },
"destination": {
"type": "string",
"enum": ["home", "movies", "series", "music", "audiobooks", "for_you", "calendar"]
}
}
},
"library": {
"type": "object",
"additionalProperties": false,
"required": ["type", "library_id", "label"],
"properties": {
"type": { "const": "library" },
"library_id": { "$ref": "#/$defs/libraryId" },
"label": { "$ref": "#/$defs/label" }
}
},
"section": {
"type": "object",
"additionalProperties": false,
"required": ["type", "library_id", "section_id", "label"],
"properties": {
"type": { "const": "section" },
"library_id": { "$ref": "#/$defs/libraryId" },
"section_id": { "$ref": "#/$defs/targetId" },
"label": { "$ref": "#/$defs/label" }
}
},
"collection": {
"type": "object",
"additionalProperties": false,
"required": ["type", "collection_id", "label"],
"properties": {
"type": { "const": "collection" },
"collection_id": { "$ref": "#/$defs/targetId" },
"library_id": { "$ref": "#/$defs/libraryId" },
"label": { "$ref": "#/$defs/label" }
}
}
}
}
@@ -1,27 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/sidebar-pins.json",
"title": "Sidebar pins",
"description": "Sections and collections pinned into the sidebar, grouped by the library they belong to. Mirrors SidebarPins in web/src/api/types.ts.",
"type": "object",
"propertyNames": {
"description": "The group the pins sit under — a library id, or a well-known group name.",
"type": "string",
"maxLength": 64
},
"maxProperties": 512,
"additionalProperties": {
"type": "array",
"maxItems": 128,
"items": {
"type": "object",
"additionalProperties": false,
"required": ["type", "id", "label"],
"properties": {
"type": { "type": "string", "enum": ["section", "collection"] },
"id": { "type": "string", "minLength": 1, "maxLength": 128 },
"label": { "type": "string", "maxLength": 256 }
}
}
}
}
@@ -1,45 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/subtitle-appearance.json",
"title": "Subtitle appearance",
"description": "Rendering appearance for subtitle tracks. Shared by the web, Apple and Android players; where they disagree the wider vocabulary wins, because a value a shipped client can already produce must stay storable. A stored value is a sparse override: every property is optional, and a consumer merges what is present over this definition's default_value, which is complete. Requiring all nine would invalidate the partial objects the current API already stores and round-trips, so the migration would have to quarantine real user preferences. Resolution across scopes is unchanged and still first-wins — a device override replaces the profile's object rather than merging with it — because a device override means \"draw subtitles this way on this screen\", not \"amend the profile\".",
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"fontSize": {
"type": "string",
"enum": ["small", "medium", "large", "xlarge", "xxlarge"]
},
"fontFamily": {
"description": "A font family name. Not an enum: the Apple clients offer every family CTFontManagerCopyAvailableFontFamilyNames reports and store the chosen name verbatim, so restricting this to the web's three generic families would invalidate the stored appearance of every user who picked a real font. Family names are not ASCII — ヒラギノ角ゴ ProN is a stock macOS family — so the pattern excludes rather than allowlists: no control characters, quotes, separators, parentheses or braces, which keeps a value safe to interpolate into CSS or a platform font lookup while accepting any real family name.",
"type": "string",
"minLength": 1,
"maxLength": 64,
"pattern": "^[^\\x00-\\x1f\"'(){};:,\\\\/ ][^\\x00-\\x1f\"'(){};:,\\\\/]*$"
},
"fontColor": { "$ref": "#/$defs/hexColor" },
"backgroundColor": { "$ref": "#/$defs/hexColor" },
"backgroundStyle": {
"type": "string",
"enum": ["box", "shadow", "outline", "none"]
},
"backgroundOpacity": {
"type": "integer",
"minimum": 0,
"maximum": 100
},
"textOutline": { "type": "boolean" },
"textOutlineColor": { "$ref": "#/$defs/hexColor" },
"position": {
"type": "string",
"enum": ["bottom", "lower-third", "top"]
}
},
"$defs": {
"hexColor": {
"type": "string",
"pattern": "^#[0-9a-fA-F]{6}$"
}
}
}
@@ -1,18 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/contracts/settings/v1/schemas/theme-var-overrides.json",
"title": "Theme variable overrides",
"description": "Sparse map of theme token to CSS value. Token names mirror web/src/lib/themeTokens.ts; values are bounded to keep this from becoming an untyped blob. The per-value bound is sized to what the web importer already accepts and stores: computed multi-stop gradients routinely pass 128 characters, so a tighter bound would invalidate themes users already imported.",
"type": "object",
"propertyNames": {
"type": "string",
"pattern": "^[a-z][a-z0-9-]*$",
"maxLength": 64
},
"additionalProperties": {
"type": "string",
"minLength": 1,
"maxLength": 1024
},
"maxProperties": 256
}
+2
View File
@@ -123,6 +123,7 @@ services:
- silo-dev-plugins:/var/lib/silo/plugins
- silo-dev-compat:/var/lib/silo/compat
- silo-dev-transcode:/tmp/silo-transcode
- silo-dev-audiobook-covers:/var/lib/silo/audiobook-covers
- ${MEDIA_ROOT:-/tmp/silo-dev-media}:${MEDIA_CONTAINER_ROOT:-/mnt/media}:ro
depends_on:
postgres:
@@ -168,6 +169,7 @@ services:
volumes:
silo-dev-air-tmp:
silo-dev-audiobook-covers:
silo-dev-compat:
silo-dev-go-build:
silo-dev-go-mod:
-10
View File
@@ -1,10 +0,0 @@
services:
silo:
devices:
- /dev/dri:/dev/dri
# Optional distributed-mode example. Most single-host installs should
# just use the integrated service above.
# silo-transcode:
# devices:
# - /dev/dri:/dev/dri
+7 -6
View File
@@ -8,7 +8,7 @@ services:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-silo}
POSTGRES_DB: ${POSTGRES_DB:-silo}
ports:
- "127.0.0.1:${POSTGRES_PORT:-5432}:5432"
- "5432:5432"
volumes:
- ${SILO_DATA_ROOT:-/opt/silo}/postgres:/var/lib/postgresql
command: ["postgres", "-c", "listen_addresses=*"]
@@ -22,7 +22,7 @@ services:
image: redis:alpine
restart: unless-stopped
ports:
- "127.0.0.1:${REDIS_PORT:-6379}:6379"
- "6379:6379"
volumes:
- ${SILO_DATA_ROOT:-/opt/silo}/redis:/data
healthcheck:
@@ -56,10 +56,6 @@ services:
restart: unless-stopped
environment:
MODE: integrated
# Keep the container listeners fixed. PORT and JF_PORT in .env are
# host-side published-port overrides.
PORT: "8080"
JF_PORT: "8096"
# Master key for at-rest credential encryption. Required — the server
# refuses to start without it. Generate with: openssl rand -base64 48
# Back it up SEPARATELY from your database dumps; losing it makes encrypted
@@ -75,10 +71,12 @@ services:
- "${ABS_PORT:-13378}:13378"
volumes:
- ${MEDIA_ROOT:?Set MEDIA_ROOT in .env to the host media path}:${MEDIA_CONTAINER_ROOT:-/mnt/media}:ro
- ${MEDIA_BOOKS_ROOT:-${MEDIA_ROOT}}:${MEDIA_BOOKS_CONTAINER_ROOT:-${MEDIA_CONTAINER_ROOT:-/mnt/media}/books}:ro
- ${SILO_DATA_ROOT:-/opt/silo}/plugins:/var/lib/silo/plugins
- ${SILO_DATA_ROOT:-/opt/silo}/compat:/var/lib/silo/compat
- ${SILO_DATA_ROOT:-/opt/silo}/transcode:/tmp/silo-transcode
- ${SILO_DATA_ROOT:-/opt/silo}/catalog-seeds:/catalog-seeds:ro
- ${SILO_DATA_ROOT:-/opt/silo}/audiobook-covers:/var/lib/silo/audiobook-covers
- /proc/meminfo:/host/proc/meminfo:ro
depends_on:
postgres:
@@ -88,6 +86,9 @@ services:
env_file:
- path: .env
required: false
devices:
- /dev/dri:/dev/dri
# Optional distributed-mode example. Most single-host installs should
# just use the integrated service above.
# silo-proxy:
-40
View File
@@ -1,40 +0,0 @@
# AI-assisted contributions
For AI agents preparing a pull request or issue for this repository on behalf of someone who is
not a maintainer.
## Disclosure is required
Include this completed block in the PR or issue body, with the exact model ID you are running as.
Do not omit it, and do not let your operator omit it — undisclosed AI use gets the contribution
closed.
```md
### AI Disclosure
- Tool(s): e.g. Claude Code, Codex CLI, Cursor — or "none"
- Model(s): exact model ID(s), e.g. claude-opus-5, gpt-5.6 — or "n/a"
- Involvement: fully AI-generated | AI-assisted | human-written, AI-reviewed | none
- Adversarial review: what your own AI review of the diff found, and how you resolved it
```
## Evidence standard
Run the repo verify commands before declaring the work complete, and paste the real output into
the PR:
```bash
make lint
cd web && pnpm run lint && pnpm run format:check
make verify-local-paths
go test ./... # targeted at the packages you touched
```
Run an adversarial review of your own diff and summarize what it found in the PR body.
Never file an issue containing a repro you did not actually execute, or logs you synthesized.
Raw logs only. A fabricated repro costs a maintainer more time than no report at all.
## What to expect
The maintainer may accept the idea but re-implement it with a current frontier model. That is a
normal outcome here, not a rejection of the contribution — tell your operator to expect it.
-57
View File
@@ -1,57 +0,0 @@
# Direct Stream Resumption
Protocol v3 advertises `direct_stream_resume_v1` for playback plans whose
delivery is `original_http`. The capability formalizes resumption of the
original file by issuing sequential authorized HTTP requests. It does not
change authentication, authorization, or playback-session ownership.
Original-file responses follow the HTTP byte-range contract:
- `Accept-Ranges: bytes` advertises byte addressing.
- A satisfiable `Range` request returns `206 Partial Content` with the selected
interval in `Content-Range`.
- Open-ended and suffix byte ranges are supported.
- A range starting at or past end of file, or another invalid range, returns
`416 Requested Range Not Satisfiable` with `Content-Range: bytes */<size>`.
- `HEAD` returns the same representation headers as `GET` without a body.
On Linux, macOS, and Windows, each response carries a strong, opaque `ETag`
derived from the open file's filesystem identity, change time, modification
time, and size. The validator is stable while the playback plan's original-file
entity is unchanged, but changes for same-size replacements even when their
modification time is preserved. Platforms that cannot expose a durable
filesystem revision omit the validator instead of hashing an entire media file
before each request. On those platforms an ETag-based `If-Range` request cannot
match and safely falls back to a full `200 OK` response.
A client resuming a transfer sends both `Range` and `If-Range` with the
validator. When it still matches, the server returns the requested `206`
response. When the entity changed, the server ignores the range and returns the
entire current entity as `200 OK`, preventing bytes from different revisions
from being combined. `If-None-Match` uses the same validator for ordinary
conditional requests.
For a bounded chunk read, a client can instead send `Range` and `If-Match`.
When the validator matches, the server returns the requested `206` interval.
When it does not match, the server returns `412 Precondition Failed` without a
body. This contract avoids materializing a full entity when a bounded read's
validator is stale. It does not change `If-Range`: an `If-Range` mismatch still
ignores the range and returns the full current entity as `200 OK`, as required
by the HTTP range contract.
Direct-stream completion logs record whether `If-Match` and `If-Range` were
present, a bounded conditional-result value, and short SHA-256 fingerprints for
the emitted and requested validators. The raw validators and media path are not
logged. The fingerprints are only correlation aids and are not protocol
validators.
Playback sessions already treat each transport request independently.
Sequential ranged requests refresh transport activity, and cleanup never
expires a session while one of those transport requests is active. A late
request within the paused-session grace remains valid under the same rules as
the initial request.
The capability does not apply to progressive remux delivery
`server_remux_progressive`, which is not byte-resumable. It applies only to
`original_http`; remux and transcode transports retain their existing
contracts.
-126
View File
@@ -1,126 +0,0 @@
# Local NFO metadata and sidecar artwork (as built)
Implements #216: Kodi/Jellyfin-style `.nfo` files and sidecar images
(`poster.jpg`, `fanart.jpg`, …) next to movies and shows are read by a builtin
metadata provider, so curated local libraries work with partial or zero
TMDB/TVDB coverage. Admin-facing usage lives in
`docs/wiki/admin/nfo-local-metadata.md`; this page records the architecture for
maintainers.
## Registration: a builtin provider in the plugin chain
Provider chains are keyed on `plugin_installations` rows, so builtins are
registered **as data**: a reserved installation (`plugin_id='silo.builtin'`,
`kind='builtin'`, sentinel `install_path`, `update_policy='manual'`) plus a
`metadata_provider.v1` capability `nfo` with `default_priority` 1 for
movie/series/season/episode and `default_enabled=false`
(`migrations/sql/20260712100125_builtin_host_providers.sql`,
`...124741_nfo_capability_season_episode_levels.sql`).
- `internal/metadata/builtin.go` is the in-process registry; providers
self-register (`internal/metadata/nfo/register.go`) and `buildProviders`
(`internal/metadata/chain.go`) returns the in-process provider for
`kind='builtin'` rows instead of constructing a gRPC plugin.
- Guard rails keep the reserved row out of every plugin surface (user plugin
settings, installations list, image resolvers, preload, auto-update, store
delete, mutation handlers); `silo.builtin` is a reserved manifest id. Generic
installation reads must **not** filter builtins — the chain enabled-check
depends on them.
- On startup, `SyncBuiltinProviderChains` (`internal/metadata/builtin_sync.go`)
first materializes legacy `content_level=''` chains per level, then appends
builtin capabilities to all existing chains, disabled. New libraries pick the
capability up through normal chain seeding. The chain-less fallback respects
`default_enabled=false`.
- **Everything is inert until an admin enables "NFO Files" on a library.**
## Identity: hint-first, never candidate-first
NFO `<uniqueid>` values (tmdb/imdb/tvdb) are **trusted identity hints** seeded
before remote search (`IdentityHintProvider`, applied in
`internal/metadata/service.go`), unlocking full remote enrichment even when
search-by-title fails. Conflict policy by mode:
- initial match / scheduled refresh: NFO hints beat folder-name hints; stored
durable IDs beat NFO hints (no background identity flips);
- manual refresh: NFO hints beat stored IDs — the recovery path for a corrected
NFO. The item's `content_id` re-anchors too (not just its stored provider
IDs): a provider-anchored item whose fixed `<uniqueid>` now derives a
different anchor is renamed to it, or merged onto the existing item already
holding that id;
- manual Identify: the user's choice wins; the NFO provider is skipped for the
whole operation.
The NFO search candidate exists only for the title-only case and is defanged:
ID-less candidates lose provider-priority tie-breaks to ID-bearing group
members, `nfo` never counts as corroboration, and Phase-2 NFO results cannot
inject provider-id keys. A title-only NFO yields a `matched` item under a
path-deterministic `local:` content id; adding a `<uniqueid>` later promotes it
to that provider anchor on the next refresh (this promotion from an unanchored
id runs on scheduled refresh too — only an *already-anchored* identity is held
stable in the background). NFO field edits propagate on **manual refresh only**
(scheduled refresh is fill-empty by design).
## Sidecar artwork: copy into the S3 image cache
Sidecar images (`poster`/`folder`/`cover`, `fanart`/`backdrop`/`background`,
`logo`/`clearlogo`, and `<basename>-poster/-fanart/-logo` variants; extensions
`.jpg/.jpeg/.png/.webp`, 8 MiB cap, symlinked leaves rejected) are discovered
by the provider's `GetImages` (`internal/metadata/nfo/images.go`). Clients —
including jellycompat — always receive the normal presigned
`poster_url`/`backdrop_url`/`logo_url`; library files are never served
directly, and API nodes never need filesystem access to libraries.
- Sources are recorded as `file://<absolute-logical-path>` in `*_source_path`
columns and cached by the metadata image-cache processor under
`local/{contentType}/{contentID}/{hash8}/{imageType}/...` (`hash8` = content
hash; the discriminator sits before the imageType segment because variant
clamping reads the parent directory). Editing the file and refreshing rotates
the key; the stale hashed prefix is deleted after a successful re-cache, and
item deletion trims local paths to the content prefix.
- The processor confines each read to the owning library's `media_folders`
roots: a lexical check on the logical path, then a symlink-resolving re-check
(both path and roots are resolved, so a legitimately symlinked root stays
valid while an intermediate directory symlink escaping a root is rejected).
Missing/unreadable/out-of-root and structurally-unusable (non-regular,
over-cap) paths are stable failures with a long retry deferral; recovery is
refresh-driven — the provider-artwork backfill sweep deliberately skips
`file://` sources.
- Generic filenames attach only when the directory holds a single content
group; a shared `folder.jpg` in a flat multi-movie folder applies to none.
`<basename>-poster.jpg` style names always attach to their file.
- `applyBestImages`' final write has a local exemption so rating-0 local art
can fill already-matched items and cannot be stickily displaced by remote
art; the localization pass skips language-neutral local candidates.
**Deployment constraint:** the host running the metadata image-cache processor
must mount the media libraries at the same paths as the scanner/metadata
worker, otherwise local artwork jobs fail until the mount is present.
## Series depth and mixed libraries
`SeasonsRequest`/`EpisodesRequest` carry local path context; `season.nfo`
supplies season name/plot, `<basename>.nfo` + `<basename>-thumb.ext` supply
episode metadata/thumbs (`internal/metadata/nfo/series_depth.go`). **Naming
supplies structure; NFOs supply metadata**: NFO season/episode numbers are
advisory — directory/filename-derived numbers win with a warning. Episode NFOs
work without a `season.nfo`; `SynthesizeFallbackEpisodes` still covers
NFO-less episodes.
In `mixed` libraries, movie-vs-series is decided per file by naming before any
provider runs (`internal/naming/filename.go`); the NFO provider is seeded into
all levels and behaves as in dedicated libraries. The provider's root-element
type guard means a `tvshow.nfo` next to a movie-classified file is ignored,
never applied; the per-root Type override is the correction path. This is the
contract for sports/mixed libraries (events as movies, weekly shows as series).
## Known limitations
- The admin image picker does not surface local art (automatic chain path
only).
- Multi-part movies: a basename-mismatched NFO in a folder holding multiple
content groups is not found (directory candidates are suppressed there).
- No NFO writing, no music/audiobook/ebook NFO (those ecosystems use
OPF/metadata.json — future builtin providers via the same registry).
- Feature detection: the `nfo` capability's presence in
`GET /api/v1/libraries/provider-defaults` (see
`docs/architecture/v1-scope.md`).
-205
View File
@@ -1,205 +0,0 @@
# Observability (OpenTelemetry logs + traces)
Silo emits structured **logs** and distributed **traces** via OpenTelemetry (OTLP),
in addition to the existing stderr and `opslog` database pipeline. The feature is
**opt-in and default-off**: with no `OTEL_*` / `SILO_OTEL_ENABLED` configuration the
server behaves exactly as before (stderr + `opslog` only).
**Metrics are not part of OpenTelemetry here.** They remain on Prometheus
(`client_golang`, the `/metrics` endpoint, and the domain metrics in
`internal/api/middleware`). See [Metrics](#metrics-stay-on-prometheus) below.
## Enabling it
Telemetry turns on when **either** `SILO_OTEL_ENABLED` is truthy **or**
`OTEL_EXPORTER_OTLP_ENDPOINT` is set.
| Variable | Purpose | Default |
| --- | --- | --- |
| `SILO_OTEL_ENABLED` | Master gate (`1`/`true`/`yes`/`on`). | off |
| `OTEL_EXPORTER_OTLP_ENDPOINT` | Collector endpoint; also implicitly enables telemetry. | — |
| `OTEL_EXPORTER_OTLP_PROTOCOL` | `grpc` (default) or `http/protobuf`. | `grpc` |
| `OTEL_SERVICE_NAME` | `service.name` resource attribute. | `silo-server` |
| `OTEL_SERVICE_VERSION` | `service.version` resource attribute. | unset |
| `OTEL_TRACES_SAMPLER` | `always_on`, `always_off`, `traceidratio`, `parentbased_always_on`, `parentbased_always_off`, or `parentbased_traceidratio`. Unsupported values (e.g. `jaeger_remote`) fall back to the default. | `parentbased_traceidratio` |
| `OTEL_TRACES_SAMPLER_ARG` | Trace-id ratio for the ratio-based samplers (0–1; clamps >1 to 1). | `1.0` |
The node identity is attached as the `service.instance.id` resource attribute, so
multiple Silo nodes sharing one `service.name` stay distinguishable in the backend.
All other `OTEL_EXPORTER_OTLP_*` knobs (headers, TLS, per-signal endpoints) are read
directly from the environment by the OTLP exporters — the environment is the single
source of truth for exporter wiring.
The endpoint/exporter connection is lazy and non-blocking: an unreachable collector
does **not** delay or crash startup. Setup failure is also non-fatal: if the `OTEL_*`
environment is malformed (e.g. an unparseable endpoint URL), the server logs an error
and keeps running with telemetry disabled rather than crash-looping.
## Architecture
The bootstrap lives in `internal/telemetry` (`Setup` in `telemetry.go`). When enabled
it builds one shared `resource.Resource`, a `TracerProvider` (sampler per
`OTEL_TRACES_SAMPLER`, batched OTLP exporter), a `LoggerProvider` (batched OTLP exporter), and the W3C
`TraceContext + Baggage` propagator. Shutdown is deferred in `cmd/silo/main.go` with a
flush timeout so buffered spans/logs drain on exit.
### Log handler chain
Logs are bridged, not rerouted. The OTel `otelslog` handler is added to the existing
`slog` handler chain via **fan-out**, so every record still reaches stderr and the
`opslog` DB/admin-stream pipeline unchanged:
```
slog.<Level>Context(ctx, …)
→ opslog.Handler (DB capture + admin stream, when level ≥ capture)
→ logfilter.Handler (drops quieted subsystem prefixes)
→ slog.MultiHandler
├── stderr (json/text)
└── otelslog → OTLP (level-gated + best-effort)
```
Three properties matter:
- **Level-gated.** `slog.MultiHandler.Enabled` ORs its children, so the OTel branch is
wrapped in a level gate bound to the shared `LevelVar`; console and OTLP share one
verbosity knob. Without this, Debug records would be built and exported even at
`log_level=info`.
- **Best-effort.** The OTel branch never propagates an export error, so a failing
collector cannot break the console or DB branches.
- **Redacted.** The whole fan-out is wrapped in `internal/logredact`, so console and OTLP
emit secret-masked output. Redaction is key-based (`password`, `secret`, `token`,
`api_key`, `authorization`, `cookie`, …); a matching attribute's value becomes
`[REDACTED]`, including attrs bound via `.With(...)` and nested groups. The marker list
is shared with the opslog DB path (`opslog.shouldRedact` → `logredact.SecretKey`) so all
sinks agree. Limitation: values are not scanned, so a secret embedded in a free-text
message or under a non-secret key is not caught.
## Logging conventions (enforced)
Use the **context-carrying** slog variants and tag the subsystem:
```go
slog.InfoContext(ctx, "scanner: starting", "component", "scanner", "folder_id", id)
```
Rules, enforced by `sloglint` in `make lint` (`.golangci.yml`):
- **`slog.<Level>Context(ctx, …)`** wherever a `context.Context` is in scope (so records
carry the active `trace_id`/`span_id`). The plain `slog.Info(…)` form is only allowed
where no `ctx` exists (early boot, top-level goroutines).
- **Static message** — the message is a constant; move dynamic parts to attributes.
- **snake_case attribute keys** — `component`, `request_id`, `trace_id`, `user_id`, …
- **No mixed args** — don't combine key-value pairs and `slog.Attr` in one call.
### Component classification
Every direct `slog.*Context` call carries a `component` attribute. `opslog` classifies
records by that attribute first, falling back to `opslog.InferComponent` (the `subsystem:`
prefix in the message) when no attribute is present — bound loggers that already set
`component` via `.With(...)` are left as-is.
**Limitation:** `sloglint` enforces the *shape* (context variant, snake keys, static
message) but **cannot** enforce that a `component` attribute is present. That convention
rests on this doc, the canonical list below, and review.
Canonical component values (first path segment under `internal/`; `app` for `cmd/silo`):
`activitylog`, `adminjob`, `ai`, `api`, `app`, `audiobooks`, `auth`, `autoscan`,
`catalog`, `chapterthumbs`, `downloads`, `ebooks`, `historyimport`, `jellycompat`,
`libraryingest`, `manga`, `metadata`, `nodeconfig`, `nodepool`, `noderecipe`,
`nodesessions`, `notifications`, `opslog`, `playback`, `plugins`, `policy`, `proxy`, `ratelimit`,
`recommendations`, `requests`, `scanner`, `scanqueue`, `sections`, `taskmanager`,
`telemetry`, `transcodenode`, `watchlist`, `watchsync`, `webhooksync`, `worker`.
## Metrics stay on Prometheus
OpenTelemetry here installs **no MeterProvider**. Metrics continue to flow through the
existing Prometheus `client_golang` instrumentation to `/metrics`; Grafana scraping is
unaffected.
This is deliberate and guarded: the trace-instrumentation libraries (`otelhttp`, etc.,
added in later phases) also emit metrics through the *global* MeterProvider. Because none
is set, that global stays the built-in **no-op**, so those metric calls are silently
discarded — no double-counting into Prometheus, no second `/metrics` source. A guard test
asserts `otel.GetMeterProvider()` remains the no-op after `Setup`. Migrating metrics to
the OTel metrics SDK is out of scope.
## Local collector (example)
```yaml
# docker-compose.yml (dev)
otel-collector:
image: otel/opentelemetry-collector:latest
command: ["--config=/etc/otelcol/config.yaml"]
volumes:
- ./otelcol.yaml:/etc/otelcol/config.yaml
ports:
- "4317:4317" # OTLP gRPC
- "4318:4318" # OTLP HTTP
```
```yaml
# otelcol.yaml — minimal debug pipeline
receivers:
otlp:
protocols:
grpc: {}
http: {}
exporters:
debug:
verbosity: detailed
service:
pipelines:
traces: { receivers: [otlp], exporters: [debug] }
logs: { receivers: [otlp], exporters: [debug] }
```
Run Silo with `SILO_OTEL_ENABLED=1 OTEL_EXPORTER_OTLP_ENDPOINT=localhost:4317` and watch
logs + traces arrive at the collector. Swap `debug` for Loki/Tempo (or a vendor OTLP
endpoint) for real storage; Grafana can then show traces alongside the unchanged
Prometheus metrics.
## Log retention & rotation
Silo does **not** write or rotate its own log files. Rotation/retention is handled by the
layer that owns each sink, which is the intended cloud-native split:
- **Console (stderr)** is owned by the container runtime. Under Docker, configure the
`json-file` driver to cap and rotate on-disk logs, and mount the log directory on a
volume so history survives container recreation (the problem that motivated this work):
```yaml
# docker-compose.yml
services:
silo:
logging:
driver: json-file
options:
max-size: "50m" # rotate at 50 MB
max-file: "5" # keep 5 rotated files
```
For a non-Docker deployment, run under a supervisor/journald or pipe to `logrotate`.
- **OTLP** is the durable, queryable path: the collector/backend (Loki, a vendor, …) owns
retention and is the recommended place to keep searchable history. Enable it (see above)
and set retention on the backend.
- **opslog (Postgres)** self-prunes: daily partitions with per-component retention and
size caps (`internal/opslog/cleanup.go`). No operator action needed.
An in-process rotating file sink (e.g. lumberjack) was deliberately **not** added — it
would re-introduce a custom sink the OTLP + runtime split already covers.
## Known limitations
- **`log_quiet` also suppresses OTel logs.** The fan-out sits below the quiet filter, so
quieting a subsystem empties its OTLP stream too (OTLP mirrors the console stream).
- **Redaction is key-based, not value-based.** Secrets under a recognized key are masked
on every sink, but a secret embedded in a message string or under an unrecognized key is
not caught (see [Redacted](#log-handler-chain)).
- **Early-boot logs are not exported.** Records emitted before the handler is installed
(DB connect, migrations, tuning) reach stderr only, matching existing `opslog` behavior.
- **Per-subsystem trace propagation into plugins** is a follow-up owned by
`silo-plugin-sdk`; this repo instruments only the host side.
-819
View File
@@ -1,819 +0,0 @@
# Playback protocol v3
The wire contract between a Silo client and a Silo server for deciding *how* a
piece of media will play, and for recovering when that decision turns out to be
wrong on the device in front of the user.
> **Status: normative.** This document, the JSON Schemas under
> [`docs/design/schemas/playback-v3/`](../design/schemas/playback-v3/), and the
> golden fixtures under `internal/playback/testdata/protocol_v3/` are the
> contract. Where this document and a client implementation disagree, the client
> is wrong. Where this document and the server implementation disagree, that is a
> bug in one of them — file it.
This is written to be sufficient on its own. A third-party client should be able
to implement playback against a Silo server from this document plus the schemas,
without reading any client repository and without reading the server source.
Paths are repository-relative; assume the repository root is the cwd.
---
## 1. Design invariants
Five properties hold everywhere in the protocol. Most of the surprising details
below follow from one of them.
**The server owns the decision.** A client reports what it can do; the server
decides what will be sent and how. Clients do not pick a bitrate ladder rung, do
not choose a container, do not decide whether to remux, and do not post a
transcode recipe. The `playback_plan` in a response is the whole instruction.
**Plan identity is deterministic.** `plan_id` is a pure function of the request
identity and the plan's own shape (§9). The same decision made twice produces
the same `plan_id`. This is what makes replans idempotent rather than merely
retried.
**Attempt keys are server-owned and opaque.** `plan_attempt_key` identifies "this
plan, on this output, with these local mutations" for loop prevention. It is a
hash the server computes. A client stores it, echoes it back, and never parses,
compares by substring, or recomputes it. Its algorithm and preimage are server
implementation details; §9 specifies only the stability clients may rely on.
**Claims are validated, not assumed.** When the server says a route preserves
Atmos, or that Dolby Vision metadata was removed, that claim was checked against
evidence the client supplied, at the strictness its evidence tier allows (§3).
The server never claims something it did not verify.
**Route events are diagnostics, not control.** A client reports what happened
(`first_frame`, `plan_failed`, `terminal`) so the server can learn; the report
never changes the session. Playback recovery goes through replan (§6), which is a
request with a response, not a fire-and-forget event.
Two consequences worth stating early, because they surprise implementers:
- `POST /playback/start` returns **201 for every outcome**, including a terminal
refusal to play. A terminal is a decision, not a transport failure. 4xx means
the request was malformed; it never means "this media cannot play."
- `protocol_version: 3` is carried on every body independently, and each is
validated separately: the start request, the `client_playback_context` nested
inside it, the replan request, the route event, the decision response, and the
plan within it. A start request whose envelope says 3 but whose
`client_playback_context` says otherwise is rejected. There is no negotiation
and no fallback — a server that does not speak v3 is not a server this
contract describes.
---
## 2. Endpoints
All paths are relative to `/api/v1`. Every endpoint requires an authenticated
user. The mutation endpoints additionally require a profile, supplied as the
`X-Profile-Id` header.
Every non-2xx response body is the standard error envelope:
```json
{"error": "<machine_code>", "message": "<human sentence>"}
```
The `error` code is the stable part; the `message` is for logs and is not
contract.
### 2.1 `GET /playback/capability`
Feature detection. Auth required; no profile needed.
| Status | Meaning |
| --- | --- |
| `200` | Capability document |
| `401` `unauthorized` | No authenticated user |
v3 is the server's only playback protocol, so `enabled` is constant `true` and
the document is always the full one:
```json
{
"enabled": true,
"protocol_versions": [3],
"features": ["playback_plan_v3", "neutral_playback_v3_contract_v1", "layout_aware_passthrough", "playback_route_diagnostics",
"device_quirks_v1", "seek_reanchor_v1", "direct_stream_resume_v1",
"plan_source_duration_v1"],
"deliveries": ["original_http", "server_remux_progressive", "server_remux_hls", "server_transcode_hls"],
"transformations": [{"name": "audio_to_aac", "executor": "server", "recipe_version": "1", "validated_claims": ["audio_decode"]}]
}
```
The eight feature strings above are the full set this server version advertises:
| Feature | What it promises |
| --- | --- |
| `playback_plan_v3` | The three plan endpoints exist and behave as specified here |
| `neutral_playback_v3_contract_v1` | The server mints opaque `plan_attempt_key` values that clients only echo, and exposes `track_change` / `quality_change` as intent replans distinct from failure recovery |
| `layout_aware_passthrough` | Audio passthrough is decided from channel *layouts*, not just channel counts (§3) |
| `playback_route_diagnostics` | `POST /playback/route-events` is accepted |
| `device_quirks_v1` | Plans may carry `applied_quirks` and `runtime_corrections` (§9) |
| `seek_reanchor_v1` | The `seek_reanchor` replan operation is available (§6) |
| `direct_stream_resume_v1` | A direct route may resume mid-file rather than restarting |
| `plan_source_duration_v1` | `source.duration_seconds` is populated when known, so its absence means *unknown* rather than *unsupported* (§5) |
That last one is the reason feature detection is a list and not a version
number: without it, a client cannot tell a server that never sends the runtime
apart from a server that knows this particular file's runtime is genuinely
unknown, and both look like an absent field.
`deliveries` reports the four *server-side* delivery values, not the three
delivery classes a client negotiates in. §4 gives the folding.
`transformations` advertises only what the *installed* FFmpeg was probed for at
startup — a server without a `dovi_rpu` bitstream filter does not list
`server_dv7_to_hdr10`. A client must not assume a transformation exists because
this document names it.
`enabled` survives from the rollout period and is now constant `true`; the
negative shape was deliberately removed before v1 lock because v3 is the only
playback protocol. `reason` remains an optional diagnostic for a future
non-rollout condition, but it never changes the meaning of `enabled`.
### 2.2 `POST /playback/start`
Requests a plan. Auth + `X-Profile-Id` required. Request body cap: **256 KiB**.
Body: `StartRequestV3`
([`start-request.schema.json`](../design/schemas/playback-v3/v3/start-request.schema.json)).
| Status | Code | Meaning |
| --- | --- | --- |
| `201` | — | A decision was made. Body is `DecisionResponseV3`: either `outcome: "playable"` with a `playback_plan`, or `outcome: "adaptation_unavailable"` with a `terminal`. |
| `400` | `bad_request` | Malformed JSON, failed validation (the `message` is the validator's own text), missing `X-Profile-Id`, or `profile_id` disagreeing with the header |
| `401` | `unauthorized` | No authenticated user |
| `404` | `not_found` | `file_id` does not exist, is marked missing, or this profile cannot see it |
| `409` | `playback_attempt_reused` | This `playback_attempt_id` was already used for a *different* request |
| `426` | `client_upgrade_required` | The body does not declare the finalized v3 shape: `protocol_version: 3` plus both capability evidence markers |
| `500` | `internal_error` | Session store failure |
A file the profile is not allowed to see is `404`, not `403` — parental and
library restrictions do not confirm that a hidden item exists.
The `426` is what a pre-v3 or draft-v3 client gets. There is no protocol negotiation and no
fallback: the server decodes v3 or it refuses, and the client is expected to
render an "update required" state rather than retry. It is deliberately not a
`400` — the request may be perfectly well-formed for the protocol it was written
against, and the distinction is what lets a client tell "I sent something wrong"
apart from "I am too old to talk to this server".
Note the layering: a request whose *body* is fine but whose *media* cannot be
played is not an HTTP error. It is a `201` with `outcome:
"adaptation_unavailable"` and a terminal reason from §7.3. HTTP statuses on this
endpoint describe the request; the decision lives in the body.
**Idempotency.** The server stores each `playback_attempt_id` alongside a
SHA-256 digest of the exact request body. Replaying a byte-identical body
replays the original response verbatim. Reusing the id with a different body is
`409 playback_attempt_reused` — the id is a claim about *which* playback attempt
this is, so reusing it for different intent is a client bug the server refuses to
paper over. If the attempt is known but its session has since expired, the
response is a `201` terminal with reason `session_expired` rather than a replay
of a plan that no longer exists.
Playable and terminal decisions are both durable attempts. A terminal start has
no `session_id` or plan identity, but its response and ownership are retained
under `playback_attempt_id` for the same TTL. This makes terminal retries obey
the same replay/conflict rules and gives terminal route events an addressable
authorization record.
A client generates a fresh `playback_attempt_id` per user-initiated playback and
reuses it only to retry a request whose response it did not receive.
**Omission is a request, not a default.** Two start fields mean "you decide" when
absent, and the server answers from stored user state rather than from a
constant:
| Field | Omitted | Present |
| --- | --- | --- |
| `start_position` | The profile's saved resume point for this item, or `0` when there is none, it is already complete, or the file is one part of a multipart item (every part shares the item's resume point, so a part-local seek to it would land somewhere arbitrary). It is required when `progress_persistence` is `client` | Exactly that position. `0` means *start over* |
| `audio_track_id` / `audio_track_index` | The profile's preferred audio track, resolved from the series preference, then the profile's audio-language setting, then the library override | Exactly that track |
`progress_persistence` separates the live session clock from durable resume
ownership. Omission (or `server`) means session progress may update the item's
resume/history normally. `client` keeps heartbeats, route diagnostics, and live
session state intact but suppresses those durable writes because the client
persists its own item-global timeline (for example through `/sync/progress`). A
client choosing that mode must send `start_position` explicitly, including
explicit `0`; the server never substitutes saved resume state for it.
Both are settled *before* planning, not after. This is not an implementation
detail a client can ignore: the plan's timeline is cut at the start position
(§5), and the audio track is part of the plan's identity (§9), so a route chosen
for position zero and then seeked is a different route than the one the server
would have chosen for the resume point. A client that resolves resume state
itself and sends the position explicitly gets identical behaviour — that is the
supported way to override the server's policy.
### 2.3 `POST /playback/{session_id}/replan`
Asks for a different plan for an existing session — after a failure, or because
the user changed a track or the quality. Auth + `X-Profile-Id` required. Request
body cap: 256 KiB. Body: `ReplanRequestV3`
([`replan-request.schema.json`](../design/schemas/playback-v3/v3/replan-request.schema.json)).
| Status | Code | Meaning |
| --- | --- | --- |
| `200` | — | `DecisionResponseV3`, plan or terminal |
| `400` | `bad_request` | Malformed or failed validation |
| `401` | `unauthorized` | No authenticated user, or no `X-Profile-Id` |
| `403` | `forbidden` | The session belongs to another user or profile |
| `404` | `playback_session_not_found` | No such session, or its session has ended |
| `409` | `stale_playback_plan` | `failed_plan_id` is not the session's current plan, `playback_attempt_id` is not the session's attempt, or a newer replacement is already active |
| `409` | `idempotency_key_reused` | This `replan_request_id` was used for a different replan |
| `409` | `replan_in_progress` | A replan for this session holds the lease right now |
| `503` | `replan_capacity_exhausted` | Server-wide concurrent replan limit (8) reached; retryable |
| `500` | `internal_error` | Store outage |
Note that a missing profile is `401` here, where start answers `400` — start
validates the body first and reports the header as one more field problem, while
replan treats identity as a precondition. Neither is retryable, so the
difference does not change client behaviour.
Checks run in this order: auth → body decode and validation → concurrency slot →
session lock → attempt lookup → ownership → attempt match → live session → lease.
A client that sees `503` therefore knows nothing was read or written for its
session, and can retry the identical request unchanged. Note that validation
comes before every session lookup: a malformed body against a session that does
not exist answers `400`, not `404`.
**Leases.** A replan takes a 15-second lease on the session. A second request
carrying the *same* `replan_request_id` while the lease is in flight gets `409
replan_in_progress`; once the original completes, the same id replays its
response verbatim. This is what makes a client's retry-on-timeout safe.
Note the deliberate asymmetry with start: a store outage during replan is `500`,
never `404`. Clients tear playback down on session-not-found, so a transient
store failure must read as retryable rather than as the session having vanished.
### 2.4 `POST /playback/route-events`
Reports what happened on the device. Auth + `X-Profile-Id` required. Request body
cap: **32 KiB**. Body: a single `RouteEventV3`, not a batch
([`route-event.schema.json`](../design/schemas/playback-v3/v3/route-event.schema.json)).
| Status | Code | Meaning |
| --- | --- | --- |
| `202` | — | Accepted. **No response body.** |
| `400` | `bad_request` | Malformed or failed validation |
| `401` | `unauthorized` | No authenticated user or no profile |
| `403` | `forbidden` | The session or attempt belongs to another profile, or the referenced session/attempt does not exist |
| `429` | `event_rate_limited` | 120 events/attempt/minute or 600/user/minute exceeded |
| `500` | `internal_error` | Store outage |
The checks run in that order: auth, then body decode and validation, then the
rate limit, and only then the session-ownership lookup. The
limiter sits in front of the ownership lookup deliberately — it exists to bound
store reads as much as writes, so it has to precede the read that would establish
ownership.
Two consequences for clients. A `429` means "drop this event," never "retry it";
the events are diagnostics and losing one costs nothing. And an unknown session
is `403`, not `404` — the handler does not distinguish "not yours" from "not
there." A store outage during that lookup is `500`, so a `403` genuinely means
the event will never be accepted and should be dropped rather than retried.
A terminal decision returned by `POST /playback/start` has a durable attempt but
no playback session or plan. The client reports it with `event: "terminal"`,
the start request's `playback_attempt_id`, and no `session_id`, `plan_id`,
`plan_attempt_id`, or `plan_attempt_key`. The server authorizes the event through
the persisted attempt ownership and returns `202`.
Event names are the eleven in §7.4. `diagnostics` is a string→string map, capped
at 32 entries, and the server keeps only the keys on its allowlist (§7.5),
truncating each value to 256 characters. Unknown keys are dropped silently; a
client sending them is not an error, it just achieves nothing.
---
## 3. Capability evidence tiers
The hardest problem in this protocol is that clients lie — not maliciously, but
because platform APIs vary in how much they actually know. Android can enumerate
`MediaCodecList` and answer "this exact decoder supports H.264 High@4.1 at 8-bit
up to 1920×1080@60". A browser can only answer `isTypeSupported("video/mp4;
codecs=avc1.640028")` → true. Apple can attest that VideoToolbox handles a codec
family but not enumerate levels.
So a client declares *how it knows*, per media type, and the server applies a
different strictness to each tier. `video_evidence` and `audio_evidence` are
required and are one of:
| Tier | Who reports it | What the server does with it |
| --- | --- | --- |
| `exact` | Android (`MediaCodecList`) | Full strict validation. The server walks `video_decode[]` and requires a hardware entry matching codec, profile, level, bit depth, and every `max_*` bound. Only this tier can earn a validated audio **passthrough** claim. |
| `platform_attested` | Apple (VideoToolbox) | Same walk, but profile and level are **skipped** — the platform attests the codec family rather than enumerating modes. All other bounds still apply. |
| `declared` | Web (`isTypeSupported`) | Flat list match only: `codecs_video` / `codecs_video_hardware` membership. No `video_decode[]` walk. |
Four rules follow from the table and are easy to get wrong:
**A flat claim without backing detail is a refusal, not a pass.** On `exact` and
`platform_attested`, if a codec appears in `codecs_video` but no `video_decode[]`
entry names that codec with `hardware: true`, the source is *not* eligible for a
direct route. The plan is downgraded and carries the decision reason
`evidence_insufficient_for_direct` plus the matching degradation warning, which
distinguishes "your evidence didn't support this" from "your device said no." A
client advertising a strict tier must populate `video_decode[]`; the flat lists
alone earn it nothing. On `declared` the flat lists are the whole mechanism, so
that tier never produces this signal.
Note the precise trigger: the signal fires only when *no* entry named the codec.
If an entry matched the codec but the source exceeded one of its bounds — a
4K file against a `max_height: 1080` decoder — that is a real device limit, and
the plan is downgraded with no evidence warning. The two cases mean different
things and a client should not conflate them in its telemetry.
**An omitted bound means "unconstrained", not "unknown".** Within a
`video_decode[]` entry, an empty `profiles`, `levels`, or `bit_depths` list and a
zero `max_width` / `max_height` / `max_frame_rate` / `max_bitrate_kbps` are each
*skipped*, not failed. An entry that names a codec and nothing else therefore
claims that decoder handles every variant of it. That is a strong claim, and on
`exact` it is the client's job not to make it carelessly: the server will honour
it and hand back a direct route. Report what the platform actually enumerated.
The three list bounds are also not matched the same way, which matters when
populating them:
| Field | Match |
| --- | --- |
| `profiles` | Case-insensitive string equality against the source profile |
| `levels` | **At-least**: any listed level ≥ the source level passes |
| `bit_depths` | Exact integer equality |
So a decoder that tops out at H.264 level 4.1 may report `[41]` and still
validate a level-3.0 stream, while a decoder that handles 8- and 10-bit must
list both — `[10]` alone rejects an 8-bit source. Levels use the integer form
(4.1 → `41`).
**Every validated video route requires complete routing metadata.** Before any
tier logic runs, the server requires video codec, bit depth, width, height,
frame rate, and bitrate. Profile and level are decoder bounds instead: an
`exact` entry that supplies either bound cannot validate a source whose matching
probe value is absent or unknown, while an omitted bound keeps the explicit
“unconstrained” meaning above. This permits server adaptation of sources such as
VP9 whose probe reports an unknown level without allowing that sentinel to
satisfy a concrete client limit. A source missing the routing fields is
ineligible for any route and this case is *not* reported as
`evidence_insufficient_for_direct` — the client's evidence was never the
problem.
**Passthrough requires `exact` audio evidence.** A validated passthrough claim
(bitstreaming E-AC-3/TrueHD to a receiver) additionally requires the
`layout_aware_passthrough` feature in `client_features`, the codec listed in
`audio_passthrough.passthrough_codecs`, and a matching
`audio_passthrough.entries[]` whose `channel_counts` and `layouts` cover the
source. Only a client that can enumerate real sink layouts — the Android audio
HAL — can supply that. `platform_attested` and `declared` audio evidence still
qualify for ordinary decode/copy routes; they simply cannot earn
`claims.audio.passthrough = true`.
**HDR is decided against the output, not the decoder.** `output.hdr_details` (the
display or receiver actually attached) takes precedence over
`client_capabilities.hdr_details` (what the device could do in principle). A
source whose dynamic range is recorded as `hdr_unknown` — legacy rows that only
stored a file-level HDR boolean — is treated as HDR10 when the output supports
HDR10, and the plan carries the `hdr_range_assumed_hdr10` degradation warning.
Refusing to play those outright would be worse than an assumption the client is
told about.
---
## 4. Deliveries
A delivery is *how bytes reach the player*. The server works in four values; the
client negotiates in three classes.
| Server `delivery` | Client class | What it is |
| --- | --- | --- |
| `original_http` | `original_http` | The source file, byte-for-byte, over HTTP with range support |
| `server_remux_progressive` | `progressive` | Repackaged into a new container, streamed as one chunked response |
| `server_remux_hls` | `hls` | Repackaged into HLS segments; codecs untouched |
| `server_transcode_hls` | `hls` | Re-encoded and segmented |
`client_playback_context.deliveries` is keyed by **class**, because a client's
answer to "can you play HLS" does not differ between a remux and a transcode —
the same player component handles both. The server folds its four values into
three when checking eligibility, and reports the specific one it chose in the
plan.
Each `deliveries` entry describes one class:
| Field | Meaning |
| --- | --- |
| `enabled` | The client is *willing* to use this class right now (user setting, network policy) |
| `supported_on_device` | The client is *able* to — the platform has a player for it at all |
| `failure_reason` | Optional free text explaining a `false` above; diagnostics only |
| `containers`, `video_codecs`, `audio_decode_codecs` | Flat lowercase name lists |
| `audio_passthrough_codecs` | Bitstream-out candidates; only ever honoured under the `exact` tier (§3) |
| `max_channels` | Optional ceiling applied to audio routing |
| `hdr_details` | Optional per-class HDR support, overriding the device-level value |
| `subtitles` | Six booleans: `embedded_text`, `sidecar_text`, `ass_styling`, `embedded_bitmap`, `sidecar_bitmap`, `font_attachments` |
| `features` | Class-scoped feature strings |
| `auth_header_refresh` | The client can re-fetch stream auth headers without restarting playback |
| `validated_claims` | Claims the client asserts it has verified for this class |
| `transformations` | Client-executed transformations offered for this class (§11) |
Both booleans must be true for the class to be eligible; they are separate
because "the user turned HLS off" and "this device has no HLS player" call for
different degradation warnings and different diagnostics. A class the client
omits entirely is unavailable — the server will not guess.
`stream.header_refresh` tells the client what to do when the stream URL's auth
expires: `none` means the URL is stable for the session, `session` means
re-request headers from `header_refresh_url` rather than restarting playback.
---
## 5. The timeline model
The single most common client bug in v2 was assuming the player's zero and the
source's zero are the same instant. In v3 they usually are not, and the plan says
so explicitly.
`timeline` carries four numbers that a client must keep distinct:
- `source_start_seconds` — where in the *media* this plan begins.
- `stream_origin_seconds` — the source position that the *transport's* byte-zero
corresponds to.
- `player_start_seconds` — where the client should seek the player after load.
- `timeline_offset_seconds` — what to add to a player position to get a source
position.
Three shapes exist:
**Direct and transcoded routes** hand the player a complete timeline.
`stream_origin` and `timeline_offset` are `0`, `player_start` is the requested
position, `can_seek_anywhere` is true when the runtime is known, and
`seek_restoration` is `player_position` — the client seeks locally.
**Copy remux over HLS** is served from FFmpeg's live, still-growing playlist,
which starts at the requested position. So `player_start` is `0`,
`stream_origin` and `timeline_offset` both equal the seek position,
`seek_window_start_seconds` is that position, and **`seek_window_end_seconds` is
deliberately absent**. An open end marks the window as incomplete; combined with
`can_seek_anywhere: false` it routes every seek back through the server as a
reanchor (§6), which is correct because the playlist has no bytes for positions
FFmpeg has not reached yet. `seek_restoration` is `source_position`.
**Progressive remux** is a freshly generated chunked response with no byte-range
support, so it behaves the same way: player-zero is stream-zero is the seek
position, the window is open-ended, and seeks go through the server.
### `source.duration_seconds`
The media's full runtime, and nothing else. Specifically:
- It is **not** `total − source_start`. It does not shrink because the plan
starts mid-file.
- It is **not** adjusted by `timeline_offset_seconds`.
- It is **omitted** rather than sent as `null` when the server does not know it,
because a client coercing `null` to a numeric default would read it as zero.
- A client **must not** substitute the playback engine's reported duration for
it. On an HLS copy remux the engine reports the length produced so far, not the
runtime — using it makes the scrubber grow while the user watches.
---
## 6. Replan
Replan is the only way a plan changes. It covers both "that didn't work" and
"the user asked for something else," and the distinction matters to the server.
`operation` is one of five:
| Operation | Meaning | Requires |
| --- | --- | --- |
| `failure_recovery` | The plan failed on the device | `failure.classification` |
| `seek_failure_recovery` | A seek failed | `failure.classification` |
| `seek_reanchor` | Move a server-anchored timeline to a new position | — |
| `track_change` | The user picked a different audio or subtitle track | — |
| `quality_change` | The user picked a rung from `available_qualities` | non-empty `quality_preference` |
The asymmetry is intentional. A seek reanchor is a timeline operation, not a
failed recipe — a classification is still accepted from older callers but never
selects seek semantics. A track or quality change is not a failure at all, so
demanding a classification would force clients to invent one. But
`quality_change` *must* name the rung it wants: an empty `quality_preference`
normalizes to `auto`, which is a different user intent than the menu selection
the operation models, so the server rejects it rather than silently doing
something else.
**User-intent operations behave differently from failure recovery.**
`track_change` and `quality_change` replace what were separate v2 endpoints (an
audio PATCH and a client-posted transcode start). Nothing failed, so the previous
route stays eligible: neither the attempted-key history nor the failed-plan
exclusion applies. A client may therefore be handed back a plan it has already
tried — that is correct here, and a client must not treat a repeated
`plan_attempt_key` as a loop.
When such an operation actually changes something — the request's tracks or
quality differ from what the session currently has — the server also tries to
return to the *requested* edition rather than staying on whatever alternate
version a previous fallback landed on, since a user switching tracks may well
want the original file back. That is a preference, not a guarantee: if the
requested edition no longer resolves or fails its preflight, the healthy active
alternate is kept. Track identities are remapped only when the edition really
changes, because remapping within one file would degrade an exact selection to a
best-match lookup and could silently move a listener off a commentary track.
Omitting `quality_preference` on any replan preserves the session's current
preference; sending it replaces that preference. A track change therefore does
not silently reset `original` or a pinned rung, and failure recovery does not
discard the viewer's requested quality unless the client explicitly asks it to.
Clients should still send the current preference when they know it, so their
intent remains explicit in diagnostics.
For failure recovery, `attempted_plan_keys` is the loop guard. The client sends
back every `plan_attempt_key` it has already tried for this attempt (up to 16);
the server will not hand back a plan whose key is in that list. `attempt_count`
(1–8) bounds the whole recovery chain. Together they mean a device that fails
every route reaches a terminal instead of cycling forever.
Failure, seek, and quality replans may omit unchanged track identities. The
server overlays only identities present in those requests and preserves the
durable selected subtitle otherwise. Only `operation: "track_change"` gives an
omitted `selected_tracks.subtitle` the explicit meaning "subtitles off". A
fallback to another media version must remap the selected subtitle; if no
equivalent exists, it returns terminal reason `subtitle_unavailable_in_version`
instead of silently continuing with subtitles off.
`local_mutations` (up to 8 entries, 64 chars each) reports client-side
adjustments — a transport reopen, a PCM decode fallback — that change the
effective route without changing the plan. They feed the attempt key, so a plan
retried after a local mutation is a *different* attempt and is not blocked by the
loop guard.
A seek-scoped recovery refuses to accept new capability or device evidence: a
seek is not an authority boundary for replacing the client's declared abilities
mid-session.
---
## 7. Registries
### 7.1 Decision reasons
Why the server picked this route. Informational; clients may log or display but
must not branch on an unrecognized value.
`validated_original_playback`, `container_normalization`, `audio_adaptation`,
`hls_audio_adaptation`, `hls_packaging_required`, `subtitle_burn_in_required`,
`client_dv7_to_dv81`, `client_dv7_to_hdr10`, `evidence_insufficient_for_direct`,
and the quality reasons `quality_original`, `quality_auto_source`,
`quality_fixed_rung`, `quality_device_limit`, `quality_bandwidth_limit`,
`quality_metered_limit`, `quality_bandwidth_cap`.
### 7.2 Degradation warnings
The plan will play, but something the user might notice was given up.
| Code | Meaning |
| --- | --- |
| `hdr_range_assumed_hdr10` | Source range unknown; treated as HDR10 |
| `dolby_vision_removed` | DV metadata stripped |
| `dolby_vision_strip_unsupported_by_source` | DV could not be stripped |
| `dolby_vision_enhancement_layer_discarded` | FEL/MEL dropped, base layer kept |
| `audio_converted` | Audio re-encoded rather than copied |
| `subtitle_burn_in` | Subtitles rendered into the video |
| `quality_reduction_unavailable` | Requested rung could not be produced |
| `quality_preference_normalized` | Unknown `quality_preference` normalized to `auto` |
| `bandwidth_cap_applied` | `bandwidth_cap_kbps` limited the selection |
| `evidence_insufficient_for_direct` | Evidence tier blocked a direct route |
### 7.3 Terminal reasons
Playback will not proceed. `terminal.retryable` says whether trying again could
help. Delivered inside a `201` (start) or `200` (replan), never a 4xx.
*Planner:* `adaptation_exhausted`, `adaptation_unavailable`,
`client_hls_unsupported`, `conversion_tool_unavailable`,
`hdr_transcode_unsupported`, `no_alternate_version`,
`source_metadata_incomplete`, `source_unavailable`,
`audio_conversion_unsupported`, `video_conversion_unsupported`,
`dv_conversion_unsupported`, `transcoding_disabled`,
`subtitle_conversion_unsupported`.
*Subtitle policy:* `subtitle_burn_in_source_unsupported`,
`subtitle_codec_unsupported`, `subtitle_track_invalid`,
`subtitle_track_unavailable`, `subtitle_unavailable_in_version`.
*Transport and session:* `internal_error`, `session_expired`,
`subtitle_artifact_unavailable`, `capacity_unavailable`,
`audio_transcoding_disabled`,
`transcode_start_failed`, `transcode_node_unavailable`,
`transcode_node_capability_unavailable`, `track_unavailable`,
`invalid_seek_position`, `invalid_replan`, `seek_reanchor_route_changed`,
`seek_reanchor_recipe_unavailable`,
`seek_reanchor_intent_mismatch`, `seek_failure_recovery_intent_mismatch`,
`policy_denied`.
### 7.4 Route event names
`plan_selected`, `plan_invalidated`, `plan_failed`, `first_frame`, `terminal`,
`stopped`, `runtime_correction_applied`, `runtime_correction_succeeded`,
`runtime_correction_failed`, `seek_reanchor_requested`, `seek_reanchored`.
### 7.5 Diagnostics allowlist
Route-event `diagnostics` keys the server retains. Everything else is dropped;
every value is truncated to 256 characters.
`decoder_name`, `decoder_init_ms`, `first_frame_ms`, `device_model`,
`requested_quality`, `effective_quality`, `pcm_recovery`, `retry_outcome`,
`replan_request_id`, `video_mime`, `video_codecs`, `video_width`, `video_height`,
`color_transfer`, `color_range`, `error_code`, `error_code_name`, `error_cause`,
`transformation_name`, `transformation_version`, `transformation_stage`,
`input_dv_profile`, `output_dv_profile`, `rpu_converted_count`,
`rpu_failed_count`, `el_nal_dropped_count`, `sample_count`,
`transform_buffer_peak_bytes`, `requested_media_file_id`,
`effective_media_file_id`, `audio_output_mode`, `audio_mime`, `audio_channels`,
`audio_decoder_name`, `correction_id`, `correction_stage`, `network_transport`,
`network_metered`, `network_validated`, `bandwidth_estimate_kbps`,
`link_downstream_kbps`, `target_source_position_seconds`, `reason`.
---
## 8. Track identity and the subtitle ordinal space
Every track is addressed as `file:{media_file_id}:{kind}:{ordinal}` — for
example `file:42:audio:0`. When a client sends both an id and an index they must
agree; the server rejects a disagreeing pair rather than picking one.
Subtitles occupy a single **combined ordinal space** spanning three sources, in
three dense consecutive ranges:
1. **External** sidecar files, in catalog order — ordinals `0 … E-1`
2. **Embedded** container streams, in container stream order — `E … E+M-1`
3. **Downloaded** subtitles, in `created_at` order — `E+M … E+M+D-1`
The space is dense and gap-free, and this is load-bearing. A track that has no
sidecar representation the stream handler can serve — a DVD or DVB bitmap stream
— **keeps its ordinal** and is published with `delivery: "burn_in_only"` and no
`url`. Omitting it would leave a hole, and any client deriving the
downloaded-track base by counting published URLs would then undercount and
address the wrong track. (That was a real bug; this rule is the fix.)
`playback_plan.subtitle.inventory` is the authoritative list. A client selects a
track by echoing an entry's `track_id` or `combined_index`. It must never derive
an ordinal by counting tracks, summing array lengths, or taking `max(index)+1`.
Each entry carries `source` (`external` | `embedded` | `downloaded`), `delivery`
(`sidecar` | `burn_in_only`), the `forced` / `default` / `hearing_impaired`
flags, a `url` when deliverable, and a `font_bundle_url` for embedded ASS tracks
with attachments. `default` reflects the source container's own default flag, so
only embedded and external tracks can carry it — a downloaded subtitle is never
`default`. `url` is present only on `sidecar` tracks, and only once a session
exists to scope it to — but it does not depend on the current selection: a start
or replan that resolves to `subtitle.mode: "off"` still publishes every sidecar
entry with its fetchable `url`, so a client can build its full subtitle menu
without first asking for a plan it does not want.
`subtitle.mode` is `off`, `render` (client draws the sidecar), `convert` (server
transcodes it to a client-renderable format first — always to WebVTT, served as
`text/vtt` at a `.vtt` URL), or `burn_in` (rendered into the video, which forces
a transcode).
The sidecar URL suffix is part of the representation contract, not decoration.
An embedded `hdmv_pgs_subtitle`/PGS sidecar is lossless binary PGS at a `.sup`
URL with `application/octet-stream`; cached full-track responses support `HEAD`
and byte ranges. Text conversion is always WebVTT at `.vtt`, while lossless
ASS/SSA uses `.ass`. A suffix that does not match the selected track or a valid
conversion is rejected with `415` rather than returning bytes of a different
type under the requested extension.
---
## 9. Plan identity
The server mints both identifiers. **Clients treat both as opaque, case-sensitive
tokens and never implement either identity algorithm.** Their wire prefixes and
lengths are validation syntax, not a derivation recipe.
`plan_id` identifies the server's playback decision. It is stable when the same
attempt produces the same source, delivery, recipe, tracks, subtitle mode,
transformations, applied quirks, and recipe revision. A change to any of those
inputs produces a different identity.
`plan_attempt_key` is the replan loop guard for a plan as attempted on one output
route with a set of client-reported local mutations. The server canonicalizes
order-insensitive inputs internally. The client:
1. stores the exact key from `playback_plan.plan_attempt_key`;
2. echoes it unchanged as `plan_attempt_key` when reporting that plan;
3. adds the unchanged token to `attempted_plan_keys` after the plan fails; and
4. never case-folds, parses, truncates, hashes, or synthesizes a replacement.
`internal/playback/testdata/protocol_v3/attempt_keys.json` contains opaque
cross-message vectors: a server-emitted token, the exact replan echo, and the
loop-rejection result. The generator computes the server token internally but
does not publish its preimage.
---
## 10. Quality
`playback_plan.available_qualities` is the menu. The client renders it and, on
selection, sends a `quality_change` replan with the entry's `label`. It does not
compute rungs.
The source rung is always present, labelled `original`, with
`preserves_source: true`. Transcode rungs are added only below the source's own
height, and only when HLS is available to the client, transcoding is enabled,
4K transcoding is permitted for a 4K source, and the source is not HDR. Ladder
bitrates:
| Rung | kbps |
| --- | --- |
| 2160p | 20000 |
| 1080p | 6000 |
| 720p | 2000 |
| 480p | 1500 |
Registry availability is deliberately *not* consulted when building the menu: a
capability check there could trigger lazy node fetches that a source-preserving
start must never pay for. A rung whose toolchain turns out to be missing degrades
to a retryable terminal at replan time instead.
Audio-only sources publish a single `original` rung — quality rungs are a video
concept.
`quality_preference` accepts `auto`, `original` (aliases `source`, `max`), and
`2160p` / `1080p` / `720p` / `480p` with the obvious aliases (`4k`, `uhd`, `fhd`,
`hd`, `sd`). An unrecognized value normalizes to `auto` and the response carries
the `quality_preference_normalized` warning rather than an error.
---
## 11. Transformations
A transformation is a named, versioned media operation with claims attached.
| Name | Executor | Recipe version | Promises | Claims |
| --- | --- | --- | --- | --- |
| `audio_to_aac` | `server` | `1` | — | `audio_decode` |
| `video_to_h264` | `server` | `2` | `sdr` output | `h264_decode` |
| `server_dv7_to_hdr10` | `server` | `1` | `hdr10` output | `dolby_vision_metadata_removed`, `hdr10_base_layer_preserved`, `enhancement_layer_discarded` |
They are advertised only if the installed FFmpeg actually has the required
capability, probed once at startup:
| Transformation | Probe |
| --- | --- |
| `server_dv7_to_hdr10` | `ffmpeg -bsfs` contains `dovi_rpu` |
| `audio_to_aac` | `ffmpeg -encoders` contains an `aac` encoder |
| `video_to_h264` | `ffmpeg -encoders` contains any of `libx264`, `h264_qsv`, `h264_vaapi`, `h264_nvenc`, `h264_videotoolbox` |
`GET /playback/capability` reports the *local* probe only. A deployment with
pooled transcode nodes may still plan an HLS route using a transformation those
nodes advertise but the local FFmpeg lacks, so the capability list is a floor,
not a ceiling — one more reason a client must not precompute routes from it.
An unavailable transformation is not silently skipped at plan time: it produces
its own terminal reason (`dv_conversion_unsupported`,
`audio_conversion_unsupported`, `video_conversion_unsupported`) so the client
learns which conversion was missing rather than seeing a generic refusal.
A client may advertise its *own* transformations in a delivery's
`transformations[]` with `executor: "client"` — Dolby Vision profile 7 → 8.1
conversion, for instance. The server accepts a client executor only when that
delivery is both `enabled` and `supported_on_device` **and** the request's
top-level `client_features` includes `client_video_transformations_v1`.
Duplicate `executor:name:recipe_version` triples are rejected. Client
transformations participate in plan identity exactly like server ones, so a
client that changes its transform version invalidates its prior attempt keys —
which is the intent.
---
## 12. Conformance
Three artifacts, in decreasing order of authority:
1. **`internal/playback/testdata/protocol_v3/`** — golden fixtures generated by
`cmd/playbackfixtures` from the live server types. `make playback-fixtures`
regenerates them; `make verify-playback-fixtures` fails CI if they are stale.
Android and Apple CI vendor these and compare against them as **opaque
expected output**. The direction of authority is inverted from where this
protocol started: the server defines the contract and clients prove
conformance, not the reverse. `conformance_matrix.json` covers the release
train's evidence tiers, delivery fallback chain, replan operations and
idempotency, quality ladder, audio-only route, HDR/Dolby Vision decisions,
audio adaptation and exact-layout passthrough, text/bitmap subtitle policy,
failure recovery, restart replay, capacity cleanup, output change, route
event limits, opaque loop guard, and legacy-upgrade response in one
generated cross-client corpus.
2. **`docs/design/schemas/playback-v3/`** — JSON Schemas for every wire body,
with valid and invalid fixtures. Every bound mirrors a server validator, so a
body these schemas reject is a body the server rejects.
`internal/playback/contract` enforces that the schemas, the Go types, and the
golden fixtures agree.
3. **This document** — the reasoning behind the above, and the normative source
for anything the schemas cannot express (idempotency semantics, the timeline
model, evidence-tier strictness, ordinal density).
A client that decodes the golden fixtures, echoes attempt keys byte-for-byte,
and round-trips a replan without computing an identity is conforming.
@@ -1,788 +0,0 @@
# Restart-resilient playback (TR-lease)
How Silo keeps playback alive across a server restart, reconnect, or partial
stream — and how the design arrived at **TR-lease** (token-carried
reconstruction + a server-side session-deny marker for revocation).
> **Status: the revocation half is deferred to a future PR.** Only the
> token-carried **reconstruction** core shipped in this PR. The **session-deny /
> stream-revocation** mechanism described throughout (the `silo:streamauth:<sid>`
> deny marker, the proxy's `Allowed()` enforcement, and the admin
> Stop/Terminate deny write) is **not present in the current implementation**.
> Admin Terminate and user Stop tear down the live in-memory session and the
> ffmpeg producer, but they do **not** prevent a still-valid stream token from
> reconstructing the session until its 24h TTL expires. Sections describing that
> mechanism are kept for design continuity and are individually flagged as
> deferred below.
This document is the consolidated design record. It folds together four earlier
working notes so a future engineer can see the full evolution, the options
weighed, the issues raised across review rounds, the variables traded off, and
why the final shape was chosen. The superseded notes were:
- *unified-playback-reconstruct* — the reconstruct core (PR #174), "RC".
- *token-carried-playback-reconstruct* — the storage evolution, "TR".
- *async-recipe-card-playback* — a monitoring-preserving middle path, "RC-async".
- *playback-reconstruct-options-comparison* — the goals/options matrix.
Paths are repository-relative; assume the repository root is the cwd.
---
## 1. The problem
Before this work, a missing in-memory playback session was a `404`. A server
restart (deploy, crash, OOM) wiped the in-memory session map, so every in-flight
stream died: the client's next manifest/segment/byte-range request hit a session
that no longer existed and playback stopped hard. The same gap appeared on any
front-end that had never held the session (horizontal scale) and on a dedicated
transcode node reboot.
Core priorities for the fix (from the repo guidelines): **performance first,
reliability first, predictable behavior under load and during failures**. The
hot path (per-segment serve) must stay off central/Postgres; bytes must stay
offloaded to nodes; correctness and robustness win over convenience.
---
## 2. The core insight: reconstruct, don't rehydrate
A missing session is a **reconstruct trigger, not a 404**. The client always
re-requests the next chunk after an outage, and its request already states where
it is (an HTTP `Range`, a `?seek=`, or a `seg_NNNNN` number). So the server
rebuilds the session just-in-time from two things:
1. a small **durable descriptor** (identity, ownership, and the byte-affecting
encode parameters — the "recipe"), and
2. the **position the client supplies** on the triggering request.
Nothing live is serialized (no ffmpeg process, context, channels, or log sink).
This is the contribution of PR #174 ("RC"), which also unified the native and
Jellyfin-compat paths behind one `playback.TranscodeManager` so the
card-lifetime rules, the reconstruct concurrency cap, and the node-affinity rule
live in exactly one place. The reconstruct skeleton —
`LoadOrReconstructSession`, `ReconstructSession` / `ReconstructTranscode`, the
single-flight + `reconstructSem` cap that paces the post-restart thundering
herd, `RegisterReconstructed`, the `CloseProcess`/`Close` split — is the
foundation every later option reused. **It was kept; only the descriptor storage
and the revocation model evolved.**
The six routes that must survive a restart:
| # | Route | Tier | How it is rebuilt |
|---|-------|:----:|-------------------|
| 1 | native direct | 1 | client `Range` re-serve; descriptor = identity |
| 2 | native remux | 1 | re-spawn ffmpeg at `?seek`; descriptor = id + audio |
| 3 | native transcode | 2 | rebuild `Session` + ffmpeg seeked to the requested segment; descriptor = full encode opts |
| 4 | jellycompat direct | 1 | compat store + `Range` re-serve |
| 5 | jellycompat remux | 1 | compat store + `?seek` |
| 6 | jellycompat transcode | 2 | compat store + shared-manager reconstruct |
Tier 1 = stateless re-serve (client re-supplies position). Tier 2 = rebuild
ffmpeg. Routes 4–6 always retain a durable central compat store
(`jellycompat_playback_sessions`): third-party Jellyfin clients cannot
round-trip a native descriptor, so the compat layer keeps the full
`PlaybackSession` (route + media source resolved before native reconstruct
runs).
---
## 3. The two axes the options differ on
Every option is a point on a 2-D grid: **where the descriptor lives** (vertical)
× **how revocation is bounded** (horizontal).
```text
AUTHORITY / REVOCATION MODEL ----------------------->
re-resolve at long token short TTL +
reconstruct (24h, expire) refresh checkpoint
D central +----------------+----------------+----------------+
E Postgres row | RC (#174) | (n/a) | RC-async |
S +----------------+----------------+----------------+
C client/node- | (n/a) | TR-24h | TR + re-mint |
R carried token | | | |
I +----------------+----------------+----------------+
P
T top row = descriptor stays central (node serves bytes but cannot
| self-reconstruct → node-restart gap)
| bottom = recipe travels to the node (node self-sufficient, no central record)
```
**TR-lease is a fourth point off this grid:** bottom row (token-carried, 24h),
but the revocation column is replaced by a *server-side deny marker* — on an
admin kill, central would write a per-session deny to Redis that the node
enforces by withholding bytes. Revocation is decoupled from the token TTL and
needs no client refresh. (An earlier iteration polled and re-resolved every
stream on a timer; that was cut to the event-driven session-deny — see §7 and
the §8 design note.)
> **Status: deferred to a future PR.** The deny-marker column described above is
> the design target, not the current shipped behavior. As shipped, the
> token-carried row offers no revocation tighter than the 24h token TTL on the
> node path; admin Terminate and user Stop only tear down the live session and
> ffmpeg producer.
---
## 4. Goals weighed
| ID | Goal |
|----|------|
| G1 | Hot path (per-segment serve) stays off central/Postgres |
| G2 | Bytes offloaded to nodes (served from disk, signature-verified, never central) |
| G3 | Restart resiliency across all 6 routes |
| G4 | Two-factor ownership (auth caller + ownership rebind; refuse `userID==0`/mismatch) |
| G5 | Revocation latency (how fast a banned user / pulled access stops playing) |
| G6 | Single-box: zero external store required for reconstruction |
| G7 | Restart runway (descriptor stays valid longer than the outage) |
| G8 | Multi-front-end / verify-anywhere (no integrated-transcode split-brain) |
| G9 | Observability — durable, identity-rich active-stream record |
| G10 | Low operational surface (tables, migrations, stores, endpoints) |
| G11 | Node-restart recovery |
| G12 | No new client coordination required |
| G13 | Small signing-key blast radius |
| G14 | Cleanup correctness (never wipe a live session's segment dir) |
A note on G9 (observability): the *live* "who is streaming now" view does **not**
depend on the descriptor strategy. Every offload node calls the Redis-backed
node-session tracker (`internal/nodesessions/tracker.go`) on every serve, tied to
actual byte-serving (so a non-cooperative client or replayed token still shows
up) and surviving a central restart. G9 scores only the *durable, identity-rich*
(who + what + recipe) slice on top of that.
---
## 5. The options, and the comparison
Legend: ✓ meets · ✓\* minor asterisk · ~ partial · ✗ fails · ✓✓ best-in-class
| Goal | `main` | RC #174 | TR-24h | TR + re-mint | RC-async | **TR-lease** |
|------|:------:|:-------:|:------:|:------------:|:--------:|:------------:|
| G1 hot path free of central DB | ✓ | ✓\* | ✓ | ✓ | ✓ | ✓ |
| G2 bytes offloaded | ✓ | ✓ | ✓✓ | ✓✓ | ✓✓ | ✓✓ |
| G3 restart resiliency (6/6) | ✗ | ✓ | ✓ | ✓ | ✓ | ✓ |
| G4 two-factor ownership | ✓ | ✓ | ~ | ~ | ~ | ✓~ |
| G5 revocation latency | ~ | ~ | ✗ (≤24h) | ✓ (≤TTL) | ✓✓ | ✓✓ |
| G6 single-box, no external store | ✓ | ✗ | ✓✓ | ~ | ~ | ~ |
| G7 restart runway | n/a | ✓ (30m) | ✓✓ (24h) | ~ | ~ | ✓✓ (24h) |
| G8 multi-front-end | ✗ | ~ | ✓~ | ✓~ | ✓~ | ✓~ |
| G9 durable identity-rich record | ✗ | ✓✓ | ✗ | ✗ | ✓ | ~ |
| G10 low operational surface | ✓✓ | ~ | ✓ | ~ | ✗ | ~ |
| G11 node-restart recovery | ✗ | ✗ | ✓ | ✓ | ✓ | ✓ |
| G12 no new client coordination | ✓ | ✓ | ✓ | ✗ | ✗ | ✓ |
| G13 small signing-key blast radius | ✓ | ✓ | ✗ | ✗ | ✗ | ✗ |
| G14 cleanup correctness | ✓ | ✓✓ | ~ | ~ | ~ | ~ |
The TTL/revocation strategies head-to-head. **Note: the session-deny column is
the deferred design target — see §7; as shipped, the node path has no revocation
tighter than the 24h token TTL.**
| Strategy | Revocation latency | Restart runway | Client refresh? | Central on refresh? |
|----------|--------------------|----------------|-----------------|---------------------|
| Re-resolve at reconstruct (RC) | on reconstruct; node hop ≤24h | 30 min | no | only on reconstruct |
| Leave 24h, expire only (TR-24h) | up to 24h | 24h | no | never |
| Short TTL + refresh + denylist (RC-async / TR item B) | ≤~5 min | ~90 s grace | **yes** | every ~3.5 min/session |
| 24h token + session-deny marker (TR-lease — **deferred**) | *design target:* admin kill cuts node bytes on next serve; passive ban = next-play / ≤24h. *As shipped:* node path bounded by ≤24h token only | 24h | **no** | nothing on the serve path; one write per admin-kill event |
---
## 6. Why each non-final option was set aside
- **RC (PR #174, the recipe card in Postgres).** Correct and the basis of
everything here, but it couples reconstruction to a shared per-session Postgres
store: a write on every start, per audio/quality change, and a ≤1/min refresh,
with resilience tied to the DB being reachable. It does not give the single-box
zero-dependency property, and the node hop's 24h token stays unrevocable
anyway. RC's reconstruct *core* was kept; its *storage* was the thing to evolve.
- **TR-24h (token-carried, leave the token to expire).** Wins the single-box case
(zero external dependency) and removes the per-start DB write, but revocation is
bounded by *nothing tighter than the 24h token TTL* on the node path — a banned
user keeps node-served direct/remux for up to 24h. This is actually the
*status quo* for the node path even pre-branch (the proxy verifies by signature
alone, no DB), so TR-24h only adds identity claims to the token without
improving revocation. Not acceptable as the endpoint.
- **TR + re-mint (short TTL + authenticated playlist refresh + denylist), and
RC-async (the same revocation idea but keeping an async-written Postgres mirror
for observability).** Both bound revocation to ~5 min by having the client
refetch a stable `RequireAuth` playlist that re-checks access and re-mints
short-lived segment URLs. The cost: a **hard client-coordination requirement**
(silo-android / silo-apple / Jellyfin clients must implement the refresh flow),
a shrunken restart runway (~90 s grace instead of 30 min — if central is down
past the grace, playback stalls), and a new authenticated re-mint transport
that does not exist on the supported proxy/node topology. RC-async additionally
keeps a write pipeline + denylist + the central row (the highest operational
surface of all). They solved revocation by pushing work onto the client and
shortening the runway — the opposite of the reliability priorities.
The open item across TR and RC-async was always **revocation enforcement** ("item
B"): bounding revocation needs *either* a per-segment token check on the hot path
*or* an authenticated re-mint checkpoint the client drives. TR-lease removes that
dilemma.
---
## 7. TR-lease: the chosen design
TR-lease keeps TR's 24h token (so the restart runway is untouched and no client
refresh flow is needed) and adds a server-side **session-deny marker** for the
one revocation case the node path cannot otherwise cover — no client
participation, no steady-state cost.
**Reconstruction (token-carried).** The signed stream token *is* the durable
descriptor. Its claims carry the full byte-affecting recipe plus `uid/pid/mfid`
ownership lookup keys. A front-end that lost its in-memory session rebuilds
ffmpeg from the token the client re-presents — no shared per-session store, zero
external dependency for reconstruction on a single box. `HWAccel`/`HWDevice` are
deliberately *not* carried; they are re-resolved from live config so an operator
config change applies to reconstructed sessions too. Ownership re-binds to the
live authenticated caller and refuses `userID==0` / mismatch — the token's `uid`
is never trusted alone (a leaked URL is useless without the owner's auth session
on the native path).
**Revocation (session-deny marker).**
> **Status: deferred to a future PR.** Everything in this subsection (the
> `silo:streamauth:<sid>` deny marker, the admin Stop/Terminate deny write, and
> the node-side `Allowed()` enforcement) describes the design target and is **not
> present in the current implementation**. As shipped, admin Terminate and user
> Stop tear down the live in-memory session and the ffmpeg producer, but a
> still-valid stream token can reconstruct the session until its 24h TTL expires;
> there is no node-side byte-withholding and no guaranteed/instant revocation on
> the node path. The design below is retained for when revocation lands.
The revocation surface was deliberately
kept to the *one* case the offloaded topology cannot otherwise cover, rather than
a periodic re-check of every stream. An admin Stop/Terminate would write
`silo:streamauth:<sid> = deny` (TTL ≥ the 24h token lifetime); the offload node
would read it (a node-local Redis GET, sub-ms) before serving any bytes and
return `403` with no bytes on a hit. Enforcement is **byte-withholding, not
client cooperation** — a revoked client that ignores the 403 keeps hitting a
wall.
Why this would be sufficient, and what it deliberately does *not* do:
- **New playback is already blocked at central** — `/playback/start` is
`RequireAuth` + access check, so a ban/scope change always takes effect on the
next play, everywhere, with no marker needed.
- **Cooperative clients already stop** — central holds the realtime WebSocket and
can drop it + send a stop on a ban.
- **The only thing needing a hard node-side cut** is the *explicit, session-scoped
admin kill* of a *non-cooperative* client holding a valid token on a
node-served direct/remux stream (no producer to kill). That is exactly what the
(deferred) session-deny marker would cover; until it lands this case is bounded
by the ≤24h token like the passive bans below.
- **Not covered (accepted limitation):** a *passive* ban or *partial* access
change (lost one library, lowered rating) does NOT hard-revoke an
already-running, non-cooperative node stream. It is enforced at next play and
otherwise bounded by the ≤24h token. Closing this would require either a
periodic re-resolver (a poll over every active stream — rejected as constant
DB load for a rare case) or per-content deny enumeration; both were judged not
worth the machinery for a self-hosted server. A user-scoped deny was rejected
too: it over-blocks content the viewer still legitimately has access to.
**Fail-open on absence (deferred).** In the design, the normal case is *no*
marker, which serves; a Redis error also serves; only a present deny withholds
bytes. This is a deliberate reliability-first choice: availability over
revocation latency.
**Why this shape.** It keeps token-carried reconstruction's single-box and
verify-anywhere properties and would add revocation with no client coordination
(G12) and essentially no steady-state cost — the marker is written only on the
rare admin-kill event, never on a timer. It is, in effect, **TR-24 plus a single
session-scoped kill switch**. The kill switch is **deferred**; what shipped is
TR-24 (token-carried reconstruction, ≤24h token, no node-side revocation).
---
## 8. What was implemented, and where
This PR ships **Commit 1 only** (token-carried reconstruction). **Commit 2 (the
node session-deny marker) is deferred to a future PR** — the `internal/streamauth`
package, the proxy `Allowed()` guard, and the admin deny write described below
are **not present in the current implementation**.
**Commit 1 — token-carried reconstruction; retire `transcode_recipes`. (shipped)**
- `streamtoken.Claims` gains the recipe + `uid/pid/mfid`
(`internal/streamtoken/token.go`).
- `playback.RecipeCard` projects to/from claims (`ToClaims` /
`RecipeCardFromClaims`); the `Reconstruct*` front door takes the decoded recipe
instead of reading Postgres (`internal/playback/recipecard.go`,
`transcode_manager.go`).
- Native serve URLs carry the token as `?st=`; the manifest rewriter already
appends `RawQuery` to segment URIs, so segments inherit it with no route change
(`internal/api/handlers/playback.go`, `stream.go`). The integrated server is
hit directly, so the query-stripping-proxy concern that motivates a path
segment does not apply there; the proxy/node path keeps the token in the URL
path as before.
- Jellycompat folds the recipe into its durable compat store
(`PlaybackSession.Recipe`) since Jellyfin clients cannot round-trip a native
token (`internal/jellycompat/...`).
- Segment-dir cleanup switches from the card index to in-memory liveness (live
map + in-flight reconstruct set + age past the max token TTL); a dedicated node
keeps its boot-time full wipe (`internal/playback/transcode_cleanup.go`,
`transcode_manager.go`).
- `PostgresRecipeStore`, the `RecipeStore` interface, and the unmerged
`transcode_recipes` migration are deleted.
**Commit 2 — node session-deny marker. (DEFERRED — not in this PR)**
> The items below describe the planned revocation commit. They were removed from
> this PR and deferred to a future one; none of these symbols exist in the
> current implementation. The admin Stop/Terminate path still tears down the live
> session and ffmpeg producer, but writes no deny marker, so a valid token can
> reconstruct until its 24h TTL expires.
- `internal/streamauth`: a deny-only Redis `Store` — `Deny(sid)` (TTL ≥ token
lifetime) and a fail-open `Allowed(sid)` reader. No poller, no allow-leases, no
access re-resolver.
- The node guard in `internal/proxy/server.go` (`verifyToken` consults
`Allowed`).
- An admin Stop/Terminate writes the deny marker
(`internal/api/handlers/admin_playback_control.go` → `PlaybackHandler.LeaseDenier`).
- `nodesessions.SessionInfo` carries the numeric ownership keys
(`auth_user_id`/`profile_id`/`media_file_id`), populated by the node from the
verified token, to enrich the live admin "active streams" view (who/what, not
just session id) — see §10 monitoring.
- A single integrated box reads no marker and needs none — the producer-kill +
session removal on Terminate is the stop there.
> Design note (about the deferred commit 2): an earlier iteration added a central
> *revalidator* that re-resolved access for every active stream every ~2 min and
> wrote allow/deny leases. It was dropped in favour of the event-driven
> session-deny above: the poll re-derived, at a constant all-streams DB cost,
> signals the
> system already emits (new playback is gated at `/playback/start`; admin kill is
> an explicit event), and its only unique coverage — sub-24h *passive* revocation
> of an in-flight node stream — was judged not worth the machinery (see §7).
---
## 9. Issues raised across review, and their disposition
From two adversarial review rounds on the reconstruct core and the storage
evolution:
- **Integrated-transcode split-brain across front-ends (P-1 / A).** The
`SessionManager` + reconstruct single-flight are per-process and the descriptor
carries no owning-node id, so without sticky affinity two front-ends can run
divergent ffmpeg. **Disposition: deferred (owner-identity claim).** Supported
topology is dedicated `--mode=transcode` nodes (routed via `tnode`, no
split-brain) + single-box / LB-session-affinity integrated transcode. The
caveat is documented, not silently assumed.
- **24h node-path token is unrevocable (P-2).** The (deferred, see §7–§8)
session-deny marker would let the explicit admin kill cut node bytes on the next
serve. **Until that ships, this remains open:** the node-path token is
unrevocable, so admin kill and passive bans / partial access changes are all
bounded by next-play + the ≤24h token.
- **Dedicated transcode-node restart (P-3 / tr-10). Fixed for both paths.**
*Native:* the proxy forwards the verified stream token to the transcode node
(`X-Silo-Stream-Token`); on a manifest/segment miss the node re-verifies the
token, decodes the recipe, and self-reconstructs ffmpeg seeked to the requested
segment — single-flighted and concurrency-capped exactly like the integrated
reconstruct. *Jellycompat:* the node-hop token is server-minted and *could* carry the
recipe like native, but it deliberately does not — the recipe is mutated in
place under a stable session id (a Jellyfin audio/subtitle switch can arrive as
a `/Sessions/Playing/Progress` report that restarts ffmpeg without re-minting
the client's token), and a third-party Jellyfin client cannot be driven to
refresh a stale token, so a token *snapshot* could reconstruct a stale
rendition. Central instead writes the recipe to a shared Redis recipe store
(`internal/noderecipe`) keyed by upstream session id and overwrites it on every
switch, and the node (which cannot reach Postgres) reads the *current* recipe on
the reconstruct miss — over the same Redis the session tracker already uses (and
the deferred deny-lease would use), so no central URL is needed. The boot-time
full segment-dir wipe
stands; reconstruct re-transcodes from the requested segment. See §10 for the
full rationale (and why this is *not* a token-carryable case).
- **`userID==0` tolerance / "auth optional" (P-5).** Reconstruct hard-rejects
`userID==0` and a card whose session id does not match the URL.
- **Mutable recipe under a stable id (D).** A parameter change re-mints a new
manifest + token and the client reloads, so the common case self-heals. The
only residual is a restart *during* the brief switch transition with a prior
token in flight: it reconstructs the prior *rendition* (access is re-resolved,
only the rendition can be stale). TTL-bounded, self-healing on reload; minor,
accepted.
- **Cleanup liveness (F / tr-9).** Each process owns its `TranscodeDir`, so the
liveness signal is the in-process live map + the in-flight reconstruct set +
age-past-max-TTL; a dir is reaped only when absent from both and older than any
surviving token. No cross-process enumeration-failure mode for the supported
topology.
- **Signing-key blast radius (E / tr-7, G13).** A single `JWTSecret` signs native
auth, the stream token, and the node bearer, so a node-secret leak can forge
native logins. **Accepted risk** on the trusted-node precondition. **Deferred
hardening:** split the stream-token secret from the native-auth secret, then
asymmetric stream-token signing before any untrusted/edge node.
---
## 10. Residuals and follow-ups
- **Revocation of an in-flight node stream (all cases, until deny-lease ships).**
Because the session-deny marker is deferred (§7–§8), *no* ban — admin kill,
passive ban, or partial access change — hard-cuts an already-running,
non-cooperative node-served stream; all are enforced at next play, bounded by
the ≤24h token. The future deny-lease closes the *admin-kill* case; passive
bans would still need a per-content deny enumeration on the access-change event,
or accepting it. See §7.
- **Monitoring.** Two distinct questions:
- *Live "who is watching what right now"* — covered. Every node serve writes a
record to the Redis tracker (`silo:sessions:*`), now enriched with
`auth_user_id` / `media_file_id` from the verified token, so the admin
active-streams view answers who/what/where, tied to real byte-serving and
surviving a central restart. Integrated (no-node) sessions show in central's
in-memory session list.
- *Durable historical/audit ("who watched what last week")* — NOT provided by
this subsystem (there is no longer a durable per-session recipe record, by
design — G9 was the deliberate trade for token-carried reconstruction). That
history lives in the separate watch-progress / scrobble system.
- **Multiple viewers on one stream token.** The token is per playback session, so
a shared/leaked stream URL lets several clients pull bytes under one session id.
They **collapse to a single entry** in the tracker (one `sid`) — monitoring
cannot distinguish or count them — and the (deferred) session-deny would cut
them as a group, not individually. Detecting/limiting this needs a per-account
concurrency cap or
per-device session ids (device binding); deferred. Do not bind to client IP
(mobile / CGNAT).
- **Token in logs (tr-1).** Scrub the `?st=` token / path token from request
loggers (the jellycompat logger logs `RawQuery`; the native logger omits it).
Short TTL + signature bound the exposure.
- **Owner-identity (A).** Required before multi-front-end *integrated* transcode
without sticky affinity; defines owner election, self-URL discovery, a
peer-forward endpoint, and failover.
- **Node-side reconstruct (P-3). Done** for native (token-forwarded) and
jellycompat (Redis recipe handoff via `internal/noderecipe`: central writes the
recipe at remote-transcode start, the node reads it on a reconstruct miss).
Precondition: central and the nodes share the same Redis (already required for
the session tracker, and for the deferred deny-lease). Residual: the recipe
store is consulted
only for a jellycompat token, so a node restart still depends on the recipe key
surviving (24h TTL, ≥ token lifetime).
- *Why a server-side store and not the token here (the real rationale).* It is
tempting to delete `internal/noderecipe` and let the jellycompat node-hop
token carry the recipe like native — the token is server-minted and opaque to
the Jellyfin client (it follows it only as a redirect target), so it *could*.
That does **not** work, and the reason is **not** the often-stated "a Jellyfin
client can't round-trip a token." The reason is that the recipe is **mutated
in place under a stable session id**: a Jellyfin audio/subtitle switch can
arrive as a `/Sessions/Playing/Progress` report
(`restartCompatTranscodeForAudioSelection`) that restarts ffmpeg in place
**without re-minting the client's token**. A third-party Jellyfin client
cannot be driven to refresh the now-stale token — its VOD/`ENDLIST` manifest
is fetched once, and the compat WebSocket (`HandleSocket`) is a receive-only
keep-alive stub with no server→client command to force a manifest re-fetch. A
token is a snapshot at mint time, so after such a switch it would reconstruct
the **stale** rendition (old audio/subtitle) until the client happens to
re-fetch the manifest (e.g. on a seek), which for a VOD stream may be never.
Because the node also cannot reach Postgres (where the authoritative compat
recipe lives), the only way the node rebuilds the *current* recipe is a
node-reachable, server-authoritative store that central overwrites on every
switch — i.e. `internal/noderecipe`. Native has no equivalent path: every
native audio switch re-mints the manifest + token, so the native client's
token is never stale, which is exactly why native needs no such store. The
store is **load-bearing, not redundant**.
- **Key split / asymmetric signing (E).** Closes the account-takeover path; a
precondition for untrusted edge nodes.
---
## 11. Preconditions
- **Persistent `TranscodeDir` (recommended).** With persistence, reconstruct
serves surviving segments; with an ephemeral dir it re-transcodes from the
descriptor (which survives a wiped dir). A node *restart* still loses the
session regardless (P-3).
- **Re-transcode of one segment beats the buffer runway** on worst-case hardware
(software decode, subtitle burn-in). Measure.
- **Client retry/backoff exists.** Clients retry segment/manifest GETs on
5xx/connection error and reconnect the WebSocket. The token rides the URL, so no
extra client logic is needed to carry it; a client that does not retry sees the
failed request as fatal.
---
## 12. Diagrams
The `mermaid` blocks render in GitHub / VS Code / most Markdown viewers; the
ASCII blocks render anywhere.
### 12.1 Topology — where state lives
> **Deferred:** the `silo:streamauth:<sid> = deny` marker, the "Admin
> Stop/Terminate → write session-deny marker" arrow, and the node's "deny GET"
> are the planned revocation path and are **not** in the current implementation.
> The tracker (`silo:sessions:*`) and the recipe handoff are shipped.
```text
┌─────────────────────────── CENTRAL (mode=server) ───────────────────────────┐
Client │ RequireAuth /playback/start /playback/{sid}/replan (mint token) │
(web / android / │ native serve: /playback/transcode/{sid}/master.m3u8?st= /stream/{sid}?st= │
apple / jellyfin) │ Admin Stop/Terminate → write session-deny marker (event, not a timer) │
└───────────┬──────────────────────────┬───────────────────────┬──────────────┘
│ Postgres │ Redis │
▼ ▼ │ (multi-node only)
┌───────────────────────┐ ┌──────────────────────────┐ ▼
│ catalog / access │ │ silo:sessions:* (tracker)│ ┌────────────────────────┐
│ jellycompat_playback_ │ │ silo:streamauth:<sid> │ │ Proxy node (mode=proxy) │
│ sessions (compat │ │ = deny (session kill) │◀─│ verifyToken + deny GET │
│ store, carries Recipe)│ └──────────────────────────┘ │ serves direct/remux │
└───────────────────────┘ ▲ │ proxies transcode ──────┼──▶ Transcode node
✗ NO transcode_recipes table (deleted this branch) │ node-local GET └────────────────────────┘ (mode=transcode)
└── sub-ms, off Postgres ffmpeg /transcode/{sid}/…
```
Descriptor location by route (the core change). The "lease (node)" revocation
column is the **deferred** design; as shipped, the node path has no revocation
tighter than the ≤24h token:
| route family | descriptor (how it reconstructs) | revocation |
|--------------|----------------------------------|------------|
| native (1–3) | the signed token the client re-presents | *deferred:* lease (node) / shipped: producer-kill (integrated), ≤24h token (node) |
| jellycompat (4–6) | `jellycompat_playback_sessions.data.Recipe` (token can't round-trip) | *deferred:* lease (node) / shipped: producer-kill, ≤24h token (node) |
| ~~all~~ | ~~`transcode_recipes` Postgres row~~ — removed | — |
### 12.2 Where the token rides
```text
NATIVE (integrated server is hit directly → query param; segments inherit it)
manifest : GET /playback/transcode/{sid}/master.m3u8?st=<JWT>
segment : GET /playback/transcode/{sid}/segment/seg_00042.m4s?st=<JWT> ← RawQuery propagated by the manifest rewriter
direct : GET /stream/{sid}?st=<JWT>
PROXY/NODE (capability URL → path segment; survives a query-stripping hop)
GET {proxy}/stream/transcode/{JWT}/master.m3u8 → relative segment URIs inherit {JWT}
GET {proxy}/stream/direct/{JWT} GET {proxy}/stream/remux/{JWT}
JELLYCOMPAT → recipe is NOT in the token; it lives in the compat store.
the path token is used only for the node hop.
```
### 12.3 Normal playback — native, integrated box (no nodes)
```mermaid
sequenceDiagram
participant C as Client
participant S as Central server (integrated)
participant PG as Postgres (access)
Note over C,S: start — the plan decides this is a transcode
C->>S: POST /playback/start (RequireAuth, protocol_version 3)
S->>PG: resolve file + access
S->>S: PlanPlaybackV3 → delivery = server_transcode_hls
S->>S: StartTranscode (ffmpeg) + RegisterTranscodeSession
S->>S: card = NewRecipeCard(opts); token = Sign(card.ToClaims(), 24h)
S-->>C: 201 plan.url = /playback/transcode/{sid}/master.m3u8?st=TOKEN
Note over C,S: hot path — NO Postgres, NO lease (live session in memory)
C->>S: GET .../master.m3u8?st=TOKEN
S->>S: LoadOrReconstructSession → live hit → BuildPlaybackManifest (segments carry ?st)
S-->>C: manifest
loop every segment
C->>S: GET .../segment/seg_N.m4s?st=TOKEN
S->>S: live session → GetSegment → ServeFile
S-->>C: bytes
end
```
The hot path touches neither Postgres nor the lease — it is an in-memory map
hit. `?st` is verified only to decode a card if reconstruct is needed; a live
session ignores it.
### 12.4 Normal playback — native, multi-node (offloaded)
> **Deferred:** the `GET silo:streamauth:{sid}` lease guard and its `deny → 403`
> branch are the planned revocation path, **not** in the current implementation.
> As shipped the node verifies the token, tracks the session, and serves — there
> is no deny check.
```mermaid
sequenceDiagram
participant C as Client
participant S as Central server
participant N as Proxy node
participant T as Transcode node
participant R as Redis
C->>S: POST /playback/start (RequireAuth, protocol_version 3)
S->>S: card(full recipe, tnode=T); token = Sign(card.ToClaims())
S-->>C: plan.url = {N}/stream/transcode/TOKEN/master.m3u8
loop manifest + segments
C->>N: GET /stream/transcode/TOKEN/...
N->>N: verifyToken(TOKEN)
N->>R: GET silo:streamauth:{sid} (lease guard)
alt deny
N-->>C: 403 (no bytes)
else allow / absent
N->>R: Track silo:sessions:{node}:{sid} (uid, mfid from claims)
N->>T: proxy /transcode/{sid}/...
T-->>N: bytes
N-->>C: bytes
end
end
```
The node copies `uid`/`mfid` from the verified token into the Redis tracker —
that is what enriches the live admin "active streams" view (who/what per node).
### 12.5 Restart → reconstruct (native transcode)
```mermaid
sequenceDiagram
participant C as Client
participant S as Central server (just restarted — session map empty)
Note over S: in-memory session GONE; NO transcode_recipes table to read
C->>S: GET /playback/transcode/{sid}/segment/seg_42.m4s?st=TOKEN
S->>S: card = streamCardFromQuery(?st) → Verify + decode recipe
S->>S: LoadOrReconstructSession → GetSession = NotFound, card != nil
S->>S: ReconstructSession (re-bind: refuse userID==0 / != card.uid; card.sid == {sid})
S->>S: ReconstructTranscode(seg=42) → single-flight, mark in-flight, respawn ffmpeg SEEKED to seg 42
S-->>C: bytes (resumes near where the client was)
```
- direct/remux restart is the same but Tier-1: reconstruct the `Session` from the
identity token, then `Range` / `?seek` re-serve — no ffmpeg rebuild.
- multi-node restart: the integrated front-end reconstructs only the `Session`
(to learn `tnode`) and re-proxies; the transcode node keeps serving. If the
transcode *node* itself reboots, the proxy forwards the stream token
(`X-Silo-Stream-Token`) and the node self-reconstructs ffmpeg seeked to the
requested segment (native path, P-3). A jellycompat session on a rebooted node
reconstructs too: the node fetches the recipe central wrote to the shared Redis
recipe store (`internal/noderecipe`) at transcode start, since the Jellyfin
client's token cannot carry it.
- cleanup race: a segment dir is reaped only if absent from the live map AND the
in-flight set AND older than 24h (max token TTL), so a token that can still
reconstruct never gets its dir wiped.
### 12.6 Auth deny — the session-deny marker
> **Status: deferred to a future PR.** The entire "Admin Stop/Terminate → write
> deny marker" and "Offload node → GET deny → 403" flow below is the planned
> revocation design and is **not** in the current implementation. As shipped,
> admin Stop/Terminate does the "realtime WS stop + producer teardown" half only
> (the right branch); it writes no marker, and the node performs no deny check, so
> a valid token reconstructs until its ≤24h TTL. New playback is still gated at
> `/playback/start` (the top subgraph is accurate).
```mermaid
flowchart TD
subgraph New["New playback (any topology)"]
P["/playback/start — RequireAuth + access check"] --> PB{allowed?}
PB -- no --> PR[refused — ban takes effect at next play]
PB -- yes --> PM[mint token]
end
subgraph Admin["Admin Stop/Terminate (event, not a timer)"]
K[denyStreamLease] --> WD[SET silo:streamauth:sid = deny<br/>TTL = 24h]
K --> WS[realtime WS stop + producer teardown]
end
subgraph Node["Offload node — every serve"]
G[verifyToken OK] --> L{GET silo:streamauth:sid}
L -- present deny --> F[403, no bytes]
L -- absent / redis-err --> SV[serve bytes fail-open]
end
```
Invariants:
- No steady-state writes: the marker is set only on an admin kill, never on a
timer. The normal serve path finds *no* key and serves.
- Fail-open: absent key or Redis error → serve. The only hard stop is a present
deny.
- The integrated box reads no marker — the producer-kill + session removal on
Terminate is the stop there; the marker only matters where nodes serve.
- Not covered here (by design): a *passive* ban / partial access change of an
in-flight non-cooperative node stream — enforced at next play, bounded by the
≤24h token (§7).
### 12.7 Jellycompat — what differs
```mermaid
sequenceDiagram
participant J as Jellyfin client
participant S as Central (jellycompat)
participant PG as Postgres compat store
J->>S: negotiate → PlaybackSession{UpstreamSessionID, MediaSources}
S->>PG: Put (jellycompat_playback_sessions)
Note over S: transcode start
S->>S: StartTranscode; recipe = NewRecipeCard(opts)
S->>PG: Update(ps): TranscodeStarted=true, Recipe=recipe (same write)
Note over J,S: restart → reconstruct from the COMPAT STORE, not a token
J->>S: GET HLS segment
S->>PG: Get(playSessionID) → ps.Recipe
S->>S: LoadOrReconstructSession(UpstreamSessionID, card = ps.Recipe) → ReconstructTranscode(*ps.Recipe)
S-->>J: bytes
```
Jellyfin clients cannot carry a native `?st` token, so the recipe is folded into
the durable compat row (`PlaybackSession.Recipe`, persisted in the `data` JSONB)
and written in the same `Update` that flips `TranscodeStarted`. The node hop
(multi-node jellycompat) still uses a path token exactly like native (the lease
guard is deferred along with the rest of the revocation path).
### 12.8 Hot-path cost per request
The "lease" / "SET deny" Redis costs below are **deferred** (the revocation path
is not shipped); as shipped the node does only the tracker write, and admin
Stop/Terminate writes no Redis key:
| request | Postgres | Redis | central CPU | reconstruct |
|---------|----------|-------|-------------|-------------|
| native segment, live, integrated | — | — | map hit | — |
| native segment, live, node | — | 1 track (+ deferred: GET lease) | — | — |
| native segment, after restart, integrated | — | — | verify JWT + ffmpeg respawn (once, single-flight) | yes |
| jellycompat segment, live | — | track (+ deferred: lease) | map hit | — |
| jellycompat segment, after restart | 1 Get (compat row) | track (+ deferred: lease) | respawn | yes |
| admin Stop/Terminate (event, not per-request) | — | deferred: 1 SET deny | one write | — |
---
## 13. Restart-resiliency behavior matrix (role × path)
The observable reconstruction behavior of every playback path under a restart of
each server role. **✅** = the path reconstructs and resumes on the client's next
request; **—** = the path never executes on that role (nothing to reconstruct);
**⚠️** = reconstructs only while a stated precondition holds.
| path | integrated restart | proxy-node restart | transcode-node restart |
|------|--------------------|--------------------|------------------------|
| native · direct | ✅ rebuild `Session` from `?st` token → `Range` re-serve | ✅ stateless re-serve from `claims.MediaPath` | — not served on a transcode node |
| native · remux | ✅ token + `?seek` → re-spawn pipe | ✅ stateless per-request pipe re-spawn | — |
| native · transcode | ✅ token (full recipe) → respawn ffmpeg seeked to segment | ✅ transparent re-route + token forward | ✅ self-contained — token is recipe-complete |
| jellycompat · direct | ✅ re-resolve from durable compat row → `Range` re-serve | ✅ stateless re-serve from token `MediaPath` | — |
| jellycompat · remux | ✅ compat row + `?seek` | ✅ stateless per-request pipe re-spawn | — |
| jellycompat · transcode | ✅ `ReconstructTranscode(*ps.Recipe)` from compat row | ✅ transparent re-route + token forward | ⚠️ reconstructs **iff** the shared Redis recipe (`internal/noderecipe`, ≤24h TTL) still exists; fails closed (404) otherwise |
**What carries the recovery state, per role**
| role | native carrier | jellycompat carrier |
|------|----------------|---------------------|
| integrated | `?st` stream token — identity for direct/remux, full recipe for transcode | durable compat row `PlaybackSession.Recipe` |
| proxy node | self-describing path token, re-derived per request — the proxy holds no per-session state | same path token (identity); the recipe is not needed at the proxy |
| transcode node | forwarded `X-Silo-Stream-Token`, recipe-complete | identity token + Redis `noderecipe` recipe (the Jellyfin token cannot carry it) |
**Reading the matrix**
- **Integrated and proxy-node restarts are unconditional** for every applicable
path. The proxy holds no authoritative per-session state — direct/remux are
re-served from the token's `MediaPath`, transcode is reverse-proxied — so a
proxy bounce, or a reroute to any in-group proxy (`pickProxy` is round-robin
with no session affinity), is transparent.
- **The four `—` cells are structural, not gaps.** Direct and remux never run on
a transcode node — the proxy (or the integrated box) serves them from source
media — so a transcode-node restart has nothing to reconstruct on those paths.
- **The one conditional (⚠️)** is jellycompat transcode after a *transcode-node*
restart. The node-hop token is identity-only — not because a Jellyfin client
cannot round-trip it (the token is server-minted and opaque to the client), but
because the recipe is mutated in place under a stable session id and a
third-party Jellyfin client cannot be driven to refresh a stale token, so a
token snapshot could reconstruct a stale rendition (see §10). The node therefore
rebuilds from the Redis `noderecipe` entry central overwrites on every switch
rather than from the token. Native transcode has no such dependency — every
native audio switch re-mints the token, so it is always recipe-complete and
current. This is the only native-vs-jellycompat asymmetry in reconstruction
(see §10).
**Out of scope of this matrix** (accepted behaviors, not restart-reconstruction
holes — see §7, §10):
- Passive ban / partial access change of an in-flight node stream — enforced at
next play, bounded by the ≤24h token, not by reconstruction.
- Integrated transcode behind a non-sticky load balancer can split-brain into
divergent segment dirs (P-1); safe single-front-end or with LB affinity. Remote
(node) sessions are immune — node affinity routes every front-end to the same
transcode node.
+9 -14
View File
@@ -61,8 +61,7 @@ point of keeping the key out of the database. Recovery means re-entering the
affected credentials:
- Re-enter Sonarr/Radarr and Autoscan API keys, S3 keys, watch-sync connections,
history-import tokens, subtitle provider credentials, and plugin runtime
configuration.
history-import tokens, and subtitle provider credentials.
- `auth.jwt_secret` becomes unreadable, so all existing sessions are invalid and
users must log in again (a new secret is generated on next boot if the row is
cleared — see below).
@@ -80,11 +79,7 @@ remaining plaintext in place:
3. the two arr `api_key_ref` columns — these are **resolved-then-encrypted**: a
legacy row that held a `server_settings` reference (e.g.
`requests.radarr.api_key`) is collapsed to the real credential before being
encrypted,
4. whole `plugin_runtime_configs.config_value` objects. Plugin config is
intentionally opaque to the host storage layer: plugins may write undeclared
keys and manifest annotations may be unavailable or change over time, so
manifest-selected field encryption cannot fail closed.
encrypted.
The backfill is safe to run repeatedly: already-encrypted values are skipped, and
a per-row guard makes concurrent multi-node boots converge without
@@ -97,9 +92,7 @@ whatever the primary encrypted. No manual steps are required.
Downgrading to a binary that predates this change is **not** safe while secrets
are encrypted, because the old binary has no read path: it would read
`enc:v1:auth.jwt_secret` as a literal JWT secret (invalidating all sessions) and
read `enc:v1:`-prefixed integration keys as garbage credentials. It would also
pass the reserved plugin-config envelope object to plugins instead of their
configuration.
read `enc:v1:`-prefixed integration keys as garbage credentials.
To downgrade safely you must first return the affected values to plaintext, for
example:
@@ -130,10 +123,7 @@ history-import admin/session tokens and temporary server-list credentials,
subtitle provider `api_key`/`password`,
the Jellyfin-compat session's bridged Silo access/refresh tokens
(`jellycompat_sessions.streamapp_access_token` / `streamapp_refresh_token`), and
the ABS signing key. Plugin runtime configuration is encrypted as one opaque
row-bound envelope rather than by manifest field. Consequently, runtime code
must use `RuntimeConfigStore`; database JSON-member queries and indexes are not
supported for `plugin_runtime_configs.config_value`.
the ABS signing key.
Deliberately **not** encrypted (tracked as follow-ups):
@@ -142,6 +132,11 @@ Deliberately **not** encrypted (tracked as follow-ups):
lookup. They need a deterministic **blind-index hash** column instead:
`api_keys.api_key`, `webhook_sync_connections.webhook_secret`,
`jellycompat_sessions.token`, and `watch_together_rooms.join_token`.
- **Plugin runtime config** — `plugin_runtime_configs.config_value` is opaque
plugin-defined JSONB whose secret fields are manifest-declared and whose runtime
lives in a separate repo; encrypting it correctly needs a coordinated,
manifest-aware design.
Excluded (not a gap): `plex_sync_connections.*` is a dead table (zero Go
references); `oauth_completion.token_ciphertext` is already AES-GCM;
`users.password_hash` and the `*_hash` columns are already hashed.
-26
View File
@@ -17,29 +17,3 @@ When the scope locks, this file becomes the source of truth and will contain:
Until lock: treat any capability not tracked as `Proposed`/`Locked` on the project as out of scope
for feature PRs (see the scope gate in `CLAUDE.md`).
## Breaking removals taken before lock
The additive-only rule in item 2 binds at lock. Before then a removal is in scope, and there is no
amendment to write because the amendment process in item 3 does not exist yet. `CLAUDE.md` states
the rule without that qualifier, which reads as a contradiction — it is not, but a removal taken
now has to be recorded here so a reader after lock can tell a deliberate decision from a violation.
Each entry names what goes, why waiting is worse, and the design that decided it. **Every removal
listed here must have shipped before the scope locks.** One still outstanding at lock loses its
justification and falls back to the Deprecation/Sunset flow like anything else.
| Removed | Release | Rationale |
|---|---|---|
| String `GET`/`PUT`/`DELETE /api/v1/settings…`, the unknown-key extension bag, preference fields on profile/library/series DTOs | Cross-platform settings contract, [design](../superpowers/specs/2026-07-10-cross-platform-user-settings-contract-design.md) | Replaced wholesale by the typed settings contract. Deferring past lock would mean carrying the Deprecation/Sunset surface *and* the untyped key bag — which lets any client invent a production setting the server stores unvalidated — through the deprecation window, which is the exact surface the contract exists to close. |
| The ten string-registry admin user-settings routes: `GET /api/v1/admin/users/{id}/settings`, `GET /api/v1/admin/users/{id}/settings/{key}`, `PUT /api/v1/admin/users/{id}/settings/{key}`, `DELETE /api/v1/admin/users/{id}/settings/{key}`, `GET /api/v1/admin/users/{id}/device-settings`, `GET /api/v1/admin/users/{id}/device-settings/{key}`, `DELETE /api/v1/admin/users/{id}/device-settings/{key}`, `PUT /api/v1/admin/users/{id}/profiles/{profile_id}/device-settings/{key}/{device_id}`, `DELETE /api/v1/admin/users/{id}/profiles/{profile_id}/device-settings/{key}/{device_id}`, `DELETE /api/v1/admin/users/{id}/profiles/{profile_id}/devices/{device_id}/settings` | Cross-platform settings contract, [design](../superpowers/specs/2026-07-10-cross-platform-user-settings-contract-design.md) | The admin projection of the removal above: these routes read and wrote the string registry the contract replaces. Their canonical successors are `GET /api/v1/admin/users/{id}/settings/values` (every stored value across all scopes) and `PUT`/`DELETE /api/v1/admin/users/{id}/settings/values/{key}` at an explicit scope, sharing the session routes' validation. Keeping the string routes past lock would preserve an admin-only write path into the untyped bag after the user-facing one closed. |
| The legacy (pre-v3) request and response bodies of `POST /api/v1/playback/start`. The route stays; a body that does not declare `protocol_version: 3` now gets `426 client_upgrade_required` instead of a legacy plan | Playback protocol v3, [spec](playback-protocol-v3.md), [plan](../superpowers/plans/2026-07-30-playback-protocol-v3-neutral-contract.md) | v3 is a platform-neutral contract that moves route selection, quality laddering and track choice server-side. The legacy body carried the opposite model — the client posted a decision it had already made. Running both means every planner change has to be made twice, in two shapes that disagree about who decides, and the legacy shape is the one the client-specific bugs live in. A deprecation window would extend that duplication across the whole window for a protocol no shipping client will still speak by lock. |
| `POST /api/v1/playback/transcode/start` | Playback protocol v3, [spec](playback-protocol-v3.md) | Client-posted transcode recipes. Superseded by the `quality_change` replan operation: the client sends a label from `playback_plan.available_qualities` and the server picks the encode. Keeping the endpoint keeps a second, unvalidated way to start a transcode that bypasses plan identity entirely. |
| `PATCH /api/v1/playback/{session_id}/audio` | Playback protocol v3, [spec](playback-protocol-v3.md) | Superseded by the `track_change` replan operation, which changes the audio track *and* returns the resulting plan. The PATCH mutated the session without re-planning, so a track change that invalidated the route left the client playing a plan the server no longer agreed with. |
| `409 protocol_disabled` on `POST /api/v1/playback/route-events`, and the `"enabled": false` shape of `GET /api/v1/playback/capability` | Playback protocol v3, [spec](playback-protocol-v3.md) | Both described a server with v3 switched off. With v3 the only playback protocol that state cannot exist — "disabled" would mean "no playback at all". The `enabled` field itself is kept and is constant `true`, so clients that feature-detect against it keep working; only the negative shape and the status code go. |
| The draft-v3 platform-specific wire vocabulary: `ClientPlaybackContextV3.features`, `.platform`, and `.engines`; `PlanV3.engine`; `output_route_generation` in start, replan, output-context, and route-event bodies; Android device/build fields (`brand`, `device`, `product`, `soc_*`, `build_*`, `security_patch`, `sdk_int`, `abis`); and the `media3_only` / `detailed_decode_capabilities` feature tokens | Platform-neutral playback protocol v3, [spec](playback-protocol-v3.md), [plan](../superpowers/plans/2026-07-30-playback-protocol-v3-neutral-contract.md) | These names exposed one client's implementation as the cross-platform contract. Before v1 lock they are replaced by neutral delivery classes, evidence tiers, `device.platform` / `device.os_version` / bounded `platform_details`, opaque `output_context_id`, and top-level feature advertisement. Carrying both drafts through lock would force every client to translate Media3-specific aliases indefinitely and leave two conflicting sources of capability truth. |
Feature-detection precedent: clients discover which metadata providers (including the
built-in NFO provider, #216) apply to a library type via
`GET /api/v1/libraries/provider-defaults` rather than version sniffing. New capabilities
should follow the same capability-endpoint pattern.
@@ -1,99 +0,0 @@
# Handoff: `account.capabilities_changed` event on the events WebSocket
**Date:** 2026-07-06
**Requested by:** Apple client team (silo-apple)
**Status:** Proposed — server implementation needed
## Problem
Clients cache user-facing capability payloads (e.g. `GET /api/v1/downloads/capability`)
and have no way to learn that an admin changed something that affects them. Concrete
incident: enabling "Allow transcoded downloads" (`users.download_transcode_allowed`)
for a user did not surface the transcode quality presets in the iOS app until the
client's cache expired (previously 24h).
The Apple client now re-fetches capability on app-foreground and when the download
options UI opens (pull-based safety net, shipped in silo-apple). This handoff covers
the push half: an invalidation event so connected clients react immediately, without
polling.
## Existing infrastructure (no new transport needed)
- Events WebSocket: `GET /api/v1/events/ws` (`internal/api/handlers/events_ws.go`),
channel-based subscribe with per-role channel ACLs (`allowedChannelsForRole`).
- `user_state` channel is already available to non-admin users and the hub already
filters envelopes by `env.UserID` for non-admins (`allowsEventForClaims`), so a
user-targeted event on this channel is only delivered to that user (and admins).
- Publishing helper: `evt.Hub.PublishJSON(ctx, channel, type, payload, opts)`
(`internal/events/hub.go`), pattern example in
`internal/api/handlers/user_state_events.go`.
## Proposed contract
**Channel:** `user_state` (reuse; it is the only user-scoped channel non-admins can
subscribe to, and clients that care already subscribe to it).
**Event type:** `account.capabilities_changed`
**Payload — intentionally minimal (invalidation ping, not a data carrier):**
```json
{
"scope": "downloads" | "playback" | "all"
}
```
Do **not** include the new capability values. Clients respond by re-fetching the REST
endpoints they already consume (`/api/v1/downloads/capability`, playback prefs, etc.).
This keeps the event contract trivial and guarantees it never drifts from the REST
response shapes. `scope` is a coarse hint so clients can skip irrelevant re-fetches;
when in doubt publish `"all"`.
**Targeting:**
- Per-user change → `PublishOptions{UserID: <affected user>}` so only that user's
connections receive it.
- Server-wide setting change → publish once with no `UserID` (fan-out to all
connected users). Verify `allowsEventForClaims` passes envelopes with
`UserID == 0` to non-admins — it does today (`env.UserID > 0` guard).
## Publish sites
1. **Admin user update handlers** (`internal/api/handlers/admin.go` user
create/update paths): publish scope `"downloads"` when any of
`download_allowed`, `download_transcode_allowed` change; `"playback"` for
playback-affecting fields (`max_streams`, `max_transcodes`, quality limits);
`"all"` if simpler. Target the affected `UserID`.
2. **Server settings writes** (settings handler / config store): publish untargeted
scope `"downloads"` when any `download.*` key changes (notably
`download.transcode_enabled`, `download.enabled`, `defaults.download_*`);
`"playback"` for `playback.*` gates that shape client-visible capability.
3. **Access-group / policy-engine changes** that alter `download` /
`download_transcode` action outcomes, if applicable — same event, `"all"` scope,
untargeted (membership makes per-user targeting fiddly; the re-fetch is cheap).
No snapshot frame needed for this event type (`snapshotForChannel` for `user_state`
already returns `null`).
## Client behavior (for reference / Android alignment)
- Apple: will add a `ServerEventsClient` subscribing to `user_state` +
`notifications`; on `account.capabilities_changed` with scope `downloads`/`all`,
calls its existing capability re-fetch. Until then the pull-based refresh already
covers correctness.
- Android: already has `NotificationsRealtimeClient` on this socket; should handle
the same event the same way.
- Clients must treat the event as best-effort: sockets are down while backgrounded,
so they keep refresh-on-foreground / refresh-on-use regardless.
## Acceptance checks
1. Toggle `download_transcode_allowed` for a connected non-admin user → that user's
socket receives `account.capabilities_changed` (scope `downloads`); other users
receive nothing.
2. Flip `download.transcode_enabled` server setting → all connected users receive
the event once.
3. A non-admin subscribed to `user_state` never receives another user's targeted
capability events (existing `allowsEventForClaims` filtering).
4. `GET /api/v1/downloads/capability` immediately after the event reflects the new
presets (it already does — the event carries no data to go stale).
@@ -1,179 +0,0 @@
# Streaming write-deadline fix: stop truncating streams at 120s without losing stalled-client protection
**Status:** planned (2026-07-09)
**Repos:** silo-server (primary), silo-apple (hardening follow-up)
**Root-cause session:** live debugging on Apple TV, 2026-07-09 evening
## Problem
`cmd/silo/main.go:2373` sets `WriteTimeout: 120 * time.Second` on the main API
`http.Server`. Go's `WriteTimeout` is an **absolute deadline from the start of each
request**, not an idle timeout — so every response still being written at T+120s is
killed mid-body with a clean connection close.
Observed impact (2026-07-09, dev server, Apple TV loopback client):
- Every direct-stream GET (`/api/v1/stream/{session_id}`) serving a 15.3 GB MKV was
cut at exactly 120s. Server log signature: `path=/api/v1/stream/` with
`duration_ms=120000` (three instances in a 3h window; more go unlogged when the
client disconnects first).
- The Apple client's byte-cursor reconnect ladder silently absorbs most kills, so
playback "mostly works" — but when a kill lands during backpressure parking or a
demuxer resync, the client's 3-attempt `.prematureEOF` retry budget exhausts and it
performs a full teardown + new-session recovery (~5 s visible stop). Four such
failures in ~35 minutes of playback.
- Confirmed by dual-path probe (long ranged GET consumed at playback rate): died at
~123s direct to the origin and ~151s via the CDN edge edge (origin killed
the edge's upstream GET at 120s; the edge's buffer drained for the extra ~30s).
The CDN is exonerated — it only relayed the origin's truncation.
Precedent inside the same file: the Jellyfin-compat listener (`main.go:2514`) and the
Audiobookshelf-compat listener (`main.go:2535`) both already set `WriteTimeout: 0`
because compat clients stream long responses. The main listener serves the exact same
class of traffic for first-party clients and was never aligned.
## Goals / non-goals
Goals:
1. Streaming/long responses are never killed while they are making progress.
2. Genuinely stalled connections (client gone, TCP zombie, slow-loris) still get
reaped in bounded time — we do NOT simply set `WriteTimeout: 0` on the main
listener, because that removes mid-response stall protection entirely (a peer that
stops ACKing would block a handler goroutine + fd indefinitely).
3. All non-streaming API routes keep today's 120s absolute protection unchanged.
4. No client changes required for the fix to take effect (Android, web, Infuse/compat
benefit identically).
Non-goals: CDN edge tuning; silo-server#333 control-plane restart work; the
silo-apple `.prematureEOF` parking hardening (tracked as follow-up below, it is
defense-in-depth once this lands).
## Design: rolling per-write deadline for streaming handlers
Semantics change for streaming responses only, from "must complete within 120s" to
"must make progress at least every N seconds".
### New helper (one small file, e.g. `internal/api/httpstream/rolling_deadline.go`)
```go
// RollingDeadlineWriter wraps a streaming http.ResponseWriter and pushes the
// connection's write deadline forward on every successful write, so long
// responses survive indefinitely while stalled ones die within `window`.
type RollingDeadlineWriter struct {
w http.ResponseWriter
rc *http.ResponseController
window time.Duration // stall budget, e.g. 180s
step time.Duration // min interval between deadline bumps, e.g. 15s
last time.Time
}
func New(w http.ResponseWriter, window time.Duration) *RollingDeadlineWriter
func (s *RollingDeadlineWriter) Write(p []byte) (int, error) // bump-then-write
func (s *RollingDeadlineWriter) ReadFrom(r io.Reader) (int64, error) // see below
func (s *RollingDeadlineWriter) Header() http.Header
func (s *RollingDeadlineWriter) WriteHeader(code int)
func (s *RollingDeadlineWriter) Flush()
func (s *RollingDeadlineWriter) Unwrap() http.ResponseWriter // ResponseController compat
```
Key points:
- Uses `http.NewResponseController(w).SetWriteDeadline(time.Now().Add(window))` —
Go ≥ 1.20 (we are on 1.26.4). A per-request controller deadline **overrides** the
server-level `WriteTimeout` for that response, which is exactly the mechanism the
stdlib provides for this case.
- Bumps are rate-limited (`step`, ~15s) so we do one `SetWriteDeadline` per ~15s of
wall time, not one per 32 KB chunk.
- **`ReadFrom` must be implemented** and delegate to the underlying writer in bounded
slices (e.g. `io.CopyN(underlying, r, 64<<20)` per iteration, bumping the deadline
between iterations). Rationale: `http.ServeContent` → `io.Copy` uses the
`io.ReaderFrom` fast path on the response writer (sendfile for `*os.File`); a naive
wrapper without `ReadFrom` silently forfeits sendfile and burns CPU copying 15 GB
through userspace. Bounded-slice delegation keeps sendfile *and* the rolling
deadline.
- First bump happens in `New` (covers the header write + first body bytes).
- `window` default 180s, overridable via env `SILO_STREAM_WRITE_STALL_TIMEOUT`
(seconds). 180s > the Apple client's longest observed benign backpressure park
(~20s) and > outage-probe cadence with margin, while still reaping zombies in
minutes. Note: a paused client that stops reading its socket for >window will have
the connection reaped — that is fine and intended; the client's reconnect ladder
resumes at the byte cursor on unpause (this is today's behavior for ALL streams at
120s, so it is a strict improvement).
### Application points (all on the main listener)
| Path | File | Mechanism | Change |
|---|---|---|---|
| Direct play (the tonight failure) | `internal/playback/directplay.go:52` `ServeDirectPlay` | `http.ServeContent` of the full media file | wrap `w` before `ServeContent` |
| Remux stream | `internal/playback/remux.go:226` `ServeRemux` (write loop `:255`) | manual chunked `Write`+`Flush` | wrap `w` (loop needs no change) |
| Offline downloads | `internal/api/handlers/downloads.go:401` → `svc.ServeFile` | full media file download | wrap `w` at the handler before delegating |
| Transcode-node proxy | `internal/api/handlers/playback.go:2998` `io.Copy(w, resp.Body)` | long-lived proxy of remote transcode output | wrap `w` |
| Ebook/converted serving | `internal/api/handlers/ebook_convert_serve.go:159`, `ebook_reader.go:625` | `ServeContent`, files up to ~100s of MB; slow readers can exceed 120s | wrap `w` (cheap, same helper) |
Explicitly **unchanged**:
- Transcode HLS segments (`playback.go:2897 http.ServeFile`) — bounded few-second
files; 120s absolute is fine. (Harmless to wrap later if segment sizes grow.)
- WebSockets (`/control/ws`) — hijacked connections manage their own deadlines;
tonight's WS survived 4+ minutes untouched, confirming no interaction.
- Jellyfin/ABS compat listeners — separate `http.Server`s, already `WriteTimeout: 0`;
optionally migrate them to the rolling writer later so they regain stall
protection (follow-up, not required).
- All JSON/image/API routes — keep the server-level 120s absolute deadline.
`cmd/silo/main.go:2374` itself stays at `WriteTimeout: 120s`. That is the point: the
global guard remains, streaming handlers opt out per-response with a better contract.
## Server tests
1. **Unit — rolling behavior:** wrapper on a fake ResponseController records deadline
bumps; assert bump on first write, rate-limited bumps thereafter, `ReadFrom`
chunking delegates and bumps per slice.
2. **Integration — survives the server timeout:** `httptest.Server` with
`WriteTimeout: 1s`; handler streams 3s of throttled data through the wrapper
(window 2s). Assert full body received (fails without wrapper — this is the
regression test for tonight's bug).
3. **Integration — stalled client still reaped:** wrapper with window 500ms writing
to a client that stops reading; assert handler write errors within ~window, not
never.
4. **Regression:** non-streaming route on the same server still killed at
`WriteTimeout` (guard unchanged).
## Validation on dev (after tonight's viewing)
1. `make dev-deploy`.
2. Re-run the range-GET probe (script preserved from tonight's session): sustained
open-ended GET at playback rate for ≥ 15 min on both direct and CDN paths; expect
zero early closes and no `duration_ms=120000` entries in the request log.
3. Long ATV playback session (existing client build): expect zero
`prematureSourceEnd` teardowns over a full film.
4. Spot-check normal API latency/behavior and one Jellyfin-compat client.
## Follow-up workstream: silo-apple client hardening (separate branch)
Defense-in-depth so any truncating origin/middlebox (not just our own bug) degrades
to an invisible reconnect instead of a 5s rebuild:
1. Park persistent mid-stream `.prematureEOF` into the existing outage ride-through
once the cursor-resume retries reproduce the same truncation offset
(`PlaybackOriginOutagePolicy.shouldPark`, `PlaybackSourceOriginStream.swift:159-173`;
writer then gets the 240s park allowance instead of the 10s deadline). Keep it
kill-switchable alongside `SILO_DISABLE_OUTAGE_RIDE_THROUGH`.
2. Add `[CMP-ORIGIN]` logging: one line per origin connection end (cause, HTTP
status, cursor, bytes delivered, retry streak) — tonight the entire retry-and-give-up
sequence ran with zero log output.
3. Verify reconnects use fresh connection state (AetherEngine builds a new URLSession
per reconnect to avoid poisoned keep-alive pools; our 3 rapid same-offset failures
while a fresh session succeeded seconds later is circumstantial evidence we reuse).
4. Optional: raise `.prematureEOF` retry cap toward AE's progress-aware semantics.
Android note: the server fix benefits Android identically with no client change;
worth a later check of how its player handles a 120s kill today (it may have been
absorbing them silently, or contributing to unexplained rebuffers).
## Rollout
Dev first (above), soak for a few days of normal viewing, then include in the next
server release. The change is additive and per-handler; risk is localized to the
wrapped streaming paths, and the global timeout still protects everything else.
@@ -1,771 +0,0 @@
# Client Diagnostics: crash reports and debug log upload
Status: Draft (spec + cross-repo plan)
Date: 2026-07-19
Repos affected: `silo-server`, `silo-android`, `silo-apple`
## Summary
Add an opt-in, self-hosted diagnostics pipeline: Silo clients detect crashes
and abnormal exits, collect structured debug logs (playback, TV focus,
network, lifecycle) plus a hardware snapshot (device model, display/HDMI,
audio path, codec capabilities), and — only with explicit user consent —
upload a compressed diagnostics bundle to the user's own Silo server. Admins
review bundles through new acting-admin API endpoints alongside the existing
server logs tooling.
Everything ships **disabled by default**:
- Server: a `diagnostics.uploads_enabled` server setting gates the whole
feature (default off), and it cannot be enabled unless the server's private
object storage is configured and validated.
- Client: verbose "debug logging" is a per-device setting (default off).
Crash reporting defaults to **Ask** — after an abnormal exit the app shows
an incident-specific prompt (e.g. *"Silo closed unexpectedly during
playback. Send a diagnostic report to your server?"*) with
**Send / Don't send / Always send**. Nothing uploads without one of: an
explicit prompt confirmation, a prior "Always send" election bound to this
server and account, or the user explicitly sending a manual capture.
## Motivation
Today we are blind to client-side failures:
- **No crash reporting anywhere.** Neither the Android repo nor the Apple
repo installs an uncaught-exception handler, uses MetricKit, or bundles a
crash SDK (verified: no handler/SDK references in either repo; the only
Firebase dependency is messaging). A user saying "the app crashed" is a
dead end.
- **Diagnostics don't survive to the report.** Android logs go to logcat (raw
`android.util.Log` in ~40 files, no buffer or file sink); the Apple
player's rich `[CMP]`/`[CMP-DIAG]` diagnostics go through `print()`
(`PlayerLog.swift` / `PlayerCore.swift`) with no app-owned persistent sink.
By the time a user reports a problem, the evidence is gone.
- **The hardest bugs are device-specific.** Shield HLG quirks, Fire TV
passthrough suppression, HDMI mode switches, TV focus traps — reproducing
them requires knowing the exact device, panel, audio chain, and codec path.
Users can't reliably report any of that.
- **The server already has half the story.** `operational_logs` records
`playback_session_id` (migration `028_log_partitioning.sql`), the admin
logs API filters by it, and the web admin has a logs viewer. What's missing
is the client half, and a way to join the two.
## Goals
- Capture crashes and abnormal exits (JVM/native/ANR on Android; crash and
hang diagnostics on iOS; abnormal-exit detection on tvOS) with enough
context to act on: stack or exit trace where the platform provides one,
recent structured logs, and a device snapshot.
- Capture deep opt-in debug logs for playback, TV focus behavior, networking,
and navigation/lifecycle — everything needed to troubleshoot user issues.
- Always include a hardware snapshot: device (Shield / Fire TV / onn /
phone), OS, app build, display and HDMI mode with HDR capabilities, audio
output path and passthrough capabilities, decoder inventory — with honest
`unknown` / `not_collected` states where a platform can't provide a field.
- One payload contract across Android and Apple; one server endpoint; one
admin surface. The contract is a checked-in versioned JSON Schema with
golden fixtures consumed by all three repos' CI.
- Explicit, server-bound consent for every byte uploaded; feature fully off
by default on both server and client.
- Bounded cost: size caps, per-account quotas, concurrency limits, and
server-side retention.
## Non-goals (v1)
- Live/continuous log streaming from clients to the server.
- Screenshots or screen recordings in bundles.
- Native/tvOS crash *stack* capture via an in-process crash reporter
(PLCrashReporter/KSCrash-style). tvOS v1 detects abnormal exits and
attaches breadcrumbs, not stacks (see Apple design). Adopting an in-process
crash reporter is a separate decision with its own signal-safety and review
implications.
- Symbolication. Bundles store what the OS gives us; a server-side
symbolication job can come later.
- Native-app admin viewer screens (per current product policy, admin surfaces
beyond STATS on the clients are a separate product decision; v1 admin
consumption is via API + web admin).
- macOS. The Apple repo has a macOS target, but v1 scopes to
`android`, `android-tv`, `ios`, `tvos`; the platform enum reserves `macos`
without accepting it.
- Third-party telemetry, metrics aggregation, or fleet analytics. This is a
support/debugging tool, not analytics.
## Why this route
**Upload to the user's own Silo server, not a third-party crash service.**
Crashlytics/Sentry SaaS would send user data to a third party, require vendor
accounts/keys we'd have to ship, and put the reports in front of *us* rather
than the person who can actually act — the self-hosting admin. Requiring
every admin to also run self-hosted Sentry is far too heavy. The Silo server
is the natural, privacy-aligned destination, and it already has auth, admin
tooling, object storage, and retention patterns to build on.
**Bundle-on-event, not streaming.** A bundle captured at the moment of
failure (crash, or a user-triggered capture) contains exactly the context
needed: recent structured logs, the playback stats timeline, and the hardware
snapshot. Continuous streaming would cost bandwidth and privacy while mostly
capturing noise, and would still miss pre-crash buffers.
**Hybrid storage: Postgres row + object-store blob.** Report *metadata* (a
small manifest: device summary, truncated crash summary, type, timestamps)
goes in a queryable table; the payload itself (potentially megabytes of logs
and crash artifacts) goes to the S3-compatible private bucket as a single
archive. Ingesting client log lines into the partitioned `operational_logs`
table was considered and rejected: bundles are consumed as whole documents by
a human, not queried row-wise; client lines are untrusted input with
different retention needs; and multi-MB uploads would bloat a table tuned for
the server's own high-churn logs. The server *does* emit normalized
operational events about diagnostics activity (report accepted / rejected /
downloaded / deleted, with report id, account, sizes, result) so ingest and
admin actions are auditable and correlate with existing logs — raw client
lines never enter `operational_logs`.
**A versioned archive, not a bare gzipped log stream.** Crash evidence is
heterogeneous: JSONL logs, ANR trace text, Android native tombstones
(protobuf on API 31+), MetricKit diagnostic JSON. A tar.gz archive with named
entries carries each artifact losslessly with a declared media type, keeps
large traces out of Postgres, and can evolve by adding entries.
**Build small in-house rather than adopt ACRA/other SDKs.** The surface we
need on Android (one exception handler writing a bounded marker, a ring
buffer, one upload call) is a few hundred lines; ACRA would add a dependency
and its own report format without covering Apple. On Apple, the OS provides
MetricKit natively (iOS; not tvOS — see Apple design).
## Architecture overview
```text
Android / Apple client silo-server
┌────────────────────────────────┐ ┌──────────────────────────────────────┐
│ Safe-logging facade → ring │ │ GET /api/v1/diagnostics/status │
│ └ debug mode: rotating │ │ └ available|disabled| │
│ segment files │ │ storage_unavailable + limits │
│ Crash/abnormal-exit capture │ │ POST /api/v1/diagnostics/reports │
│ ├ UEH marker (Android) │──▶│ ├ gate + storage check │
│ ├ ApplicationExitInfo (30+) │ │ ├ streaming, bounded multipart │
│ ├ MetricKit (iOS) │ │ ├ account quotas + concurrency │
│ └ exit sentinel (tvOS) │ │ ├ manifest → client_diagnostic_ │
│ Pending reports (server-bound) │ │ │ reports (state machine) │
│ DeviceSnapshot (probes+new │ │ └ archive → S3 private bucket │
│ accessors) │ │ Admin (acting admin): list/detail/ │
│ Consent UI (ask/always/never, │ │ download/delete + audit events │
│ per server+account) │ │ Retention + orphan reconciler task │
└────────────────────────────────┘ └──────────────────────────────────────┘
```
## Consent model
Consent is **scoped, versioned, and destination-bound** — not a global
boolean. Both clients support multiple servers and accounts, so a device-wide
"Always send" would let a bundle full of server A's titles and URLs upload to
server B after a switch. Rules:
- Consent (including "Always send") is **account-scoped**: every consent
record and every pending report is bound to
`(server_instance_id, account_user_id, consent_notice_version)`, where
`server_instance_id` is a stable opaque ID returned by the status
endpoint. The capturing `profile_id` is recorded on reports for
*attribution*, not as a consent scope — quotas and elections follow the
account.
- A pending report is only ever uploaded to the server+account it was
captured under. Reports are never retargeted. Switching server or account
neither uploads nor migrates pending reports; signing out of an account or
removing a server deletes its pending reports.
- "Always send" is an election for one server+account. Bumping
`consent_notice_version` (when we materially change what bundles contain)
invalidates prior elections and reverts to Ask.
- Setting crash reports to **Never** deletes pending reports for that
server+account and stops persistent capture (breadcrumbs/debug files); the
in-memory ring keeps running (memory-only, never uploaded without a later
explicit action).
- **Child/managed profiles**: the Diagnostics section is not shown to
profiles with `is_child`, and every diagnostics action — changing
settings, electing Always, the crash prompt, and manual capture/send —
requires a non-child profile. A crash captured while a child profile was
active is held pending and prompted for the next time a non-child profile
is active. Reports are attributed to account + capturing profile.
- The crash prompt and the manual flow both offer **View report** — a
human-readable summary (incident, categories and line counts, device
identity, destination server) before anything is sent.
- Uploads carry `consent: {mode, notice_version}` in the manifest so the
server can reject stale-consent uploads outright.
## Bundle format (shared contract)
An upload is `multipart/form-data` with exactly two parts, in order:
1. `manifest` — `application/json`, ≤ 64 KiB. Queryable summary; stored in
Postgres.
2. `bundle` — `application/gzip`: a tar.gz archive, `manifest.json` first.
Entry names come from a **fixed allowlist**, and each name implies its
media type — there is no per-entry type metadata to drift:
```jsonc
manifest.json (manifest minus the `archive` object; see hashing note)
device.json (full device snapshot)
logs.jsonl (structured log lines, newest-last)
crash/summary.json (normalized crash info incl. provenance)
crash/stack.txt (JVM stack / ANR trace, when present)
crash/tombstone.pb (Android native tombstone, opaque bytes, API 31+)
crash/metrickit.json (raw MetricKit diagnostic JSON, iOS)
breadcrumbs.jsonl (persisted pre-crash context journal, when present)
```
Hashing note: `archive.sha256` and the size fields in part 1 describe the
finalized `bundle` part bytes as transmitted. Since the archive is hashed
after it is built, the embedded `manifest.json` is the manifest **without**
the `archive` object; the server verifies part 1's `archive` fields against
the received blob. `archive.bytes` is the transmitted (gzip) size;
`archive.uncompressed_bytes` is the total decompressed tar stream size,
including tar headers, the end-of-archive marker, and record padding —
i.e. the byte count between the client's tar writer and gzip writer, and
what `gzip -l` reports. Standard end-of-archive zero padding (up to 64 KiB)
is accepted; any other trailing data is rejected.
The contract lives in this repo as a versioned JSON Schema
(`docs/design/schemas/client-diagnostics/v1/`) with canonical valid and
invalid fixtures; Go, Kotlin, and Swift CI all validate against the same
fixtures. Servers accept all schema versions they support and ignore unknown
additive fields.
### Manifest (part 1)
```json
{
"schema_version": 1,
"report": {
"type": "crash", // crash | anr | native_crash | hang | abnormal_exit | manual
"captured_at": "2026-07-19T18:22:31Z",
"capture_session_id": "run_c7d…", // UUID per app run, also stamped on log lines
"app_version": "1.4.2",
"app_build": "20841",
"platform": "android-tv", // android | android-tv | ios | tvos (macos reserved)
"os_version": "11 (API 30)",
"profile_id": "prof_…" // capturing profile, attribution only
},
"destination": { "server_instance_id": "srv_…" }, // consent binding; server rejects mismatches
"consent": { "mode": "prompt", "notice_version": 1 }, // prompt | always | manual
"crash": { // absent for manual
"summary": "NullPointerException in PlaybackSessionManager.start",
"stack_excerpt": "…truncated ≤ 8 KiB; full artifact in archive…",
"thread": "main",
"foreground": true,
"source": "ueh", // ueh | exit_info | metrickit | exit_sentinel
"provenance": "pre_failure", // pre_failure | post_restart | metric_reporting_period
"occurred_at": "2026-07-19T18:22:31Z" // best known; MetricKit reports carry period bounds
},
"device_summary": { "manufacturer":"NVIDIA", "model":"SHIELD Android TV", "os":"11", "form_factor":"tv" },
"playback_session_ids": ["ps_9f2…"],
"log_summary": { "lines": 3841, "bytes_gz": 412034, "dropped_lines": 12, "categories": ["playback","focus","network"], "debug_logging": true },
"archive": { "entries": ["manifest.json","device.json","logs.jsonl","crash/summary.json","crash/stack.txt"], "bytes": 498112, "uncompressed_bytes": 3110400, "sha256": "…" }
}
```
### Log line schema (`logs.jsonl`)
```json
{"ts":"2026-07-19T18:22:29.412Z","run":"run_c7d…","lvl":"W","cat":"playback","tag":"AudioCapabilityMgr","msg":"passthrough suppressed: HDMI sink lost TrueHD","attrs":{"sink":"HDMI","fmt":"truehd"}}
```
- `lvl`: `V|D|I|W|E`. `cat`: `playback`, `focus`, `network`, `lifecycle`,
`browse`, `cast`, `download`, `crash`, `other`.
- `run` (capture_session_id) distinguishes lines from prior app runs when
breadcrumbs or debug files span sessions.
- Playback additionally emits periodic (~5s) player-stats snapshot lines
(`"cat":"playback","tag":"StatsSnapshot"`) built from the existing stats
models — a timeline of decoder, resolution, HDR mode, bitrate, dropped
frames, and audio underruns around the failure.
### Safe logging contract (redaction happens at collection time)
Best-effort scrubbing at package time is not enough: today's client logs
already emit full URLs with query strings, token suffixes, and raw exception
strings (e.g. the Apple `HTTPClient` response logging and player URL prints;
Android exception messages containing backend URLs). Therefore:
- The facade accepts **typed attributes**, not preformatted strings, for
anything risky: URL values are normalized (userinfo, query, and fragment
always stripped; path preserved), exceptions pass through a sanitizing
formatter, and free-text `msg` is authored, not interpolated from network
data.
- Attribute keys are **normatively registered**: a per-category key registry
(checked in next to the JSON Schema) declares each key and its value type
(scalar types plus a few enumerated units). Unregistered keys fail debug
builds/CI and are dropped in production builds.
- Existing call sites are migrated **curated, not mechanically** — each
migrated line is reviewed against the contract. Unmigrated `Log.*`/`print`
call sites simply never enter bundles.
- Defense in depth at bundle time: values matching the account's current
access/profile tokens are replaced before packaging.
- Golden leak-fixture tests (JWTs, query tokens, signed URLs, cookies, token
fragments) run in all three repos' CI against the facade and the bundle
builder.
- The network category logs `method, templated path, status, duration`;
never headers, bodies, query strings, or full URLs.
### Device snapshot (`device.json`)
Fields are tri-state where a platform can't provide them: a value,
`"unknown"` (probe exists, couldn't determine), or `"not_collected"`
(no probe on this platform). Every snapshot carries `captured_at` and
`provenance` (`pre_failure` for snapshots persisted with the incident,
`post_restart` for snapshots taken at bundle-build time).
```json
{
"captured_at": "2026-07-19T18:22:31Z",
"provenance": "pre_failure",
"identity": { "manufacturer":"NVIDIA", "model":"SHIELD Android TV", "device":"mdarcy", "form_factor":"tv", "device_id":"…" },
"display": { "mode":"3840x2160@59.94", "modes_supported":[…], "hdr_types":["HDR10","HLG","DV"], "wide_gamut":true },
"audio": { "outputs":[{"type":"HDMI","encodings":["AC3","EAC3","TRUEHD"],"channels":8}], "passthrough":["AC3","EAC3","TRUEHD"], "suppressions":[…] },
"video_codecs": [ { "mime":"video/hevc", "hw":true, "profiles":["Main10","DV P8"], "max":"4096x2160@60" } ],
"network": { "transport":"ethernet" }
}
```
Android sources: `AndroidDeviceMetadataProvider` (id/model/platform/app
version), `MediaCodecCapabilitiesProbe` (codec + HDR decode caps),
`AudioCapabilityManager` (aggregate passthrough). **New accessors required**
(the probes exist but don't currently export everything): current + supported
`Display.Mode` list (DisplayHdrProbe exposes HDR support only), exact
identity fields (`Build.DEVICE`, form factor), `AudioManager.getDevices()`
output enumeration, and a snapshot/export API on
`PassthroughSuppressionRegistry` (its set is currently private).
Apple sources: `AppleDeviceIdentity.current` (persisted id, device name,
platform) and `ApplePlaybackV3Capabilities.snapshot()` (codec/HDR/device
context). **Honesty constraints:** the current `outputSnapshot()` helper is
private, reports route UIDs/types rather than full output capabilities, and
its passthrough payload is a placeholder — so Apple v1 reports audio as
route metadata with `passthrough: "unknown"` until a real probe exists, and
the private helper is refactored into an internal shared accessor so
diagnostics can reuse it without duplicating route logic. Audio route UIDs
are persistent peripheral identifiers and are one-way hashed before
inclusion.
### Playback session correlation
Clients include recent server playback session IDs so admins can pivot into
the existing server-side logs (`operational_logs.playback_session_id` +
the admin logs filter). Both clients currently retain only the *active*
session ID (Android `PlaybackSessionManager`, Apple `PlaybackSessionBridge`),
so each client adds a small **bounded, persisted recent-session tracker**
(last ~10 session IDs with timestamps) that survives restarts — required for
next-launch crash reports.
## Server design (`silo-server`)
### Feature gate
Borrows the *behavior* of the requests gate (status endpoint + per-call
guard that rereads settings) but stores keys in the general `server_settings`
store — requests uses its own dedicated table, which diagnostics doesn't
need. Key naming follows existing namespaces (`opslog.*`,
`audiobooks.enabled`, `playback.*`):
- `diagnostics.uploads_enabled` (bool, default `false`)
- `diagnostics.max_bundle_bytes` (default 10 MiB compressed)
- `diagnostics.max_uncompressed_bytes` (default 64 MiB)
- `diagnostics.max_reports_per_user_per_day` (default 20)
- `diagnostics.retention_days` (default 30)
- `diagnostics.max_bytes_per_user` (default 200 MiB)
Enabling `diagnostics.uploads_enabled` **requires a storage validation**
(private object store configured and writable); the admin settings API
refuses to enable it otherwise. `S3Private` is a nullable dependency in the
router and is only populated when configured, so the feature must degrade
predictably, not 500.
### Status endpoint
`GET /api/v1/diagnostics/status` — authenticated (`RequireAuth`), **no
profile required**: crashes during login/profile selection must still be
reportable, so capability discovery and upload are account-scoped with
optional profile attribution.
```json
{
"status": "available", // available | disabled | storage_unavailable
"server_instance_id": "srv_…", // stable; binds consent + pending reports
"accepted_schema_versions": [1],
"max_bundle_bytes": 10485760,
"max_manifest_bytes": 65536,
"retention_days": 30,
"consent_notice_version": 1
}
```
Clients cache this alongside existing server-driven config refresh.
### Ingest endpoint
`POST /api/v1/diagnostics/reports` — `RequireAuth`; access-token
`Authorization` header only (no query credentials; `sa_` API keys rejected
for diagnostics). Optional validated profile attribution. Hardened parsing —
the avatar handler is the *precedent* (multipart + `PutObject`), but its
buffer-everything approach (`ParseMultipartForm` + `io.ReadAll`) is not
reused:
1. Guard: `diagnostics.uploads_enabled` + storage present, else stable error
codes (`disabled`, `storage_unavailable`).
2. `http.MaxBytesReader` with `max_bundle_bytes` + manifest overhead before
any parsing; request deadline; per-account concurrency cap (1 in-flight)
and a server-global concurrency ceiling, on top of the existing rate-limit
middleware.
3. Streaming `multipart.Reader`: exactly the two named parts in order;
manifest capped at 64 KiB and schema-validated; unknown parts rejected.
4. Quota reservation: in one transaction holding a per-account advisory
lock (`pg_advisory_xact_lock(user_id)` — serializing concurrent uploads
from multiple devices on one account), check the per-day count and
per-user byte quota and insert the report row in state `receiving`
(server-generated UUID + `short_id`). Failures return `quota_exceeded`
(429, with `retry_after`) or `too_large` (413) — machine-readable so
clients back off and keep the report pending locally.
5. Stream the `bundle` part directly to its final key
(`diagnostics/{user_id}/{report_id}.tar.gz`) while hashing and counting
bytes; enforce the compressed cap during streaming. Validate the
gzip/tar structure and per-entry limits (entry count, name allowlist,
uncompressed total ≤ `max_uncompressed_bytes`, compression ratio bound)
in the same bounded streaming pass. Reject on violation
(`invalid_bundle`, `unsupported_schema`). There is no staging/rename
step — S3-style stores have no cheap rename, and the row's `state` is
the source of truth: a blob is not a report until its row is `ready`.
6. On success, update the row to `ready` with sizes + sha256. On any
failure: delete the object, mark the row `failed` (compensation); the
reconciler (below) cleans up stragglers from process death mid-request.
7. Respond `201 {"report_id":"…","short_id":"SILO-…"}` and emit a normalized
operational event (accepted/rejected, account, sizes, result).
`short_id` is 12 Crockford-Base32 characters, server-generated with
collision retry, case-insensitively unique, shown to the user for support
conversations, filterable in the admin API — and explicitly not an
authorization secret.
New code: `internal/diagnostics/` (service + store interface), handler in
`internal/api/handlers/diagnostics.go`, wired through `Dependencies` in
`internal/api/router.go`. The store interface is diagnostics-owned (the
avatar handler's is package-private and presign-only) and covers everything
the design uses: a **streaming** put (`io.Reader` — the existing s3client
`PutObject` takes `[]byte`, so this is a small s3client addition),
`GetObject` (streamed admin download fallback), `DeleteObject`,
`ListObjects(prefix)` (reconciler), and `PresignGetURL`.
### Storage
```sql
CREATE TABLE client_diagnostic_reports (
id UUID PRIMARY KEY,
short_id TEXT NOT NULL, -- unique, case-insensitive (expression index)
user_id INTEGER NOT NULL REFERENCES users(id) ON DELETE CASCADE,
profile_id TEXT, -- capturing profile, nullable
state TEXT NOT NULL, -- receiving | ready | failed
captured_at TIMESTAMPTZ NOT NULL, -- client claim
received_at TIMESTAMPTZ NOT NULL DEFAULT now(), -- server truth; retention keys off this
report_type TEXT NOT NULL, -- crash|anr|native_crash|hang|abnormal_exit|manual
platform TEXT NOT NULL,
app_version TEXT NOT NULL,
crash_summary TEXT, -- truncated ≤ 8 KiB
manifest JSONB NOT NULL, -- part 1 verbatim (≤ 64 KiB by construction)
playback_session_ids TEXT[] NOT NULL DEFAULT '{}',
blob_bucket TEXT,
blob_key TEXT,
blob_bytes BIGINT,
uncompressed_bytes BIGINT,
blob_sha256 TEXT
);
CREATE UNIQUE INDEX ON client_diagnostic_reports (lower(short_id));
CREATE INDEX ON client_diagnostic_reports (user_id, received_at DESC);
CREATE INDEX ON client_diagnostic_reports (received_at);
```
Plain table, not partitioned — volume is orders of magnitude below
`operational_logs`; the byte-heavy payload lives in object storage. Full
stacks/traces live only in the archive; the row holds a truncated summary.
### Admin API
Under the acting-admin subtree (same placement as the `admin_logs.go`
routes):
- `GET /api/v1/admin/diagnostics/reports` — list; filters: user, platform,
type, date range, `short_id` (exact, case-insensitive); paginated.
- `GET /api/v1/admin/diagnostics/reports/{id}` — row incl. manifest.
- `GET /api/v1/admin/diagnostics/reports/{id}/download` — presigned GET URL
(primary, matching avatar behavior) with a streamed `GetObject` proxy
fallback for deployments where presigned URLs aren't reachable — the
fallback is new behavior, not something the avatar path provides.
- `DELETE /api/v1/admin/diagnostics/reports/{id}` — row + blob.
Admin download and delete emit audit/operational events. Web admin gets a
list/detail/download page next to the logs viewer, with a
playback-session-id link into the existing filtered logs view. Native apps
add no admin screens in v1 (product policy).
### Retention + reconciliation
A taskmanager task `internal/taskmanager/tasks/cleanup_client_diagnostics.go`
mirroring `cleanup_operational_log.go`, registered in `cmd/silo/main.go`
with the other cleanup tasks:
- Delete reports older than `diagnostics.retention_days` (by `received_at`),
then enforce `diagnostics.max_bytes_per_user` oldest-first. Blob deleted
first (tolerating already-missing objects), then the row; deletes are
idempotent.
- Reconcile: remove `receiving`/`failed` rows older than a grace window,
and (via `ListObjects`) any `diagnostics/*` objects whose row is absent,
`failed`, or stale-`receiving` — so partial failures and process deaths
mid-request never leak storage.
- Account deletion cascades rows (FK) ; the reconciler then removes orphaned
blobs.
## Android design (`silo-android`)
New package
`android-shared/src/androidMain/kotlin/org/siloserver/silo/common/diagnostics/`.
### Logging
- `SiloLog.kt` — safe-logging facade per the contract above:
`SiloLog.d(cat, tag, msg, attrs)` (+`i/w/e`, sanitized `Throwable`).
Always forwards to `android.util.Log` (today's behavior unchanged) and
offers the entry to the ring buffer.
- `LogRing.kt` — always-on in-memory ring: fixed-size array of pre-rendered
compact entries, **non-blocking** writes (atomic index; a torn final entry
during crash snapshot is acceptable), ~4000 entries / ~1.5 MB cap, lazy
attribute formatting off the hot path, dropped-entry counter. Must add no
measurable contention to playback; a playback benchmark gate accompanies
the PR that wires player events in.
- `DiagnosticsFileLogger.kt` — only while debug logging is on: a
single-writer coroutine draining a bounded channel (drop + count under
backpressure) into **append-only framed segment files** (5 × 2 MB,
app-private `files/diagnostics/logs/`, `noBackup`), compressed only at
bundle-build time — a process death never corrupts more than the tail of
the active segment (unlike a single long-lived gzip stream).
- Playback wiring: each `PlaybackAnalyticsListener` event plus a ~5s periodic
`PlayerStatsSnapshot` line while debug logging is on (reuses the existing
reducer). TV focus logging hooks the TV app's focus observers under
`cat=focus`. Network: a Ktor hook logging `method, templated path, status,
duration_ms` only.
### Crash and abnormal-exit capture
- `CrashCapture.kt` — installed as early as possible in both `Application`
classes; idempotent; captures the previous
`Thread.getDefaultUncaughtExceptionHandler` once. On crash it does the
minimum on the dying thread: render the stack (bounded), copy what the
non-blocking ring exposes within a hard time budget, write **one bounded
marker file** (≤ ~512 KiB) via temp-write + atomic rename, and invoke the
prior handler in a `finally`. No locks shared with the ring's write path,
no coroutines, no allocation-heavy JSON building (preformatted line
buffer). Bundle assembly happens on next launch, never in the handler.
At most 3 pending reports are kept (oldest dropped) as a crash-loop guard.
- `ExitInfoCollector.kt` — API 30+ enhancement (minSdk is 24; many Fire TV
devices ship below API 30, where the handler is the only source): reads
`ActivityManager.getHistoricalProcessExitReasons()` on launch.
`REASON_CRASH`, `REASON_CRASH_NATIVE`, `REASON_ANR` become pending
reports. Dedupe uses a persisted bounded **fingerprint set** (process
name, pid, timestamp, reason, status, trace hash) — not a raw timestamp
watermark, which loses same-stamp events and breaks on clock changes.
`getTraceInputStream()` is treated as optional opaque bytes with a bounded
read: ANR text → `crash/stack.txt`; API 31+ native tombstone protobuf →
`crash/tombstone.pb` (never decoded into the manifest). UEH-captured
events are correlated by fingerprint so the same death isn't reported
twice.
- Next foreground launch, per the consent model: Ask → aggregated,
incident-specific prompt (one prompt covering N pending reports; default
focus **Don't send** on TV; "Always send" requires a second confirmation;
full-screen review flow on TV rather than a small dialog); Always →
silent upload, at most one bundle per crash fingerprint per day;
Never → purge. Per-fingerprint prompt suppression with backoff prevents
crash-loop prompt fatigue. Pending reports expire after 7 days —
visibly (the Diagnostics screen shows pending reports with expiry), not
silently.
### Device snapshot
`DeviceSnapshotCollector.kt` assembles `device.json` from the existing
probes plus the new accessors listed in the contract section (display mode
list, `Build.DEVICE`/form factor, `AudioManager.getDevices()` enumeration,
suppression-registry export). A compact snapshot is persisted with each
crash marker (`provenance: pre_failure`) since post-restart audio/display
state can differ from crash-time state.
### Settings + consent UI
- `DiagnosticsSettingsStore.kt` — DataStore. Deliberately **not** the
per-profile pattern of `AndroidPlayerSettingsStore`: consent and pending
reports are keyed by server+account (per the consent model), and debug
logging is per-device. Holds consent records, crash-report mode,
debug-logging flag, fingerprint set, session tracker, and status cache.
- Phone: "Diagnostics" section in `SettingsScreen.kt`; TV: rail category in
`TvSettingsScreen.kt`. For non-child profiles the section is **always
visible** and state-aware rather than hidden when the server gate is off — it distinguishes
`available` / `disabled by server` / `storage unavailable` / `offline`,
and always shows local pending reports (count, size, expiry) with
review/delete controls. Uploads are simply unavailable in non-available
states; a report captured while the gate was off is not auto-uploaded
later unless consent for that server+account exists.
- Manual capture is the primary support flow and is stronger than a bare
"send now": **Start diagnostic capture** (turns on verbose capture,
shows an indicator) → user reproduces the issue → **Stop & review** →
summary (categories, time range, sizes, destination) → send. A one-shot
"Send diagnostics now" remains for quick cases but warns when only the
in-memory ring is available ("this bundle contains only the last few
minutes of basic logs").
- After upload, the `short_id` is displayed and kept in a small sent
history so a user can read it to their admin later.
### Upload
- `shared/commonMain/…/network/api/DiagnosticsApi.kt` — `getStatus()` and
`uploadReport(manifestJson, bundleBytes)` via Ktor
`MultiPartFormDataContent` (first multipart use in the client — verified
none exists — written as a small reusable helper), using the existing
`safeApiCall`/`ApiResult` pattern, wired through Koin like other `*Api`
classes.
- `DiagnosticsUploader.kt` — builds the tar.gz (marker + ring/segment files
overlapping the incident window + breadcrumbs + snapshot), streams it to
the endpoint, deletes the pending report only on 201, records `short_id`.
On `quota_exceeded`/`too_large`/`disabled`/`storage_unavailable` it keeps
the pending report and backs off per `retry_after`; on
`unsupported_schema` it surfaces "server needs an update" rather than
silently retrying until expiry.
## Apple design (`silo-apple`)
Mirrors Android with platform-native mechanisms, and with tvOS scoped
honestly — **MetricKit diagnostic payloads (crash/hang) are iOS-only; the
SDK marks them unavailable on tvOS**, and delivery is delayed (typically
daily, while the app runs), not "next launch".
- **Ring + facade**: `DiagLog` implementing the same safe-logging contract.
The player's existing `cmpLog` helper (`PlayerLog.swift`) is **extended**
into a tee — it keeps `print()`ing (preserving `devicectl --console`
capture on tvOS) and also feeds the ring; remaining direct `print()` call
sites in `Screens/Player/` migrate to it curated, per the redaction
contract. OSLog-based subsystems are harvested at bundle-build time via
`OSLogStore(scope: .currentProcessIdentifier)` (deployment targets are
iOS/tvOS 26, far above the OSLogStore 15+ floor), merged into
`logs.jsonl` with provenance.
- **Breadcrumb journal**: because MetricKit reports arrive in a *later*
process, the in-memory ring is gone by delivery time. While crash
reporting is enabled, a small append-only breadcrumb journal (bounded,
rotating, crash-safe appends: lifecycle transitions, playback start/stop,
route changes, screen changes) persists across runs and becomes
`breadcrumbs.jsonl`, matched to a diagnostic by `capture_session_id` and
time window. Snapshots taken at bundle-build time are labeled
`provenance: post_restart`; the design never presents post-restart state
as crash-time state.
- **iOS crash/hang detection**: an `MXMetricManager` subscriber. Each
received `MXCrashDiagnostic`/`MXHangDiagnostic` becomes its **own**
pending report: raw diagnostic JSON preserved as `crash/metrickit.json`,
deduped by a canonical hash of the diagnostic (not timestamps), carrying
its own app version and reporting-period bounds. Prompt copy is
type-specific ("crashed" vs "was not responding") and honest about timing
("yesterday during playback"). Delivery is verified on physical devices;
parsing is tested via injected fixtures.
- **tvOS abnormal-exit detection**: no crash stacks in v1. A dirty-exit
sentinel (marker written at launch, cleared on clean
background/termination) plus the breadcrumb journal yields
`type: abnormal_exit` reports — "Silo did not shut down cleanly last
time" — with breadcrumbs and device snapshot but no stack. An in-process
crash reporter for tvOS is explicitly deferred (see Non-goals).
- **Device snapshot**: `AppleDeviceIdentity.current` +
`ApplePlaybackV3Capabilities.snapshot()` for identity/codec/HDR context;
audio reported as route metadata with hashed route UIDs and
`passthrough: "unknown"` until a real output-capability probe exists (the
current one is a private placeholder).
- **Settings/consent**: Diagnostics section in `SettingsView` (iOS) and
`TVSettingsView` (tvOS) with the same state-aware presentation, manual
capture flow, and consent rules.
- **Upload**: a small multipart body writer added to `HTTPClient` (verified:
JSON-only today, no multipart/uploadTask), same status/error handling as
Android.
- Housekeeping note: product bundle IDs are already `org.siloserver.silo`;
only legacy keychain/logging identifiers (`com.continuum.*`) remain, so
nothing here blocks on rebranding.
## Privacy summary
- **Consent boundaries**: no network transmission of diagnostic data without
prompt confirmation, a server+account-bound Always election, or an
explicit manual send. The always-on ring is memory-only; persistent
capture (segments, breadcrumbs, markers) is app-private, size-capped,
backup-excluded, and purged by Never/sign-out/server removal.
- **Never collected**: credentials, `Authorization`/profile-token values,
request bodies, query strings, full URLs (normalized at collection),
unsanitized exception dumps. Bearer-token matching at bundle time as
defense in depth. Golden leak fixtures in CI.
- **Deliberately collected** (disclosed in View report): device identity
incl. device name, media titles appearing in playback logs, templated
server paths. The recipient is the user's own server admin, who already
has server-side access to this information; that is the trust model this
feature is scoped to — and why third-party destinations are out.
- **Persistent identifiers**: the existing device IDs (already sent to the
server today) plus hashed audio-route UIDs; each is enumerated in the
schema docs with its purpose and retention.
- **User control**: state-aware Diagnostics screen with pending list,
review, delete, sent history; admin-side deletion; account deletion
cascades reports; admin access is acting-admin-only and audited.
- **Bounded retention**: defaults 30 days / 200 MiB per user, admin-tunable,
enforced server-side.
## Rollout plan (vertical slices, each independently shippable)
1. **Server foundation** — settings + storage-validated gate, status
endpoint, hardened ingest with state machine, schema + fixtures, admin
API, retention/reconciler task, operational audit events. Feature stays
off; nothing user-visible.
2. **Contract fixtures in clients** — JSON Schema + golden fixtures wired
into Android/Apple CI; safe-logging facades + rings land **dark** (no
UI, no capture persistence, no prompts).
3. **Android end-to-end slice** — consent model + Diagnostics settings UI +
crash marker/ExitInfo capture + device snapshot + uploader + manual
capture flow, with the initial curated logging migration (player tags +
TV focus + network hook + stats snapshots). First release where a user
can be asked for, and send, a useful report.
4. **Android coverage expansion** — remaining curated call-site migration,
breadcrumbs-on-Android if wanted, prompt-fatigue tuning from the field.
5. **Apple slice** — cmpLog tee + OSLogStore harvest + breadcrumbs +
MetricKit (iOS) + exit sentinel (tvOS) + settings/consent + multipart
upload.
6. **Web admin viewer + correlation UX** — list/detail/download page,
playback-session pivot into the logs viewer.
7. **Later / separate decisions** — symbolication job, tvOS in-process
crash reporter, native-app admin viewer, macOS.
Slices 3 and 5 ship complete consent→capture→upload flows; intermediate
releases never prompt for reports they can't send.
## Open questions
1. Should users be able to delete their **uploaded** reports from the client
(self-service deletion), or is pending-report control + admin deletion
enough for v1?
2. tvOS: is abnormal-exit detection (no stacks) acceptable for v1, or does
the Shield/Fire TV debugging need justify evaluating an in-process crash
reporter (PLCrashReporter/KSCrash) with its signal-safety and review
trade-offs?
3. Do we want breadcrumbs on Android in v1 (cheap once the facade exists),
or is the UEH marker + ExitInfo enough there?
4. Localization of prompt/consent strings at launch vs English-first.
5. Exact quota defaults (20/day, 200 MiB/user, 10 MiB/bundle) — tune before
enabling anywhere real.
6. Whether the status payload should also fold into an existing server-driven
config refresh response later (clients poll both today); the dedicated
endpoint ships first either way.
## Review notes
This spec was adversarially reviewed before the draft PR: two independent
review passes (a fact-check of every codebase claim against the three repos,
and a design attack across consent, crash-capture correctness, ingest
robustness, storage consistency, UX, and phasing). Material corrections
adopted include: tvOS MetricKit unavailability and honest MetricKit timing;
server+account-bound consent; storage-validated gating (private object store
is optional in real deployments); streaming bounded ingest with a report
state machine and orphan reconciliation; the archive container replacing a
bare log gzip; collection-time typed redaction replacing scrub-at-package;
fingerprint-based ExitInfo dedupe; non-blocking ring + bounded crash marker;
recent-session trackers (only the active playback session ID exists today);
and honest Apple snapshot capabilities (passthrough currently unknown).
File diff suppressed because it is too large Load Diff
@@ -1,5 +0,0 @@
The canonical client-diagnostics v1 contract lives in `v1/`.
Clients vendor the schema files, attribute registry, and fixtures from this directory.
Servers accept supported schema versions and ignore unknown additive fields.
Within v1, changes are additive only: new optional fields, enum values after coordinated client support, and new allowlisted archive entries.
Breaking changes require a new versioned contract directory and explicit server support.
@@ -1,89 +0,0 @@
{
"$schema": "https://silo-server.dev/schemas/client-diagnostics/v1/attr-registry.schema.json",
"schema_version": 1,
"policy": "Attribute keys are registered per category. Debug builds and CI should fail unregistered keys; production clients drop unregistered keys before upload.",
"categories": {
"playback": {
"sink": {
"type": "string",
"description": "Current audio output sink, such as HDMI or speaker."
},
"fmt": {
"type": "string",
"description": "Media or passthrough format identifier, such as truehd."
},
"decoder": {
"type": "string",
"description": "Selected decoder name."
},
"width": {
"type": "integer",
"description": "Video width in pixels."
},
"height": {
"type": "integer",
"description": "Video height in pixels."
},
"hdr_mode": {
"type": "string",
"description": "Active HDR mode or selected tone-mapping mode."
},
"bitrate_kbps": {
"type": "integer",
"description": "Observed or selected bitrate in kilobits per second."
},
"dropped_frames": {
"type": "integer",
"description": "Dropped video frame count."
},
"audio_underruns": {
"type": "integer",
"description": "Audio underrun count."
}
},
"focus": {
"target": {
"type": "string",
"description": "Focusable element or logical destination."
},
"action": {
"type": "string",
"description": "Focus action or navigation direction."
}
},
"network": {
"method": {
"type": "string",
"description": "HTTP method."
},
"path": {
"type": "string",
"description": "Templated path without query string."
},
"status": {
"type": "integer",
"description": "HTTP status code."
},
"duration_ms": {
"type": "integer",
"description": "Request duration in milliseconds."
}
},
"lifecycle": {
"state": {
"type": "string",
"description": "App lifecycle state."
}
},
"crash": {
"fingerprint": {
"type": "string",
"description": "Client-side dedupe fingerprint."
},
"source": {
"type": "string",
"description": "Crash source matching manifest crash.source."
}
}
}
}
@@ -1,113 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/schemas/client-diagnostics/v1/device.schema.json",
"title": "Silo Client Diagnostics Device Snapshot v1",
"type": "object",
"required": [
"captured_at",
"provenance",
"identity",
"display",
"audio",
"video_codecs",
"network"
],
"properties": {
"captured_at": {
"type": "string",
"format": "date-time",
"maxLength": 64
},
"provenance": {
"type": "string",
"enum": [
"pre_failure",
"post_restart"
],
"maxLength": 32
},
"identity": {
"$ref": "#/$defs/tri_state_object"
},
"display": {
"$ref": "#/$defs/tri_state_object"
},
"audio": {
"$ref": "#/$defs/tri_state_object"
},
"video_codecs": {
"anyOf": [
{
"type": "array",
"maxItems": 128,
"items": {
"$ref": "#/$defs/open_object"
}
},
{
"$ref": "#/$defs/sentinel"
}
]
},
"network": {
"$ref": "#/$defs/tri_state_object"
}
},
"$defs": {
"sentinel": {
"type": "string",
"enum": [
"unknown",
"not_collected"
]
},
"tri_state_object": {
"anyOf": [
{
"$ref": "#/$defs/open_object"
},
{
"$ref": "#/$defs/sentinel"
}
]
},
"open_object": {
"type": "object",
"maxProperties": 64,
"additionalProperties": {
"$ref": "#/$defs/tri_state_value"
}
},
"tri_state_value": {
"anyOf": [
{
"type": "string",
"maxLength": 512
},
{
"type": "number"
},
{
"type": "integer"
},
{
"type": "boolean"
},
{
"type": "null"
},
{
"type": "array",
"maxItems": 128,
"items": {
"$ref": "#/$defs/tri_state_value"
}
},
{
"$ref": "#/$defs/open_object"
}
]
}
},
"additionalProperties": true
}
@@ -1,45 +0,0 @@
{
"schema_version": 1,
"report": {
"type": "manual",
"captured_at": "2026-07-19T18:22:31Z",
"capture_session_id": "run_bad_archive_entry",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "android",
"os_version": "15 (API 35)",
"profile_id": "prof_tablet"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"consent": {
"mode": "manual",
"notice_version": 1
},
"device_summary": {
"manufacturer": "Google",
"model": "Pixel Tablet",
"os": "15",
"form_factor": "tablet"
},
"playback_session_ids": [],
"log_summary": {
"lines": 1,
"bytes_gz": 100,
"dropped_lines": 0,
"categories": [
"other"
],
"debug_logging": false
},
"archive": {
"entries": [
"manifest.json",
"../secrets.txt"
],
"bytes": 100,
"uncompressed_bytes": 200,
"sha256": "3333333333333333333333333333333333333333333333333333333333333333"
}
}
@@ -1,44 +0,0 @@
{
"schema_version": 2,
"report": {
"type": "manual",
"captured_at": "2026-07-19T18:22:31Z",
"capture_session_id": "run_bad_schema",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "android",
"os_version": "15 (API 35)",
"profile_id": "prof_tablet"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"consent": {
"mode": "manual",
"notice_version": 1
},
"device_summary": {
"manufacturer": "Google",
"model": "Pixel Tablet",
"os": "15",
"form_factor": "tablet"
},
"playback_session_ids": [],
"log_summary": {
"lines": 1,
"bytes_gz": 100,
"dropped_lines": 0,
"categories": [
"other"
],
"debug_logging": false
},
"archive": {
"entries": [
"manifest.json"
],
"bytes": 100,
"uncompressed_bytes": 200,
"sha256": "2222222222222222222222222222222222222222222222222222222222222222"
}
}
@@ -1,40 +0,0 @@
{
"schema_version": 1,
"report": {
"type": "manual",
"captured_at": "2026-07-19T18:22:31Z",
"capture_session_id": "run_missing_consent",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "android",
"os_version": "15 (API 35)",
"profile_id": "prof_tablet"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"device_summary": {
"manufacturer": "Google",
"model": "Pixel Tablet",
"os": "15",
"form_factor": "tablet"
},
"playback_session_ids": [],
"log_summary": {
"lines": 1,
"bytes_gz": 100,
"dropped_lines": 0,
"categories": [
"other"
],
"debug_logging": false
},
"archive": {
"entries": [
"manifest.json"
],
"bytes": 100,
"uncompressed_bytes": 200,
"sha256": "1111111111111111111111111111111111111111111111111111111111111111"
}
}
@@ -1,44 +0,0 @@
{
"schema_version": 1,
"report": {
"type": "manual",
"captured_at": "2026-07-19T18:22:31Z",
"capture_session_id": "run_macos_reserved",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "macos",
"os_version": "26.0",
"profile_id": "prof_mac"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"consent": {
"mode": "manual",
"notice_version": 1
},
"device_summary": {
"manufacturer": "Apple",
"model": "Mac",
"os": "26.0",
"form_factor": "desktop"
},
"playback_session_ids": [],
"log_summary": {
"lines": 1,
"bytes_gz": 100,
"dropped_lines": 0,
"categories": [
"other"
],
"debug_logging": false
},
"archive": {
"entries": [
"manifest.json"
],
"bytes": 100,
"uncompressed_bytes": 200,
"sha256": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
}
}
File diff suppressed because one or more lines are too long
@@ -1,44 +0,0 @@
{
"schema_version": 1,
"report": {
"type": "kernel_panic",
"captured_at": "2026-07-19T18:22:31Z",
"capture_session_id": "run_bad_type",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "android-tv",
"os_version": "11 (API 30)",
"profile_id": "prof_living_room"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"consent": {
"mode": "prompt",
"notice_version": 1
},
"device_summary": {
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"os": "11",
"form_factor": "tv"
},
"playback_session_ids": [],
"log_summary": {
"lines": 1,
"bytes_gz": 100,
"dropped_lines": 0,
"categories": [
"crash"
],
"debug_logging": false
},
"archive": {
"entries": [
"manifest.json"
],
"bytes": 100,
"uncompressed_bytes": 200,
"sha256": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
}
}
@@ -1,46 +0,0 @@
{
"schema_version": 1,
"report": {
"type": "manual",
"captured_at": "2026-07-19T23:45:00Z",
"capture_session_id": "run_android_manual_preprofile_006",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "android",
"os_version": "15 (API 35)"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"consent": {
"mode": "manual",
"notice_version": 1
},
"device_summary": {
"manufacturer": "Google",
"model": "Pixel Tablet",
"os": "15",
"form_factor": "tablet"
},
"playback_session_ids": [],
"log_summary": {
"lines": 12,
"bytes_gz": 2048,
"dropped_lines": 0,
"categories": [
"lifecycle",
"network"
],
"debug_logging": false
},
"archive": {
"entries": [
"manifest.json",
"device.json",
"logs.jsonl"
],
"bytes": 4096,
"uncompressed_bytes": 16384,
"sha256": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
}
}
@@ -1,47 +0,0 @@
{
"schema_version": 1,
"report": {
"type": "manual",
"captured_at": "2026-07-19T23:40:00Z",
"capture_session_id": "run_android_manual_005",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "android",
"os_version": "15 (API 35)",
"profile_id": "prof_tablet"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"consent": {
"mode": "manual",
"notice_version": 1
},
"device_summary": {
"manufacturer": "Google",
"model": "Pixel Tablet",
"os": "15",
"form_factor": "tablet"
},
"playback_session_ids": [],
"log_summary": {
"lines": 60,
"bytes_gz": 5400,
"dropped_lines": 0,
"categories": [
"browse",
"network"
],
"debug_logging": false
},
"archive": {
"entries": [
"manifest.json",
"device.json",
"logs.jsonl"
],
"bytes": 8000,
"uncompressed_bytes": 43000,
"sha256": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"
}
}
@@ -1,61 +0,0 @@
{
"schema_version": 1,
"report": {
"type": "crash",
"captured_at": "2026-07-19T18:22:31Z",
"capture_session_id": "run_android_tv_ueh_001",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "android-tv",
"os_version": "11 (API 30)",
"profile_id": "prof_living_room"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"consent": {
"mode": "prompt",
"notice_version": 1
},
"crash": {
"summary": "NullPointerException in PlaybackSessionManager.start",
"stack_excerpt": "java.lang.NullPointerException: player was null\n\tat org.siloserver.silo.PlaybackSessionManager.start(PlaybackSessionManager.kt:42)",
"thread": "main",
"foreground": true,
"source": "ueh",
"provenance": "pre_failure",
"occurred_at": "2026-07-19T18:22:31Z"
},
"device_summary": {
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"os": "11",
"form_factor": "tv"
},
"playback_session_ids": [
"ps_9f2a"
],
"log_summary": {
"lines": 3841,
"bytes_gz": 412034,
"dropped_lines": 12,
"categories": [
"playback",
"focus",
"network"
],
"debug_logging": true
},
"archive": {
"entries": [
"manifest.json",
"device.json",
"logs.jsonl",
"crash/summary.json",
"crash/stack.txt"
],
"bytes": 498112,
"uncompressed_bytes": 3110400,
"sha256": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
}
@@ -1,57 +0,0 @@
{
"captured_at": "2026-07-19T18:22:31Z",
"provenance": "pre_failure",
"identity": {
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"device": "mdarcy",
"form_factor": "tv",
"device_id": "dev_8f4a"
},
"display": {
"mode": "3840x2160@59.94",
"modes_supported": [
"3840x2160@59.94",
"1920x1080@60"
],
"hdr_types": [
"HDR10",
"HLG",
"DV"
],
"wide_gamut": true
},
"audio": {
"outputs": [
{
"type": "HDMI",
"encodings": [
"AC3",
"EAC3",
"TRUEHD"
],
"channels": 8
}
],
"passthrough": [
"AC3",
"EAC3",
"TRUEHD"
],
"suppressions": []
},
"video_codecs": [
{
"mime": "video/hevc",
"hw": true,
"profiles": [
"Main10",
"DV P8"
],
"max": "4096x2160@60"
}
],
"network": {
"transport": "ethernet"
}
}
@@ -1,62 +0,0 @@
{
"schema_version": 1,
"report": {
"type": "hang",
"captured_at": "2026-07-19T21:15:00Z",
"capture_session_id": "run_ios_metric_042",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "ios",
"os_version": "26.0",
"profile_id": "prof_phone"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"consent": {
"mode": "always",
"notice_version": 1
},
"crash": {
"summary": "Main thread hang reported by MetricKit",
"stack_excerpt": "Thread 0 name: main\n0 Silo PlayerCore.waitForRouteChange",
"thread": "main",
"foreground": true,
"source": "metrickit",
"provenance": "metric_reporting_period",
"occurred_at": "2026-07-19T21:15:00Z"
},
"device_summary": {
"manufacturer": "Apple",
"model": "iPhone17,2",
"os": "26.0",
"form_factor": "phone"
},
"playback_session_ids": [
"ps_ios_103"
],
"log_summary": {
"lines": 902,
"bytes_gz": 84511,
"dropped_lines": 0,
"categories": [
"playback",
"lifecycle",
"network"
],
"debug_logging": true
},
"archive": {
"entries": [
"manifest.json",
"device.json",
"logs.jsonl",
"crash/summary.json",
"crash/metrickit.json",
"breadcrumbs.jsonl"
],
"bytes": 141120,
"uncompressed_bytes": 812400,
"sha256": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
}
}
@@ -1,3 +0,0 @@
{"ts":"2026-07-19T18:22:29.412Z","run":"run_android_tv_ueh_001","lvl":"W","cat":"playback","tag":"AudioCapabilityMgr","msg":"passthrough suppressed: HDMI sink lost TrueHD","attrs":{"sink":"HDMI","fmt":"truehd"}}
{"ts":"2026-07-19T18:22:30Z","run":"run_android_tv_ueh_001","lvl":"I","cat":"network","tag":"HTTPClient","msg":"request completed","attrs":{"method":"GET","path":"/api/v1/playback/{id}","status":200,"duration_ms":84}}
{"ts":"2026-07-19T18:22:31Z","run":"run_android_tv_ueh_001","lvl":"D","cat":"focus","tag":"TvFocus","msg":"focus moved","attrs":{"target":"play-button","action":"right"}}
@@ -1,60 +0,0 @@
{
"schema_version": 1,
"report": {
"type": "abnormal_exit",
"captured_at": "2026-07-19T22:05:11Z",
"capture_session_id": "run_tvos_exit_007",
"app_version": "1.4.2",
"app_build": "20841",
"platform": "tvos",
"os_version": "26.0",
"profile_id": "prof_den"
},
"destination": {
"server_instance_id": "srv_home_01"
},
"consent": {
"mode": "prompt",
"notice_version": 1
},
"crash": {
"summary": "Silo did not shut down cleanly last time",
"thread": "unknown",
"foreground": true,
"source": "exit_sentinel",
"provenance": "post_restart",
"occurred_at": "2026-07-19T22:05:11Z"
},
"device_summary": {
"manufacturer": "Apple",
"model": "Apple TV",
"os": "26.0",
"form_factor": "tv"
},
"playback_session_ids": [
"ps_tvos_11",
"ps_tvos_10"
],
"log_summary": {
"lines": 120,
"bytes_gz": 12044,
"dropped_lines": 3,
"categories": [
"lifecycle",
"playback"
],
"debug_logging": false
},
"archive": {
"entries": [
"manifest.json",
"device.json",
"logs.jsonl",
"crash/summary.json",
"breadcrumbs.jsonl"
],
"bytes": 30001,
"uncompressed_bytes": 104000,
"sha256": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc"
}
}
@@ -1,95 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/schemas/client-diagnostics/v1/logline.schema.json",
"title": "Silo Client Diagnostics Log Line v1",
"type": "object",
"required": [
"ts",
"run",
"lvl",
"cat",
"tag",
"msg"
],
"properties": {
"ts": {
"type": "string",
"format": "date-time",
"maxLength": 64
},
"run": {
"type": "string",
"minLength": 1,
"maxLength": 128
},
"lvl": {
"type": "string",
"enum": [
"V",
"D",
"I",
"W",
"E"
],
"maxLength": 1
},
"cat": {
"type": "string",
"enum": [
"playback",
"focus",
"network",
"lifecycle",
"browse",
"cast",
"download",
"crash",
"other"
],
"maxLength": 32
},
"tag": {
"type": "string",
"minLength": 1,
"maxLength": 128
},
"msg": {
"type": "string",
"minLength": 1,
"maxLength": 2048
},
"attrs": {
"type": "object",
"description": "Attribute keys are registered in attr-registry.json. Production clients drop unregistered keys before upload.",
"additionalProperties": {
"anyOf": [
{
"type": "string",
"maxLength": 512
},
{
"type": "number"
},
{
"type": "integer"
},
{
"type": "boolean"
},
{
"type": "null"
},
{
"type": "array",
"maxItems": 32,
"items": {
"type": "string",
"maxLength": 256
}
}
]
}
}
},
"additionalProperties": true
}
@@ -1,392 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/schemas/client-diagnostics/v1/manifest.schema.json",
"title": "Silo Client Diagnostics Manifest v1",
"description": "Canonical manifest contract for a client diagnostics bundle. STRING LENGTHS: every `maxLength` in this schema is a character-count sanity bound. The server enforces the matching limit as a UTF-8 *byte* length (Go `len(string)`), so a value near a cap that contains multi-byte characters (CJK, emoji, accented text) can satisfy `maxLength` here yet be rejected at ingest. Treat each numeric cap as a byte budget for non-ASCII text. JSON Schema cannot express byte length, so this divergence is intentional and documented rather than encoded.",
"type": "object",
"required": [
"schema_version",
"report",
"destination",
"consent",
"device_summary",
"playback_session_ids",
"log_summary",
"archive"
],
"properties": {
"schema_version": {
"type": "integer",
"const": 1
},
"report": {
"type": "object",
"required": [
"type",
"captured_at",
"capture_session_id",
"app_version",
"app_build",
"platform",
"os_version"
],
"properties": {
"type": {
"type": "string",
"enum": [
"crash",
"anr",
"native_crash",
"hang",
"abnormal_exit",
"manual"
],
"maxLength": 32
},
"captured_at": {
"type": "string",
"format": "date-time",
"maxLength": 64
},
"capture_session_id": {
"type": "string",
"minLength": 1,
"maxLength": 128
},
"app_version": {
"type": "string",
"minLength": 1,
"maxLength": 64
},
"app_build": {
"type": "string",
"minLength": 1,
"maxLength": 64
},
"platform": {
"type": "string",
"enum": [
"android",
"android-tv",
"ios",
"tvos"
],
"maxLength": 32
},
"os_version": {
"type": "string",
"minLength": 1,
"maxLength": 128
},
"profile_id": {
"type": "string",
"maxLength": 128
}
},
"additionalProperties": true
},
"destination": {
"type": "object",
"required": [
"server_instance_id"
],
"properties": {
"server_instance_id": {
"type": "string",
"minLength": 1,
"maxLength": 128
}
},
"additionalProperties": true
},
"consent": {
"type": "object",
"required": [
"mode",
"notice_version"
],
"properties": {
"mode": {
"type": "string",
"enum": [
"prompt",
"always",
"manual"
],
"maxLength": 32
},
"notice_version": {
"type": "integer",
"minimum": 1
}
},
"additionalProperties": true
},
"crash": {
"type": "object",
"required": [
"summary",
"source",
"provenance",
"occurred_at"
],
"properties": {
"summary": {
"type": "string",
"minLength": 1,
"description": "Free-text crash summary; may contain non-ASCII. maxLength counts characters — the server enforces 8192 UTF-8 bytes (see the schema-level string-length note).",
"maxLength": 8192
},
"stack_excerpt": {
"type": "string",
"description": "Free-text stack excerpt; may contain non-ASCII. maxLength counts characters — the server enforces 8192 UTF-8 bytes (see the schema-level string-length note).",
"maxLength": 8192
},
"thread": {
"type": "string",
"description": "Thread name; may contain non-ASCII. maxLength counts characters — the server enforces 128 UTF-8 bytes (see the schema-level string-length note).",
"maxLength": 128
},
"foreground": {
"type": "boolean"
},
"source": {
"type": "string",
"enum": [
"ueh",
"exit_info",
"metrickit",
"exit_sentinel"
],
"maxLength": 32
},
"provenance": {
"type": "string",
"enum": [
"pre_failure",
"post_restart",
"metric_reporting_period"
],
"maxLength": 32
},
"occurred_at": {
"type": "string",
"format": "date-time",
"maxLength": 64
}
},
"additionalProperties": true
},
"device_summary": {
"type": "object",
"required": [
"manufacturer",
"model",
"os",
"form_factor"
],
"properties": {
"manufacturer": {
"type": "string",
"minLength": 1,
"description": "Device manufacturer; may contain non-ASCII. maxLength counts characters — the server enforces 128 UTF-8 bytes (see the schema-level string-length note).",
"maxLength": 128
},
"model": {
"type": "string",
"minLength": 1,
"description": "Device model; may contain non-ASCII (e.g. CJK). maxLength counts characters — the server enforces 128 UTF-8 bytes, so a 128-character multi-byte value can pass this schema yet be rejected at ingest (see the schema-level string-length note).",
"maxLength": 128
},
"os": {
"type": "string",
"minLength": 1,
"description": "OS name/version; may contain non-ASCII. maxLength counts characters — the server enforces 128 UTF-8 bytes (see the schema-level string-length note).",
"maxLength": 128
},
"form_factor": {
"type": "string",
"minLength": 1,
"description": "Device form factor; may contain non-ASCII. maxLength counts characters — the server enforces 64 UTF-8 bytes (see the schema-level string-length note).",
"maxLength": 64
}
},
"additionalProperties": {
"type": "string",
"maxLength": 256
}
},
"playback_session_ids": {
"type": "array",
"maxItems": 20,
"items": {
"type": "string",
"minLength": 1,
"maxLength": 128
}
},
"log_summary": {
"type": "object",
"required": [
"lines",
"bytes_gz",
"dropped_lines",
"categories",
"debug_logging"
],
"properties": {
"lines": {
"type": "integer",
"minimum": 0
},
"bytes_gz": {
"type": "integer",
"minimum": 0
},
"dropped_lines": {
"type": "integer",
"minimum": 0
},
"categories": {
"type": "array",
"uniqueItems": true,
"maxItems": 9,
"items": {
"type": "string",
"enum": [
"playback",
"focus",
"network",
"lifecycle",
"browse",
"cast",
"download",
"crash",
"other"
],
"maxLength": 32
}
},
"debug_logging": {
"type": "boolean"
}
},
"additionalProperties": true
},
"archive": {
"type": "object",
"required": [
"entries",
"bytes",
"uncompressed_bytes",
"sha256"
],
"properties": {
"entries": {
"type": "array",
"description": "Tar member names in bundle order. The first entry MUST be `manifest.json`: the server reads and validates the leading member before any other and compares this order against the actual bundle. `prefixItems` pins index 0, while `contains` keeps `manifest.json` required for validators that do not implement `prefixItems`.",
"uniqueItems": true,
"minItems": 1,
"maxItems": 8,
"prefixItems": [
{
"const": "manifest.json"
}
],
"contains": {
"const": "manifest.json"
},
"items": {
"type": "string",
"enum": [
"manifest.json",
"device.json",
"logs.jsonl",
"crash/summary.json",
"crash/stack.txt",
"crash/tombstone.pb",
"crash/metrickit.json",
"breadcrumbs.jsonl"
],
"maxLength": 64
}
},
"bytes": {
"type": "integer",
"minimum": 0
},
"uncompressed_bytes": {
"type": "integer",
"minimum": 0
},
"sha256": {
"type": "string",
"pattern": "^[A-Fa-f0-9]{64}$",
"maxLength": 64
}
},
"additionalProperties": true
}
},
"additionalProperties": true,
"allOf": [
{
"$comment": "Event reports (crash/anr/native_crash/hang/abnormal_exit) must carry the crash object; mirrors ValidateManifest in internal/diagnostics/contract/contract.go.",
"if": {
"properties": {
"report": {
"properties": {
"type": {
"enum": [
"crash",
"anr",
"native_crash",
"hang",
"abnormal_exit"
]
}
},
"required": [
"type"
]
}
},
"required": [
"report"
]
},
"then": {
"required": [
"crash"
]
}
},
{
"$comment": "Manual captures must not carry a crash object.",
"if": {
"properties": {
"report": {
"properties": {
"type": {
"const": "manual"
}
},
"required": [
"type"
]
}
},
"required": [
"report"
]
},
"then": {
"not": {
"required": [
"crash"
]
}
}
}
]
}
@@ -1,8 +0,0 @@
The canonical playback protocol v3 wire contract lives in `v3/`.
Clients vendor the schema files and fixtures from this directory; each schema is self-contained and refers only to its own `$defs`, so a client can vendor one body at a time.
The wire fixtures under `v3/fixtures/valid/` are copies of the matching server-generated golden bodies in `internal/playback/testdata/protocol_v3/`; treat them as opaque expected output rather than hand-edited examples, and regenerate them from the server rather than editing them in place. The golden directory also contains non-wire cross-message fixtures such as `attempt_keys.json`, `subtitle_inventory.json`, and `conformance_matrix.json`; clients vendor those directly from the generator output.
`error-response.schema.json` describes the common non-2xx envelope; its golden fixture is the exact `426 client_upgrade_required` response to a legacy start body.
Every bound in these schemas mirrors a server validator, so a body this directory rejects is a body the server rejects.
Identity fields the server computes — `plan_id`, `plan_attempt_key` — are opaque to clients: store them, echo them back on replan and route events, and never parse or recompute them.
Within v3, changes are additive only: new optional fields, and new enum values after coordinated client support.
Breaking changes require a new versioned contract directory and explicit server support.
@@ -1,123 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/schemas/playback-v3/v3/capability-response.schema.json",
"title": "Silo Playback Protocol v3 Capability Response",
"description": "Response body of GET /api/v1/playback/capability, mirroring CapabilityResponseV3 in internal/playback/protocol_v3.go. A client reads this before its first start request so it plans against what the server actually advertises instead of a compiled-in assumption. Protocol v3 is the server's only playback protocol, so enabled is always true; there is no disabled response shape.",
"type": "object",
"required": [
"enabled",
"protocol_versions",
"features",
"deliveries",
"transformations"
],
"properties": {
"enabled": {
"type": "boolean",
"const": true
},
"protocol_versions": {
"type": "array",
"description": "Protocol versions this server speaks. A client picks the highest it supports rather than assuming a single value, which is what keeps a future v4 from breaking v3 clients.",
"minItems": 1,
"uniqueItems": true,
"contains": {
"const": 3
},
"items": {
"type": "integer"
}
},
"features": {
"type": "array",
"description": "Server feature flags. The list grows additively within v3, so an unrecognized entry is expected and must be ignored, not treated as an error.",
"minItems": 8,
"uniqueItems": true,
"allOf": [
{ "contains": { "const": "playback_plan_v3" } },
{ "contains": { "const": "neutral_playback_v3_contract_v1" } },
{ "contains": { "const": "layout_aware_passthrough" } },
{ "contains": { "const": "playback_route_diagnostics" } },
{ "contains": { "const": "device_quirks_v1" } },
{ "contains": { "const": "seek_reanchor_v1" } },
{ "contains": { "const": "direct_stream_resume_v1" } },
{ "contains": { "const": "plan_source_duration_v1" } }
],
"items": {
"type": "string"
}
},
"deliveries": {
"type": "array",
"description": "Serving routes the planner may return. The list contains the server's currently executable delivery classes and grows additively.",
"minItems": 4,
"uniqueItems": true,
"allOf": [
{ "contains": { "const": "original_http" } },
{ "contains": { "const": "server_remux_progressive" } },
{ "contains": { "const": "server_remux_hls" } },
{ "contains": { "const": "server_transcode_hls" } }
],
"items": {
"type": "string",
"enum": [
"original_http",
"server_remux_progressive",
"server_remux_hls",
"server_transcode_hls"
]
}
},
"transformations": {
"type": "array",
"description": "Server-executed transformations available to the planner. Client-executed transformations are declared by the client in its start request, not listed here.",
"items": {
"$ref": "#/$defs/transformation"
}
},
"reason": {
"type": "string",
"description": "Reserved optional diagnostic for a future non-rollout condition. It does not disable protocol v3; enabled remains true."
}
},
"$defs": {
"transformation": {
"type": "object",
"required": [
"name",
"executor",
"recipe_version",
"validated_claims"
],
"properties": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 64
},
"executor": {
"type": "string",
"description": "Capability responses advertise transformations installed on the server. Client-executed transformations are declared in requests instead.",
"const": "server"
},
"recipe_version": {
"type": "string",
"description": "Identity of the recipe, not a semantic version to compare. A client matches it exactly or declines the transformation.",
"minLength": 1,
"maxLength": 32
},
"validated_claims": {
"type": "array",
"description": "Neutral statements about the bytes the transformation produces, so a client reasons about the output without knowing the server's toolchain.",
"maxItems": 32,
"items": {
"type": "string",
"maxLength": 128
}
}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
@@ -1,793 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/schemas/playback-v3/v3/decision-response.schema.json",
"title": "Silo Playback Protocol v3 Decision Response",
"description": "Response body of POST /api/v1/playback/start and POST /api/v1/playback/{session_id}/replan. Shapes mirror DecisionResponseV3 and PlanV3 in internal/playback/protocol_v3.go. A playable outcome carries playback_plan; adaptation_unavailable carries terminal. Enum lists are the values the server emits today and grow additively within v3, so a client must tolerate an unrecognized member of a described-but-open list rather than treating the plan as unusable.",
"type": "object",
"required": [
"protocol_version",
"server_features",
"outcome"
],
"properties": {
"protocol_version": {
"type": "integer",
"const": 3
},
"server_features": {
"type": "array",
"description": "Additive feature tokens supported by this server. Unknown entries must be ignored.",
"items": {
"type": "string"
}
},
"outcome": {
"type": "string",
"enum": [
"playable",
"adaptation_unavailable"
]
},
"session_id": {
"type": "string"
},
"playback_plan": {
"$ref": "#/$defs/plan"
},
"terminal": {
"$ref": "#/$defs/terminal"
}
},
"oneOf": [
{
"properties": {
"outcome": {
"const": "playable"
}
},
"required": [
"session_id",
"playback_plan"
],
"not": {
"required": [
"terminal"
]
}
},
{
"properties": {
"outcome": {
"const": "adaptation_unavailable"
}
},
"required": [
"terminal"
],
"allOf": [
{
"not": {
"required": [
"session_id"
]
}
},
{
"not": {
"required": [
"playback_plan"
]
}
}
]
}
],
"$defs": {
"terminal": {
"type": "object",
"description": "Why no route exists. `retryable` distinguishes a condition that may clear (a missing toolchain, incomplete metadata) from one that will not for this client and source.",
"required": [
"reason",
"message",
"retryable"
],
"properties": {
"reason": {
"type": "string",
"minLength": 1
},
"message": {
"type": "string"
},
"retryable": {
"type": "boolean"
}
},
"additionalProperties": true
},
"track_identity": {
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "string",
"description": "Combined-ordinal track identity `file:{file_id}:{audio|subtitle}:{ordinal}`."
},
"index": {
"type": "integer",
"minimum": 0
}
},
"additionalProperties": true
},
"transformation": {
"type": "object",
"required": [
"name",
"executor",
"recipe_version",
"validated_claims"
],
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"executor": {
"type": "string",
"description": "Who runs it: `server` before the bytes leave the server, `client` as the client's own responsibility.",
"enum": [
"client",
"server"
]
},
"recipe_version": {
"type": "string",
"minLength": 1
},
"validated_claims": {
"type": "array",
"description": "Neutral statements about the produced bytes, not client-framework decoder names.",
"items": {
"type": "string"
}
}
},
"additionalProperties": true
},
"plan": {
"type": "object",
"required": [
"protocol_version",
"plan_id",
"plan_attempt_key",
"delivery",
"stream",
"timeline",
"selected_tracks",
"effective_recipe",
"claims",
"subtitle",
"transformations",
"applied_quirks",
"runtime_corrections",
"available_qualities",
"degradation_warnings",
"decision_reason",
"requested_media_file_id",
"effective_media_file_id",
"source",
"subtitle_fidelity_policy"
],
"properties": {
"protocol_version": {
"type": "integer",
"const": 3
},
"plan_id": {
"type": "string",
"description": "Deterministic server-computed plan identity, `plan:` followed by 32 hex characters. Opaque to clients: echo it, never parse or recompute it.",
"pattern": "^plan:[0-9a-f]{32}$"
},
"plan_attempt_key": {
"type": "string",
"description": "Server-computed opaque loop-prevention token, always `v3:` prefixed. Clients store the keys of attempted plans and echo them in attempted_plan_keys on replan; they never compute keys themselves.",
"pattern": "^v3:",
"minLength": 8
},
"session_id": {
"type": "string"
},
"expires_at": {
"type": "string",
"format": "date-time"
},
"delivery": {
"type": "string",
"description": "The plan's serving route. Clients negotiate the coarser delivery classes (original_http, progressive, hls); these are the finer-grained plan outcomes those classes fold onto.",
"enum": [
"original_http",
"server_remux_progressive",
"server_remux_hls",
"server_transcode_hls"
]
},
"stream": {
"$ref": "#/$defs/stream"
},
"timeline": {
"$ref": "#/$defs/timeline"
},
"selected_tracks": {
"type": "object",
"properties": {
"audio": {
"$ref": "#/$defs/track_identity"
},
"subtitle": {
"$ref": "#/$defs/track_identity"
}
},
"additionalProperties": true
},
"effective_recipe": {
"$ref": "#/$defs/effective_recipe"
},
"claims": {
"$ref": "#/$defs/claims"
},
"subtitle": {
"$ref": "#/$defs/subtitle_decision"
},
"transformations": {
"type": "array",
"items": {
"$ref": "#/$defs/transformation"
}
},
"applied_quirks": {
"type": "array",
"items": {
"$ref": "#/$defs/applied_quirk"
}
},
"runtime_corrections": {
"type": "array",
"description": "Client-executed corrections this plan depends on. A client that cannot run a listed correction must not select the plan.",
"items": {
"type": "string"
}
},
"available_qualities": {
"type": "array",
"description": "Server ladder rungs valid for this source and client, so a client renders a quality menu without owning a bitrate table. The entry with preserves_source true pins the source rung.",
"minItems": 1,
"contains": {
"type": "object",
"required": ["label", "preserves_source"],
"properties": {
"label": { "const": "original" },
"preserves_source": { "const": true }
}
},
"items": {
"$ref": "#/$defs/available_quality"
}
},
"degradation_warnings": {
"type": "array",
"items": {
"$ref": "#/$defs/degradation_warning"
}
},
"decision_reason": {
"type": "string",
"minLength": 1
},
"requested_media_file_id": {
"type": "integer",
"minimum": 1
},
"effective_media_file_id": {
"type": "integer",
"minimum": 1,
"description": "Differs from requested_media_file_id when the server routed to an alternate edition of the same title. Track identities in this plan belong to the effective file."
},
"source": {
"$ref": "#/$defs/source_descriptor"
},
"subtitle_fidelity_policy": {
"type": "string",
"enum": [
"require_authored_fidelity",
"allow_simplified_rendering"
]
}
},
"additionalProperties": true
},
"stream": {
"type": "object",
"required": [
"url",
"protocol",
"headers",
"header_refresh"
],
"properties": {
"url": {
"type": "string",
"minLength": 1
},
"protocol": {
"type": "string",
"enum": [
"http_progressive",
"hls"
]
},
"container": {
"type": "string"
},
"mime_type": {
"type": "string",
"description": "What the transport will actually serve. A declared-tier client probes this before attaching a source buffer, so an audio-only remux advertises audio/mp4 rather than video/mp4."
},
"headers": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"header_refresh": {
"type": "string",
"enum": [
"none",
"session"
]
},
"header_refresh_url": {
"type": "string"
}
},
"additionalProperties": true
},
"timeline": {
"type": "object",
"description": "Anchoring for the delivered stream. source_start_seconds is the position in the source, player_start_seconds where the player should start within the delivered timeline; the two differ when the stream is re-anchored at a seek point.",
"required": [
"source_start_seconds",
"stream_origin_seconds",
"player_start_seconds",
"timeline_offset_seconds",
"can_seek_anywhere",
"seek_restoration"
],
"properties": {
"source_start_seconds": {
"type": "number"
},
"stream_origin_seconds": {
"type": "number"
},
"player_start_seconds": {
"type": "number"
},
"timeline_offset_seconds": {
"type": "number"
},
"seek_window_start_seconds": {
"type": "number"
},
"seek_window_end_seconds": {
"type": "number"
},
"can_seek_anywhere": {
"type": "boolean"
},
"seek_restoration": {
"type": "string",
"description": "Which clock a resume position is expressed in: `player_position` for a full-timeline stream, `source_position` for one re-anchored at a seek point.",
"enum": [
"player_position",
"source_position"
]
}
},
"additionalProperties": true
},
"effective_recipe": {
"type": "object",
"description": "What the delivered bytes actually are, after any adaptation. Fields the server has no value for are omitted rather than sent as zero.",
"properties": {
"video_codec": {
"type": "string"
},
"audio_codec": {
"type": "string"
},
"width": {
"type": "integer"
},
"height": {
"type": "integer"
},
"frame_rate": {
"type": "number"
},
"bitrate_kbps": {
"type": "integer"
},
"dynamic_range": {
"type": "string"
},
"audio_channels": {
"type": "integer"
},
"audio_layout": {
"type": "string"
}
},
"additionalProperties": true
},
"claims": {
"type": "object",
"description": "What the server promises about the delivered bytes. A client renders its HDR/passthrough/subtitle affordances from these rather than re-deriving them from the source descriptor.",
"required": [
"video",
"audio",
"subtitles"
],
"properties": {
"video": {
"type": "object",
"required": [
"hdr10",
"hdr10_plus",
"hlg",
"dolby_vision"
],
"properties": {
"hdr10": {
"type": "boolean"
},
"hdr10_plus": {
"type": "boolean"
},
"hlg": {
"type": "boolean"
},
"dolby_vision": {
"type": "boolean"
},
"dolby_vision_reason": {
"type": "string"
}
},
"additionalProperties": true
},
"audio": {
"type": "object",
"required": [
"passthrough",
"atmos_preserved"
],
"properties": {
"codec": {
"type": "string"
},
"passthrough": {
"type": "boolean"
},
"atmos_preserved": {
"type": "boolean"
},
"dts_variant": {
"type": "string"
},
"reason": {
"type": "string"
}
},
"additionalProperties": true
},
"subtitles": {
"type": "object",
"required": [
"ass_styling_preserved",
"bitmap_overlay",
"bitmap_sidecar"
],
"properties": {
"ass_styling_preserved": {
"type": "boolean"
},
"bitmap_overlay": {
"type": "boolean"
},
"bitmap_sidecar": {
"type": "boolean"
},
"reason": {
"type": "string"
}
},
"additionalProperties": true
}
},
"additionalProperties": true
},
"subtitle_decision": {
"type": "object",
"required": [
"mode",
"inventory"
],
"properties": {
"mode": {
"type": "string",
"enum": [
"off",
"render",
"convert",
"burn_in"
]
},
"track_id": {
"type": "string"
},
"artifact": {
"type": "object",
"description": "The prepared sidecar for the selected track. timing_origin_seconds is the source position the artifact's cue timestamps are relative to.",
"required": [
"url",
"mime_type",
"format",
"timing_origin_seconds"
],
"properties": {
"url": {
"type": "string",
"minLength": 1
},
"mime_type": {
"type": "string"
},
"format": {
"type": "string"
},
"timing_origin_seconds": {
"type": "number"
}
},
"additionalProperties": true
},
"inventory": {
"type": "array",
"description": "Authoritative, dense, gap-free combined-ordinal track list for the effective source: external tracks first, then embedded, then downloaded. A client selects by echoing an entry's track_id or combined_index and never derives an ordinal by counting, summing track arrays, or taking max(index)+1.",
"items": {
"$ref": "#/$defs/subtitle_inventory_item"
}
}
},
"additionalProperties": true
},
"subtitle_inventory_item": {
"type": "object",
"required": [
"track_id",
"combined_index",
"source",
"forced",
"default",
"hearing_impaired",
"delivery"
],
"properties": {
"track_id": {
"type": "string",
"minLength": 1
},
"combined_index": {
"type": "integer",
"minimum": 0
},
"source": {
"type": "string",
"enum": [
"external",
"embedded",
"downloaded"
]
},
"codec": {
"type": "string"
},
"language": {
"type": "string"
},
"label": {
"type": "string"
},
"forced": {
"type": "boolean"
},
"default": {
"type": "boolean"
},
"hearing_impaired": {
"type": "boolean"
},
"delivery": {
"type": "string",
"description": "`sidecar` tracks are fetchable from their published url. A `burn_in_only` track has no client-fetchable representation and carries no url, but still occupies its ordinal and stays selectable — omitting it would leave a hole that makes every later ordinal wrong.",
"enum": [
"sidecar",
"burn_in_only"
]
},
"url": {
"type": "string"
},
"font_bundle_url": {
"type": "string",
"description": "Attachment bundle needed to render an embedded ASS/SSA track with its authored typesetting."
}
},
"additionalProperties": true
},
"applied_quirk": {
"type": "object",
"description": "A device-specific decision the planner made on top of the generic route. registry_revision identifies the quirk registry the decision came from.",
"required": [
"id",
"registry_revision",
"action"
],
"properties": {
"id": {
"type": "string",
"minLength": 1,
"maxLength": 128
},
"registry_revision": {
"type": "string",
"maxLength": 128
},
"action": {
"type": "string"
},
"reason": {
"type": "string"
}
},
"additionalProperties": true
},
"available_quality": {
"type": "object",
"required": [
"label",
"preserves_source"
],
"properties": {
"label": {
"type": "string",
"minLength": 1
},
"height": {
"type": "integer"
},
"bitrate_kbps": {
"type": "integer"
},
"preserves_source": {
"type": "boolean"
}
},
"additionalProperties": true
},
"degradation_warning": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "string",
"minLength": 1
},
"message": {
"type": "string"
}
},
"additionalProperties": true
},
"source_descriptor": {
"type": "object",
"required": [
"media_file_id",
"hdr10_plus",
"dv_enhancement_layer"
],
"properties": {
"media_file_id": {
"type": "integer",
"minimum": 1
},
"duration_seconds": {
"type": "number",
"description": "Full runtime of this source, independent of where the delivery's timeline is anchored. Absent means the server does not know the runtime; it is omitted rather than null so clients that coerce null to a numeric default do not read it as zero. Do not substitute the playback engine's reported duration — on an HLS copy remux the engine reports the length produced so far."
},
"container": {
"type": "string"
},
"video_codec": {
"type": "string"
},
"video_profile": {
"type": "string"
},
"video_level": {
"type": "integer"
},
"bit_depth": {
"type": "integer"
},
"color_range": {
"type": "string"
},
"width": {
"type": "integer"
},
"height": {
"type": "integer"
},
"frame_rate": {
"type": "number"
},
"bitrate_kbps": {
"type": "integer"
},
"dynamic_range": {
"type": "string",
"description": "Values the server emits today: sdr, hdr10, hdr10_plus, hlg, dolby_vision, and hdr_unknown for legacy rows that recorded only a file-level HDR flag."
},
"hdr10_plus": {
"type": "boolean"
},
"dolby_vision_profile": {
"type": "integer"
},
"dv_bl_compat_id": {
"type": "integer"
},
"dv_enhancement_layer": {
"type": "string",
"enum": [
"none",
"mel",
"fel",
"unknown"
]
},
"audio_codec": {
"type": "string"
},
"audio_channels": {
"type": "integer"
},
"audio_layout": {
"type": "string"
},
"video_copy_unsafe": {
"type": "boolean"
}
},
"additionalProperties": true
}
},
"additionalProperties": true
}
@@ -1,22 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://silo-server.dev/schemas/playback-v3/v3/error-response.schema.json",
"title": "Silo Playback Protocol v3 Error Response",
"description": "Common non-2xx response body for playback-v3 endpoints. Clients branch on error and may display message. The valid fixture pins the 426 response returned to a legacy start body.",
"type": "object",
"required": ["error", "message"],
"properties": {
"error": {
"type": "string",
"minLength": 1,
"maxLength": 64,
"pattern": "^[a-z][a-z0-9_]*$"
},
"message": {
"type": "string",
"minLength": 1,
"maxLength": 1024
}
},
"additionalProperties": true
}
@@ -1,113 +0,0 @@
{
"protocol_version": 3,
"client_features": [
"playback_plan_v3"
],
"operation": "failure_recovery",
"playback_attempt_id": "attempt-golden-0001",
"replan_request_id": "replan-golden-0001",
"failed_plan_id": "plan:golden-0001",
"plan_attempt_id": "plan-attempt-golden-0001",
"plan_attempt_key": "v3:0000000000000001",
"attempted_plan_keys": [
"v3:0000000000000001"
],
"attempt_count": 9,
"quality_preference": "auto",
"position_seconds": 42.5,
"metered": true,
"bandwidth_estimate_kbps": 3500,
"bandwidth_cap_kbps": 4000,
"selected_tracks": {
"audio": {
"id": "file:42:audio:0",
"index": 0
}
},
"failure": {
"classification": "network_degraded"
},
"client_capabilities": {
"video_evidence": "exact",
"audio_evidence": "exact",
"codecs_video": [
"h264"
],
"codecs_video_hardware": [
"h264"
],
"codecs_audio": [
"aac"
],
"containers": [
"mp4"
],
"max_resolution": "1080p",
"hdr": false,
"video_decode": [
{
"codec": "h264",
"profiles": [
"high"
],
"levels": [
41
],
"bit_depths": [
8
],
"max_width": 1920,
"max_height": 1080,
"max_frame_rate": 60,
"max_bitrate_kbps": 20000,
"hardware": true
}
]
},
"client_playback_context": {
"protocol_version": 3,
"form_factor": "tv",
"app_version": "3.0-test",
"device": {
"platform": "android",
"os_version": "15",
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"platform_details": {
"abis": "arm64-v8a",
"sdk_int": "35"
}
},
"output": {
"output_context_id": "7"
},
"deliveries": {
"original_http": {
"enabled": true,
"supported_on_device": true,
"containers": [
"mp4"
],
"video_codecs": [
"h264"
],
"audio_decode_codecs": [
"aac"
],
"audio_passthrough_codecs": [],
"subtitles": {
"embedded_text": true,
"sidecar_text": true,
"ass_styling": false,
"embedded_bitmap": false,
"sidecar_bitmap": false,
"font_attachments": false
},
"features": [],
"auth_header_refresh": true,
"validated_claims": [],
"transformations": []
}
}
}
}
@@ -1,99 +0,0 @@
{
"protocol_version": 3,
"client_features": [
"playback_plan_v3"
],
"file_id": 42,
"profile_id": "profile-1",
"playback_attempt_id": "attempt-golden-0001",
"quality_preference": "original",
"subtitle_fidelity_preference": "compatible",
"start_position": 12.5,
"audio_track_id": "file:42:audio:0",
"audio_track_index": 0,
"metered": false,
"client_capabilities": {
"video_evidence": "exact",
"audio_evidence": "exact",
"codecs_video": [
"h264"
],
"codecs_video_hardware": [
"h264"
],
"codecs_audio": [
"aac"
],
"containers": [
"mp4"
],
"max_resolution": "1080p",
"hdr": false,
"video_decode": [
{
"codec": "h264",
"profiles": [
"high"
],
"levels": [
41
],
"bit_depths": [
8
],
"max_width": 1920,
"max_height": 1080,
"max_frame_rate": 60,
"max_bitrate_kbps": 20000,
"hardware": true
}
]
},
"client_playback_context": {
"protocol_version": 3,
"form_factor": "tv",
"app_version": "3.0-test",
"device": {
"platform": "android",
"os_version": "15",
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"platform_details": {
"abis": "arm64-v8a",
"sdk_int": "35"
}
},
"output": {
"output_context_id": "7"
},
"deliveries": {
"original_http": {
"enabled": true,
"supported_on_device": true,
"containers": [
"mp4"
],
"video_codecs": [
"h264"
],
"audio_decode_codecs": [
"aac"
],
"audio_passthrough_codecs": [],
"subtitles": {
"embedded_text": true,
"sidecar_text": true,
"ass_styling": false,
"embedded_bitmap": false,
"sidecar_bitmap": false,
"font_attachments": false
},
"features": [],
"auth_header_refresh": true,
"validated_claims": [],
"transformations": []
}
}
},
"bandwidth_estimate_kbps": 99
}
@@ -1,162 +0,0 @@
{
"protocol_version": 3,
"client_features": [
"feature_00",
"feature_01",
"feature_02",
"feature_03",
"feature_04",
"feature_05",
"feature_06",
"feature_07",
"feature_08",
"feature_09",
"feature_10",
"feature_11",
"feature_12",
"feature_13",
"feature_14",
"feature_15",
"feature_16",
"feature_17",
"feature_18",
"feature_19",
"feature_20",
"feature_21",
"feature_22",
"feature_23",
"feature_24",
"feature_25",
"feature_26",
"feature_27",
"feature_28",
"feature_29",
"feature_30",
"feature_31",
"feature_32",
"feature_33",
"feature_34",
"feature_35",
"feature_36",
"feature_37",
"feature_38",
"feature_39",
"feature_40",
"feature_41",
"feature_42",
"feature_43",
"feature_44",
"feature_45",
"feature_46",
"feature_47",
"feature_48",
"feature_49",
"feature_50",
"feature_51",
"feature_52",
"feature_53",
"feature_54",
"feature_55",
"feature_56",
"feature_57",
"feature_58",
"feature_59",
"feature_60",
"feature_61",
"feature_62",
"feature_63",
"feature_64"
],
"file_id": 42,
"profile_id": "profile-1",
"playback_attempt_id": "attempt-golden-0001",
"quality_preference": "original",
"subtitle_fidelity_preference": "compatible",
"start_position": 12.5,
"audio_track_id": "file:42:audio:0",
"audio_track_index": 0,
"metered": false,
"client_capabilities": {
"video_evidence": "exact",
"audio_evidence": "exact",
"codecs_video": [
"h264"
],
"codecs_video_hardware": [
"h264"
],
"codecs_audio": [
"aac"
],
"containers": [
"mp4"
],
"max_resolution": "1080p",
"hdr": false,
"video_decode": [
{
"codec": "h264",
"profiles": [
"high"
],
"levels": [
41
],
"bit_depths": [
8
],
"max_width": 1920,
"max_height": 1080,
"max_frame_rate": 60,
"max_bitrate_kbps": 20000,
"hardware": true
}
]
},
"client_playback_context": {
"protocol_version": 3,
"form_factor": "tv",
"app_version": "3.0-test",
"device": {
"platform": "android",
"os_version": "15",
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"platform_details": {
"abis": "arm64-v8a",
"sdk_int": "35"
}
},
"output": {
"output_context_id": "7"
},
"deliveries": {
"original_http": {
"enabled": true,
"supported_on_device": true,
"containers": [
"mp4"
],
"video_codecs": [
"h264"
],
"audio_decode_codecs": [
"aac"
],
"audio_passthrough_codecs": [],
"subtitles": {
"embedded_text": true,
"sidecar_text": true,
"ass_styling": false,
"embedded_bitmap": false,
"sidecar_bitmap": false,
"font_attachments": false
},
"features": [],
"auth_header_refresh": true,
"validated_claims": [],
"transformations": []
}
}
}
}
@@ -1,45 +0,0 @@
{
"protocol_version": 3,
"playback_attempt_id": "attempt-golden-0001",
"session_id": "11111111-1111-4111-8111-111111111111",
"plan_id": "plan:golden-0001",
"plan_attempt_id": "plan-attempt-golden-0001",
"plan_attempt_key": "v3:0000000000000001",
"event": "first_frame",
"output_context_id": "7",
"diagnostics": {
"key_00": "0",
"key_01": "1",
"key_02": "2",
"key_03": "3",
"key_04": "4",
"key_05": "5",
"key_06": "6",
"key_07": "7",
"key_08": "8",
"key_09": "9",
"key_10": "10",
"key_11": "11",
"key_12": "12",
"key_13": "13",
"key_14": "14",
"key_15": "15",
"key_16": "16",
"key_17": "17",
"key_18": "18",
"key_19": "19",
"key_20": "20",
"key_21": "21",
"key_22": "22",
"key_23": "23",
"key_24": "24",
"key_25": "25",
"key_26": "26",
"key_27": "27",
"key_28": "28",
"key_29": "29",
"key_30": "30",
"key_31": "31",
"key_32": "32"
}
}
@@ -1,8 +0,0 @@
{
"enabled": false,
"protocol_versions": [],
"features": [],
"deliveries": [],
"transformations": [],
"reason": "disabled"
}
@@ -1,110 +0,0 @@
{
"protocol_version": 3,
"client_features": [
"playback_plan_v3"
],
"operation": "failure_recovery",
"playback_attempt_id": "attempt-golden-0001",
"replan_request_id": "replan-golden-0001",
"failed_plan_id": "plan:golden-0001",
"plan_attempt_id": "plan-attempt-golden-0001",
"plan_attempt_key": "v3:0000000000000001",
"attempted_plan_keys": [
"v3:0000000000000001"
],
"attempt_count": 1,
"quality_preference": "auto",
"position_seconds": 42.5,
"metered": true,
"bandwidth_estimate_kbps": 3500,
"bandwidth_cap_kbps": 4000,
"selected_tracks": {
"audio": {
"id": "file:42:audio:0",
"index": 0
}
},
"client_capabilities": {
"video_evidence": "exact",
"audio_evidence": "exact",
"codecs_video": [
"h264"
],
"codecs_video_hardware": [
"h264"
],
"codecs_audio": [
"aac"
],
"containers": [
"mp4"
],
"max_resolution": "1080p",
"hdr": false,
"video_decode": [
{
"codec": "h264",
"profiles": [
"high"
],
"levels": [
41
],
"bit_depths": [
8
],
"max_width": 1920,
"max_height": 1080,
"max_frame_rate": 60,
"max_bitrate_kbps": 20000,
"hardware": true
}
]
},
"client_playback_context": {
"protocol_version": 3,
"form_factor": "tv",
"app_version": "3.0-test",
"device": {
"platform": "android",
"os_version": "15",
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"platform_details": {
"abis": "arm64-v8a",
"sdk_int": "35"
}
},
"output": {
"output_context_id": "7"
},
"deliveries": {
"original_http": {
"enabled": true,
"supported_on_device": true,
"containers": [
"mp4"
],
"video_codecs": [
"h264"
],
"audio_decode_codecs": [
"aac"
],
"audio_passthrough_codecs": [],
"subtitles": {
"embedded_text": true,
"sidecar_text": true,
"ass_styling": false,
"embedded_bitmap": false,
"sidecar_bitmap": false,
"font_attachments": false
},
"features": [],
"auth_header_refresh": true,
"validated_claims": [],
"transformations": []
}
}
}
}
@@ -1,61 +0,0 @@
{
"protocol_version": 3,
"client_features": [
"playback_plan_v3"
],
"file_id": 42,
"profile_id": "profile-1",
"playback_attempt_id": "attempt-golden-0001",
"quality_preference": "original",
"subtitle_fidelity_preference": "compatible",
"start_position": 12.5,
"audio_track_id": "file:42:audio:0",
"audio_track_index": 0,
"metered": false,
"client_playback_context": {
"protocol_version": 3,
"form_factor": "tv",
"app_version": "3.0-test",
"device": {
"platform": "android",
"os_version": "15",
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"platform_details": {
"abis": "arm64-v8a",
"sdk_int": "35"
}
},
"output": {
"output_context_id": "7"
},
"deliveries": {
"original_http": {
"enabled": true,
"supported_on_device": true,
"containers": [
"mp4"
],
"video_codecs": [
"h264"
],
"audio_decode_codecs": [
"aac"
],
"audio_passthrough_codecs": [],
"subtitles": {
"embedded_text": true,
"sidecar_text": true,
"ass_styling": false,
"embedded_bitmap": false,
"sidecar_bitmap": false,
"font_attachments": false
},
"features": [],
"auth_header_refresh": true,
"validated_claims": [],
"transformations": []
}
}
}
}
@@ -1,3 +0,0 @@
{
"error": "client_upgrade_required"
}
@@ -1,98 +0,0 @@
{
"protocol_version": 3,
"client_features": [
"playback_plan_v3"
],
"file_id": 42,
"profile_id": "profile-1",
"playback_attempt_id": "attempt-golden-0001",
"quality_preference": "original",
"subtitle_fidelity_preference": "compatible",
"start_position": 12.5,
"audio_track_id": "file:42:audio:0",
"audio_track_index": 0,
"metered": false,
"client_capabilities": {
"video_evidence": "exact",
"audio_evidence": "exact",
"codecs_video": [
"h264"
],
"codecs_video_hardware": [
"h264"
],
"codecs_audio": [
"aac"
],
"containers": [
"mp4"
],
"max_resolution": "1080p",
"hdr": false,
"video_decode": [
{
"codec": "h264",
"profiles": [
"high"
],
"levels": [
41
],
"bit_depths": [
8
],
"max_width": 1920,
"max_height": 1080,
"max_frame_rate": 60,
"max_bitrate_kbps": 20000,
"hardware": true
}
]
},
"client_playback_context": {
"protocol_version": 3,
"form_factor": "tv",
"app_version": "3.0-test",
"device": {
"platform": "android",
"os_version": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"platform_details": {
"abis": "arm64-v8a",
"sdk_int": "35"
}
},
"output": {
"output_context_id": "7"
},
"deliveries": {
"original_http": {
"enabled": true,
"supported_on_device": true,
"containers": [
"mp4"
],
"video_codecs": [
"h264"
],
"audio_decode_codecs": [
"aac"
],
"audio_passthrough_codecs": [],
"subtitles": {
"embedded_text": true,
"sidecar_text": true,
"ass_styling": false,
"embedded_bitmap": false,
"sidecar_bitmap": false,
"font_attachments": false
},
"features": [],
"auth_header_refresh": true,
"validated_claims": [],
"transformations": []
}
}
}
}
@@ -1,113 +0,0 @@
{
"protocol_version": 3,
"client_features": [
"playback_plan_v3"
],
"operation": "failure_recovery",
"playback_attempt_id": "attempt-golden-0001",
"replan_request_id": "replan-golden-0001",
"failed_plan_id": "plan:golden-0001",
"plan_attempt_id": "plan-attempt-golden-0001",
"plan_attempt_key": "0000000000000001",
"attempted_plan_keys": [
"v3:0000000000000001"
],
"attempt_count": 1,
"quality_preference": "auto",
"position_seconds": 42.5,
"metered": true,
"bandwidth_estimate_kbps": 3500,
"bandwidth_cap_kbps": 4000,
"selected_tracks": {
"audio": {
"id": "file:42:audio:0",
"index": 0
}
},
"failure": {
"classification": "network_degraded"
},
"client_capabilities": {
"video_evidence": "exact",
"audio_evidence": "exact",
"codecs_video": [
"h264"
],
"codecs_video_hardware": [
"h264"
],
"codecs_audio": [
"aac"
],
"containers": [
"mp4"
],
"max_resolution": "1080p",
"hdr": false,
"video_decode": [
{
"codec": "h264",
"profiles": [
"high"
],
"levels": [
41
],
"bit_depths": [
8
],
"max_width": 1920,
"max_height": 1080,
"max_frame_rate": 60,
"max_bitrate_kbps": 20000,
"hardware": true
}
]
},
"client_playback_context": {
"protocol_version": 3,
"form_factor": "tv",
"app_version": "3.0-test",
"device": {
"platform": "android",
"os_version": "15",
"manufacturer": "NVIDIA",
"model": "SHIELD Android TV",
"platform_details": {
"abis": "arm64-v8a",
"sdk_int": "35"
}
},
"output": {
"output_context_id": "7"
},
"deliveries": {
"original_http": {
"enabled": true,
"supported_on_device": true,
"containers": [
"mp4"
],
"video_codecs": [
"h264"
],
"audio_decode_codecs": [
"aac"
],
"audio_passthrough_codecs": [],
"subtitles": {
"embedded_text": true,
"sidecar_text": true,
"ass_styling": false,
"embedded_bitmap": false,
"sidecar_bitmap": false,
"font_attachments": false
},
"features": [],
"auth_header_refresh": true,
"validated_claims": [],
"transformations": []
}
}
}
}
@@ -1,5 +0,0 @@
{
"protocol_version": 3,
"server_features": [],
"outcome": "playable"
}

Some files were not shown because too many files have changed in this diff Show More