Awesome Reviewers

Reviewer · Temporal

Deadline-safe poll budgets

When a workflow step polls for completion (e.g. waiting on an external action), design the retry/poll loop around explicit timing budgets, not just happy-path counts:

Instruction

When a workflow step polls for completion (e.g. waiting on an external action), design the retry/poll loop around explicit timing budgets, not just happy-path counts:

  • Size maxAttempts/ceilings with real margin above the worst-case number of polls the step’s wait_timeout could require once jitter and backoff are applied (e.g. a 1h wait at the shortest possible interval can need ~250+ attempts, so leave headroom rather than a tight bound). Hitting the ceiling fails the step after the underlying action/side effect already exists, and an on-failure.retry on that failure can trigger a duplicate action — so a false ceiling failure is not benign.
  • Bound every poll call itself with a timeout so a single slow read can’t silently exceed the step’s deadline before it is even checked; if the step framework doesn’t expose a per-call timeout, rely on the client’s default cap and track exposing one explicitly.
  • Re-check the deadline immediately after each call returns. If the deadline has passed, fail the step (or fall back) instead of scheduling another poll; if it hasn’t, schedule the next poll per policy rather than immediately.
  • Keep poll ceilings/constants consistent across all step kinds and open tickets/trackers that share them, so a later change doesn’t silently reintroduce a tight ceiling for one kind.
  • Validate scheduled task params with a paramsSchema (shared between the HTTP route and the task definition where applicable) so malformed input fails at scheduling time, and define a stateSchemaByVersion for any persisted task state, even if it’s short-lived, so an unexpected shape is rejected rather than silently misread.

Example shape for a poll ceiling comment that documents the margin reasoning:

/**
 * maxAttempts must cover the kind's max wait_timeout at the shortest possible poll
 * interval (jitter can make the gap as short as half the computed backoff).
 * Going over the ceiling fails the step after the action already exists, so keep
 * a wide margin instead of a tight bound.
 */
export const POLL_CEILINGS = {
  confirm: { maxAttempts: 300, maxWaitMs: 30_000 },
};