Skip to content

fix: mark stale running scans as failed on restart; stop unconditional polling - #107

Merged
reloadfast merged 1 commit into
mainfrom
fix/stale-scan-on-restart
Mar 2, 2026
Merged

reloadfast merged 1 commit into
mainfrom
fix/stale-scan-on-restart

Conversation

@reloadfast

Copy link
Copy Markdown
Owner

Problem

After a container restart, any scan that was status='running' when the container was killed remains stuck in that state forever. The frontend then polls /api/scans every 3 seconds indefinitely, generating 50+ requests/minute even when nothing is happening.

Fix

Backend — app/main.py

  • Added _mark_interrupted_scans(): called in lifespan startup after init_db()
  • Finds all scans with status='running', sets them to status='failed' with error_message='Scan interrupted by server restart'
  • Wrapped in try/except so a pre-migration local DB never prevents the server from starting

Frontend — hooks/useScanStatus.ts

  • Replaces the unconditional 3s poll with adaptive intervals:
    • 3s while a scan is actively running
    • 30s when idle (no scan in progress)
  • Interval rescheduled whenever running state changes

Testing

  • 274 backend tests pass
  • 146 frontend tests pass

Closes #107

…l polling

Backend (main.py):
- _mark_interrupted_scans() runs in lifespan after init_db()
- Finds all scans with status='running', sets status='failed',
  error_message='Scan interrupted by server restart', current_stage=None
- Wrapped in try/except so a pre-migration DB never crashes startup

Frontend (useScanStatus.ts):
- Replaces unconditional 3s polling with adaptive intervals:
  - 3s fast-poll only while a scan is running
  - 30s slow-poll when idle (was: always 3s, even at rest)
- Interval is rescheduled whenever running state changes

Fixes: stale '102m 0s running scan' after restart + dozens of
/api/scans requests per minute when nothing is happening

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@reloadfast
reloadfast merged commit a7ba5d6 into main Mar 2, 2026
7 checks passed
@reloadfast
reloadfast deleted the fix/stale-scan-on-restart branch March 2, 2026 13:12
@reloadfast

Copy link
Copy Markdown
Owner Author

Implemented in #107.

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.

1 participant