Skip to main content
← Back to list
01Issue
BugOpenSwamp CLIPublic
AssigneesNone

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:

  1. The worker authenticated. Serve logged Worker "immich-backup-worker-20261115" enrolled ("first-connect"). The worker process logged Enrolled as "immich-backup-worker-20261115".
  2. The previous pod drained. Serve logged Draining worker "immich-backup-worker-20261115" disconnected — removed from pool.
  3. Runtime data poller: 9 file(s) updated, invalidating catalog.
  4. The replacement worker enrolled (first-connect) again.
  5. Worker GC: pruned 1 worker(s) (first sweep 5 minutes after boot, grace 24 hours).
  6. 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 (tag 20261122.185402.0).
  • CLI 20261125.033127.0-sha.4ed119ce. swamp update --check reports up to date. That build still contains has no recorded state, come from different mints, the runtime-data poller, and secretFingerprint pairing.
  • Datastore pin @swamp/s3-datastore@2026.11.02.2.
  • One replica, Recreate. The worker uses swamp worker connect with default reconnect, --server-token-file, and --label pool=immich-backup.

Reproduction

  1. Run one swamp serve against a remote datastore, with a worker enrolled under a stable token name.
  2. Leave that worker's stored state-main as disconnected in the datastore.
  3. Replace the serve process. Let the worker connect again.
  4. Within the first minute the runtime-data poller invalidates the catalog and serve commits the index.
  5. Compare the worker process log (Enrolled) with state-main and swamp worker list --all. The stored record is still the old disconnected instance.
  6. Place a step on that worker's label. When state-main is missing, the step fails immediately with has no recorded state instead 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.

02Bog Flow
◉OPEN○TRIAGED○IN PROGRESS○SHIPPED

Open

11/25/2026, 3:56:49 AM

No activity in this phase yet.

03Sludge Pulse

Sign in to post a ripple.