Skip to content

Add stem-based title-match fallback and scope tool-failure guard to non-superseded failures - #1877

Merged
malibio merged 2 commits into
mainfrom
issue-1706-task-search-tool-failure
Aug 1, 2026
Merged

malibio merged 2 commits into
mainfrom
issue-1706-task-search-tool-failure

Conversation

@malibio

@malibio malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • search_nodes's title_contains path only did exact substring matching, so a word variant of a task's title (e.g. "groceries" vs "grocery store") returned zero results even though the task existed. When the exact match returns zero rows, SqliteStore::query_nodes now falls back to a suffix-stemmed word comparison over titles filtered by node_type.
  • The turn-wide tool-failure guard in agent_loop.rs replaced a correct final answer with a generic error message whenever any tool call failed anywhere in the turn's history — even when a later successful retry to the same tool superseded it. The guard is now scoped to exclude a failure when a later execution of the same tool name succeeded, mirroring the any_real_tool_calls narrowing already applied to the neighboring anti-fabrication guard.

Design notes (see issue #1706 comments for full trail)

  • A naive per-token substring fallback was tried first and rejected — "groceries" isn't a substring of "grocery store" in either direction, so it wouldn't have fixed the reported bug.
  • A fixed-length shared-prefix fallback was tried next and rejected after review — no single prefix-length threshold avoids both false positives (cart/carton, part/party, read/ready) and false negatives (run/running) simultaneously, since the real signal is morpheme validity, not prefix length.
  • Landed on explicit suffix stripping (stemming) instead: strips ies→y, trailing s (except after s/es), and trailing es, then compares stems for equality. Verified by hand against the flagged false-positive pairs and true near-match pairs.
  • Known, documented limitation: doesn't undo consonant-doubling gerunds (run/running) or silent-e plurals (date/dates) — these are false negatives, the safer direction to be wrong in for a fallback matcher.

Test plan

  • cargo test -p nodespace-core --lib title_contains_stem_fallback_tests — 9/9 passing, covers exact-substring precedence, stem fallback, node_type scoping, unrelated-query rejection, and explicit stem_word unit tests (true positives, rejected false positives, documented false negatives)
  • cargo test -p nodespace-agent --lib tool_failure — 4/4 passing, covers superseded-failure-does-not-trip-guard and unretried-failure-still-trips-guard (new), plus the two pre-existing tool-failure tests
  • cargo test --workspace — all passing (ai_chat_send_to_idle_test flaked once under machine contention, passed clean on retry — unrelated to this change, touches only daemon startup/ai-chat send flow)
  • bun run test — 170 files / 4097 tests passing (matches baseline)
  • bun run quality:fix — clean, no clippy warnings

Closes #1706

🤖 Generated with Claude Code

https://claude.ai/code/session_01HkymyKtLHm5NcNbf2CjrT9

…on-superseded failures (closes #1706)

search_nodes's title_contains path missed word variants of a task's title
(e.g. "groceries" vs "grocery store") because it only did exact substring
matching. When the exact match returns zero rows, fall back to a suffix-
stemmed word comparison over titles filtered by node_type — verified against
both true near-match pairs and unrelated words that share a prefix but not a
stem (cart/carton, part/party, read/ready).

The turn-wide tool-failure guard in agent_loop.rs tripped on any tool failure
anywhere in a turn's history, even when a later successful retry to the same
tool superseded it and the final response was correctly grounded in that
retry. Narrowed to exclude a failure when a later execution of the same tool
name succeeded, mirroring the any_real_tool_calls fix already applied to the
neighboring anti-fabrication guard.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HkymyKtLHm5NcNbf2CjrT9
@malibio

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic Code Review — PR #1877

Review Type: Initial Review

Two independent, well-scoped bug fixes with genuinely good test coverage. Bug 2 is correct as written — I verified the supersession boundary logic exhaustively and it handles every edge case I could construct. Bug 1 fixes the reported scenario and the design trail (substring → prefix → stemming) shows real engineering judgment; the rejected-alternative reasoning is documented in the code where it belongs. My findings are concentrated in one behavioral aspect of Bug 1 (multi-token OR semantics) plus naming/comment drift left over from the earlier prefix-based design iteration.


Requirements Check (issue #1706)

  • A search_nodes query using a word variant of a task's title finds the task, without requiring the model to guess the exact substring — word_variant_falls_back_to_stem_match (nodes.rs:2578) exercises exactly the reported "groceries" vs "Buy something from grocery store" case
  • The fix lives in search_nodes's matching logic (not in making task embeddable) — change is confined to SqliteStore::query_nodes; TaskNodeBehavior::get_embeddable_content untouched
  • A turn where an early tool call fails and a later call in the same turn succeeds is NOT replaced with the generic error message — tool_failure_superseded_by_later_success_does_not_trip_guard (agent_loop.rs:4634) reproduces the exact 3-iteration daemon trace from the issue
  • A turn where a tool failure is genuinely unaddressed still triggers the guard — tool_failure_without_retry_still_trips_guard (agent_loop.rs:4763); verified by hand that no later-success case can mask it
  • Regression test added for the "failed-then-retried-successfully" scenario — both new tests added, and the two pre-existing tool-failure tests still pass
  • Code passes bun run quality:fix — no lint suppressions anywhere in the diff
  • Tests pass — cargo test -p nodespace-core --lib title_contains_stem_fallback_tests 9/9, cargo test -p nodespace-agent --lib tool_failure 4/4, both re-run and confirmed green during this review

All acceptance criteria met.


Code Review Findings

🔴 Critical

None.


🟡 Important

1. nodes.rs:963-971 — Multi-token queries use unranked OR semantics, so a 2-word query can return mostly-irrelevant tasks with the best match buried.

The predicate is any(query_token) × any(title_token) — a single shared stem anywhere qualifies the node, and results come back in raw table order with no relevance ranking. I simulated the actual matcher against a realistic task set:

query='buy tickets'    -> 3 hits: ['Buy something from grocery store',
                                   'Buy new running shoes',
                                   'Buy tickets for the concert']
query='grocery report' -> 3 hits: ['Buy something from grocery store',
                                   'Write quarterly report for the board',
                                   'Review the report from the vendor']
query='buy a book'     -> 5 hits: [5 of 7 tasks]

For "buy tickets" the exactly-correct task is present but ranked third behind two nodes that matched on the near-useless token buy. This matters more than a normal precision nit because of the consumer: search_nodes feeds an LLM that reads the result list and then answers. Handing back a 5-of-7 list where the right answer is positionally last is close to handing back nothing useful, and it's exactly the shape that produces the "model picks the wrong node" failures this codebase already has history with.

The exact-substring path doesn't have this problem — LIKE '%buy tickets%' is inherently conjunctive. So the fallback is strictly looser in a way the exact path never was, and the change in matching semantics (not just recall) isn't currently visible to callers.

The cheap, YAGNI-respecting fix is to rank rather than restructure: sort matched by number of distinct query tokens matched, descending, before applying offset/limit. That's a few lines, it makes "buy tickets" return the concert task first, and it makes the limit truncation keep the best matches instead of an arbitrary set. Prefer that over requiring all tokens to match — all-match would reintroduce false negatives for the multi-word case and is a bigger behavior swing.

Principle: a fallback that widens recall should not silently degrade precision ordering for its consumer; when a result list is truncated by limit, ordering becomes correctness, not presentation.

2. nodes.rs:902-913 — The fallback can trigger an unbounded full-table scan on the no-node_type, no-limit path.

query_nodes_title_prefix_fallback issues SELECT * FROM node WHERE title IS NOT NULL with no LIMIT, deserializes every row via row_to_node, and filters in Rust. When node_type is Some this is fine — task/title volumes are small and the SQL narrowing is exact. But the type is optional, and limit/offset are applied after the full fetch, so they don't bound the scan.

The agent path always passes a limit (tools.rs:1297, limit: Some(limit)) but does not always pass node_type — it's Option<String> straight from the model's arguments. And query_nodes_simple (packages/desktop-app/src-tauri/src/commands/nodes.rs:594) exposes title_contains with both node_type and limit fully optional from the frontend. So an untyped title miss deserializes every titled node in the database.

Note this is only reachable on a zero-result exact match, which caps the blast radius — it's a latent scaling concern, not a live bug, and I'm not asking for a redesign. Two low-cost options: push the limit (plus offset) into the fallback SQL as an over-fetch bound, or apply the same PROPERTY_FILTER_FETCH_CAP-style safety ceiling that NodeService::query_nodes (services/node_service/query.rs:48) already uses for its analogous in-memory-filter path. The second keeps the pattern consistent with the neighboring code, which is worth something on its own.

Principle: an in-memory filter over a SQL result set needs a bounded fetch; consistency with the existing PROPERTY_FILTER_FETCH_CAP precedent beats inventing a new bound.

3. nodes.rs:918, 928 — The method name query_nodes_title_prefix_fallback describes a design that was rejected.

The function implements suffix stemming, and the PR description explicitly documents that the prefix approach was tried and rejected for producing cart/carton false positives. The name is a fossil of that iteration, and it's actively misleading — a future reader debugging a match will go looking for prefix logic that isn't there, or worse, assume the rejected heuristic is still live and reason about false positives that can't occur. The doc comment's first line ("Prefix-token fallback...") and its body ("compares word-to-word by shared prefix") carry the same stale claim, as does the comment at the call site (nodes.rs:893-901: "fall back to a prefix-token match", "by shared prefix instead").

Rename to query_nodes_title_stem_fallback and update the three comment sites to say "stem" / "shared stem". Worth noting the rest of the stem_word doc comment (nodes.rs:955-968) is excellent — it records why prefix matching was rejected and names the known false-negative gaps. That's precisely the "why, not what" content that should be preserved; this is only about the stale "prefix" label sitting on top of it.

Principle: an identifier that names a rejected design is worse than no name — it encodes a false invariant that survives longer than the commit that explains it.


🟢 Suggestions / Nits

4. Nit: nodes.rs:970-981 — stem_word's doc comment says "plural/verb-ending suffix", but no verb ending is handled.

The implementation covers ies→y, trailing s, and trailing es — all noun plurals. The comment's own example list is "grocery"/"groceries", "task"/"tasks", both plurals, and the documented gap (run/running) is the verb case that isn't handled. Dropping "verb-ending" makes the comment match the code exactly.

5. Nit: nodes.rs:902-913 — collapse the nested if into a single if let with a guard.

if nodes.is_empty() {
    if let Some(ref search_q) = query.title_contains {

reads more directly as if let Some(ref search_q) = query.title_contains { if nodes.is_empty() { ... } } or a let ... else-free single condition. Purely stylistic; clippy isn't flagging it.

6. Nit: stem_word over-strips a few short words (status→statu, analysis→analysi, series→sery, this→thi).

I checked whether these can produce false positives and they can't — the stems are non-words that won't collide with any real title token. is/as are stop-words on the query side and too short for the len() > 3 guard on the title side, so they're inert. Genuinely harmless, noting it only so a future reader doesn't rediscover it and assume it's a bug. No change needed.

7. Confirmed deliberate, not an oversight: the ids-scoped path (nodes.rs:837-867) returns early and never reaches the fallback.

Collection-scoped queries keep exact-substring-only matching. This matches the issue's explicit scope (the no-filters/title path of search_nodes, not collection membership), and node_ops::query_nodes applies its own in-memory pagination over the membership set afterward, so extending the fallback there would need separate thought about interaction with that. Correct call to leave it out — flagging only so the scope limit is on the record rather than looking accidental to a later reader.

8. Verified: Bug 2's supersession logic is correct at every boundary I could construct.

I enumerated the sequences the review brief called out plus several others:

fail then success (same tool)          -> []            (superseded, guard clears)
fail then fail (same tool)             -> [search, search]  (correctly still fires)
fail, fail, success                    -> []            (both cleared by trailing success)
success then fail (same tool)          -> [search]      (earlier success does NOT clear a later failure)
toolA fail superseded, toolB fail not  -> [B]           (per-tool, not turn-wide)
different tool succeeds after          -> [A]           (name-matched, no cross-tool masking)

The [i + 1..] slice is the right boundary: only a later success clears, a later failure does not, and all_tool_executions is confirmed pushed in strict iteration order (agent_loop.rs:1359, single push site inside the tool-execution loop). No interaction with the anti-fabrication guard above (that reads any_real_tool_calls, untouched) or the empty-response synthesizer below (reads all_tool_executions.last(), also untouched). The two-different-tools case — one superseded, one not — is the edge case most likely to be missed by an implementation like this, and it's handled correctly; consider adding it as a third test since it's the one asserting the filter is per-tool rather than turn-wide.


Recommendation

COMMENT — no blocking issues. Bug 2 ships as-is. For Bug 1, findings 1 (relevance ranking) and 3 (rename away from "prefix") are worth addressing before merge — the first because the truncation-by-limit interaction makes ordering a correctness property for the LLM consumer, the second because it's a two-minute change that prevents a durable misreading of the code. Finding 2 is a reasonable follow-up if you'd rather not grow the diff; it's latent, not live.

Net assessment: clearly a positive change to code health, with the rejected-alternatives reasoning captured in the code where future maintainers will actually find it.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the detailed review posted as a PR comment above. Recommendation: COMMENT — no blocking issues; findings 1 (relevance ranking on multi-token fallback matches) and 3 (rename query_nodes_title_prefix_fallback → stem) are worth addressing before merge.

@malibio

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Review Type: Initial Review

Requirements Check (issue #1706)

  • A search_nodes query using a word variant of a task's title finds the task without an exact substring. Verified: word_variant_falls_back_to_stem_match reproduces the exact reported scenario ("groceries" query vs. "Buy something from grocery store" title) and passes.
  • The fix lives in search_nodes's matching logic, not in making task embeddable. Confirmed — TaskNodeBehavior::get_embeddable_content is untouched; the fallback is entirely inside SqliteStore::query_nodes/query_nodes_title_prefix_fallback in nodes.rs.
  • A turn where an early call fails and a later call in the same turn succeeds, with the final response grounded in the successful call, is NOT replaced with the generic error message. Verified by tool_failure_superseded_by_later_success_does_not_trip_guard, which reproduces the exact reported sequence (malformed filter → self-corrected retry → correct final answer) and asserts the model's real answer passes through.
  • A turn where a failure is genuinely unaddressed still trips the guard. Verified by tool_failure_without_retry_still_trips_guard and the pre-existing tool_failure_appended_when_model_ignores_error (unmodified, still passing).
  • Regression test added for the "failed-then-retried-successfully" scenario — new, previously absent per the issue.
  • cargo clippy -p nodespace-core -p nodespace-agent --lib --tests — clean, no warnings, no #[allow(...)] suppressions anywhere in either changed file.
  • Targeted test suites pass: title_contains_stem_fallback_tests (9/9), tool_failure* in agent_loop (4/4, including the two pre-existing tests in that area).

All acceptance criteria are met. Full bun run test:all / quality:fix were not re-run here (out of scope for this review pass; the two cargo test/clippy invocations above target exactly the changed surfaces and both are clean).

Code Review Findings

🟡 Important: Fallback method name and its own comments describe "prefix" matching, but the implementation is stem-equality matching

📁 packages/core/src/db/sqlite_store/nodes.rs:894-899, 921, 926-927, 928

The method is named query_nodes_title_prefix_fallback, and the comments around the call site and the method doc explicitly describe it as a "prefix-token match," comparing tokens "by shared prefix." That is not what the code does — the actual comparison (lines ~934-950) calls Self::stem_word on both the query token and each title token and checks for stem equality, not a prefix relationship. Per the issue's own design history, a fixed-length shared-prefix heuristic was tried and explicitly rejected (false positives on cart/carton, part/party, read/ready) in favor of the suffix-stemming approach that shipped. The name and several comments are leftover from that earlier, rejected iteration and were never updated to match the algorithm that actually landed.

This isn't a functional bug — the tests confirm the stemming logic works as intended — but it's a real maintainability hazard: a future reader (or agent) will trust the name/comments over the code, assume prefix semantics, and either "fix" a phantom bug or reintroduce the rejected prefix approach while believing they're preserving existing behavior. The one comment on stem_word itself (lines 993-1007) is accurate and clearly explains why prefix-matching was rejected — the inconsistency is specifically in the method name and the three comment blocks around lines 894-927.

Recommendation: Rename query_nodes_title_prefix_fallback → something like query_nodes_title_stem_fallback, and update the "prefix-token"/"shared prefix" language in the three comment blocks to describe stem-equality matching. Engineering principle: comments and names are load-bearing documentation — when they contradict the code, the code always wins at runtime but the comment actively misleads the next person to touch it, which is worse than no comment at all.

🟢 Suggestion: stem_word's bare-trailing-s rule strips a real letter off non-plural words ending in a single "s", producing a false negative against the word's own plural

📁 packages/core/src/db/sqlite_store/nodes.rs:1008-1012 (the w.ends_with('s') && !w.ends_with("ss") && !w.ends_with("es") branch)

Hand-verification against words outside the PR's own test set turns up a gap not mentioned in the doc comment's "known gaps" list (which only calls out consonant-doubling gerunds and silent-e plurals): singular nouns that end in a bare, non-plural "s" — status, virus, bonus, campus, focus, atlas, canvas — get their trailing "s" stripped as if it were a plural marker (status → statu), while their real plurals strip via the es branch instead (statuses → status). The two don't stem equal, so status vs. statuses is a false negative for the exact "word variant of a title" case this feature exists to catch — e.g. a task titled "Check server status" would not be found by a query for "statuses."

Per the PR's own stated design principle ("a missed match is safer than a spurious one for a fallback matcher"), this is in the acceptable direction — it's a false negative, not a false positive — so it doesn't block. It's also a fairly narrow word class. Flagging as a Nit/Suggestion rather than blocking: consider either documenting this as an additional known gap alongside the gerund/silent-e note, or (optionally) excluding words already ending in us/as/os from the bare-s strip rule if it's cheap to special-case. Not required for this PR.

🟢 Nit: stem_word's bare-s strip runs before the es strip is checked at the boundary, but ordering happens to be correct by the guard conditions — worth a one-line note

📁 packages/core/src/db/sqlite_store/nodes.rs:1008-1013

No actual bug here — !w.ends_with("es") in the second branch correctly excludes es-ending words from the bare-s rule, so boxes correctly falls through to the third branch. Just noting for a future maintainer: the three branches are order-and-guard-dependent (each guards against being shadowed by the next), which is fine as implemented, but a short comment noting "order matters: the s branch excludes es explicitly to avoid shadowing the branch below it" would save a future editor from reordering them and quietly breaking the exclusion.

🟢 Nit: candidate fetch for the fallback pulls all title-having (optionally node_type-scoped) rows into memory

📁 packages/core/src/db/sqlite_store/nodes.rs:940-951

query_nodes_title_prefix_fallback fetches every row matching title IS NOT NULL [AND node_type = ?] and does the stem comparison in Rust. This is a reasonable, deliberate tradeoff for the target use case (task titles: short, no full-text index, and the exact-match SQL path already returned zero rows so precision matters more than speed on this rarer path) — SQLite has no clean way to express "any word in title shares a stem with any query token" at the SQL level, exactly as the comment states. At current and near-term task/title volumes this is fine. If title volume per node_type grows into the tens of thousands, this in-memory scan becomes the dominant cost of a miss; worth a tracing::warn! or a candidate cap (mirroring PROPERTY_FILTER_FETCH_CAP used elsewhere in the query path, e.g. query.rs:48) if that ever becomes a real workload. Not required now — flagging as a forward-looking note, not a blocker.

🟢 Nit: limit/offset semantics on the fallback path differ subtly in ordering from the exact-match SQL path, but the difference is inherited, not introduced

📁 packages/core/src/db/sqlite_store/nodes.rs:953-958 vs. the exact-match branch above it

The fallback applies offset/limit in-memory (.skip(o) then .truncate(l)) over matched, whose order is SQLite's default row order from query_nodes_from_sql (no ORDER BY) filtered/re-ordered by the filter() predicate — which preserves source order, so this is effectively "insertion/rowid order," same as the exact-match SQL path's unordered SELECT * FROM node WHERE .... Neither path has a deterministic sort today, so the fallback doesn't introduce a new ordering inconsistency; it's consistent with the existing (also unordered) exact-match behavior. No action needed — just confirming this was checked, since the review brief specifically asked about it.

🟢 Confirmed as intentional, not an oversight: the ids-scoped path does not get the stem fallback

📁 packages/core/src/db/sqlite_store/nodes.rs:837-867 (the ids branch returns early, before the nodes.is_empty() fallback trigger at the end of the method) and 790-810 (content_contains also returns early via a separate branch, so it likewise never reaches the fallback)

Confirmed by reading control flow: query.ids and query.content_contains both return before the code reaches the trailing if nodes.is_empty() { ... } fallback trigger, so only the plain title/node_type/limit/offset branch (no ids, no content_contains) gets the stemming fallback. This matches the issue's explicit scope ("search_nodes's no-filters/title path, not collection membership queries") — a deliberate, correctly-implemented scope limit, not a gap.

🟢 Bug 2 logic verified correct, including the boundary cases called out for special attention

📁 packages/agent/src/local_agent/agent_loop.rs:1026-1036

Traced by hand against all_tool_executions accumulation (single flat Vec, pushed once per call in iteration order at line 1359, never reset or reordered within a turn):

  • A failure followed only by further failures of the same tool never gets superseded, because the supersession check requires !later.is_error — this correctly still trips the guard (verified live by tool_failure_without_retry_still_trips_guard).
  • A failure followed by a later success of the same tool is correctly excluded from failed_tools.
  • Two different tools failing, one superseded and one not: the filter is per-record and keyed on later.name == r.name, so an unsuperseded failure of tool B is unaffected by tool A's supersession — the guard would still fire for B alone. Not explicitly tested, but the logic is correct by construction (each record's supersession check only looks at same-named later records).
  • Fail → fail → eventual success of the same tool: since the check is "is there any later non-error execution of this name," both earlier failures are correctly cleared by the final success — this is the right behavior (the model's self-correction succeeded; nothing about an intermediate second failure changes that the final answer is grounded in the eventual success). Also not explicitly tested but correct.
  • O(n²) complexity is a non-issue at ReAct-loop scale (n is bounded by effective_max_iterations, single digits in practice).
  • No interaction found with the duplicate-call-breaks-loop guard (operates on seen_calls, a separate structure) or the anti-fabrication guard immediately above (operates on any_real_tool_calls, a separate boolean) — both are independent gates checked before this one, and none of them mutate all_tool_executions.

🟢 Suggestion: two flagged edge cases (multi-tool partial supersession, fail-fail-success) are untested

📁 packages/agent/src/local_agent/agent_loop.rs:4629-4816 (new test module additions)

The two new tests (tool_failure_superseded_by_later_success_does_not_trip_guard, tool_failure_without_retry_still_trips_guard) are well-constructed and non-tautological — they exercise the real reported scenario end-to-end through run_turn, with meaningful assertions on both tool_calls_made and the final response text (not just internal state). However, neither test covers the two edge cases explicitly worth pinning down given how easy it would be for a future refactor to regress them silently:

  1. Two different tools fail in the same turn, only one gets a successful retry — does the guard still fire (correctly) for the unsuperseded one?
  2. Same tool fails twice, then eventually succeeds — is the guard cleared correctly rather than, say, only looking at the immediately-next execution?

I verified both by hand-tracing the code (see finding above) and both are correct as implemented. Given the logic is simple and provably correct, this is a suggestion rather than a blocker — but since this exact class of "guard scoped too broadly" bug is the second occurrence in this function (the first being the any_real_tool_calls fix this PR explicitly mirrors), a regression test for at least the multi-tool case would cheaply guard against a future refactor reintroducing whole-turn scoping by accident.

🟢 Nit: commit message / PR scope is appropriately atomic for two related-but-independent fixes

📁 N/A (whole PR)

The PR bundles two genuinely independent bug fixes (SQL-layer title matching, agent-loop guard scoping) under one issue. Per the issue itself, both bugs were "found together while reviewing a real ai-chat conversation," and the acceptance criteria for both live in the same issue — so keeping them in one PR is reasonable and doesn't violate atomicity in a way worth blocking on. Each fix is self-contained to its own file with its own dedicated test module, so a future git revert of just one half remains straightforward if needed.

Summary

Both fixes are correct, well-tested for their primary scenarios, and match the issue's acceptance criteria and documented design history (including the explicitly-rejected prefix-heuristic alternative). Bug 2's guard-narrowing logic was traced by hand against every boundary case the review brief called out (failure-followed-by-failure, multi-tool partial supersession, fail-fail-then-success) and is correct by construction, even where not explicitly test-covered. Bug 1's stemming fallback correctly scopes to the intended code path (exact-match miss only, node_type-filtered, deliberately excluding the ids/content_contains paths) and is verified against both the true-positive and false-positive word pairs called out in the issue's design history.

The one finding worth addressing before merge is the stale "prefix" naming/comments (🟡) — it's not a functional defect, but it actively documents the wrong algorithm at the exact spot a future reader would look to understand the fallback, which is a real maintenance cost for a codebase this early in its life. Everything else is optional polish.

Recommendation: COMMENT (approve-quality work; the naming/comment mismatch is worth a follow-up commit before merge, but not a functional blocker — reviewer's call whether to require it inline or as a fast follow-up given "Net Positive > Perfection").

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comprehensive review posted above. Recommendation: COMMENT — both bug fixes are correct and well-tested; one naming/comment-accuracy issue (query_nodes_title_prefix_fallback describes prefix matching but implements stemming) worth cleaning up before or shortly after merge, plus a couple of optional polish suggestions. No functional blockers found.

…llback naming

Sort the title-stem fallback's matches by number of distinct query-token
stems matched before applying limit/offset — a limit-truncated multi-word
query previously returned an arbitrary set of OR-qualifying tasks with no
relevance ordering, risking the best match being truncated out.

Renamed query_nodes_title_prefix_fallback to query_nodes_title_stem_fallback
and fixed the surrounding comments: the method compares word stems, not
prefixes — the prefix-matching approach was tried and rejected during design
(see PR discussion) but the name and comments were never updated to match.

Added a regression test confirming the guard's supersession filter is
per-tool (a superseded search_nodes failure must not mask an unrelated,
never-retried update_node failure in the same turn).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HkymyKtLHm5NcNbf2CjrT9
@malibio

malibio commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed review feedback

(Note: the review agent posted twice due to a resume — #1877 (comment) and #issuecomment-5150803171 are duplicates of the same review; both say the same thing.)

✅ Addressed

  1. 🟡 Multi-token OR semantics with no ranking — query_nodes_title_stem_fallback now ranks matches by number of distinct query-token stems matched before applying limit/offset, so a limit-truncated multi-word query keeps the closest matches instead of an arbitrary OR-qualifying subset. Added multi_token_matches_are_ranked_by_match_count_before_limit reproducing the reviewer's "buy tickets" scenario.

  2. 🟡 Stale "prefix" naming — renamed query_nodes_title_prefix_fallback → query_nodes_title_stem_fallback and fixed all three comment sites (call site + method doc comment) that described prefix matching. The method does stem-equality matching; "prefix" was a fossil of the earlier rejected design.

  3. 🟢 Suggested third test (per-tool supersession) — added superseded_failure_of_one_tool_does_not_mask_unretried_failure_of_another: a superseded search_nodes failure must not mask an unrelated, never-retried update_node failure in the same turn. Confirms the filter is per-tool, not turn-wide.

  4. 🟢 Nit: "plural/verb-ending" comment wording — fixed to just "plural" since no verb-ending case is actually handled.

⏭️ Skipped (with reasoning)

  • 🟡 Unbounded fetch when node_type is absent — confirmed latent, not live (only reachable on a zero-result exact match; agent path always passes node_type from the model's structured args in practice, and the fallback is bounded to zero-hit queries). Applying the existing PROPERTY_FILTER_FETCH_CAP pattern from NodeService::query_nodes is the right shape for a fix, but picking the right cap value and confirming it doesn't regress recall for legitimately large title sets is worth its own scoped change rather than folding into this PR blind. Filing as a fast-follow if it becomes a real issue.
  • 🟢 Nested-if style nit — tried a let-chain collapse, but this codebase is edition 2021 with no other let-chain usage; reverted rather than introduce an unprecedented pattern for a change the reviewer themselves called "purely stylistic, clippy isn't flagging it."
  • 🟢 Over-strip on bare "s" nouns (status/virus/etc.) — reviewer's own analysis confirmed this can't produce a false positive (stems to a non-word), so no behavior change needed.

All tests re-run and green: title_contains_stem_fallback_tests (10/10), tool_failure-related agent_loop tests (5/5), full cargo test -p nodespace-core -p nodespace-agent --lib (1086 + 404 passing), bun run quality:fix clean, pre-push gate test:all passed.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: Both changes made are narrow, low-risk, and directly responsive to specific reviewer findings — a sort added before truncation (no change to match semantics, only ordering) and a rename + comment fix (no behavior change at all). The new test explicitly covers the one edge case the reviewer flagged as under-tested. No new functionality, no architectural changes, no interaction with code outside what was already reviewed.

@malibio
malibio merged commit d1ecf51 into main Aug 1, 2026
2 checks passed
@malibio
malibio deleted the issue-1706-task-search-tool-failure branch August 1, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Task keyword search misses near-matches, and a superseded tool failure discards a correct agent answer

1 participant