The Ghost in the Graph: Catching Unbounded Recursion & Taint Drift with Gemini 1.5 Pro FluxTrace, an open-source real-time financial security engine, fixed unbounded recursion and taint drift in its graph-based money laundering detection system using Gemini 1.5 Pro. The team diagnosed a cycle-detection bug that caused exponential memory growth and taint scores exceeding 1.0, then refactored the recursive traversal into an iterative BFS with cycle bounds and decay limits. Sentry Performance Monitoring confirmed memory usage stabilized at ~140 MB, down from spikes over 4 GB. This is a submission for DEV's Summer Bug Smash: Smash Stories powered by Sentry. FluxTrace is an open-source real-time financial security engine designed to trace illicit funds across graph databases Neo4j using Dynamic Taint Scores. It ingests thousands of dynamic financial events per second, mapping transaction topologies and assigning risk scores to connected wallets to expose complex money laundering schemes before funds can be laundered through mixers. During high-throughput synthetic testing, our telemetry pipeline began silently degrading under dense cyclic transaction topologies e.g., wallet circular routing or "smurfing" rings . The issues manifested as: Transaction Event Ingest --- Recursive Taint Engine │ ┌─────────────────────┴─────────────────────┐ ▼ ▼ Cyclic Graph Detected Unbounded Stack Growth │ │ ▼ ▼ Infinite Propagation OOM Worker Crash We diagnosed the issue by loading a 2M-node cyclic graph dataset into Google AI Studio alongside our recursive graph traversal engine using Gemini 1.5 Pro . To isolate the exact stack behavior, we prompted Gemini 1.5 Pro in Google AI Studio with our recursive execution path: System Prompt / User Query: "Analyze the Python graph traversal function below. In cyclic topologies A - B - C - A , worker memory escalates exponentially, and floating-point taint scores exceed 1.0. Identify why cycle detection fails to halt memory growth during high-concurrency event loops, and refactor the method using memoization and a strictly bounded iterative stack." Google AI Studio identified that our visited-node cache was scoped locally to individual recursive calls rather than globally across the propagation path. We refactored the dynamic calculation from recursive execution to an iterative Breadth-First Traversal BFS pattern with explicit cycle bounds and decay limits: python python BEFORE Buggy Recursive Implementation def propagate taint score node id, current score, visited=None : if visited is None: visited = set visited.add node id Bug: Scoped locally in recursive chain, fails in cyclic networks neighbors = get connected wallets node id for neighbor in neighbors: new score = current score DECAY FACTOR Unbounded recursion on cyclic paths: propagate taint score neighbor.id, new score, visited AFTER Optimized Bounded Iterative Stack from collections import deque def propagate taint score iterative start node id: str, initial score: float, max depth: int = 10 - None: queue = deque start node id, initial score, 0 visited state = {} Map node id - max seen score while queue: curr node, curr score, depth = queue.popleft if depth = max depth or curr score < 0.01: continue Prune redundant recalculations if node was processed with a higher score if curr node in visited state and visited state curr node = curr score: continue visited state curr node = curr score Enforce clamp bound: max taint value is 1.0 clamped score = min curr score, 1.0 update wallet risk curr node, clamped score for neighbor in get connected wallets curr node : next score = clamped score DECAY FACTOR queue.append neighbor.id, next score, depth + 1 Best Use of Sentry We leveraged Sentry Performance Monitoring and Distributed Tracing to locate and confirm the fix: Custom Span Profiling: Created Sentry spans sentry sdk.start span op="taint.propagation" to record execution duration and stack depth across graph nodes. Memory & Out-of-Memory Tracking: Monitored worker RAM trends via Sentry's profile visualizer to confirm memory usage stabilized at a flat ~140 MB footprint down from exponential spikes 4 GB. Python import sentry sdk def process transaction event event : with sentry sdk.start span op="graph.taint analysis", description="Process cyclic taint propagation" : propagate taint score iterative event.sender, event.initial risk