Skip to content

fix(query): respect response_limit and report result_count for event/config patterns#676

Open
Alaa-Taieb wants to merge 1 commit into
tirth8205:mainfrom
Alaa-Taieb:fix/query-result-count
Open

fix(query): respect response_limit and report result_count for event/config patterns#676
Alaa-Taieb wants to merge 1 commit into
tirth8205:mainfrom
Alaa-Taieb:fix/query-result-count

Conversation

@Alaa-Taieb

@Alaa-Taieb Alaa-Taieb commented Jul 20, 2026

Copy link
Copy Markdown

Summary

In code_review_graph/tools/query.py, seven query-pattern branches (triggers_of, triggered_by, publishers_of, listeners_of, handlers_of, endpoints_for, consumers_of) bypassed the canonical add_result() helper. As a result they ignored the max_results / response_limit cap and never incremented total_results, so the returned result_count was always 0 while the response still contained N results — a contradiction that breaks pagination and any agent/UI relying on result_count / results_omitted.

This is Issue #674, Finding #4.

Fix

Route the seven branches through add_result() exactly like the sibling branches already do. Edges are still emitted unconditionally when the resolved node is None (preserving the prior contract — no edges disappear). consumers_of keeps its dedup and now only emits an edge for a newly-added result or a missing node, eliminating duplicate edges for already-seen consumers.

Patterns fixed

Pattern Edge kind Direction
triggers_of TRIGGERS source → target
triggered_by TRIGGERS target → source
publishers_of PUBLISHES target → source
listeners_of HANDLES target → source
handlers_of HANDLES target → source
endpoints_for HANDLES (Endpoint) source → target
consumers_of config consumer config → source

Verification

  • grep -n "results.append" code_review_graph/tools/query.py returns zero matches in the seven branches (only inside add_result and one unrelated branch at line 783).
  • New regression test test_event_query_patterns_respect_max_results_and_report_count in tests/test_spring_events.py builds 5 publishers + 5 listeners against one event and asserts:
    • publishers_of(... max_results=3) returns ≤3 results, result_count == 5, results_omitted == 2.
    • listeners_of / handlers_of report result_count == 5.
  • The new test fails on the old code (returns all 5, result_count == 0) and passes after the fix (negative proof done).
  • ruff check clean; full tests/ -k query suite passes (22 passed).
  • One pre-existing, unrelated test (test_event_resolver_does_not_cross_link_same_named_packages) fails on the Windows baseline regardless of this change; left untouched (it's a Windows path-separator issue in the test itself, not in the code under fix).

Manual test checklist (post-merge)

  • query_graph("publishers_of", "event::X", max_results=3) returns ≤3 results but result_count == total publishers.
  • query_graph("listeners_of" / handlers_of / triggers_of / triggered_by / endpoints_for / consumers_of) similarly report a correct (non-zero) result_count.
  • No edges disappear from the edges array vs. pre-fix behavior (edges still emitted even when a node can't be resolved).

Closes #674.

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.

Whole-project code review: 6 High / 17 Medium / 11 Low findings

1 participant