Your agent trusts the first match. Should it?
Описание и применение
Инструмент анализа кода возвращал неверную функцию из-за поиска первого совпадения, что приводило к ошибочным решениям ассистента. Заменив простое сравнение имени на разрешение через API TypeScript и добавив обработку неоднозначностей, ошибка устранена.
Задача
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.
Результат
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.
Рабочий процесс
- 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.
Доказательства
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.
- Дата записи: 2026-09-07T05:07:38.033Z