Relationships
#5087 serve: runtime-data sync restores a stale worker record and can mispair its server token
Opened by jamesakeech · 11/25/2026
Summary
swamp serve accepts a worker enrollment, then a runtime-data pull and datastore index commit restore an older disconnected state-main for the same worker. A scheduled step placed on that worker fails immediately with Worker 'worker-<name>' has no recorded state — enroll first instead of waiting for queueTimeout. The same startup sync can replace a server-token record with a different mint while leaving the _token-secrets secret unchanged. The open session is closed as rotated, and later connects fail with mispaired-secret.
This is in swamp serve: worker state (state-main on definition worker-<enrollment name>) and server-token consistency (secretFingerprint compared with the control-plane _token-secrets vault). The runtime-data poller pulls data and auto-definitions. Its own comment says a server or enrollment token is read from the local repo when its credential is presented, and otherwise pulled only at boot. The secret stays in the control-plane vault, which does not support existence checks.
The fix should apply a worker or server-token record and its control-plane secret together. A pull should not replace state-main for a worker that is currently connected, and should not resurrect a pruned disconnected record from an older snapshot. The instance written by enrollment has to be the stored record before the next pull. A dispatch that finds no state-main should wait until queueTimeout. A pulled server-token record whose fingerprint does not match the loaded secret should not become the live record and should not close live sessions as rotated.
What happened
One swamp serve replica uses the Recreate strategy. One remote worker enrolls with a stable enrollment token name and label pool=immich-backup. A workflow scheduled 0 0 * * * places its only step on that label and sets queueTimeout: 1800.
On 2026-11-22 and 2026-11-23 the scheduled runs waited the full 30 minutes and failed with Timed out waiting for a worker matching labels pool=immich-backup to become available. After each Serve pod replacement the worker connected once. Serve then logged a catalog commit, Closed 1 session(s) for token "<server-token-name>" (rotated), and mispaired-secret: Server token '<name>' is inconsistent: its record and its secret come from different mints — rotate it. The worker exits after three of those pre-enrollment failures. The startup consistency sweep did not report that server token. The worker presented the same secret; the record had moved.
On 2026-11-24 the tokens were rotated and the worker enrolled (first-connect). Scheduled run 5b2aa9d9-c604-4c7c-b7c1-2caf1c1d1f78 at 2026-11-24T13:00:00Z failed at 13:00:05Z. The error was Worker 'worker-immich-backup-worker-20261115' has no recorded state — enroll first. The step log was empty. Nothing was dispatched.
Stored state-main for worker-immich-backup-worker-20261115 stayed the disconnected instance fede66be-4a01-403a-b8fd-41b2d7a357aa (enrolled 2026-11-21T01:22:10Z, disconnected 2026-11-22T10:59:14Z). swamp worker list --all showed only that record.
A Serve pod start at 2026-11-25T03:26:10Z reproduced the clobber:
- The worker authenticated. Serve logged
Worker "immich-backup-worker-20261115" enrolled ("first-connect"). The worker process loggedEnrolled as "immich-backup-worker-20261115". - The previous pod drained. Serve logged
Draining worker "immich-backup-worker-20261115" disconnected — removed from pool. Runtime data poller: 9 file(s) updated, invalidating catalog.- The replacement worker enrolled (
first-connect) again. Worker GC: pruned 1 worker(s)(first sweep 5 minutes after boot, grace 24 hours).Committed 10 file(s) to datastore index.
After that, state-main was still status disconnected, instance fede66be, disconnectedAt 2026-11-22T10:59:14Z. parseStoredWorkerState throws when state-main is null, and that error fails the step. The run does not wait for queueTimeout.
Expected
A connected worker's enrollment is the stored state-main: the new instance, status idle. A runtime-data pull does not replace it with an older disconnected snapshot and does not restore a record GC just pruned. Missing state-main means no matching worker, and the step waits until queueTimeout. A server-token record and its _token-secrets entry stay one mint across the startup catalog commit.
Environment
- Serve image
swampclub/swamp@sha256:260cfa56a064bd8e50296e3bf5c266c58c6e964d2e7b211a08058f54dd314b8a(tag20261122.185402.0). - CLI
20261125.033127.0-sha.4ed119ce.swamp update --checkreports up to date. That build still containshas no recorded state,come from different mints, the runtime-data poller, andsecretFingerprintpairing. - Datastore pin
@swamp/s3-datastore@2026.11.02.2. - One replica, Recreate. The worker uses
swamp worker connectwith default reconnect,--server-token-file, and--label pool=immich-backup.
Reproduction
- Run one
swamp serveagainst a remote datastore, with a worker enrolled under a stable token name. - Leave that worker's stored
state-mainasdisconnectedin the datastore. - Replace the serve process. Let the worker connect again.
- Within the first minute the runtime-data poller invalidates the catalog and serve commits the index.
- Compare the worker process log (
Enrolled) withstate-mainandswamp worker list --all. The stored record is still the old disconnected instance. - Place a step on that worker's label. When
state-mainis missing, the step fails immediately withhas no recorded stateinstead of queueing.
Separately, after the replacement's catalog commit, a previously consistent server token can log Closed N session(s) for token "<name>" (rotated) and then reject the same secret with mispaired-secret.
Open
No activity in this phase yet.
Sign in to post a ripple.