Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

query_graph: aggregate grouped by type(r)/labels(n) returns a single fabricated row whose key column holds the aggregate value #1358

Closed as not planned

Description

@artaommahe

Version

codebase-memory-mcp 0.9.1-rc.1

Platform

macOS (Apple Silicon)

Install channel

GitHub release archive / install.sh / install.ps1

Binary variant

standard

What happened, and what did you expect?

A query_graph aggregate whose grouping key is a scalar function (type(r), labels(n)) does not group. It returns a single row, and the grouping-key column is overwritten with the aggregate value. No error or warning is emitted, so the caller gets a plausible-looking, entirely wrong answer.

MATCH (a)-[r]->(b) RETURN type(r) AS t, count(*) AS c ORDER BY c DESC — the canonical "what edge types exist and how many of each" query, and the natural first query to write against an unfamiliar graph — returns one row where both columns equal the total edge count.

Both halves work in isolation, which is what makes this silent rather than obvious:

  • RETURN type(r) AS t LIMIT 5 → correct edge type names.
  • RETURN a.name AS n, count(*) AS c ORDER BY c DESC → correct grouping by a plain property.

Expected: one row per distinct type(r) with its count — or, if grouping by function-derived keys isn't supported, a clear error like the one toInteger already produces (unsupported function 'toInteger' in WHERE (supported: coalesce, substring, replace, left, right)).

Related but separate: comparing two properties in WHERE (WHERE a.file_path <> b.file_path) fails with expected value at pos 60. That one at least errors rather than fabricating a row, so it's a lesser concern — mentioning it only because both were hit while trying to characterise the call graph.

Reproduction

Public repro repo: https://github.com/artaommahe/codebase-memory-mcp-rc-repros — see Case E. Reproduces on any indexed project.

git clone https://github.com/artaommahe/codebase-memory-mcp-rc-repros
cd codebase-memory-mcp-rc-repros
codebase-memory-mcp cli index_repository --repo-path "$PWD" --mode full --name cbm-rc-repros

# BUG: aggregate grouped by type(r)
codebase-memory-mcp cli query_graph --project cbm-rc-repros \
  --query "MATCH (a)-[r]->(b) RETURN type(r) AS t, count(*) AS c ORDER BY c DESC LIMIT 10"

Observed:

rows: 1  (cols: t c)
  "54" "54"
total: 1

54 is the graph's total edge count (MATCH (a)-[r]->(b) RETURN count(r) → 54). Expected roughly DEFINES 20 / DEFINES_METHOD 6 / IMPORTS 5 / CALLS 5 / ....

labels() behaves identically:

codebase-memory-mcp cli query_graph --project cbm-rc-repros \
  --query "MATCH (a)-[r]->(b) RETURN labels(a) AS al, count(*) AS c ORDER BY c DESC LIMIT 5"
#   rows: 1  (cols: al c)
#     "54" "54"

Controls, both correct:

codebase-memory-mcp cli query_graph --project cbm-rc-repros \
  --query "MATCH (a)-[r]->(b) RETURN type(r) AS t LIMIT 5"
#   DEFINES_METHOD / DEFINES_METHOD / DEFINES_METHOD / ...

codebase-memory-mcp cli query_graph --project cbm-rc-repros \
  --query "MATCH (a)-[r]->(b) RETURN a.name AS n, count(*) AS c ORDER BY c DESC LIMIT 5"
#   variants.ts "8" / alias-consumer.ts "5" / app "4" / report.service.ts "3" / toast.service.ts "3"

Also reproduces on a large graph: on a private 63,840-node / 120,805-edge project the same query returns rows: 1 with both columns "120805".

Confirmations

  • I searched existing issues and this is not a duplicate.
  • My reproduction uses shareable code (a dummy snippet or a public OSS repository), not proprietary code.

Posted by Claude Code on behalf of @artaommahe

Activity

  1. added
    parsing/quality
    windows
    on Jul 30, 2026
  2. artaommahe commented on Jul 30, 2026

    @artaommahe
    Author

    Closing this as a duplicate of #1292, which was already open (labeled bug/cypher/priority/high, milestoned 0.9.1-rc) and describes the same defect in the same terms — including the "single row, aggregate value written into the non-aggregate column, no error raised" signature and the same working/non-working control pair. #1111 had also already published the type(r) variant with the two-identical-columns output. Apologies for the noise; my duplicate search used the wrong terms (GROUP BY, "aggregate wrong", "count group by") and missed #1292, which is in fact the top hit for the obvious query, grouping.

    Three things from my investigation that I don't think are on #1292 yet — reposting there rather than here:

    1. The trigger is broader than "the grouping key is a function". Every function-call column in an aggregating RETURN is excluded from the group key and overwritten with the aggregate value, even when grouping itself succeeds on a different column:

      MATCH (a)-[r]->(b) RETURN type(r) AS t, a.name AS n, count(*) AS c LIMIT 10
        "2" AliasConsumer "2"      <- correctly grouped by a.name; t is clobbered with the count
        "5" alias-consumer.ts "5"
      
    2. Two smaller repros showing the function value evaluates to empty inside an aggregate: RETURN count(DISTINCT type(r)) → 1 (should be the number of distinct edge types), and RETURN collect(type(r)) → ["","", …].

    3. A working workaround for users hitting this: materialise the value through WITH first — verified correct on both a 58-edge and a 120,805-edge graph.

      MATCH (a)-[r]->(b) WITH type(r) AS t RETURN t, count(*) AS c ORDER BY c DESC
        DEFINES 31 / CONTAINS_FILE 7 / CALLS 7 / DEFINES_METHOD 6 / USAGE 3 / …
      

    Also correcting one thing I got wrong here: I speculated this might relate to #1196. It doesn't — that's unlabeled-source-node patterns returning empty, a different symptom and mechanism.

    Separately, and with no existing issue that I could find: property-to-property comparison in WHERE fails outright — WHERE a.file_path <> b.file_path → expected value at pos 60, and likewise WHERE a.name <> b.name. That one errors rather than fabricating a row, so it's a much lesser concern, but I'm happy to file it separately if useful.


    Posted by Claude Code on behalf of @artaommahe

  3. artaommahe commented on Jul 30, 2026

    @artaommahe
    Author

    Closing as duplicate of #1292 (see comment above).


    Posted by Claude Code on behalf of @artaommahe

  4. added
    editor/integration
    on Jul 30, 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

    Labels

    editor/integrationparsing/qualitywindows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions