Skip to content

Commit e400672

Browse files
debug: add console logging to background analysis loop
Detailed [bg] logs at each stage to diagnose why background analysis doesn't run during drill play. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 180f9f7 commit e400672

1 file changed

Lines changed: 36 additions & 4 deletions

File tree

src/hooks/useOpeningDrillController/useOpeningDrillController.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -926,23 +926,43 @@ export const useOpeningDrillController = (
926926
}, [ensureStockfishForNode])
927927

928928
const runBgLoop = useCallback(async () => {
929-
if (bgRunningRef.current) return
929+
if (bgRunningRef.current) {
930+
console.log('[bg] loop already running, skipping')
931+
return
932+
}
930933
bgRunningRef.current = true
934+
console.log('[bg] loop STARTED, queue size:', bgQueueRef.current.length)
931935
try {
932936
while (bgQueueRef.current.length > 0) {
933-
if (bgCancelledRef.current) break
937+
if (bgCancelledRef.current) {
938+
console.log('[bg] cancelled flag set, breaking')
939+
break
940+
}
934941
const node = bgQueueRef.current[0]
942+
const fen = node.fen.split(' ').slice(0, 3).join(' ')
935943

944+
console.log('[bg] maia start:', fen)
936945
await ensureMaiaRef.current(node)
937-
if (bgCancelledRef.current) break
946+
const hasMaia =
947+
node.analysis.maia &&
948+
MAIA_MODELS.every((m) => node.analysis.maia?.[m])
949+
console.log('[bg] maia done:', fen, 'hasMaia:', hasMaia)
950+
if (bgCancelledRef.current) {
951+
console.log('[bg] cancelled after maia, breaking')
952+
break
953+
}
938954

955+
console.log('[bg] stockfish start:', fen)
939956
await ensureStockfishRef.current(node)
957+
const sfDepth = node.analysis.stockfish?.depth ?? 0
958+
console.log('[bg] stockfish done:', fen, 'depth:', sfDepth)
940959
bgQueueRef.current.shift()
941960
}
942961
} catch (error) {
943-
console.error('[bg-analysis] error:', error)
962+
console.error('[bg] error:', error)
944963
} finally {
945964
bgRunningRef.current = false
965+
console.log('[bg] loop ENDED, remaining:', bgQueueRef.current.length)
946966
}
947967
// eslint-disable-next-line react-hooks/exhaustive-deps
948968
}, [])
@@ -990,6 +1010,18 @@ export const useOpeningDrillController = (
9901010
return !hasMaia || !hasStockfish
9911011
})
9921012

1013+
console.log(
1014+
'[bg] enqueue effect: drillNodes:',
1015+
drillNodes.length,
1016+
'newNodes:',
1017+
newNodes.length,
1018+
'queueSize:',
1019+
bgQueueRef.current.length,
1020+
'running:',
1021+
bgRunningRef.current,
1022+
'cancelled:',
1023+
bgCancelledRef.current,
1024+
)
9931025
if (newNodes.length > 0) {
9941026
bgQueueRef.current.push(...newNodes)
9951027
const promise = runBgLoop()

0 commit comments

Comments
 (0)