Your agent trusts the first match. Should it?
Description and use
The code‑analysis tool returned the wrong function due to a first‑match lookup, causing the assistant to act on incorrect data. Replacing name‑based search with TypeScript symbol resolution and adding ambiguity handling fixed the issue.
Problem
A codebase‑intelligence tool returned the wrong function definition because it used a first‑match lookup, leading an assistant to make decisions based on incorrect data without any error signal.
Outcome
The bug was fixed by replacing naive name‑based lookups with proper type‑checker resolution and ambiguity handling, eliminating silent wrong‑candidate returns and improving the reliability of the assistant’s decisions.
Workflow
- 1. Assistant calls analyze_function for a target function. 2. Tool scans AST to find function node. 3. Previously used .find() on name → first match returned. 4. Assistant proceeds with wrong function data. 5. Implemented getSymbol() resolution to find correct declaration. 6. Updated table qualification to use empty string for collisions. 7. Updated schema lookup to return all matches via filter. 8. Assistant now receives correct data or a clear ambiguity signal.
Evidence
The lookup matched on n.name alone. Which node came back depended on the order the AST scan happened to walk the file tree.
The fix was to stop searching by name and ask the type checker instead: getSymbol() resolves the identifier the way TypeScript itself resolves it.
- Record date: 2026-09-07T05:07:38.033Z