Skip to main content

SERVE FEDERATION

Serve federation joins serves to a hub, which records what each member reports about itself.

Note

Preview. Serve federation is a preview feature: no flag turns it on, and its commands and the serve-hub app may change in later releases. Every serve and every CLI that uses it must run Swamp 20261129.160739.0 or later.

Overview

Term Meaning
Hub A serve whose serve.yaml sets federation.role: hub. It accepts members and records them
Member A serve whose serve.yaml sets federation.hub: <url>. It joins one hub and checks in
Instance One serve process of a member. A member running several serve nodes has several instances
Join token A single-use, time-limited secret minted on the hub for one member name
Credential A secret the hub issues on join. The member presents it on every check-in
Check-in A member instance's outbound HTTPS call to the hub, carrying its fingerprint
Fingerprint The fixed, allowlisted set of facts a serve reports about itself
Member status online, stale, offline or removed, derived by the hub from check-in times
  • A serve is a hub, a member, or neither. A member belongs to exactly one hub. A hub cannot join another hub.
  • The hub only records. It never changes anything on a member.
  • Members pull: each instance calls the hub over HTTPS every 30 seconds. The hub never opens a connection to a member.
  • Serve federation needs serve.yaml version 2 on the hub and on every member. See Versions.

For why it works this way, see Serve Federation.

Configuration

The federation block is read only from a version 2 serve.yaml. In a version 1 file it is an unknown key: serve logs a warning and ignores it.

A hub:

version: 2
federation:
  role: hub
  name: central

A member, as swamp serve hub join writes it:

version: 2
federation:
  hub: "https://hub.example.com"
  join-token-file: "join-token.txt"
Key Set on Type Rules
federation.role Hub string Only hub
federation.name Hub string The hub's own member name. Default hub. Follows the member name rules
federation.hub Member string The hub URL. See Hub URL
federation.join-token-file Member string Path to a file holding a join token. A relative path resolves against the repository. Read up to 4 KiB

The block must set exactly one of role and hub. Any other key is refused. Serve refuses to start, and swamp serve check-config fails, with these errors:

File Error
Both role and hub, or neither Invalid federation in <path>: set exactly one of role: hub or hub: <url>
A hub with join-token-file Invalid federation.join-token-file in <path>: a hub joins no hub
A member with name Invalid federation.name in <path>: only a hub names itself in serve.yaml

A join token can never be minted for the hub's own name.

Hub URL

Rule
https://, or http:// only to a loopback host
Loopback is exactly localhost, 127.0.0.0/8 and [::1], compared on the parsed host name
127.0.0.1.example.com is not loopback
No credentials, query string or fragment
A path prefix is allowed and stored without a trailing slash: https://hub.example.com/fed/ is stored as https://hub.example.com/fed
An error never echoes the URL

Reload

federation is read once at startup. swamp serve reload does not apply a change to it, and reports it under needsRestart while the file differs from the value serve started with:

"needsRestart": [
  {
    "setting": "federation",
    "reason": "restart serve to change it; it needs a new process: the federation role, hub and name are read once at startup"
  }
]

Commands

Every command is under swamp serve.

Command Runs against Access on access:swamp/federation (with --server)
swamp serve fingerprint Any repo —
swamp serve hub join <hub-url> A member —
swamp serve hub A member read
swamp serve hub forget A member — (local only)
swamp serve member list A hub read
swamp serve member get <name> A hub read
swamp serve member remove <name> A hub admin
swamp serve member token create <name> A hub admin
swamp serve member token list A hub admin
swamp serve member token revoke <name> A hub admin

Local mode and --server

Without --server, swamp serve member and swamp serve hub open the store serve uses in this repository. Local mode needs a version 2 serve.yaml with the matching role, and refuses otherwise:

Error: This repository's serve is not a federation hub: its serve.yaml needs version: 2 and federation.role: hub. Pass --server to ask a running hub.
Error: This repository's serve is not a federation member: its serve.yaml needs version: 2 and federation.hub. Pass --server to ask a running member.

swamp serve member local mode is also refused on a checkout that writes through serve, and on a version 2 extension datastore, where serve may keep its control-plane store remotely. Use --server there.

With --server <url>, the command runs on that serve and takes the remote options --token, --token-file and --ca-cert, as other --server commands do.

Error replies: in local mode the CLI prints the message. With --json, swamp serve hub join and swamp serve hub forget print { error, code }, and every command run with --server prints { error, code }:

{
  "error": "Server reported token_not_unused: Join token for 'edge-1' is used; only an unused token can be revoked",
  "code": "token_not_unused"
}

