Skip to content

NodeFilter order_by is never applied anywhere — LIMIT executes over an unordered set, so query_nodes returns an arbitrary (oldest-first) subset while the code documents CreatedDesc, and collection pagination is unstable across calls #2211

Closed

Description

@mstomar125

Summary

ops::query_nodes sets OrderBy::CreatedDesc (ops/node_ops.rs:491) and its pagination comment relies on the set being 'CreatedDesc-ordered', but NodeService::query_nodes only logs 'order_by handled via in-memory sorting after database query' (query.rs:40-44) and no in-memory sort exists anywhere on the path; SqliteStore::query_nodes then applies LIMIT/OFFSET with no ORDER BY (nodes.rs:1034-1041), and the collection-scoped branch iterates a per-call freshly-seeded HashSet of member ids into 900-id IN-chunks (ops/node_ops.rs:401-441, nodes.rs:996-1026), so even the row order the chunks produce differs between two identical calls.

Failure scenario

Database has 250 tasks. Agent tool query_nodes {node_type:"task"} (default limit 100, no explicit sorting — the default enumerate path in packages/agent tools.rs:1914) runs 'SELECT * FROM node WHERE node_type=? LIMIT 100': SQLite returns the first 100 rows in table-scan order ≈ the 100 OLDEST tasks; the newest tasks are silently absent from a listing the code intends to be newest-first. Worse, for a collection with >900 members, paging with offset across two RPC calls chunks the member ids in two different random orders, so page 2 repeats some nodes from page 1 and skips others entirely — items are silently missing from a paginated listing.

Location

packages/core/src/services/node_service/query.rs:40

Severity

important


Found via a full-repo adversarial bug sweep, independently verified by two separate skeptical reviewers reading the actual current code before filing.

Activity

  1. self-assigned this
    on Aug 21, 2026
  2. mstomar125 commented on Aug 28, 2026

    @mstomar125
    ContributorAuthor

    Frontend baseline: 4794 passed (227 test files), 0 failed. Starting combined fix with #2212 (same query_nodes function).

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions