fix(cypher): add a wall-clock execution deadline to abort runaway queries (#601)#1109
Merged
Conversation
…ries An unbounded whole-graph OPTIONAL MATCH or a GROUP BY that produces roughly one group per node does O(bindings x groups) work in execute_return_agg and can run for minutes on a large graph before emitting a single row. The 100k row ceiling never fires (no rows are produced), so query_graph just hangs with no partial result and no error (#601). Arm a monotonic wall-clock budget (default 30s) at query entry and check it (throttled, every 1024 iterations) in the scan, relationship-expansion and aggregation hot loops. On expiry the query aborts with a clear, actionable error instead of hanging. A thread-local test hook forces the budget so the guard is covered by a deterministic reproduce-first test; a companion test confirms the default budget does not false-positive on a normal query. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
DeusData
enabled auto-merge
July 16, 2026 01:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (#601)
An unbounded whole-graph
OPTIONAL MATCH— or aGROUP BYthat yields roughly one group per node — doesO(bindings × groups)work inexecute_return_aggand can run for minutes on a large graph (reporter: 93k nodes / 488k edges) before producing a single row. The existing 100k row ceiling never fires because no rows are produced, soquery_graphjust hangs — no partial result, no error, the caller waits indefinitely.Fix
Add a monotonic wall-clock deadline alongside the row ceiling (same guard philosophy, complementary trigger):
cbm_now_ms().expand_pattern_rels), and aggregation grouping (execute_return_agg).State is
_Thread_local(per-query, concurrency-safe). No new MCP tool / env var / config knob — a hardcoded budget, consistent with the existing hardcoded row ceiling.Tests (reproduce-first)
cypher_exec_deadline_aborts_runaway_query_issue601— RED-verified: with enforcement neutralized the query completes (rc==0) exactly as today; with the fix it aborts with the time-limit error and 0 rows.cypher_exec_deadline_allows_normal_query_issue601— the default budget does not false-positive on a normal small query.A thread-local test hook (
cbm_cypher_test_set_deadline_ms) forces the budget so the guard is covered deterministically without needing a giant graph.Full
cypher(152) andmcp(165) suites pass; lint-ci clean.Closes #601.