Repository navigation
Add stem-based title-match fallback and scope tool-failure guard to non-superseded failures - #1877
Conversation
…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
Pragmatic Code Review — PR #1877Review 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)
All acceptance criteria met. Code Review Findings🔴 CriticalNone. 🟡 Important1. The predicate is For The exact-substring path doesn't have this problem — The cheap, YAGNI-respecting fix is to rank rather than restructure: sort Principle: a fallback that widens recall should not silently degrade precision ordering for its consumer; when a result list is truncated by 2.
The agent path always passes a 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 Principle: an in-memory filter over a SQL result set needs a bounded fetch; consistency with the existing 3. The function implements suffix stemming, and the PR description explicitly documents that the prefix approach was tried and rejected for producing Rename to 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 / Nits4. Nit: The implementation covers 5. Nit: if nodes.is_empty() {
if let Some(ref search_q) = query.title_contains {reads more directly as 6. Nit: 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. 7. Confirmed deliberate, not an oversight: the Collection-scoped queries keep exact-substring-only matching. This matches the issue's explicit scope (the no- 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: The RecommendationCOMMENT — 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- 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
left a comment
There was a problem hiding this comment.
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.
|
Review Type: Initial Review Requirements Check (issue #1706)
All acceptance criteria are met. Full Code Review Findings🟡 Important: Fallback method name and its own comments describe "prefix" matching, but the implementation is stem-equality matching📁 The method is named 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 Recommendation: Rename 🟢 Suggestion:
|
malibio
left a comment
There was a problem hiding this comment.
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
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
⏭️ Skipped (with reasoning)
All tests re-run and green: Re-Review DecisionDecision: 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. |
Summary
search_nodes'stitle_containspath 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_nodesnow falls back to a suffix-stemmed word comparison over titles filtered bynode_type.agent_loop.rsreplaced 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 theany_real_tool_callsnarrowing already applied to the neighboring anti-fabrication guard.Design notes (see issue #1706 comments for full trail)
cart/carton,part/party,read/ready) and false negatives (run/running) simultaneously, since the real signal is morpheme validity, not prefix length.ies→y, trailings(except afters/es), and trailinges, then compares stems for equality. Verified by hand against the flagged false-positive pairs and true near-match pairs.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 explicitstem_wordunit 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 testscargo test --workspace— all passing (ai_chat_send_to_idle_testflaked 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 warningsCloses #1706
🤖 Generated with Claude Code
https://claude.ai/code/session_01HkymyKtLHm5NcNbf2CjrT9