Repository navigation
Honour sorting on a filterless search (closes #2249) - #2252
Conversation
`run_node_query` branched on `filters.is_empty()` alone. The filterless branch calls `node_ops::query_nodes`, whose input struct has no sorting field, so `sorting` was parsed, accepted, and dropped — the call returned an arbitrary row and reported success. A model answering "which is the longest-running one?" via `sorting` + `limit: 1` was handed the wrong node with nothing to notice. Route on the presence of `sorting` as well, so a sorted request reaches `query_ops::execute_query`, which honours it. Unsorted filterless searches keep their title-keyword path unchanged; only a sorted call shifts to matching content instead of title, and `a_sorted_search_still_ narrows_by_keyword` pins that the keyword still narrows there. Flips the deliberate `filterless_search_silently_ignores_sorting` pin to a regression test and drops the compensating `gt 0` filter from `scenario_12_sorted_single_result_route_is_also_accepted`. All three sorting tests were verified to fail with the fix reverted. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012A1ryuphm1PidSY1KTvcKG
Pragmatic Code Review — PR #2252Review Type: Initial Review Requirements CheckAgainst issue #2249:
Both explicit asks are done, and the core bug is genuinely fixed. The three tests are non-vacuous — I confirmed the discriminating shape of each. Code Review SummaryThe routing change is correct, minimal, and the right call. However, the PR makes one specific empirical claim that I measured and found to be false in general, and it is the exact claim the PR itself identifies as the thing that must hold:
Title is not derived from content when the node's schema defines a I ran this against a live Code Review Findings🔴 Critical📁 The PR's stated safety property does not hold. Measured, with a schema carrying Adding a The converse also reproduces. With So the same This is not hypothetical distance from the test: Principle: the Principle of Least Astonishment, and correctness over silent degradation. A fix that trades a wrong-row bug for a zero-rows bug on an adjacent input has moved the failure, not removed it — and a Suggested resolutions, in order of preference:
🟡 Important📁
The consequence is not merely "unsorted". SQL applies So a typeless superlative query at a small limit returns internal schema registry rows, sorted meaninglessly, reported as success. This is the same silent-wrong-answer family as the original bug, at a shape the fix newly makes reachable, and none of the three tests covers it — every one passes Two things worth separating here:
Principle: don't widen the blast radius of a known-broken code path. YAGNI cuts the other way too — if typeless sorting isn't meant to work, say so explicitly rather than leaving it silently reachable. 📁
This is honest about the trade and I appreciate that it's called out rather than buried. But given the Critical above, the cost is understated — the comment reads as "slightly different matching", where the measured behavior is "0 results instead of 2". If the divergence survives review, the comment should name the concrete failure (templated titles) so the next reader doesn't have to rediscover it. Also, Principle: comments should explain the "why" AND remain accurate; a stale routing summary directly above a changed routing decision is worse than no summary. 🟢 Suggestions📁 The test is well-constructed for what it covers — the largest node deliberately doesn't match the keyword, so "narrowed then sorted" and "sorted, keyword ignored" are genuinely distinguishable, and the failure message correctly enumerates all three outcomes. The assertion substrings ( The gap is coverage, not quality: the schema it creates has no 📁 Sorting on a property absent from some rows puts those rows first on Sorting on a genuinely nonexistent field is benign — measured as returning all rows in insertion order, no error, no truncation surprise. Fine as-is. 📁
Limit semantics — no user-visible divergence found. CLAUDE.md compliance — clean. No lint suppression, no RecommendationREQUEST CHANGES The routing fix is right and I'd merge it happily on its own. The blocker is narrow and specific: the PR rests on a stated safety property — "for nodes created through That's a real regression on a reachable shape, in the same silent-wrong-answer family the issue was filed to eliminate. Adding a title path to The Findings marked "measured" were reproduced against a live |
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review: REQUEST CHANGES (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
…rt key The first commit's safety claim was wrong. It asserted that title and content coincide for `create_node`-created nodes, so routing a sorted search to QueryService (which matched content) was harmless. A schema carrying a `title_template` builds the title from properties instead — `compute_title` checks the template first and only falls back to `strip_markdown(content)` when there is none. Measured: same `query: "payments"`, `count: 2` unsorted and `count: 0` sorted. Adding `sorting` silently dropped both real matches while reporting success — the dropped-`sorting` bug traded for a dropped-keyword one. The test written to pin that shift passed only because it built its schema WITHOUT a template, the one shape where the claim holds. Fixed at the source rather than documented: `title` is a real indexed column, so QueryService now accepts it as a metadata field (whitelist, `resolve_field`, and the in-Rust re-sort comparator), and `run_node_query` sends its keyword as a title filter. Both paths now select on title, so which backend runs cannot change what a keyword means. `query_ops::category()` routes a bare `property: "title"` to metadata for the same reason `content` is already special-cased — otherwise it builds an always-NULL `json_extract`. Also fixes the wildcard sort key the routing change made reachable. With `target_type: "*"` the properties namespace differs per row, so a fixed `$.<field>` path was NULL for every row; SQL ordered and limited on that NULL before the in-Rust re-sort could see anything. Measured at `limit: 3`: three schema-registry rows instead of the seeded data, reported as success. Now resolved per row via `'$.' || node_type || …`, in both the ORDER BY and the property filter. `build_property_filter` deliberately does NOT reuse `resolve_field` — its metadata shortcut would make a user field named `title` query the column instead. Tests: the keyword test is rebuilt on a templated schema (the fixture that discriminates) and verified to fail when the filter is switched back to content; a new typeless-sorted test covers the wildcard case at a limit small enough to expose it. All 11 winnability tests pass, core is clean at 1178 + integration, test:all matches baseline. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012A1ryuphm1PidSY1KTvcKG
Addressed review feedback — commit 42df6baAll three findings addressed. The 🔴 was confirmed independently before implementing, not taken on faith. 🔴 Critical — title/content divergence: fixed at the sourceReproduced exactly as reported. With The reviewer is right and my PR description was wrong. Took the reviewer's preferred direction — give
Now The test was rebuilt on the fixture that discriminates. 🟡 Important — typeless sorted search: fixed, not just documentedConfirmed and worse than a latent concern — my change made it reachable: Under
New test 🟢 Suggestions
Verification
Re-review recommended — the fix moved into shared |
Pragmatic Code Review — PR #2252 (Re-Review)Review Type: Re-Review of commit Previous Review Summary
3 addressed / 1 reasonably declined / 0 new blocking issues found. The author took the harder and better of the two offered directions on the 🔴 — giving Verification PerformedI did not take the response summary on faith. Reproduced independently in this worktree: 1. The keyword test genuinely discriminates. Reverted the filter to Exactly the claimed 2→0 collapse, with the failure message correctly naming the cause. The old test passed under both filters; this one does not. Claim verified. 2. The typeless test's The comment's claim that a large limit hides the bug (the in-Rust re-sort repairs order after the fact) is exactly right. Both new tests fail against their respective unfixed code and pass against the fix. 3. Full core suite clean. Blast-Radius Analysis (the wider-surface concern)The response flags the wider blast radius honestly. I audited each vector; none regress.
|
malibio
left a comment
There was a problem hiding this comment.
Automated pragmatic-code-review (re-review): APPROVE (posted as a comment — GitHub blocks self-approval). Full findings in the review comment above.
The two resolve the same field name differently on purpose: a sort entry reads a same-named top-level column, a property filter always reads the properties JSON. That asymmetry reads like an oversight without the reason attached, and "unifying" it would silently redirect a property filter to a column — answering a different question than the caller asked. Comment only; no behavior change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012A1ryuphm1PidSY1KTvcKG
Addressed re-review 🟢 items — commit e135bbdAll three triaged. One addressed, one filed as follow-up, one skipped with reasoning. ✅ Addressed — asymmetry note on
|
Summary
search_nodesaccepted asortingargument and silently dropped it wheneverfilterswas empty — returning an arbitrary row while reporting success. A model answering "which is the longest-running one?" viasorting+limit: 1was handed the wrong node with no error to notice.run_node_querybranched onfilters.is_empty()alone:node_ops::query_nodes, whoseQueryNodesInputhas no sorting field at all.query_ops::execute_query, which honours sorting.So the same logical request behaved differently depending on whether an unrelated filter happened to be present.
Fix
Direction 2 from the issue: route on the presence of
sortingas well, so a sorted request reachesexecute_queryregardless of filters.Direction 1 (plumbing sorting into
QueryNodesInput) was considered and rejected as materially larger:NodeFilter/NodeQueryhave no ordering support today, so it would push ORDER BY down through the store layer.Behavior change, scoped
Unsorted filterless searches are untouched — they keep the
query_nodestitle-keyword path. The one shifted shape is a sorted search carrying a keyword: on theQueryServicepath the keyword becomes a content filter rather than a title filter, sinceQueryServicehas no title path. For nodes created throughcreate_nodethe two coincide (title is derived from content), so the keyword still narrows.a_sorted_search_still_narrows_by_keywordpins exactly that, because a keyword that quietly stopped matching would trade one silent-wrong-answer bug for another.Tests
filterless_search_silently_ignores_sorting→filterless_search_honours_sorting. The deliberate bug pin now asserts the correct 21-day result.scenario_12_sorted_single_result_route_is_also_accepted: compensatinggt 0filter removed, as the issue asked. It passes on the plain phrasing now.a_sorted_search_still_narrows_by_keyword: new, covering the shifted keyword+sorting shape.All three were verified to fail with the fix reverted and pass with it, so none is vacuous.
bun run test:allclean (frontend 227 files / 4794 tests, matching baseline; no Rust failures).bun run quality:fixclean — clippy passes under-D warnings, no stray reformatting. Full pre-push gate passed.🤖 Generated with Claude Code
https://claude.ai/code/session_012A1ryuphm1PidSY1KTvcKG