Skip to content

feat(web): live scan progress via the existing /api/scan/events SSE endpoint (#152) - #234

Merged
falbany merged 10 commits into
mainfrom
feat/152-scan-progress
Nov 24, 2026
Merged

falbany merged 10 commits into
mainfrom
feat/152-scan-progress

Conversation

@falbany

@falbany falbany commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Closes #152.

What does this PR do?

While a scan runs, ScanStatusStrip now shows a live file count — Scanning <dir> — 45 461 files — 42s — fed by the previously dead /api/scan/events SSE endpoint (#143's dead-surface finding), updating at the 1s tick. The strip also appears during the initial-load scan (startup), which previously had no progress feedback and is typically the longest scan of a session on a network share. Count segment renders only while the server reports in_progress — cache-only spinner runs (sort reloads) keep the elapsed-only display, never stale numbers.

The issue as filed assumed a web-only change; that premise was false (cached_results only lands after the whole scan), so the scope is core + server + web per the approved design:

  • Spec: docs/superpowers/specs/2026-11-23-scan-progress-design.md
  • Plan: docs/superpowers/plans/2026-11-23-scan-progress.md

Change summary

  • core — scan_and_process_dynamic gains optional on_progress: Callable[[int], None] | None, invoked at the _scan_and_filter consumption point with the running count of filter-passing candidates (monotonic, converges to the result count; existing callers unaffected).
  • server — ServerState.scan_progress_count (reset at the top of execute_scan, before the exists() early return; writes generation-guarded); SSE status payload gains progress.
  • web — useScanProgress(active) hook (one EventSource open while scanning || initialScanActive, silent elapsed-only fallback on stream errors, inert without EventSource); count segment in ScanStatusStrip gated on SSE in_progress; ActionBar strip gate extended to the startup scan.

Notable bug found in live verification

The SSE endpoint was unusable by any browser client all along: the installed sse-starlette str()-ifies dict payloads, so the wire carried Python repr ({'in_progress': True, ...}) that JSON.parse rejects. Fixed by pre-serializing with json.dumps(), pinned by a wire-format regression test that drives a real uvicorn server (ASGITransport buffers infinite SSE bodies, so in-process reads hang — the reason the original plan's wire test was ruled out). Live-verified in a real browser over a 240k-file scan: 0 files → 45 461 → 134 910 → 240 000 ticking at the SSE cadence, converging to the server's final count.

Type of change

  • ✨ New feature (non-breaking change that adds functionality)
  • 🐛 Bug fix (SSE wire format, found during verification)

Pre-commit checklist

  • ruff format applied
  • ruff check --fix passes
  • Pylint score > 8.0 (9.89)
  • Tests pass (pytest)
  • Coverage > 85% (88.98%)
  • Type hints added for public functions
  • Docstrings present for public APIs
  • No TODOs left
  • AGENTS.md / tests/AGENTS.md unchanged (no module tree / public-import changes)

Testing

  • TDD throughout: each task's tests watched failing first (6 tasks, one commit each).
  • Backend: uv run pytest --cov=src/profiles --cov-fail-under=85 → 1650 passed, 1 skipped, coverage 88.98%; pylint 9.89/10; ruff clean.
  • Web: npm test → 40 files / 499 passed; tsc -b clean; dist rebuilt and committed.
  • Live real-browser verification (--server-only + synthetic 240k-file tree): strip visible instantly on click and during startup; count ticks 0 → 45 461 → 134 910 → 240 000 at the 1s SSE cadence and converges to the server total; strip unmounts on completion; count segment hidden pre-fix wire (regression confirmed) and present post-fix.

Screenshots

Live progress mid-scan (bottom-left, 240k-file scan at the 6s mark):

⟳ Scanning …/progress-demo — 240 000 files — 6s

(Screenshot verified in-session via browser automation; the strip replaces the elapsed-only spinner and the count ticks once per second.)

Multi-window note (accepted limitation)

The progress counter is server-global — two windows scanning simultaneously would see each other's numbers. This inherits the existing single-active-scan state model (shared scan_generation/cached_results/active_directory); documented in the spec. If multi-client use ever becomes real, the fix is a broader scan-session design, not a progress-only id.

The installed sse-starlette str()-ifies dict payload data — the wire
carried Python repr (single quotes, capitalized booleans) that no
browser EventSource client can JSON.parse. This wire-format defect is
why the endpoint was dead surface in #143. Pre-serialize with
json.dumps(); regression test drives a real uvicorn server (ASGITransport
buffers infinite SSE bodies, so in-process reads hang).
pyright: files_to_process holds the worker's (Path, str, str) input
tuples from _scan_and_filter, not the generic result T — the original
untyped list() inferred this; the counting loop's explicit list[T]
annotation broke it. Caught by CI's pyright gate (the local Task 6
gates ran ruff/pylint/pytest but not pyright).
@falbany
falbany merged commit 74be00c into main Nov 24, 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.

Web UI: live scan progress via the existing /api/scan/events SSE endpoint

1 participant