swamp serve fingerprint

Prints this repository's fingerprint and its hash without starting a server or syncing the datastore.

Flag Description
--config <path> Serve config file. Default .swamp/serve.yaml
--repo-dir <dir> Repository directory
$ swamp serve fingerprint
Fingerprint: 7973e9400d69eface1c316dcce42c65cab8ef918d6361dd4e424c1cf052ff163

Build:
  Swamp version: 20261129.213627.0-sha.b1e10d9f
  Platform: darwin/aarch64
  serve.yaml version: 2

Deployment:
  Mode: local
  Datastore: filesystem (v2)
  Vaults: local_encryption
  Federation role: hub

Access:
  Auth mode: token
  TLS: off
  Remote only: no
  Loopback only: yes
  Settings hash: 48ad85c059e3aa28f5f3cf6a2c585e1ce1f28c1b65cb4a732181bb6108fee306

Extensions:
  none

Pool: (not part of the fingerprint hash)
  Workers: 0
  By swamp version: none
  By label key: none

Runtime: (not part of the fingerprint hash)
  Team: known only to a running serve
  Started: known only to a running serve
  Ready: known only to a running serve

With --json it prints { fingerprint, hash }. The runtime fields team, startedAt and ready are null, since only a running serve knows them. The hash covers configuration only. See Fingerprint fields.

swamp serve hub join

swamp serve hub join <hub-url> --token-file <path>

Writes the federation block for a member into serve.yaml. It never reads the token and never starts serve.

Flag Description
--token-file <path> Required. The file holding the join token. It must exist
--config <path> The serve config file to write. Default .swamp/serve.yaml. Serve must then start with the same --config
--repo-dir <dir> Repository directory

A relative --token-file resolves against the current directory. When the file is inside the repository, join-token-file is written relative to the repository.

Starting file Result
No file Writes a version 2 file holding only version and federation
Version 1, no key version 2 refuses Stamps version: 2, then adds federation. Every other line is kept
Version 1, keys version 2 refuses Writes nothing; lists the keys (not_ready_for_version_2)
Version 2, no federation Adds federation
Any file with federation Writes nothing (already_federated)
$ swamp serve hub join http://localhost:19600 --token-file join-token.txt
✓ Wrote /srv/swamp/edge-1/.swamp/serve.yaml to join http://localhost:19600 with the join token in join-token.txt.
Start (or restart) serve to join: federation is read only at startup. Then run swamp serve hub to watch the join.

For a file that already exists, the first line reads ✓ Updated <path>.

With --json:

{
  "configPath": "/srv/swamp/edge-2/.swamp/serve.yaml",
  "defaultConfig": true,
  "fromVersion": 1,
  "hubUrl": "http://localhost:19600",
  "tokenFile": "join-token.txt"
}

fromVersion is "none", 1 or 2. defaultConfig is false when --config named another file.

swamp serve hub

Shows this member's link to its hub and each instance's last check-in, or its last attempt and result while it is not checking in.

$ swamp serve hub
Hub: http://localhost:19600 (central)
State: joined
Member: edge-1 e581dcbd-c776-4510-af87-e3aa77687d5e
Joined: 2026-11-29T23:49:45.161Z
Instances:
  c0163988-5359-4f0e-942e-1e8f655be449  ok, last check-in 2026-11-29T23:49:45.175Z

With --json it prints { link }:

Field Description
state A link state
hubUrl The hub the member joined, or null
configuredHubUrl The hub serve.yaml names
hubName The hub's own member name, or null
memberName This member's name, or null
memberId This member's id, or null
joinedAt When the member joined, or null
instances[] Per instance: instanceId, startedAt, aliveAt, lastAttemptAt, lastSuccessAt, consecutiveFailures, nextAttemptAt, stoppedAt, result
joinTokenFileSet Whether serve.yaml names a join-token-file, never its path. Absent from a serve older than 20261130.004414.0

result is an instance result. Locally, joinTokenFileSet reads the current serve.yaml; with --server it reads the config the running serve started with.

While the link is unjoined, the hint below the instances follows joinTokenFileSet and the result of the newest instance (the latest startedAt):

Case Hint
No join-token-file Not joined: set federation.join-token-file in serve.yaml to a token minted on the hub, then restart serve.
A join-token-file, no refusal Not joined yet: serve.yaml names a join-token-file. Start (or restart) serve to join, as federation is read only at startup; a running serve's log says why it has not joined.
The newest instance's result is name_taken The hub refused the join: a live member already has this name. Remove it on the hub, or set a join-token-file minted for another name, then restart serve.
The newest instance's result is join_refused The hub refused the join token (used, expired, revoked or unknown). Mint a new one, set it as the join-token-file, then restart serve.

