The federation.deliver worker task sends queued activities:
- signed POSTs as the user, draft-cavage first and RFC 9421 after a
401 (double-knocking), several at once (FEDERATION_DELIVERY_
CONCURRENCY), up to 50 per pass
- 2xx delivered; 410 removes whoever that inbox belongs to as a
follower and marks them gone; other 4xx (except 401/408/429) are
abandoned; everything else retries at 1m, 5m, 30m, 2h, 6h, then
every 12h, abandoned after 2 days
- claiming leases a delivery (pushes its next attempt forward), so a
crashed worker's sends become due again on their own; claiming
skips the eager join Postgres can't lock through
- metrics: deliveries by result, delivery time, outgoing signatures,
queue depths and follower totals (gauges set every 30s)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
Generating 2048-bit keys for every sharing user and scripted remote
account dominated federation test time. Tests only need distinct valid
keys, so an autouse fixture hands out a pool of 16 generated once per
run (50s -> 40s for the suite).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- net.py: the only client federation uses, on httpcore (BSD-3-Clause)
with a guarded network backend: https only, every resolved address
must be public (private, loopback, link-local, CGNAT, multicast and
IPv4-mapped forms refused), and the connection goes to the checked
address; 3 redirects max (GET only), 1 MB cap, 10s/20s timeouts
- outbound.py: signed GETs (instance actor, so authorized-fetch servers
answer) and signed POSTs (as the user), trying the configured
signature schemes in order and the next only on a 401
- remote.py + federation_remote_actors: fetch, validate (id matches
URL and host, actor type, inbox on its host, key owned by the actor),
cache for 24h, refresh on demand, 410 marks an actor gone; resolve a
key id to its actor, including standalone key documents
- Config: FEDERATION_SIGNATURE_SCHEMES, FEDERATION_BLOCKED_DOMAINS,
FEDERATION_DELIVERY_CONCURRENCY, and FEDERATION_INSECURE_TESTING
(http and private addresses; only allowed for .test domains)
- Tests against a real local HTTP server, including verifying that our
fetches carry a valid signature
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- federation_settings (per user; off, followers-only, not discoverable
by default) and federation_keys (RSA-2048; NULL user = instance
actor), on the federation migration branch
- Private keys encrypted at rest with Fernet, keyed by HKDF-SHA256 from
FEDERATION_KEY_SECRET (now required, 32+ chars, never printed)
- Keys are created when a user first enables sharing and never
regenerated; sharing.shared_user() treats unknown and non-sharing
users identically
- One flask-smorest Api per app (get_api(app)), so apps with and
without federation never share an OpenAPI spec
- Test fixtures for a second, federation-enabled app on the same DB
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- scrobbler.federation with init_app() as its only entry point, called
from create_app(); does nothing unless FEDERATION_ENABLED
- FederationConfig validates FEDERATION_DOMAIN (bare host) and
FEDERATION_BASE_URL (https) when enabled, with clear errors
- federation/protocol/ package for pure, framework-free protocol code
- Package README with the boundary rules, configuration and migration
workflow; .env.example lists the settings (off)
- Alembic: existing history labelled `core`; new empty `federation`
branch root (depends on the core users table). Everything upgrades
`heads` (entrypoint, CI, tests); tests check both branches apply and
that federation can be removed without touching core
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- flask-smorest API under /api/v1 with a uniform JSON error shape;
spec at /api/openapi.json, Swagger UI at /api/docs, ReDoc at /api/redoc
- Register/login/logout/me with hashed, expiring bearer tokens,
documented as an OpenAPI bearer security scheme
- API application and client-session management endpoints
- CORS restricted to the configured UI origin(s)
- Flask no longer serves static files: it is API-only
- Login and registration metrics
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- /2.0/ dispatcher backed by a method registry that declares each
method's params and signature/session requirements
- api_sig verification per the Last.fm auth spec
- XML (default) and Last.fm-style JSON rendering, including error shapes
and HTTP statuses per error code
- Last.fm request, error and auth-failure metrics with bounded labels
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Flask app factory with env-driven config (.env loaded at import)
- SQLAlchemy models: users, API apps, UI tokens, Last.fm auth tokens,
sessions, scrobbles (deduplicated) and now-playing
- Initial Alembic migration; CI checks migrations match the models
- Prometheus metric definitions, per-endpoint RED hooks with bounded
labels, and a standalone metrics server
- docker compose Postgres with a test database; CI test job runs
against a Postgres service container
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>