Skip to content

query: show the expansion state of hits and the content-budget cut (#52, #53) - #54

Merged
coconutbird merged 2 commits into
mainfrom
fix/search-expanded-fields
Nov 10, 2026
Merged

coconutbird merged 2 commits into
mainfrom
fix/search-expanded-fields

Conversation

@coconutbird

Copy link
Copy Markdown
Member

Part of the semctx docstore cutover (napbat/semctx#103). Closes #52 and #53.

  • Search hits show their expansion state: [expanded], or [not expanded: <reason> — <next step>].
  • top_k and grep max outside 1 to 1000 are refused in the client.
  • When the server cut a search or a grep to its content budget (X-Semctx-Result-Truncated: content-budget), the result starts with one note line that names the budget and a next step.

semctx feat/docstore-cutover sends these fields and the header. Merge this PR with the semctx cutover PR (see the cutover runbook in napbat/docstore#36).

…x outside 1-1000 (#52, #53)

#52: semctx (napbat/semctx#94, commit 1cb9e81) sets `expanded` on each hit
of a Symbol search, and `expansionReason` when the hit keeps its chunk
snippet. semctl did not read the fields, so an agent could not tell a chunk
from the whole symbol. SearchHit now reads both fields, and the hit renderer
ends the header line of each such hit with `[expanded]` or
`[not expanded: <reason> — <next step>]`. The MCP result of search_codebase
and `semctl search --expand` both use this renderer.

The server limits the snippet text of a search to 32 KiB
(Search:ContentBudgetBytes). The client budget of 30,000 characters from #39
was a stand-in for that budget. It could show a hit that the server expanded
as a 4-line snippet. The client budget is removed, and an expanded search
prints each snippet in full.

#53: semctx (napbat/semctx#93) answers 400 to a topK or grep max outside 1 to
1000 instead of clamping it. query::search and query::grep now refuse such a
value with an invalid-argument error before a request. The prompt hook does
not search when SEMCTX_HOOK_TOP_K is above 1000.

The tool docs, the argument schema, the CLI help, and the skill describe the
limits, the server budgets, and the expansion markers.

Fixes #52.
Fixes #53.
…tent budget (#52)

semctx sends `X-Semctx-Result-Truncated: content-budget` on POST /v1/search
and GET /v1/codebases/{id}/grep when its content budget cut a snippet or
line, left a Symbol hit unexpanded, or dropped later results
(SearchResponseHeaders in semctx 1cb9e81 and feat/docstore-cutover). The
status stays 200, and semctl did not read the header, so an agent took a
shortened result as complete.

Client::post_read_budgeted and Client::get_budgeted return the result with
the ResultTruncation that the header reports. query::search and query::grep
start the result with one note line that names the budget (32 KiB of
snippet text, or 32 KiB of path and line text with 512 bytes for each line,
by default) and a next step: a narrower query, a lower top_k, or no expand
for a search; a narrower path or pattern, or a lower max for a grep. A value
other than content-budget is reported as the server sent it. The MCP tools
and `semctl search` use the same functions.

Refs #52.
@coconutbird
coconutbird merged commit 9851c0e into main Nov 10, 2026
6 checks passed
@coconutbird
coconutbird deleted the fix/search-expanded-fields branch November 12, 2026 08:58
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.

search_codebase does not show which expanded hits are chunks, and why

1 participant