Skip to content

query_graph: RETURN DISTINCT … ORDER BY … LIMIT still under-returns on v0.8.1 (regression / incomplete fix for #237) #873

Description

@rudi193-cmd

Summary

On v0.8.1, the single-clause shape RETURN DISTINCT … ORDER BY … LIMIT still silently under-returns rows. #237 was closed 2026-05-31 for a DISTINCT execution-order bug; we re-checked after syncing to current main (affa223, 2026-07-05) and the failure mode below is still reproducible.

This matters for audit/dead-code queries that look complete but are truncated.

Environment

  • Binary: codebase-memory-mcp 0.8.1 (linux-amd64, ~/.local/bin/codebase-memory-mcp)
  • Project: home-sean-campbell-github-willow-2.0 — 17,832 nodes / 57,737 edges, status ready
  • Public repo indexed: https://github.com/rudi193-cmd/willow-2.0 (Willow fleet)

Reproduction

Ground truth — five distinct labels exist:

MATCH (n) RETURN count(DISTINCT n.label) AS distinct_labels
--5

Broken (under-returns):

MATCH (n) RETURN DISTINCT n.label AS label ORDER BY label LIMIT 30
--2 rows: Section, Variable  (expected 5)

MATCH (n:Function) RETURN DISTINCT n.file_path AS path ORDER BY path LIMIT 5
--1 row  (expected 5)

Workaround (correct):

MATCH (n) WITH DISTINCT n.label AS label RETURN label ORDER BY label LIMIT 20
--5 rows: File, Folder, Module, Section, Variable

MATCH (n:Function) WITH DISTINCT n.file_path AS path RETURN path ORDER BY path LIMIT 5
--5 rows

Expected

RETURN DISTINCT expr ORDER BY expr LIMIT k should apply DISTINCT (and ORDER BY) before LIMIT, matching the workaround semantics and count(DISTINCT …).

Impact

Agents running bounded “list all distinct X” queries via a single RETURN DISTINCT … ORDER BY … LIMIT clause get silently incomplete results — indistinguishable from a genuinely small universe. We hit this during a fleet structural audit (Willow F-005); our wrapper now steers to WITH DISTINCT first.

Relation to #237

#237 reported DISTINCT applied after ORDER BY + LIMIT. This report is the same user-facing failure class on v0.8.1: either the fix did not cover the RETURN DISTINCT … ORDER BY … LIMIT surface, or there is a regression. Happy to provide a minimal indexed fixture if helpful.

Confirmations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcypherCypher query language parser/executor bugspriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions