First-generation AI code review tools operate on a deceptively simple premise: take a git diff, wrap it in a prompt ('You are a senior security engineer, find all bugs in this diff'), and stream the model's output to the pull request.
Within 48 hours of enabling these tools, developers start ignoring their comments. The reviewer claims a function parameter is undefined when it is imported three lines above the diff fold. It claims an SQL query is vulnerable when the query builder sanitizes parameters by default.
The Root Cause: The Context Window Illusion
A git diff is not code; it is an edit script. It contains additions and deletions, but almost none of the semantic environment needed to interpret those changes. Types, interface implementations, base classes, and global middleware live in other files.
When an LLM is presented with incomplete context, its probabilistic training forces it to predict what might be there. If a variable is used in the diff without an obvious definition in the 10 lines of surrounding context, the model will confidently hallucinate that the variable is undeclared.
- Git diffs lack symbol tables and import definitions.
- Models cannot verify whether a function exists or how its signature is typed.
- Increasing token context windows does not solve the problem — it introduces 'needle-in-a-haystack' retrieval noise.
The Fix: Ground-Truth AST Syntax Trees Before Inference
The fix is separating determinism from reasoning. In ScanDrix, every file in the repository is parsed into a concrete Abstract Syntax Tree using Tree-sitter. We build a deterministic call graph and symbol table before calling any LLM.
Instead of asking the model 'Are there any bugs in this diff?', we ask verifiable, grounded questions: 'Given that function sanitizeInput() was called at line 34, does untrusted param ID reach query sink on line 58?'.
// Deterministic AST Validation Loop
1. Parse codebase into syntax trees (AST)
2. Resolve all identifiers to their actual symbol definitions
3. Build cross-file taint path from Source -> Sanitizer -> Sink
4. ONLY if a sink is reachable with tainted data, invoke LLM to draft the patch explanation
5. Verify the drafted patch against compiler AST rules before postingThe Result: Trust Re-Established
By grounding AI reasoning in mathematical AST reachability, false positives drop dramatically. Developers stop muting review bots because every comment represents a verified dataflow path, accompanied by an actionable patch.