Skip to content

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

Closed

Description

@malibio

Overview

Two independent local-agent bugs were found together while reviewing a real ai-chat conversation about grocery tasks: (1) search_nodes cannot find a task by a word variant of its title because tasks are not embedded and search_nodes only does exact substring matching, and (2) a turn-wide tool-failure guard discards a correct final answer when an earlier, superseded tool call failed and the model already self-corrected.

Problem Statement

Bug 1: No fuzzy/keyword-variant match for task titles

User asked "Are there any tasks for groceries?" with a task titled "Buy something from grocery store" already in the database.

  • The agent called search_nodes({"node_type":"task","query":"groceries"}) → 0 results (confirmed via daemon log Tool executed tool=search_nodes ... args_preview={"node_type":"task","query":"groceries"} result_preview={"count":0,"nodes":[]}).
  • A later, differently-worded call in the same session (query:"grocery store") found it (1 result).
  • The user then asked "What tasks do you have?" (empty query, list-all) and the task appeared correctly.

search_nodes's no-filters path (packages/agent/src/local_agent/tools.rs:998-1023 → node_ops::query_nodes, packages/core/src/ops/node_ops.rs:463 → packages/core/src/models/node.rs:352 → packages/core/src/db/sqlite_store/nodes.rs:756-762) builds a plain case-insensitive LOWER(title) LIKE '%<query>%' — no stemming, no tokenization, title-only. "groceries" is not a substring of "grocery store", so the miss is correct per that implementation.

The tool's own schema description tells the model to use search_semantic for fuzzy/meaning-based queries instead — but that guidance is structurally misleading for task nodes: TaskNodeBehavior::get_embeddable_content (packages/core/src/behaviors/mod.rs:734) always returns None ("Tasks are not embedded as standalone roots... They don't carry semantic content worth embedding independently"), and ../nodespace-docs/architecture/data-layer.md confirms task is explicitly in the Not embeddable list. So even a model that picks search_semantic correctly would find nothing — there is no tool path that can fuzzy-match a task by a word variant of its title.

Considered and rejected: making task embeddable. This would let search_semantic handle the fuzzy case, but doesn't fix the actual reported bug on its own — search_nodes is the tool the model reaches for first per its own "prefer this when you know the name" guidance, and would still miss "groceries" vs "grocery store" via plain substring match regardless of whether tasks are embedded; the fix would depend on the model choosing search_semantic instead, which is a routing bet, not a guarantee. It also has real costs: tasks are typically short, high-volume, and frequently mutated (status/priority changes, completions, deletions), so embedding every one means chunking overhead for often one-line text, repeated re-embedding on every edit, and vector-index bloat for low-signal content — exactly the "don't carry semantic content worth embedding independently" reasoning already documented on TaskNodeBehavior::get_embeddable_content. See Non-Goals.

Bug 2: Turn-wide tool-failure guard discards a correct, self-corrected answer

Later in the same conversation, the user asked Was any of the task called "Buy something from grocery store"?. Within one turn:

  1. Iteration 0: model called search_nodes with a malformed filter (missing required type field) → is_error: true ("invalid arguments for tool search_nodes: missing field 'type'").
  2. Iteration 1 (self-correction): model retried with a valid call ({"node_type":"task","query":"grocery store"}) → succeeded, 1 correct result.
  3. Iteration 2 (final): model produced a correct answer grounded in the successful retry: "Yes, there is a task titled \"Buy something from grocery store\"...".

But the daemon logged WARN Tool failures not surfaced in model response — replacing with error message failed_tools=search_nodes, and the user received the generic "⚠️ node search encountered an error. Please try again or check the details and retry." instead of the model's correct answer.

Root cause: the guard in packages/agent/src/local_agent/agent_loop.rs:587-611 checks failed_tools, derived from all_tool_executions — a list accumulated across every ReAct iteration of the whole turn (populated at line ~795, spanning the full turn) — not just the iteration(s) whose output the final response actually relied on. Any failure anywhere in the turn's history trips the guard, even if a later successful retry superseded it and the final response is correct and non-contradictory.

