Document following on the fediverse; mark phase 2 done (phase 2, step 9)
CI / validate-monitoring (push) Successful in 9s
CI / lint (push) Successful in 11s
CI / federation-interop (push) Successful in 1m3s
CI / test (push) Successful in 2m4s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 1m20s

README: following works, the Followers page, optional federation
settings and the worker requirement. Federation README: settings,
module layout, worker tasks and the interop test. Design doc: what
interop testing changed. Phase 2 plan marked done with its deviations
(httpcore, no in-process two-instance test, Undo of Block), leaving
only the manual Mastodon check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
This commit is contained in:
mattandClaude Opus 5.5 committed 2026-09-25 22:17:02 +01:00
1 parent fe95f59fc8
commit fefdeb90ec
4 files changed
+54 -3

No files matched your search

+14 -1
View File
@@ -94,7 +94,12 @@ Unlike live scrobbles, imports keep plays of any age. They still skip rows with
## Sharing on the fediverse (in development)
Users can make their profile findable from Mastodon and other fediverse apps as `@name@<your UI host>`. Following, and posts (weekly summaries, milestones, now playing), are still being built; see `docs/design/activitypub.md`. Until then, profiles advertise follower approval, so a follow waits as a request rather than failing.
Users can make their profile findable from Mastodon and other fediverse apps as `@name@<your UI host>`, and be followed:
- Follows are accepted automatically, or wait for approval if the user turns that on.
- The **Followers** page lists requests, followers and blocked accounts, with approve, decline, remove, block and unblock.
Posts (weekly summaries, milestones, now playing) are still being built; see `docs/design/activitypub.md`. Federation is tested in CI against a real GoToSocial server (`scripts/interop/run.sh`).
It's **off unless the server enables it**, and then **off for each user** until they switch it on under **Sharing**. To enable it:
@@ -110,6 +115,14 @@ Handles and actor URLs **can't change once anyone follows** a user, so choose th
`FEDERATION_KEY_SECRET` encrypts each user's signing key. **Back it up, and never change it**: losing it means users' keys can't be read, and followers would have to follow again.
Optional settings:
- `FEDERATION_BLOCKED_DOMAINS`: comma-separated domains, including subdomains, whose deliveries and follows are refused.
- `FEDERATION_DELIVERY_CONCURRENCY`: parallel outgoing deliveries per worker (default 4).
- `FEDERATION_SIGNATURE_SCHEMES`: the signing order (default `draft-cavage,rfc9421`).
The worker must be running: it processes incoming activities and delivers outgoing ones.
## Develop
```sh
+8
View File
@@ -1,5 +1,13 @@
# ActivityPub phase 2: followers
**Status: done** on `feature/activitypub` (`a6d3fb6` … `fe95f59`). The GoToSocial interop test passes locally and in CI. Before merging, the plan still calls for a manual pass with a real Mastodon account through a tunnel.
Where this differed from the plan:
- **httpcore instead of httpx.** httpcore is the transport layer underneath httpx, and it publicly supports the custom network backend that connecting to a pre-checked address needs.
- **No in-process test with two Scrobbler instances.** Scrobbler can't initiate follows yet, so one instance has nothing to send the other. Scripted remote accounts over real HTTP cover the same paths, and GoToSocial is the real second server.
- **Undo of a Block.** Unblocking needed it: GoToSocial otherwise keeps the block.
This implements phase 2 of [activitypub.md](activitypub.md), building on [phase 1](activitypub-phase1.md).
**Outcome:** people on Mastodon, GoToSocial and similar servers can follow a user who shares. Follows are accepted automatically, or wait for the user's approval if they've turned it on. The user sees their followers and can approve, decline, remove or block them. Scrobbler signs everything it sends and checks the signature on everything it receives. Posts come in phase 3; this phase makes the relationship work end to end.
+10
View File
@@ -391,3 +391,13 @@ Still open (neither is needed before phase 3):
- [SocialHub: RFC 9421 HTTP signatures in 2026](https://socialhub.activitypub.rocks/t/rfc-9421-http-signatures-in-2026/8427)
- [Funkwhale federation docs](https://docs.funkwhale.audio/develop/developer/federation/index.html): the `Listen` activity with a `Track` object
- [Pubby on PyPI](https://pypi.org/project/pubby/): features and AGPL-3.0-or-later licence
## Lessons from interop testing (phase 2)
Testing against a real GoToSocial server changed a few details:
- **Key IDs come in three shapes.** A fragment of the actor (`<actor>#main-key`, used by Mastodon), a path that serves the actor document (`<actor>/main-key`, used by GoToSocial), or a separate key document with an `owner`. All three are resolved.
- **Rejects reference the Follow by ID rather than embedding it.** Some servers match an embedded Follow by the pair of accounts. A late Reject of an old Follow would then cancel a newer request between the same two accounts.
- **An Undo only removes the Follow it names.** Deliveries race, so an Undo of an older Follow can arrive after a newer one.
- **Unblocking sends an Undo of the Block**, so the other server lets the person follow again.
- **Actors publish a `featured` collection** (empty for now). Mastodon and GoToSocial fetch it.
+22 -2
View File
@@ -32,6 +32,10 @@ or switched off without touching anything else. Design: `docs/design/activitypub
| `FEDERATION_DOMAIN` | Handle domain, normally the web UI's host: users are `@name@<domain>`. **Permanent once anyone follows.** |
| `FEDERATION_BASE_URL` | Public `https://` URL actors live under (`<base>/users/<name>`). Normally the web UI's origin, with the UI's nginx forwarding the ActivityPub paths to the API. |
| `FEDERATION_KEY_SECRET` | 32+ characters; encrypts actors' private keys at rest (HKDF → Fernet). **Back it up; never change it.** |
| `FEDERATION_SIGNATURE_SCHEMES` | Outgoing signing order; the next scheme is tried only on a 401. Default `draft-cavage,rfc9421` |
| `FEDERATION_BLOCKED_DOMAINS` | Comma-separated domains (subdomains included) refused at the inbox |
| `FEDERATION_DELIVERY_CONCURRENCY` | Parallel deliveries per worker (1-32, default 4) |
| `FEDERATION_INSECURE_TESTING` | **Tests only.** Allows `http://` and private addresses; refused unless the domain is under `.test` |
The UI container forwards these paths to the API when `API_INTERNAL_URL` is set (see `docker/ui-config.sh`):
@@ -44,15 +48,31 @@ Every ActivityPub ID is built from `FEDERATION_BASE_URL`, never from the incomin
| Module | Holds |
|---|---|
| `protocol/` | Pure protocol code: media types, vocabulary, WebFinger, NodeInfo, host-meta |
| `models.py` | `federation_settings` and `federation_keys` |
| `protocol/` | Pure protocol code: media types, vocabulary, WebFinger, NodeInfo, host-meta, and `signatures/` (draft-cavage and RFC 9421, one module each) |
| `net.py` | The SSRF-safe HTTP client, the only way out |
| `outbound.py` | Signed GETs (as the instance actor) and POSTs (as a user), with scheme fallback on 401 |
| `remote.py` | Remote actors: fetched, validated, cached; key id to actor |
| `inbox.py` | Intake (no network) and worker processing: signature check, identity checks, handlers by activity type |
| `followers.py` | Follower state: follows, undo, approve, remove, block, sharing off |
| `activities.py` | Activities we send (Accept, Reject, Block, Undo), stored and queued per inbox |
| `delivery.py` | The delivery worker task: leases, retries with backoff, gone inboxes, gauges |
| `models.py` | `federation_*` tables |
| `keys.py` | Key pairs, created once and encrypted at rest |
| `sharing.py` | Per-user settings, and who is sharing |
| `ids.py` | Our ActivityPub ids, all from `FEDERATION_BASE_URL` |
| `web.py` | The endpoints other servers call |
| `api.py` and `schemas.py` | `/api/v1/federation/*` for the web UI |
| `openapi.py` | OpenAPI descriptions of `web.py`'s endpoints |
| `metrics.py` | Federation's own Prometheus metrics |
## Worker tasks
`federation.inbox` (process received activities), `federation.deliver` (send queued ones), `federation.inbox.maintenance` (re-queue stalled, prune after 30 days) and `federation.gauges` (queue and follower gauges). All are registered only when federation is on.
## Interop
`scripts/interop/run.sh` runs Scrobbler against a real GoToSocial server on a private `.test` network and checks the whole follow life cycle. CI runs it on every push. GoToSocial 0.22.1 ignores a Reject of an already-accepted follow (a TODO in its code, fixed on its main branch), so that one check on its side is skipped until a release includes the fix.
## Migrations
Federation's tables (all prefixed `federation_`) live in their own Alembic branch,