Skip to content

In JS, direct function call in a file puts it as dead code, which is somewhat misleading #600

Closed

Description

@debangi29
Image

Activity

  1. github-actions commented on Feb 7, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  2. eshaanag commented on Jun 4, 2026

    @eshaanag
    Contributor

    I would like to work on this as part of GSSoC 2026. I traced the module-level call path through the current indexing code: resolve_function_call() returns type: "file" when a call has no enclosing function, build_function_call_groups() puts that into file_to_fn, and GraphWriter.write_function_call_groups() persists a valid (:File)-[:CALLS]->(:Function) edge.

    The misleading dead-code result appears to happen later because CodeFinder.find_dead_code() only checks OPTIONAL MATCH (caller:Function)-[:CALLS]->(func). A function called directly from a JavaScript file therefore still gets a caller count of zero even though the graph contains a file-level call edge. SystemTools.find_dead_code_tool() has the same label restriction.

    My plan is to update the dead-code checks to count valid incoming CALLS edges from module/file callers as well as function callers, preserve the existing dependency/ignore filtering, and add a regression test covering a JavaScript function invoked at top level. Please assign this to me if that scope matches the intended behavior.

  3. github-actions commented on Jun 6, 2026

    @github-actions
    Contributor

    Assigning to the PythonDevs (Core Engine Developers) team.
    CC: @CodeGraphContext/pythondevs

  4. github-actions commented on Jun 6, 2026

    @github-actions
    Contributor

    Assigning to the AdminArchs (Senior Maintainers & Core Architecture) team.
    CC: @CodeGraphContext/adminarchs

  5. UnmeshaSingh commented on Jun 12, 2026

    @UnmeshaSingh

    Hi @Shashankss1205! I'm a GSSoC 2026 contributor and I'd like to work on this issue.

    I found the exact bug in the codebase. In src/codegraphcontext/tools/code_finder.py at line 806:

    OPTIONAL MATCH (caller:Function)-[:CALLS]->(func)

    This only matches Function callers, missing valid File-level callers in JavaScript.

    My fix -> change line 806 to:

    OPTIONAL MATCH (caller)-[:CALLS]->(func)
    WHERE (caller:Function OR caller:File)
    AND (caller.is_dependency = false)

    This ensures JS functions called directly from a file are not incorrectly marked as dead code.

    I'll also add a regression test covering a JS function invoked at top level.

    No active assigned issues. PR ready within 3 days.Could you please assign this to me?
    Thank you!

  6. WHH-JULIET commented on Jun 17, 2026

    @WHH-JULIET

    Hi @Shashankss1205, I noticed another contributor has claimed this, but I am still very interested in working on this issue if it becomes available. I have already analyzed the codebase and identified the necessary fix in src/codegraphcontext/tools/code_finder.py. Please let me know if you would like me to proceed with a PR or if there is another way I can help!

  7. moved this from Backlog tasks to In progress in CGC Progress Boardon Jul 6, 2026
  8. Shashankss1205 commented on Aug 2, 2026

    @Shashankss1205
    Collaborator

    Root cause found — this is a one-word fix, and it's a good first issue for anyone who wants it.

    tools/code_finder.py:823 only counts Function callers:

    OPTIONAL MATCH (caller:Function)-[:CALLS|HEURISTIC_CALLS]->(func)

    But a call at JS module level is not inside a function, so the writer persists it as a File-sourced edge — tools/indexing/persistence/writer.py:848 has an explicit caller_label == "File" branch producing (:File)-[:CALLS]->(:Function).

    Those edges exist in the graph and are simply not counted, so caller_count = 0 and the function is reported dead. Exactly the symptom in your screenshot.

    Why Python doesn't hit this: the Python parser synthesizes a <module> frame (tools/languages/python.py:211, :493), so module-level calls get a Function caller. javascript.py has no equivalent — which is why this is JS-specific.

    Corroboration: the report generator does the same query correctly with an anonymous caller — tools/report_generator.py:229:

    AND NOT ()-[:CALLS|HEURISTIC_CALLS]->(fn)

    So the two dead-code implementations already disagree, and the report generator has it right on this point.

    Fix: drop the :Function label in code_finder.py:823 so any caller counts (the caller.is_dependency filter on the next line needs to tolerate File nodes, which do carry that property). Adding a synthetic module frame to javascript.py would also work but is a much larger change.

    Note this is distinct from #1332 (confidence scoring) — that's a ranking/UX request, whereas this is a plain missed-edge bug. Both should stay open.

  9. WHH-JULIET commented on Aug 3, 2026

    @WHH-JULIET

    /claim

  10. moved this from In progress to Done in CGC Progress Boardon Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions