Task · CFO-0091

Do not count a poll cut short by shutdown as a collector failure

Description

Every redeploy recorded aigateway.logs scrape errors (class other): the in-flight poll is cancelled at SIGTERM and reported through OnPoll as a failure, and because a long poll usually overruns its ticker, runEntry’s select can pick the queued tick over ctx.Done and start a second poll that fails at once with context canceled. Seen in Loki at 2026-10-21 04:25:02 UTC as two collector run failed lines 35 microseconds apart. This inflated error counters and the poll alerts on every deploy and misled CFO-0085 diagnosis.

Acceptance Criteria

Definition of Done

Implementation Notes

Red first: TestShutdownInterruptsPollWithoutFailureOrRetry reported 2 polls for one shutdown with a tick queued (the live 04:25:02 pattern). runEntry checks ctx before each poll and returns, logging INFO, when RunOnce fails with context.Canceled after shutdown began; CodeRabbit’s one minor finding (suppress only cancellation errors, not any error racing shutdown) applied. Collector and cmd race tests pass; remote just check exit 0 before the errors.Is tightening, which re-passed the collector race suite. DoD2/DoD3 not applicable.

Final Summary

Shutdown no longer records collector failures: the scheduler stops before starting a poll once its context is cancelled, and a poll that returns context.Canceled after shutdown began is logged at INFO instead of reported. Removes the two spurious aigateway.logs scrape errors every redeploy produced. The process being replaced by this deploy still runs the old code, so its shutdown records them one last time.

View the source file on GitHub