From fd039d743ed02e95ff49c6d13646eed5c229ba1e Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Fri, 29 May 2026 17:46:45 +0000 Subject: [PATCH] fix: move _aiFallbackExhausted reset out of stopScanner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stopScanner() is called internally by initScanner() on every restart, so resetting the flag there caused the AI timer to re-arm on every internal cycle — creating an infinite 5-second loop. Flag now resets only in showPage('scan'), which fires exclusively when the user opens the scanner page (fresh session). Internal stop/restart cycles leave the flag untouched. --- assets/js/app.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 8f8c3c2..c187f04 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -3886,7 +3886,7 @@ function showPage(pageId, param = null) { } loadInventory(); break; - case 'scan': initScanner(); clearQuickNameResults(); updateSpesaBanner(); updateScanRecents(); switchScanTab('barcode'); + case 'scan': _aiFallbackExhausted = false; initScanner(); clearQuickNameResults(); updateSpesaBanner(); updateScanRecents(); switchScanTab('barcode'); // Pre-warm the embedding model the first time user visits scan page if (typeof window._getCategoryPipeline === 'function' && !window._categoryPipelineReady) { window._getCategoryPipeline(); // fire-and-forget @@ -6951,7 +6951,9 @@ function stopScanner() { _scanZoomLevel = 2; // always 2x on next start _torchActive = false; clearTimeout(_aiFallbackTimer); _aiFallbackTimer = null; - _aiFallbackExhausted = false; // reset so a new scanner session can try again + // NOTE: _aiFallbackExhausted is intentionally NOT reset here. + // It is only reset in showPage('scan') so that internal stop/restart + // cycles (e.g. initScanner calling stopScanner) don't re-arm the AI timer. if (scannerStream) { scannerStream.getTracks().forEach(t => t.stop()); scannerStream = null;