Skip to content

Fix get_graph_context reporting an empty graph as "not found"#43

Merged
mvalancy merged 3 commits into
developfrom
fix/empty-graph-context-not-found
Jun 13, 2026
Merged

Fix get_graph_context reporting an empty graph as "not found"#43
mvalancy merged 3 commits into
developfrom
fix/empty-graph-context-not-found

Conversation

@mvalancy

Copy link
Copy Markdown
Member

Problem

get_graph_context (MCP GraphService.getGraphContext) threw "Graph with ID X not found" for any graph that had zero work items — even though the Graph node clearly existed. Found during the skeptical live-app audit: created an empty graph via MCP, then getGraphContext threw while a direct MATCH (g:Graph {id}) confirmed the node was present.

Root cause

The type/status tally used a correlated subquery:

CALL { WITH items UNWIND items as i RETURN i.type as type, count(i) as cnt }

UNWIND of an empty list produces zero rows, and a CALL subquery that returns zero rows eliminates the outer row (correlated-join semantics). So an empty graph collapsed to 0 records → the if (result.records.length === 0) guard fired → false "not found".

The blockers/recent subqueries were already safe because they end in collect(...), an aggregation that always yields exactly one row.

Fix

Return the raw types/statuses lists from Cypher ([x IN items | x.type]) and tally them in JS. No row-dropping UNWIND, so the graph row always survives.

Tests

Two new real-Neo4j contract cases (run in the MCP Real-Neo4j Contract CI job, gated by RUN_DB_CONTRACT):

  • empty graph → getGraphContext returns zero counts (byType/byStatus {}, no blockers/recent), not an error;
  • populated graph → byType/byStatus tally correctly.

All 5 contract tests pass against live Neo4j locally.

🤖 Generated with Claude Code

The type/status tally used `CALL { WITH items UNWIND items as i RETURN
i.type as type, count(i) as cnt }`. UNWIND of an empty list yields ZERO
rows, and a correlated CALL subquery returning zero rows eliminates the
outer row — so for a brand-new empty graph the whole query returned no
records and getGraphContext threw "Graph with ID X not found", even
though the Graph node plainly existed.

Return the raw type/status lists from Cypher and tally them in JS
instead. The blockers/recent subqueries were already safe because they
end in `collect(...)` (aggregation always yields one row).

Adds two real-Neo4j contract cases: an empty graph returns zero counts
(not an error), and a populated graph tallies byType/byStatus correctly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🧪 Comprehensive Test Suite

  • Unit suites (Node 18.x & 20.x) — core, web, server, mcp-server: ❌ failure
  • Installer & deploy config: ✅ passed

Full-stack smoke gate runs in the CI workflow.

…n error

UI counterpart to the get_graph_context empty-graph fix. Verifies that
creating a graph with zero work items and opening it renders the
"Create Your First Work Item" invitation with no error chrome and no
uncaught JS errors. Passes against the live dev stack.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🧪 Comprehensive Test Suite

  • Unit suites (Node 18.x & 20.x) — core, web, server, mcp-server: ❌ failure
  • Installer & deploy config: ✅ passed

Full-stack smoke gate runs in the CI workflow.

getGraphContext now returns raw types/statuses lists (tallied in JS)
instead of pre-aggregated typeCounts/statusCounts, so the mock driver's
canned record must match. Match on the new query (size(items) as
nodeCount / as statuses) and return raw label arrays.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🧪 Comprehensive Test Suite

  • Unit suites (Node 18.x & 20.x) — core, web, server, mcp-server: ✅ passed
  • Installer & deploy config: ✅ passed

Full-stack smoke gate runs in the CI workflow.

@mvalancy mvalancy merged commit 423c932 into develop Jun 13, 2026
16 checks passed
@mvalancy mvalancy deleted the fix/empty-graph-context-not-found branch June 13, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant