Skip to content

search_nodes silently ignores sorting when filters is empty — superlative queries return an arbitrary row #2249

Closed

Description

@malibio

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, so sorting is parsed, accepted, and dropped on the floor.
  • filters non-empty → query_ops::execute_query, which is passed sorting and 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:

  1. Update that test to assert the correct (21-day) result.
  2. Remove the compensating filters argument from scenario_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:

  1. Pass sorting through to node_ops::query_nodes (needs a sorting field on QueryNodesInput) so both branches behave alike.
  2. Route to execute_query whenever sorting is present, regardless of filters.
  3. At minimum, reject the call rather than silently dropping the argument — a loud error beats a wrong answer.

Activity

  1. malibio commented on Aug 23, 2026

    @malibio
    CollaboratorAuthor

    Baseline (worktree issue-2249-sorting-filterless-search): Frontend: 227 test files passed, 4794 tests passed.

  2. self-assigned this
    on Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions