Agent Loop: Reliability & Verification · Part 3 of 7
A Successful Search That Never Searched

An agent can be wrong because a model misunderstood evidence. It can also be wrong because the evidence request never reached a source at all.
That second failure is deceptively quiet. A search tool receives an explicit source selector, resolves it to zero indexed sources, and returns a successful response containing zero hits. From the caller's point of view, the operation looks like a legitimate empty search. The agent may continue, summarize the absence of results, and make a decision with missing context.
I found this boundary while investigating Context Mode 2.2.0. The important result was not a benchmark number or a claim about every retrieval system. It was a small, reproducible protocol observation: through the real MCP stdio JSON-RPC interface, an unknown explicit source selector produced isError: false and a zero-hit message instead of a source-resolution error.
The failure mode
The minimal shape of the request was:
{
"method": "tools/call",
"params": {
"name": "ctx_search",
"arguments": {
"source": "https://example.invalid/missing",
"queries": ["alpha-token"]
}
}
}
The observed response was equivalent to:
isError: false
No hits in scope "worktree" across 0 source(s).
That response conflates two different states:
- The requested source exists and contains no matching evidence.
- The requested source does not resolve in the active search scope.
Those states have different meanings. The first is a valid negative result. The second is a failed precondition.
The test was differential: the same request was sent through the actual MCP boundary and compared against the baseline behavior. That matters because a unit test around an internal resolver could miss serialization, adapter, or JSON-RPC behavior. The failure was observed where an agent observes it.
Why “zero hits” is not harmless
An empty result normally carries useful information. It can mean that a known document does not contain the requested term. But an empty result from zero sources says nothing about the document.
This distinction is especially important in agent workflows because tool success often becomes an implicit control signal. A model is more likely to treat a successful tool reply as evidence that the requested operation happened. If the tool returns a normal success envelope for an invalid source, the model has to infer an infrastructure failure from a sentence that does not say one occurred.
That is a poor contract. It makes “the source is empty,” “the query is too narrow,” “the source is out of scope,” and “the selector is misspelled” look similar.
The narrow correction
The safest correction is small: validate an explicit source selector after the existing resolver has handled all supported aliases and special selectors. If the selector is not a known indexed source or a valid memory selector, return a structured UNKNOWN_SOURCE error.
The intended diagnostic is along these lines:
UNKNOWN_SOURCE:
source "..." is not indexed in scope "worktree".
Use the exact label or source handle returned by ctx_index/ctx_search,
or omit source to search available content.
The key compatibility rule is that a known source with no matching query must remain a normal successful zero-hit result. The change should not broaden a search, retry with another source, or reject valid forms such as source handles, #N aliases, normalized path labels, memory selectors, or the reserved decision selector.
The scope caveat
There is a subtle distinction between “unknown globally” and “not available in this scope.” A source may exist in another worktree while being unavailable to a worktree search in the current one. A global existence check can therefore still misclassify an out-of-scope source.
The experiment establishes the unknown-selector behavior. It does not, by itself, settle the final product semantics for every cross-worktree case. That contract needs to be decided explicitly. One reasonable design is to keep UNKNOWN_SOURCE as the public error while stating the effective scope in the diagnostic. Another is to introduce a separate SOURCE_OUT_OF_SCOPE code. The important property is that neither case should silently become a successful search over zero sources.
There is another practical constraint: the source selector is user-controlled input. Error formatting should keep the message bounded and single-line, rather than allowing arbitrary newlines or very long selectors to corrupt the diagnostic or journal output.
What this test does—and does not—prove
It proves a concrete contract mismatch in the tested baseline: an explicit selector that resolved to no indexed sources was reported as a successful zero-hit search through the real MCP interface.
It does not prove that every empty retrieval result is a bug. It does not prove that an agent will always hallucinate after this response. It does not justify automatically retrying with a broader query. The reproduction itself was run against the Context Mode 2.2.0 baseline; it is not evidence about behavior after a later fix.
The reproduction is tracked in Context Mode issue #1390. As of the latest issue update, the maintainer marked it fixed-on-main and linked fix commit 334094e; the issue says the change ships in the next release. That status should not be read as proof that every released version already contains the fix, so the tested baseline and the post-fix behavior remain separate claims.
The broader lesson is simple: retrieval tools should fail closed at the boundary between source resolution and search. “No matches” is evidence. “No source” is an error.
This article belongs to a series about making tool-using agents observable and conservative. The next article looks at the analogous failure on the action side: what to do when an external effect commits immediately before the agent process crashes.
Related: The Crash Window: Recovering AI Agent Actions Without Blind Retries.