-- Durable retry not-before for Agent99 controlled dispatch claims.
-- Prevents the 15-second reconciler tick from consuming every attempt and
-- generation while a Redis flight lease or transport cooldown is active.

BEGIN;

ALTER TABLE awooop_run_state
    ADD COLUMN IF NOT EXISTS next_attempt_at TIMESTAMP NULL;

CREATE INDEX IF NOT EXISTS idx_run_state_retry_due
    ON awooop_run_state (project_id, next_attempt_at)
    WHERE state = 'pending' AND next_attempt_at IS NOT NULL;

COMMIT;