A CLI on 20261130.004414.0 or later talking with --server to an older serve gets no joinTokenFileSet, and shows the first hint unless the newest instance records a refusal.

swamp serve hub forget

swamp serve hub forget [--yes]

Deletes this member's credential, then its link records. Local only. Without --yes it asks for confirmation, and refuses when stdin is not a terminal.

It is refused while any instance on the link refreshed its aliveAt within the last 2 minutes (serve_running):

Error: A serve for this repository checked in within the last 2 minutes (1 instance). Stop it first. If it stopped without shutting down, wait 2 minutes and retry.

An instance that shut down cleanly is marked stopped and does not block it. forget does not edit serve.yaml.

✓ Forgot the link to http://localhost:19600 as edge-2, and its credential.
Run swamp serve hub join <hub-url> --token-file <path>, then start serve, to join a hub again.

With --json it prints { forgot, hubUrl, memberName }.

swamp serve member list

Lists every member of the hub, the hub's own row included.

$ swamp serve member list
NAME     ROLE    STATUS  LAST SEEN  INSTANCES  SWAMP                           JOINED
central  hub     online  24s ago    1          20261129.213627.0-sha.b1e10d9f  2026-11-29T23:49:17.433Z
edge-1   member  online  26s ago    1          20261129.213627.0-sha.b1e10d9f  2026-11-29T23:49:45.149Z
edge-2   member  online  4s ago     1          20261129.213627.0-sha.b1e10d9f  2026-11-29T23:50:07.627Z
Column Description
NAME The member name
ROLE hub or member
STATUS A member status
LAST SEEN The freshest check-in of any instance
INSTANCES Live instances only
SWAMP The Swamp version in the member's fingerprint
JOINED When the member joined

Ages are shown in their largest unit, measured against the hub's now, so clock skew between the CLI and the hub does not change them.

With --json it prints { members, now }. Each member carries memberId, name, role, status, joinedAt, fingerprint, instances (the recorded instances) and live, which holds lastSeenAt and per instance its lastSeenAt and runtime (team, startedAt, ready), freshest first. live comes from check-ins, never from the record.

swamp serve member get

$ swamp serve member get edge-2
Member: edge-2 (member)
Status: stale
Member id: db82931a-6a83-4e20-a91c-26383b4fe240
Joined: 2026-11-29T23:50:07.627Z

Fingerprint:
  Swamp version: 20261129.213627.0-sha.b1e10d9f
  Platform: darwin/aarch64
  Mode: local
  Datastore: filesystem (v2)
  Auth mode: none

Instances:
  7a8c4a9b-ca1c-43c5-bbbe-a0656352ddf0 (swamp 20261129.213627.0-sha.b1e10d9f, first seen 2026-11-29T23:50:07.644Z)

Live:
  Last seen: 2m ago (2026-11-29T23:51:05.021Z)
  7a8c4a9b-ca1c-43c5-bbbe-a0656352ddf0 stale 2m ago

Instances lists every recorded instance. Live labels each instance live, stale or offline by the status thresholds, and shows runtime facts (team role and size, start time, readiness) only for a live one. An unknown name is not_found.

swamp serve member remove

swamp serve member remove <name>

Marks the member's record removed, then deletes its credential. The member's next check-in is refused and its link becomes refused. The record is kept. The command takes no --yes.

✓ Member edge-2 removed.
Its credential no longer checks in; the record is kept, marked removed.

Remove a member only with this command, never by deleting its data.

swamp serve member token create

swamp serve member token create <name> [--duration <duration>]
Flag Default Description
--duration <duration> 1h How long the token can be used to join. At most 30d
$ swamp serve member token create edge-1
Join token: edge-1
Expires: 2026-11-30T00:48:57.982Z

  edge-1.<secret>

This token is shown once and will not be displayed again; the hub keeps only its hash.
Give it to the member's operator; it joins once, as the name it was minted for.

The token's wire form is <name>.<secret>. Creating a token again for a name replaces that name's unused token. Minting does not check whether a live member already holds the name; the join is refused with name_taken instead.

With --json:

{
  "token": {
    "memberName": "edge-2",
    "state": "unused",
    "createdAt": "2026-11-29T23:48:58.163Z",
    "expiresAt": "2026-11-30T01:48:58.163Z"
  },
  "joinToken": "edge-2.<secret>"
}

swamp serve member token list

$ swamp serve member token list
NAME    STATE  EXPIRES                   USED
edge-1  used   2026-11-30T00:48:57.982Z  2026-11-29T23:49:45.149Z
edge-2  used   2026-11-30T01:48:58.163Z  2026-11-29T23:50:07.627Z

STATE is unused, used, expired or revoked. With --json it prints { tokens }, each with memberName, state, createdAt, expiresAt and, when set, usedAt, memberId, admittedAt and revokedAt.

swamp serve member token revoke

swamp serve member token revoke <name>

Takes the member name. Revokes only an unused token; any other state is token_not_unused.

✓ Join token edge-3 revoked.

Statuses and timing

Status When
online An instance checked in within 3 check-in intervals (90 seconds)
stale No check-in for 3 intervals. Shown about 90–120 seconds after the last
offline No check-in for 10 minutes
removed swamp serve member remove ran. Terminal

The hub's leading node applies status changes. The same thresholds label each instance live, stale or offline in swamp serve member get.

Timing Value
Check-in interval 30 seconds, set by the hub in its reply. A member clamps it to 5 seconds – 1 hour
Jitter ±10%
Backoff After a network error, 5xx, 429 or refusal: exponential from the interval up to 5 minutes, with jitter. retry-after is a floor
After 409 The full 5 minutes
Request timeout 10 seconds. Redirects are not followed. Replies over 64 KiB are not read
forget window 2 minutes since an instance's last aliveAt

The member joins and checks in in the background once serve is ready. Serve's startup, /ready, runs, schedules and workers never wait on the hub.

A member's link to its hub is in one of five states.

State Meaning What to do
unjoined No join has succeeded Set join-token-file (swamp serve hub join) and start serve
joining A join request is open. It is retried with the same join id Wait. If it persists, check the hub URL, TLS and that the hub is reachable
joined Joined; instances check in —
mismatched serve.yaml names a different hub than the one joined. No requests Restore the hub URL, or move the member to the new hub
refused The hub refused the credential: the member was removed Put a new join token in the token file and restart serve

A refused link holds no credential, so a new join token is enough to join again, to the same hub or another. A mismatched link keeps its credential; restoring the hub URL resumes check-ins.

Instance results

Each instance records the result of its last attempt.

Result Meaning What to do
ok The last check-in succeeded —
waiting Another node of the member holds the join claim; this one waits for the credential Wait
unreachable A network error or timeout reaching the hub Check the URL, network and TLS
rate_limited The hub answered 429 Wait; the member backs off
server_error The hub answered 5xx Check the hub's log
rejected The hub answered another non-200 status, such as 400, or an unreadable reply Check the hub's log and that both run Swamp 20261129.160739.0 or later
instance_limit The member already has 64 live instances Wait: an instance drops out once it stops checking in
refused The hub refused the credential See the refused link state
join_refused The hub refused the join token: used, expired, revoked or unknown Mint a new token and restart serve
name_taken A live member already has this name Remove it on the hub, or mint a token for another name
mismatched serve.yaml names another hub See the mismatched link state
not_joining No link and no join-token-file Set join-token-file and restart serve

The member logs a refused join once, for example:

The hub refused the join token (used, expired, revoked or unknown). Mint a new one and restart serve
The hub refused the join: a live member already has this name. Remove it on the hub, then restart serve

Error codes

Commands

Code Command Meaning
invalid_hub_url hub join The URL breaks a hub URL rule
token_file_missing hub join The --token-file does not exist
not_ready_for_version_2 hub join The version 1 file has keys version 2 refuses
already_federated hub join serve.yaml already has a federation block
hub_join_failed hub join Reading, editing or writing serve.yaml failed
serve_running hub forget An instance was alive within 2 minutes
invalid_duration member token create --duration is not positive or exceeds 30d
invalid_name member token create The name breaks the member name rules
token_not_unused member token revoke The token is used, expired or revoked
not_found member get, member remove No member has that name
unauthorized Any, with --server The caller lacks the access the command needs

hub join checks the URL before the token file.

HTTP

Status error When
400 invalid_request A malformed body, a missing joinId, another protocolVersion, or a fingerprint field it refuses. The message names the field path and echoes nothing sent
401 invalid_join_token Join with a used, expired, revoked or unknown token. One body for every reason
401 unauthorized Check-in with a credential that is invalid or belongs to a removed member
405 method_not_allowed Any method but POST
409 name_taken Join under a name a live member holds
409 instance_limit A check-in from a 65th live instance
413 payload_too_large A body over 64 KiB
429 rate_limited Too many requests from the address. Carries retry-after
500 internal_error The hub could not complete the request
{
  "error": "invalid_request",
  "message": "fingerprint.swampVersion: Invalid input: expected string, received undefined"
}

