Skip to content

Calls inside anonymous callbacks are dropped from the call graph (JS/TS) — find_callers misses them #1570

Description

@thackerronak

Summary

A function call whose nearest enclosing function is an anonymous callback (the arrow/function passed to setTimeout, .then, app.use, an event handler, …) is not recorded as a CALLS edge, so find_callers misses it. The call is attributed to a nameless caller and dropped, instead of to the nearest named enclosing function.

For agent/LLM consumers this is an incompleteness problem: a blast-radius query silently omits real call sites that happen to live inside callbacks.

Environment

  • codegraphcontext==0.5.5 (PyPI); also main
  • Python 3.13, macOS arm64
  • Backend: embedded FalkorDB (-db falkordb)
  • Languages: TypeScript (.ts, .tsx) and JavaScript

Reproduction

// probe.ts
export const requestTimeout = (req, res, next) => {
  setTimeout(() => {
    customErrorHandler(req, res);   // ← call inside an anonymous callback
  }, 1000);
};
function customErrorHandler(...args: unknown[]) {}
cgc -db falkordb index /tmp/probe --force
cgc -db falkordb analyze callers customErrorHandler
# → requestTimeout is absent (0 callers reported)

Observed on a real file: a symbol with 55 grep-confirmed call sites returns 54 from find_callers; the single miss is a call inside a setTimeout(() => { … }) arrow nested in a named function.

Root cause

_get_parent_context (tools/languages/typescript.py, javascript.py; .tsx inherits from the TS parser) walks up to the first function-like node, and arrow_function / function_expression are in the match set. When that node is an anonymous callback it cannot resolve a name and returns a nameless caller:

return self._get_node_text(name_node) if name_node else None, curr.type, curr.start_point[0] + 1

A caller with no name produces no node, so the CALLS edge is dropped. The walk stops at the anonymous scope instead of continuing to the enclosing named function (e.g. requestTimeout).

(Python is unaffected — its _get_parent_context matches only named function_definition / class_definition; lambdas can't hold statement calls.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions