Skip to content

[P2] Startup orphan reconciliation aborts on ListWorkers pagination error — ghost workers persist #609

Closed

Description

Severity: P2 (orphaned workers persist until next ateapi restart)
Component: Control Plane — cmd/ateapi/internal/controlapi/syncer.go
Audit ID: CP-8
Maps to suspect: S2


Summary

reconcileOrphanedWorkers runs once at ateapi startup and paginates through all
worker records. If any store.ListWorkers call returns an error (e.g., Valkey is
intermittently slow during startup), the function returns immediately — skipping all
workers on remaining pages. Those workers' orphaned assignments and stale actors persist
until the next ateapi restart. The function logs the error but does not schedule a retry.


Root Cause

File: cmd/ateapi/internal/controlapi/syncer.go lines 234–270

func (s *WorkerPoolSyncer) reconcileOrphanedWorkers(ctx context.Context) error {
    // ...
    for {
        workers, err := store.ListWorkers(ctx, cursor)
        if err != nil {
            s.logger.Error("Failed to list workers during startup reconcile", ...)
            return err  // ABORTS — remaining pages are never processed
        }
        for _, w := range workers {
            if err := s.reconcileDeadWorker(ctx, w); err != nil {
                s.logger.Error(...)  // individual error: continues
            }
        }
        if !more {
            break
        }
    }
    return nil
}

Individual reconcileDeadWorker failures (line 267) continue to the next worker, but
a ListWorkers pagination error aborts the entire function.


Steps to Reproduce

  1. Have many workers in Valkey (enough to span multiple pages, typically > 100).
  2. Delete all worker pods while ateapi is down.
  3. Configure Valkey to return a transient error on the second HSCAN call (use a proxy
    or temporarily set maxmemory-policy = noeviction and fill Valkey to trigger OOM
    errors on writes, or use a packet filter timed to fire on the second scan).
  4. Start ateapi; observe in logs:
    Failed to list workers during startup reconcile: <error>
    
  5. Verify workers from the first page are cleaned up; workers from the second+ pages
    remain with stale actor assignments:
    kubectl ate list actors -a <atespace>
    # Shows actors in STATUS_RUNNING or STATUS_RESUMING that have no running pods

Expected Behavior

A ListWorkers error during startup reconciliation should either:

  1. Retry the entire reconciliation after a backoff delay, or
  2. Log a warning and continue to the next cursor position (best-effort reconciliation).

Suggested Fix

Wrap the reconciliation loop in a retry with exponential backoff:

func (s *WorkerPoolSyncer) reconcileOrphanedWorkers(ctx context.Context) {
    backoff := wait.Backoff{...}
    wait.ExponentialBackoffWithContext(ctx, backoff, func(ctx context.Context) (bool, error) {
        err := s.runOrphanReconcilePass(ctx)
        if err != nil {
            s.logger.Warn("Orphan reconcile pass failed, will retry", "err", err)
            return false, nil
        }
        return true, nil
    })
}

Activity

  1. changed the title [-]Startup orphan reconciliation aborts on ListWorkers pagination error — ghost workers persist[/-] [+][P2] Startup orphan reconciliation aborts on ListWorkers pagination error — ghost workers persist[/+] on Jul 30, 2026
  2. added
    prio/P2
    kind/bug
    on Jul 30, 2026
  3. added a commit that references this issue on Aug 17, 2026
    517e48e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/api-machinerykind/bugprio/P2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions