Skip to content

fix: handle audit polling timeout state - #632

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
BharadwajKanneveti:fix/audit-polling-timeout-state
Aug 3, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
BharadwajKanneveti:fix/audit-polling-timeout-state

Conversation

@BharadwajKanneveti

Copy link
Copy Markdown
Contributor

Summary

Fix audit detail page polling timeout handling. Previously, when an audit remained in running state after the 120-second polling deadline, the page would silently stop polling and keep showing an infinite spinner with no available actions.

This change:

  • Tracks a timedOut state when polling reaches the deadline while the audit is still running.
  • Shows a dedicated "taking longer than expected" state instead of an endless spinner.
  • Adds a "Check again" action to restart polling.
  • Restores header actions (re-run/delete) when an audit times out.
  • Adds translations for the new timeout state messages.

Related issue

Closes #612

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timeout handling itself is right — the dedicated state, Check again with a fresh deadline, and unhiding the header actions all match #612. One correctness issue in the refactor before merge:

The original effect used a per-invocation let cancelled; this PR switches to a shared cancelledRef that loadAndPoll resets to false on every call. That opens a race when id changes without an unmount (navigating /audit/A → /audit/B re-renders with new params):

  1. A's loop is asleep in its 3s timeout; cleanup sets cancelledRef = true.
  2. The new effect immediately calls loadAndPoll, which resets cancelledRef = false.
  3. A's loop wakes, sees false, and keeps polling the old id — setAudit then writes A's results onto B's page.

Suggested fix — a generation counter instead of a shared boolean:

const genRef = useRef(0);

const loadAndPoll = useCallback(async () => {
  const gen = ++genRef.current;          // this call's token
  const cancelled = () => genRef.current !== gen;
  // ... use cancelled() everywhere cancelledRef.current is checked
}, [id, tFailed]);

// cleanup: genRef.current++; clearTimeout(...)

Each call owns its token, so starting a new poll (Check again or an id change) automatically invalidates every older loop with no shared flag to reset. Happy to re-review once that's in.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generation-counter fix is exactly right — cleanup only ever advances the counter, so stale loops can never resurrect. Thanks for the quick turnaround!

@gkhngyk
gkhngyk merged commit 50624af into ansvisor:main Aug 3, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site Audit: detail page hangs on the spinner forever when polling times out — no retry, actions hidden

2 participants