Repository navigation
Description
Summary
search_nodes accepts a sorting argument and silently ignores it whenever filters is empty. The call succeeds, returns a plausible node, and gives the model no signal that the result is unsorted.
Surfaced by the #2248 winnability audit while checking whether "sort descending, take one" is a viable route to a comparative question.
Mechanism
run_node_query in packages/agent/src/local_agent/tools.rs branches on filters.is_empty():
- filters empty →
node_ops::query_nodes. Its input struct (QueryNodesInput) has no sorting field at all, sosortingis parsed, accepted, and dropped on the floor. - filters non-empty →
query_ops::execute_query, which is passedsortingand honours it.
So the same logical request behaves differently depending on whether an unrelated filter happens to be present.
Reproduction
Measured against a live SqliteStore + NodeService + GraphToolExecutor. Three feature_writeup nodes with estimated_days of 9, 21 and 4, created in that order.
// Returns the 9-day node (simply the first row), reporting success.
{"query": "*", "node_type": "<type>",
"sorting": [{"field": "estimated_days", "direction": "desc"}], "limit": 1}
// Returns the 21-day node, correctly.
{"query": "*", "node_type": "<type>",
"filters": [{"property": "estimated_days", "operator": "gt", "value": 0}],
"sorting": [{"field": "estimated_days", "direction": "desc"}], "limit": 1}The gt 0 predicate is true of every instance. Its only effect is to route to the branch that honours sorting.
Why it matters
The failure mode is the dangerous kind: no error, no warning, a plausible node returned. A model answering "which is the longest-running one?" via sorting + limit: 1 is handed an arbitrary row and has no way to tell it was not sorted — it will then state that answer confidently.
Asking for a superlative this way is ordinary phrasing rather than an exotic call shape, and sorting/limit are both advertised on the tool's own schema (search_nodes_schema_exposes_filters_and_sorting), so nothing warns the model off it.
Already pinned
filterless_search_silently_ignores_sorting in packages/agent/tests/matrix_scenario_winnability.rs asserts the current wrong behavior deliberately, so the bug is characterized rather than merely known. When this is fixed that test will fail — that is intended. The fix should:
- Update that test to assert the correct (21-day) result.
- Remove the compensating
filtersargument fromscenario_12_sorted_single_result_route_is_also_accepted, which carries a comment pointing here.
Note on scope
Not fixed as part of #2248 — that issue is about matrix coverage, and scenario 12 stays winnable regardless because enumerate-then-compare works and is the route its diagnostic names. Filed separately so the production bug is not buried in a fixture change.
Possible directions, in rough order of preference:
- Pass sorting through to
node_ops::query_nodes(needs a sorting field onQueryNodesInput) so both branches behave alike. - Route to
execute_querywheneversortingis present, regardless offilters. - At minimum, reject the call rather than silently dropping the argument — a loud error beats a wrong answer.
Activity
Add a comparative-reference scenario to the agent matrix (#2250)
malibio commentedon Aug 23, 2026
Baseline (worktree issue-2249-sorting-filterless-search): Frontend: 227 test files passed, 4794 tests passed.