Skip to content

ClusterCron InitialRun messages are deduplicated on pod restart, breaking cron chain #6

Open

Description

@Smerly

Description

When using ClusterCron.make() with SQL storage, the InitialRun singleton's message gets silently rejected on pod/process restart if a previous "initial" message still exists in the database. This breaks the cron chain and requires manual database cleanup to fix.

Current Behavior

  1. First deployment: InitialRun singleton creates a message with entity_id="initial" and message_id="ClusterCron/{name}/initial/run/"
  2. Cron chain works correctly, scheduling subsequent runs with timestamp-based entity_ids
  3. Pod restarts (or deployment update)
  4. InitialRun singleton attempts to create a new "initial" message
  5. Message is silently rejected due to UNIQUE constraint on message_id in cluster_messages table
  6. Cron chain is broken - no new executions occur

Expected Behavior

Pod restarts should not break the cron chain. Either:

  • InitialRun should detect an existing cron chain and skip re-initialization
  • InitialRun messages should have unique message_ids (e.g., include timestamp)
  • The message should use upsert semantics

Root Cause

The CronPayload class has an empty PrimaryKey:

// From @effect/cluster/src/ClusterCron.ts
class CronPayload extends Schema.Class<CronPayload>("@effect/cluster/ClusterCron/CronPayload")({
  dateTime: Schema.DateTimeUtc
}) {
  [PrimaryKey.symbol]() {
    return ""  // Empty string means all InitialRun messages have same message_id
  }
  // ...
}

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions