codebase-memory-mcp icon indicating copy to clipboard operation
codebase-memory-mcp copied to clipboard

query_graph: `=~` with an unsupported pattern such as `(?i)` silently returns 0 rows instead of an error

Open noelsaw1 opened this issue 2 weeks ago • 0 comments

Problem

In query_graph, a =~ pattern that POSIX ERE cannot compile makes every row fail the filter. The query returns total: 0 with the generic "no results" hint. The most common trigger is the Neo4j-style case-insensitive flag (?i), which Cypher users and agents write by habit. A caller cannot tell "nothing matches" from "your regex was rejected", so a negative result looks real.

Reproduce

On any indexed project that has functions whose names start with claim:

MATCH (f:Function) WHERE f.name =~ 'claim.*' RETURN f.name LIMIT 5
-> 5 rows

MATCH (f:Function) WHERE f.name =~ '(?i)claim.*' RETURN f.name LIMIT 5
-> rows: 0, total: 0, hint: "Query returned no results..."

The second query should either match the same rows case-insensitively or fail with an error that names the pattern.

Cause

src/cypher/cypher.c (around line 2585, at ec08f76e1):

if (strcmp(op, "=~") == 0) {
    cbm_regex_t re;
    if (cbm_regcomp(&re, expected, CBM_REG_EXTENDED | CBM_REG_NOSUB) != 0) {
        return false;   // compile failure becomes "row does not match"
    }

The same pattern appears near line 2767. POSIX ERE has no inline (?i) group, so regcomp fails and the failure is swallowed per row.

Suggested fix (either or both)

  1. Report a compile failure as a query error (for example invalid regex for =~: '(?i)claim.*') instead of returning false.
  2. Support the common case: strip a leading (?i) and compile with REG_ICASE. Document that =~ is POSIX ERE, not Java/PCRE.

Related: #2050 (regex vs glob semantics undocumented in search_graph).

noelsaw1 avatar Nov 17 '26 16:11 noelsaw1