A fifth provisioned Grafana dashboard: fediverse lookups by kind and
result, sharing switched on/off, federation endpoint rates and p95
latency, and inbox deliveries. Dashboard tests now know federation's
own metrics, and a new test rejects PromQL string escapes Prometheus
can't parse (the endpoint filter first used \. and failed live).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
TestConfig pins FEDERATION_ENABLED off and LASTFM_API_KEY empty, so a
developer's .env (e.g. federation switched on to try it locally) can't
change what the "feature off" tests see. Tests that need a feature turn
it on explicitly (FederatedTestConfig, lastfm_config).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- The UI container forwards /.well-known/{webfinger,nodeinfo,host-meta},
/nodeinfo/, /users/, /inbox and /actor to API_INTERNAL_URL (compose:
http://api:8000), passing Host and X-Forwarded-*; unset means no
forwarding
- The API's name is resolved per request via the container's resolver,
so the UI starts before the API and survives API restarts
- Compose passes the FEDERATION_* settings to api and worker;
.env.example documents them, including FEDERATION_KEY_SECRET
- gunicorn: disable the 26.x control socket (the container user has no
home directory)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- sharing.html: switch sharing on/off, see the handle (with the
"permanent once followed" warning and a note that following comes
later), choose who sees posts (followers only by default; help text
on why approval matters), follower approval, directory and search
opt-ins, display name and bio; save status shown by the button
- profile.html?u=<name>: the public page browsers land on from an actor
URL: name, handle (with copy), bio and how to follow; never asks the
visitor to sign in
- "Sharing" appears in the nav only when the server federates
(remembered per tab)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- /api/v1/federation/settings (GET, PATCH): sharing on/off, visibility
(followers-only default), follow approval, discoverable/indexable,
display name and bio, plus the read-only handle and URLs
- /api/v1/federation/profiles/<name>: public profile for the UI page,
only for users sharing
- ActivityPub endpoints documented under an ActivityPub tag
- docs/openapi.json is now exported with every optional module on
(python -m scrobbler.openapi.export); the drift test and route checks
cover both a federation-off and a federation-on app
- Boundary: federation may use scrobbler.api.get_api to register its
blueprint; the checker proves other scrobbler.api modules stay off
limits
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
Registered only when federation is enabled:
- WebFinger (acct: and actor-URL resources, the instance actor, CORS *)
- host-meta, NodeInfo discovery and 2.1 (counts users sharing)
- /users/<name>: the Person actor for ActivityPub clients, a redirect to
the UI profile page for browsers (for any name, so redirects don't
reveal accounts); outbox/followers/following collections
- /actor: the instance Application actor
- Inboxes accept (202) and count deliveries; size-limited; processing
arrives in phase 2. Actors advertise manual approval until then.
- Unknown and non-sharing users get byte-identical 404s; all IDs come
from FEDERATION_BASE_URL, never the request
- Federation metrics: lookups, sharing changes, inbox deliveries
- scrobbler.__version__ joins the core's public surface for NodeInfo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
Pure, framework-free code in federation/protocol:
- media: ActivityPub content types and Accept negotiation
- vocab: actor URLs, Person and Application actors (Mastodon's extension
terms), public keys, collections, plain text to safe HTML
- webfinger: acct:/actor-URL resource parsing (other domains and bad
usernames rejected) and JRD documents
- nodeinfo: discovery and NodeInfo 2.1; hostmeta: XRD pointing at
WebFinger
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
- Handles and actor URLs live on the web UI's domain; the UI's nginx
forwards the ActivityPub paths to the API
- Posts default to followers only, settable per user, with the privacy
caveat about automatic follow approval spelled out
- docs/design/activitypub-phase1.md: the discoverable-profile phase,
step by step
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
Static checks (ast, so imports inside functions and relative imports
count): nothing outside scrobbler.federation imports it except
create_app; federation.protocol imports no framework or scrobbler code;
the rest of federation uses only the core's public surface (events,
extensions, worker, services, api.decorators, schemas). The checker is
itself tested against deliberate violations and permitted imports.
Runtime checks: with federation off no federation views, event
receivers or worker tasks exist; enabling it needs a bare domain and
an https base URL.
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
scrobbler/worker.py runs tasks that modules register: queue tasks
(called while they report work) and periodic tasks. A failing task is
logged, counted, rolled back and doesn't stop the others. Imports are
now just a registered task plus a periodic stall check.
- `flask worker` replaces `flask imports worker` (kept as an alias);
compose uses the new command
- scrobbler_worker_tasks_total{task,outcome} and a Worker tasks panel
on the Usage dashboard
- WORKER_METRICS_PORT (IMPORT_WORKER_METRICS_PORT still honoured)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
scrobbler/events.py defines blinker signals sent after commit:
scrobbles_stored (newly stored plays only, source scrobble/import),
now_playing_changed (track or None) and import_finished. A receiver
that raises is logged and skipped, so optional modules can't break
scrobbling or imports. store_chunk now reports which plays it stored.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
Step-by-step plan: domain events, a generic worker with imports moved
onto it, the empty federation module and config, separate Alembic
branches, and boundary tests enforcing the module rules.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Settles build vs buy: write it ourselves (Scrobbler is BSD-3-Clause;
the Python library option is AGPL)
- New "Module structure" section: everything in scrobbler.federation,
a pure protocol/ subpackage for spec-dependent code, pluggable
signature schemes/inbox handlers/post kinds, core → federation only
via blinker domain events, own federation_* tables in a separate
Alembic branch, generic task worker, and boundary tests enforcing it
- Adds a groundwork phase 0 and updates the open decisions
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
Research write-up for making Scrobbler users followable from the
fediverse: protocol pieces (WebFinger, actor, inbox, signatures in both
draft-cavage and RFC 9421, delivery), what gets posted (weekly summary,
milestones, now playing), build-vs-library, data model, security,
testing against GoToSocial, phased plan and open decisions.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- New Import page: upload an export (with upload progress) or, when the
server has a Last.fm API key, import straight from a Last.fm username;
jobs list with live progress, counts, errors and cancelling
- docker compose runs the import worker from the API image; the API
image no longer sets PROMETHEUS_MULTIPROC_DIR (gunicorn.conf.py does,
and other commands must not inherit multiprocess mode)
- Prometheus scrapes the worker; Usage dashboard gains an Imports row;
ImportWorkerDown and ImportJobsWaiting alerts
- README and .env.example document imports and LASTFM_API_KEY
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- /api/v1/imports/options lists the available sources; `lastfm` only
appears when the server has a Last.fm API key
- POST /imports/file (multipart; format detected or forced with
?format=), POST /imports/lastfm, GET /imports, GET /imports/{id},
POST /imports/{id}/cancel
- Upload size limit (IMPORT_MAX_BYTES, default 200 MB) with a 413
- Documented in OpenAPI under the Imports tag
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Import jobs (import_jobs table): uploaded exports stored gzipped,
processed by `flask imports worker`, which claims jobs with
SKIP LOCKED, inserts in chunks with progress, supports cancelling and
re-queues jobs whose worker died
- CSV: lastfm-to-csv (no header) or any header-labelled CSV/TSV with
comma, semicolon or tab delimiters; several date formats and Unix
seconds/milliseconds
- JSON: pages of user.getRecentTracks (e.g. lastfm.ghan.nl), a single
recenttracks response, or a flat list; gzipped files accepted
- Last.fm API pull (only when LASTFM_API_KEY is set): pages through
user.getRecentTracks up to the job's creation time, rate limited,
with retries and resume
- Imports keep plays older than 14 days, skip empty/future ones and
dedupe against existing history
- Import metrics and pending/running job gauges
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Pushes to main and v* tags publish only after every check passes:
API and UI images to the ProGet Docker feed, the OpenAPI spec,
dashboards and Prometheus config to the asset feed
- v* tags also publish the wheel/sdist to the ProGet PyPI feed
- The version comes from the tag (main builds: <version>+g<sha>) and
__version__ reads it from package metadata
- One ntfy notification per run summarising every job that ran and
the image tags published
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Serves the app over HTTPS with a throwaway certificate and drives it
with pylast: web-auth sign-in, now playing, single and batch
scrobbles (non-ASCII too), recent tracks, top artists, play count,
and Last.fm error codes surfacing as pylast WSError
- README: architecture, running with compose, configuration, connecting
players, development workflow, monitoring and CI/CD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- API image (uv multi-stage, non-root, gunicorn, migrations on start,
health check) and UI image (nginx, CSP, config.js rendered from
API_BASE_URL); /healthz documented in OpenAPI
- docker compose runs db, api and ui; the "monitoring" profile adds
Prometheus, postgres-exporter and Grafana, all provisioned from files
- Grafana dashboards: API overview (RED), Last.fm API, Usage, Database
- Prometheus alert rules: API down, error rate, latency, auth failure
spike, ignored scrobbles, DB pool saturation, Postgres down
- Pool checkout gauge counts events (the pool's own counters lag the
checkin event); error ratios show 0 instead of "No data"
- Tests check dashboards and alerts only use metrics that exist
- scripts/generate_traffic.py drives realistic traffic for demos
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Statement latency by operation and connection-pool gauges via
SQLAlchemy events
- Users, active users (1h/24h/7d) and now-playing gauges computed at
scrape time, cached for 60s, from a NullPool engine that is safe in
the gunicorn master; exports nothing (not an error) if the DB is down
- gunicorn.conf.py: multiprocess metrics aggregated across workers and
served by the master on METRICS_PORT, stale files cleared at start,
dead workers marked
- Tests cover labels, in-flight gauge, DB metrics, the collector and a
real two-worker gunicorn aggregation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- /2.0/ and /api/auth/ are described from the Last.fm method registry:
method enum, per-method parameter tables, auth requirements, notes,
request schemas and XML example responses
- Readable tags (Auth, Apps, Sessions, Tokens, Stats, Last.fm)
- docs/openapi.json is exported with `flask openapi write`; tests fail
if it drifts from the code, if any route is undocumented, or if a UI
route is missing its bearer-auth security declaration
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Plain HTML + vanilla JS modules, no build step; talks to /api/v1 with
a bearer token and only ever inserts server data as text
- Overview: now-playing dot-matrix display with live progress, totals,
30-day plays meter, top artists/tracks by period, recent plays
- History (paged, grouped by day), Apps (create/delete, reveal/copy
keys, player setup details), Sessions (revoke), sign-in approval page
for the Last.fm desktop auth flow, sign in and registration
- Light and dark themes, responsive to phone widths, vendored fonts
(SIL OFL) so the UI has no third-party requests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- Stats service shared by both APIs: recent scrobbles, top artists,
albums and tracks over Last.fm periods, per-day/week/month counts
(with empty days filled) and totals
- Case-insensitive grouping that displays the most common spelling
- user.getInfo, user.getRecentTracks (now playing first, from/to),
user.getTopArtists/Albums/Tracks with Last.fm paging attributes
- /api/v1/me: now-playing, recent, top/{artists,albums,tracks},
counts and summary
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
- track.scrobble: batches of up to 50 (array params or a single track),
Last.fm ignore rules (empty artist/track, too old, too new), duplicate
submissions accepted but stored once
- track.updateNowPlaying: upserted per user, expiring after the track's
duration; cleared when the same track is scrobbled
- Scrobble result, ignore reason, batch size, lag and now-playing metrics
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- auth.getMobileSession (username + password), auth.getToken and
auth.getSession with Last.fm error codes 4/14/15
- /api/auth/ redirects clients' approval links to the web UI's
approve page; /api/v1/tokens lets the UI show and approve a token
- Tokens expire after an hour, are single use and bound to their app
- The legacy md5 authToken form is deliberately unsupported (it needs
unsalted password hashes)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 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>
- Rename the project to "scrobbler" with a src/ layout (hatchling)
- ruff + pytest dev tooling and a smoke test
- CI workflow (lint, test) that reports every run to ntfy via a
reusable composite action
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>