From 205f396942828833e46d9f2af6bd9889d4e599b3 Mon Sep 17 00:00:00 2001 From: James Smith Date: Fri, 20 Mar 2026 21:52:29 +0000 Subject: [PATCH] Fix TSCM sweep module variable scoping and remove stale progress bar call - Access module-level _sweep_running, _current_sweep_id, and tscm_queue via explicit package import to avoid UnboundLocalError from closure variable shadowing in route handlers - Remove orphaned tscmProgressBar.style.width assignment in index.html Co-Authored-By: Claude Sonnet 4.6 --- routes/tscm/sweep.py | 16 ++++++++++------ templates/index.html | 1 - 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/routes/tscm/sweep.py b/routes/tscm/sweep.py index 480f109..b3d580b 100644 --- a/routes/tscm/sweep.py +++ b/routes/tscm/sweep.py @@ -36,7 +36,8 @@ logger = logging.getLogger('intercept.tscm') @tscm_bp.route('/status') def tscm_status(): """Check if any TSCM operation is currently running.""" - return jsonify({'running': _sweep_running}) + import routes.tscm as _tscm_pkg + return jsonify({'running': _tscm_pkg._sweep_running}) @tscm_bp.route('/sweep/start', methods=['POST']) @@ -95,14 +96,15 @@ def stop_sweep(): @tscm_bp.route('/sweep/status') def sweep_status(): """Get current sweep status.""" + import routes.tscm as _tscm_pkg status = { - 'running': _sweep_running, - 'sweep_id': _current_sweep_id, + 'running': _tscm_pkg._sweep_running, + 'sweep_id': _tscm_pkg._current_sweep_id, } - if _current_sweep_id: - sweep = get_tscm_sweep(_current_sweep_id) + if _tscm_pkg._current_sweep_id: + sweep = get_tscm_sweep(_tscm_pkg._current_sweep_id) if sweep: status['sweep'] = sweep @@ -113,12 +115,14 @@ def sweep_status(): def sweep_stream(): """SSE stream for real-time sweep updates.""" + import routes.tscm as _tscm_pkg + def _on_msg(msg: dict[str, Any]) -> None: process_event('tscm', msg, msg.get('type')) return Response( sse_stream_fanout( - source_queue=tscm_queue, + source_queue=_tscm_pkg.tscm_queue, channel_key='tscm', timeout=1.0, keepalive_interval=30.0, diff --git a/templates/index.html b/templates/index.html index f09b6ac..6485d77 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14740,7 +14740,6 @@ document.getElementById('tscmProgress').style.display = 'none'; document.getElementById('tscmProgressLabel').textContent = 'Sweep Complete'; document.getElementById('tscmProgressPercent').textContent = '100%'; - document.getElementById('tscmProgressBar').style.width = '100%'; // Final update of counts updateTscmThreatCounts();