Limits

Limit Value
Member name Letters, digits, - and _; at most 64 characters
Live instances 64 per member
Instance pruning An instance unseen for 24 hours is pruned
Join token duration Default 1h, at most 30d
Join token use Single use
Hubs per member One
Request body 64 KiB

Join is idempotent. A member sends a joinId it chose with each join. A join with a used token and the same joinId, before the token expires and while its member is not removed, is a replay: it gets the same reply with a new credential for the same memberId, and the old credential stops working. A replay whose member record was deleted after the join is refused with 401, except for a token spent before the hub recorded admittedAt on join tokens, which still re-admits.

HTTP

Routes on serve's existing listener, mounted only on a hub. On any other serve the paths answer 404.

Route Body Reply
POST /federation/v1/join { joinToken, joinId, fingerprint, protocolVersion, capabilities } { memberId, memberName, credential, hub, checkInIntervalSeconds }
POST /federation/v1/check-in { instanceId, fingerprint, protocolVersion, capabilities } { hub, checkInIntervalSeconds, jobs: [] }
  • hub is { name, swampVersion, protocolVersion: 1 }. checkInIntervalSeconds is 30. jobs is always empty.
  • joinId and instanceId are lower-case UUIDs.
  • Check-in sends the credential as Authorization: Bearer <credential>. A credential's form is swfm1.<memberId>.<secret>. The hub stores only its sha256 hash.
  • Unknown capabilities strings are ignored on both sides.
  • Fingerprint fields outside the hub's contract are dropped, never stored.
  • These routes authenticate their own callers and are outside user sign-in. Join has a per-address burst limit. Failed joins count per address. Failed check-ins count per member and address.
  • On a hub running several serve nodes, a follower forwards the request to its leader.

Join and check-in refusals are audited as auth events. See Audit Actions.

Data

Record Where
Each member, the hub included A swamp/serve-member record on the hub: Swamp data
Join tokens (hashes) The hub's control-plane store, federation/tokens/<name>
Credentials (hashes) The hub's control-plane store, federation/credentials/<memberId>
Last check-in per instance The hub's control-plane store, federation/seen/<memberId>/<instanceId>
The member's link The member's control-plane store, federation/link/record
The member's credential The member's _token-secrets vault, federation-member-credential

A swamp/serve-member record holds no secret and no hash of one. It gets a new data version only when its fingerprint hash, its worker pool or its status changes, so its data versions are its history. data:read reads it, and swamp data query can query it. Check-in times live outside the record, so a check-in never writes a data version.

Fingerprint fields

The fingerprint is an allowlist. Hostnames, IP addresses, ports, paths, usernames, grants, secrets and hashes of secrets are never included.

Field Value Class
swampVersion The Swamp release Config
platform, arch Operating system and CPU Config
serveYamlVersion 1 or 2 Config
deploymentMode local, durable or durable (limited) Config
datastoreKind filesystem or the datastore type name Config
datastoreFormat v2 or v3 Config
vaultKinds Vault type names Config
authMode none, token or oauth Config
tls Boolean Config
remoteOnly Boolean Config
loopbackOnly Boolean, from the merged host Config
federationRole hub, member or none Config
extensions { name, version } from the extension lockfile Config
settingsHash sha256 over an allowlist of merged settings Config
workers { total, byVersion, byLabelKey } Pool
team { role, nodes }; role leader, follower, peer or single Runtime
startedAt When serve started Runtime
ready Whether serve is ready Runtime
Class In the hash A change on the hub
Config Yes A new member record version
Pool No A new member record version
Runtime No Nothing in data

The hash is sha256 over canonical JSON of the config fields. Restarts and workers reconnecting never change it. workers counts worker records by Swamp version and by label key; label values are never read.

settingsHash covers: auth mode, TLS, remote-only, verify-on-enroll, dispatch-env-allow names, max-concurrent-runs, max-runs-per-principal, max-run-duration, the approve, signal and tag explicit-grant flags, grant-reload mode, hot-reload, reuse-port, schedule, dashboard, auto-resume, shutdown-drain-timeout, restricted behavior types and commands, and reserved-worker-labels names. It never covers admins, allowed users or collectives, webhook routes or secrets, the OAuth client, token secrets, any file path, host or port.