This is the same class of bug already found and fixed once in the same commit (5e9e9859, #1345/#1332) for the sibling anti-fabrication guard, which was changed from scanning the whole-turn all_tool_executions.is_empty() to a narrower any_real_tool_calls check scoped to the iteration that matters. The equivalent narrowing was never applied to the tool-failure guard right below it.

Proposed Solution

Bug 1 (recommended direction)

Make search_nodes's no-filters title path tolerant of near-misses instead of requiring an exact substring: e.g. tokenize the query and title and match on shared tokens/stems, or fall back to a looser match (subset of query words, or a prefix/edit-distance pass) when the exact substring search returns zero results. This fixes the bug at the tool the model actually uses by default, without paying embedding cost on every task and without depending on the model picking a different tool. Tuning the search_nodes/search_semantic tool descriptions to steer retry behavior is a weaker fallback option if the matching fix proves difficult, but should not be the primary fix — it only improves the odds the model retries with better wording, it doesn't make the underlying match capability correct.

Bug 2

Scope the tool-failure check to the tool execution(s) that actually ground the final response (e.g. only the last iteration, or only executions not superseded by a later successful call to the same tool), mirroring the any_real_tool_calls fix already applied to the neighboring anti-fabrication guard in the same function. A same-turn retry that succeeds should clear the "unacknowledged failure" concern the guard exists for, since the model demonstrably reacted to the failure by retrying, and the original contradiction risk (claiming success while masking a real error) does not apply when the failed call was superseded by a successful one whose output grounds the final answer.

Acceptance Criteria

  • A search_nodes query using a word variant of a task's title (e.g. "groceries" vs. a task titled "...grocery store") finds the task, without requiring the model to guess the exact substring
  • The fix lives in search_nodes's matching logic (not in making task embeddable — see Non-Goals)
  • A turn where an early tool 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
  • A turn where a tool failure is genuinely unaddressed (no successful retry, and the model's response ignores/contradicts the failure) still triggers the existing guard — the narrowing must not reintroduce the original fabrication-masking bug the guard was written to prevent
  • Regression test added for the tool-failure guard covering the "failed-then-retried-successfully" scenario (no existing test coverage today — confirmed no matches for "Tool failures not surfaced" or failed_tools in packages/agent/tests/)
  • Code passes bun run quality:fix
  • Tests pass (bun run test:all)

Technical Specifications

Reference Files

  • packages/agent/src/local_agent/tools.rs: exec_search_nodes (~lines 998-1023, no-filters branch), tool schema descriptions for search_nodes/search_semantic (~lines 262-277)
  • packages/core/src/ops/node_ops.rs: query_nodes (~line 463), the ("title","contains") filter arm
  • packages/core/src/models/node.rs: with_title_contains (~line 352)
  • packages/core/src/db/sqlite_store/nodes.rs: the SQL LIKE query construction (~lines 756-762) — target for the tokenized/near-match fallback
  • packages/core/src/behaviors/mod.rs: TaskNodeBehavior::get_embeddable_content (~line 734, returns None — tasks are never embedded, by design; do not change as part of this issue)
  • packages/agent/src/local_agent/agent_loop.rs: tool-failure guard (~lines 587-611), all_tool_executions accumulation (~line 329, pushed ~line 795), and the neighboring anti-fabrication guard's any_real_tool_calls fix (same function) as the pattern to mirror

Related Documentation

  • ../nodespace-docs/architecture/data-layer.md — "Embeddable types: text, header, code-block, schema" / "Not embeddable: task, date, person, ai-chat, child nodes" (Semantic Search section), and the search_nodes/search_semantic tool comparison table (Query System section)

Non-Goals

  • Does not propose making task nodes embeddable. This was explicitly considered (see Bug 1 discussion above) and rejected: it doesn't fix the bug for the tool the model actually uses first (search_nodes), and has real costs (chunking/re-embedding overhead for short, high-churn task content) that the existing TaskNodeBehavior::get_embeddable_content design deliberately avoids. If semantic task search becomes valuable for other reasons in the future, that should be its own issue weighing those tradeoffs on their own merits, not a side effect of fixing this keyword-match bug.

Activity

  1. malibio commented on Jul 30, 2026

    @malibio
    CollaboratorAuthor

    Cross-reference on Bug 1 (task keyword search misses near-matches).

    The prompting spike (#1802) found the same root cause from a different direction: the model cannot construct a query that matches, and no amount of prose guidance fixes it. Measured across three request phrasings, the mechanism that works is having the resolution step perform the search and return a resolved node rather than returning query fragments — 100% vs 0% for the current shape. That is now #1637.

    If #1637 lands, an indirect request like "any tasks for groceries?" would route through resolution rather than the model hand-writing query="groceries", which may subsume Bug 1 without a separate fuzzy-matching change. Worth re-testing this scenario after #1637 before building stemming or tokenization into search_nodes.

    Bug 2 (a superseded tool failure discarding a correct answer) is unaffected by this and remains independently valid.

  2. malibio commented on Aug 1, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 170 test files passed, 4097 tests passed (50.76s).

  3. self-assigned this
    on Aug 1, 2026
  4. malibio commented on Aug 1, 2026

    @malibio
    CollaboratorAuthor

    Implementation note on Bug 1 matching strategy: a plain per-token substring LIKE fallback (split query into words, OR-match each as a substring of title) does NOT actually fix the reported case — "groceries" is not a substring of "grocery store" and vice versa, so that naive tokenization still misses.

    Going with a prefix-match fallback instead: when the exact-substring title_contains query returns zero rows, split the query into significant tokens (reusing the same tokenization/stop-word rules as bm25_search_roots), split each candidate title into words, and consider a query token and a title word a match if they share a prefix at least ~4-5 chars long (covers plurals/verb-ending variants like grocery/groceries, run/running, cheap and dependency-free). Falls back to exact token equality for short (<4 char) tokens to avoid false positives like "to" matching "tomorrow".

    Proceeding with this approach unless redirected.

  5. malibio commented on Aug 1, 2026

    @malibio
    CollaboratorAuthor

    Agreed the plain substring-OR fallback doesn't fix the reported case — correct catch, "groceries" and "grocery store" share no substring relationship either direction, so that approach would've shipped a fix that doesn't fix the bug it's for.

    The prefix-match approach is reasonable, but a fixed 4-5 char shared-prefix threshold has a real false-positive edge: unrelated words that happen to share a stem length ("cart"/"carton", "part"/"party", "read"/"ready") would match as near-matches when they shouldn't. Not a reason to block this — just worth a couple of explicit test cases in both directions (true near-match pairs like grocery/groceries, run/running, and true negatives like the ones above) so the threshold choice is verified rather than assumed. If false positives show up in the negative cases, bumping the minimum prefix length or requiring it to cover a larger fraction of the shorter word are both cheap adjustments at that point.

    Proceed on this basis.

  6. malibio commented on Aug 1, 2026

    @malibio
    CollaboratorAuthor

    Switched from prefix-matching to suffix-stemming after verifying the flagged false positives by hand: a fixed shared-prefix threshold (any length I tried) either matched cart/carton+part/party+read/ready (too loose) or missed running/run (too strict) — there's no single prefix-length threshold that gets both sides right, since the deciding signal isn't length, it's whether the extra characters form a real morpheme (a plural/verb-ending suffix) vs. an arbitrary continuation of the word.

    Implemented as explicit suffix stripping instead (ies→y, trailing s except after s/es, trailing es) and compare stems for equality. Verified by hand against both the true near-match pairs and all three flagged negatives:

    • groceries/grocery, tasks/task, boxes/box, grocery/groceries → match (correct)
    • cart/carton, part/party, read/ready, is/iss → no match (correct)

    Known gap, called out in the code comment: doesn't undo consonant-doubling gerunds (run/running) or silent-e plurals (date/dates) — those stay false negatives rather than false positives, which is the safer direction for a fallback matcher to be wrong in. Adding these as explicit test cases now.

  7. malibio commented on Aug 1, 2026

    @malibio
    CollaboratorAuthor

    This is the right outcome — you didn't just patch around my flagged cases, you found the actual reason no prefix-length threshold could work (length isn't the signal; morpheme validity is) and switched approach accordingly. The verification set is solid: all three false positives I raised are now correctly rejected, the original true positives still match, and you caught an extra short-token edge case (is/iss) I didn't think to ask for.

    Agreed the known gaps (run/running, date/dates as false negatives) are the right side to be wrong on for a fallback matcher — silently missing a near-match is far less harmful than a bogus match polluting results. Good to land as-is with those documented as known limitations rather than chased further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions