aft_search: pattern without query fails in a parent-folder session
Summary
Sometimes the project root of a session is a parent folder: a folder that is not a Git repository and that contains child repositories. In such a session, aft_search with pattern and no query gives this error:
semantic_search: missing required param 'query'
The tool schema shows that query is optional when the call has pattern. When the project root of the session is a repository, the same call works.
Versions
- Seen on v0.66.0 (Linux, subc daemon mode, OpenCode plugin).
- The same check is in v0.64.0 and v0.65.0, and on
mainat 62e808f1b.
Cause
The plugin is correct. It sends pattern without query to the native semantic_search command.
For a parent-folder session, the native command goes to the parent route before the usual handler:
crates/aft/src/data_layer/parent_session/query.rs:547-553(route) sendssemantic_searchtoengine::search.crates/aft/src/data_layer/parent_session/engine.rs:165-171(search_with_disclosure) givesinvalid_requestwhenqueryis missing. It does not readpattern.
On main, the same code is at crates/aft/src/commands/parent_query/engine.rs:151.
The usual handler accepts pattern (crates/aft/src/commands/semantic_search/mod.rs:761, :1078).
Steps to reproduce
- Make a folder that is not a Git repository and that contains two or more Git repositories.
- Start a session with that folder as the project root.
- Call
aft_searchwith onlypattern(for example"fn main").
Result: semantic_search: missing required param 'query'.
Control: the same call with query added works. The same call also works when the project root of the session is one of the child repositories.
Effect
A session that controls work in many repositories usually has their parent folder as its project root. In such a session, each pattern-only search gives this error. The schema and the tool description tell the model that this call is correct. Thus the model cannot predict the error.
Possible repairs
- Make the parent route accept
patternwithoutquery, the same as the usual handler. It can do a lexical search of each child index. - Or, for a parent-folder session, refuse a pattern-only call with a clear message that
queryis necessary there.
Option 1 keeps the tool contract the same for all sessions.
Thanks for the precise report and the file-and-line trace. Your diagnosis was right: in a parent-folder session, the search went down a route that required query and never read pattern.
While fixing it, we found a second problem in the same place: when a call had both query and pattern, the parent route dropped pattern without saying so.
The fix, which goes into the next AFT release:
- A parent-folder session now accepts
patternalone,queryalone, or both, the same as a repository session. Each child repository gets the full request. - For a pattern-only call, the output is what a repository session prints, with paths relative to the parent folder and counts summed across the child repositories. Results from all children are ranked together, so a definition in one repository comes before a mention in another.
- A call with neither
querynorpatterngets the same refusal as in a repository session. - Search results in repository sessions are unchanged. We checked this byte for byte on our search benchmark.
We'll update this issue when the release is out.
Fixed in v0.67.0 by a54699a32 ("support parent folder pattern search"), and the fix is in v0.67.1 and v0.68.0. Thank you. Closing.