Repository navigation
Description
Problem Statement
backendAdapter.queryNodes cannot evaluate a QueryFilter list, so a saved query is fetched by its targetType and then filtered, sorted, and limited on the client — see the comment at packages/desktop-app/src/lib/components/query/query-node-model.ts (the "Client-side query execution" block). The wire type confirms it: NodeQuery in packages/desktop-app/src/lib/services/adapter-core.ts carries only id, mentionedBy, contentContains, titleContains, nodeType, limit — there is no sorting field, so sort config never reaches the backend.
The result is two independent implementations of the same query semantics, which must be kept in agreement by hand.
This became concrete with priority rank ordering. Because the frontend never delegates, it had the identical lexicographic-priority bug in its own comparator, and fixing it required copying the rank table into TypeScript:
TaskPriority::rank()—packages/core/src/models/task_node.rs- the SQL
CASEinQueryService::resolve_order_field— pinned torank()bytest_sql_priority_rank_matches_enum_rank TaskNodeHelpers.priorityRank—packages/desktop-app/src/lib/types/task-node.ts
The two Rust copies are pinned together by a test. The TypeScript copy is pinned to nothing — no test spans both languages, so a one-sided edit to the rank table produces a silent disagreement between what the backend returns and what a saved query displays. Comments on both sides record the coupling, which is the weakest possible guarantee.
The same split applies beyond priority: ordered() backs the gt/gte/lt/lte filter operators client-side, so any future ordering rule has the same duplication problem.
Proposed Solution
Add sorting (and ideally filters) to the NodeQuery wire type, route saved queries through QueryService, and delete the client-side executor (applyFilters / applySorting / executeQueryDefinition) along with the duplicated rank helper.
QueryService already implements all of this — data-layer.md's search_nodes routing section documents it as the sorting-capable path — so this is about reaching it from the frontend, not building new capability.
Worth confirming while doing this: whether the client-side limit slicing and the backend's LIMIT agree on ordering semantics, since the backend applies LIMIT in SQL before its in-Rust re-sort.
Acceptance Criteria
-
NodeQuerycarriessorting(andfilters, if the same pass covers it) - Saved-query execution routes through
QueryServicerather than sorting in the browser -
applySorting/applyFilters/executeQueryDefinitiondeleted, along withTaskNodeHelpers.priorityRankandCORE_PRIORITY_RANKS - Priority ordering still verified end-to-end (the coverage added alongside the rank work must not simply be dropped with the code it tested)
- Any query-view tests depending on client-side execution updated
Reference Files
packages/desktop-app/src/lib/components/query/query-node-model.ts— the client-side executorpackages/desktop-app/src/lib/services/adapter-core.ts—NodeQuery, the wire type missingsortingpackages/core/src/services/query_service/mod.rs— the backend implementation to delegate topackages/desktop-app/src/lib/types/task-node.ts— the unpinned TS rank copy
Activity
malibio commentedon Sep 17, 2026
Discovered while implementing #2692 (priority rank ordering). That issue deliberately duplicated the rank into TypeScript rather than leaving saved-query sorting alphabetically wrong — this issue removes the duplication by delegating to the backend.
malibio commentedon Sep 17, 2026
Baseline on worktree-issue-2727-backend-query-sorting: Frontend 5183 passed (254 files), 61.94s.
Execute saved queries on the backend instead of sorting in the browser (