mastra-ai/mastra · error

Platform Linear event polling interval must be a positive nu

Error message

Platform Linear event polling interval must be a positive number.

What it means

The Platform Linear event worker constructor validates that the event polling interval (`config.intervalMs`) is a finite number greater than 0 before starting. This check runs after applying the default (`DEFAULT_POLL_INTERVAL_MS`), so it only fires when an explicit interval was supplied but is invalid (0, negative, NaN, or Infinity). It is thrown synchronously at construction time so a misconfigured worker fails fast instead of silently never polling.

Source

Thrown at mastracode/factory/src/integrations/platform/linear/event-worker.ts:157

  #hasLease = false;
  #startedAt = 0;
  #lastReconcileAt = 0;
  #settings: PlatformLinearEventWorkerSettings = { version: 1, workspaces: {} };

  constructor(config: PlatformLinearEventWorkerConfig) {
    super();
    this.#client = config.client;
    this.#linear = config.linear;
    this.#storage = config.storage;
    this.#projects = config.projects;
    this.#workItems = config.workItems;
    this.#ingestFactoryIssue = config.ingestFactoryIssue;
    this.#reconcileFactoryState = config.reconcileFactoryState;
    this.#pollEventsEnabled = config.pollEventsEnabled ?? true;
    this.#intervalMs = config.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
    this.#reconcileIntervalMs = config.reconcileIntervalMs ?? DEFAULT_RECONCILE_INTERVAL_MS;
    if (!Number.isFinite(this.#intervalMs) || this.#intervalMs <= 0) {
      throw new Error('Platform Linear event polling interval must be a positive number.');
    }
    if (!Number.isFinite(this.#reconcileIntervalMs) || this.#reconcileIntervalMs <= 0) {
      throw new Error('Platform Linear reconcile interval must be a positive number.');
    }
    this.#leaseTtlMs = Math.max(MIN_LEASE_TTL_MS, this.#intervalMs * 3);
    this.#now = config.now ?? Date.now;
  }

  async init(deps: WorkerDeps): Promise<void> {
    await super.init(deps);
    this.#leaseProvider = getLeaseProvider(deps.pubsub);
  }

  async start(): Promise<void> {
    if (this.#running) return;
    if (!this.deps) throw new Error('PlatformLinearEventWorker: call init() before start()');

    this.#startedAt = this.#now() - 1;

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Set `intervalMs` to a finite positive integer in milliseconds (e.g. 30000).
  2. If you want polling disabled, use `pollEventsEnabled: false` instead of intervalMs: 0.
  3. Validate the env/config value before passing it: `const n = Number(raw); if (Number.isSafeInteger(n) && n > 0) config.intervalMs = n;`
  4. Omit `intervalMs` entirely to use DEFAULT_POLL_INTERVAL_MS.

Example fix

// before
new LinearEventWorker({ intervalMs: Number(process.env.LINEAR_POLL_MS), ... });
// after
const pollMs = Number(process.env.LINEAR_POLL_MS);
new LinearEventWorker({ intervalMs: Number.isSafeInteger(pollMs) && pollMs > 0 ? pollMs : undefined, ... });
Defensive patterns

Strategy: validation

Validate before calling

function isValidInterval(v: unknown): v is number {
  return typeof v === 'number' && Number.isFinite(v) && v > 0;
}
if (config.intervalMs !== undefined && !isValidInterval(config.intervalMs)) {
  throw new Error('intervalMs must be a finite positive number');
}

Type guard

function isPositiveFiniteNumber(v: unknown): v is number {
  return typeof v === 'number' && Number.isFinite(v) && v > 0;
}

Prevention

When it happens

Trigger: Constructing the Linear event worker with `intervalMs` explicitly set to 0, a negative number, NaN, or Infinity (e.g. `intervalMs: Number.parseInt(process.env.LINEAR_POLL_MS ?? '')` where the env value parses to NaN).

Common situations: Env vars like `LINEAR_POLL_MS=0` or `LINEAR_POLL_MS=abc` parsed with Number() and passed through unvalidated; a config generator emitting 0 for 'disabled'; floating-point computed values like `seconds * 1000` where seconds was NaN.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/85c9b97d4c886d18. Report an issue: GitHub.