fix: trim the per-call ctx_batch_execute footer#922
Open
uwuclxdy wants to merge 1 commit into
Open
Conversation
Two footers were appended on every ctx_batch_execute call. The `Searchable terms for follow-up:` line now appears only when a query returned no matches, threaded via a `stats.anyMiss` out-parameter on `formatBatchQueryResults` that keeps its `string[]` return type. The `Results are scoped to this batch only` tip is now emitted once per server process instead of on every call; `resetBatchFooterState()` restores the flag so tests stay deterministic under vitest's shared fork pool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / Why / How
Root cause:
ctx_batch_executeappended two footers on every call. TheSearchable terms for follow-up:line fired wheneverstore.getDistinctiveTermsreturned terms, though the adjacent comment scopes it to "edge cases where follow-up is needed". Separately,formatBatchQueryResultsrepeated its> **Tip:** Results are scoped to this batch only...line on every non-global call. On a batch whose queries all matched, that is roughly 140 tokens of trailing footer with nothing to act on.Fix: two changes, each tying a footer to when it is actually useful.
formatBatchQueryResultstakes an optionalstatsout-parameter and setsstats.anyMisswhen a query returns no matches. The handler computesdistinctiveTermsonly whenbatchStats.anyMissis true, so the searchable-terms line shows only on the follow-up case the comment describes. The return type staysstring[], so existing callers are unaffected.query_scope: "global"line is unchanged. An exportedresetBatchFooterState()restores the flag so tests stay deterministic under vitest's shared fork pool; production never calls it.The flag lives inside the formatter for locality. It could equally sit at the handler call site if you prefer to keep the formatter free of module state.
Affected platforms
Test plan
npx tsc -b --noEmitclean.npx vitest run tests/core/server.test.tsgreen (500 tests). Added coverage:stats.anyMissisfalsefor an all-hit batch andtruewhen a query misses. A separate case asserts the scoping tip shows on the first batch call in a fresh process and is omitted on a second call in the same process.Checklist
npm testpassesnpm run typecheckpassesnextbranch (unless hotfix)Cross-platform notes
Our CI runs on Ubuntu, macOS, and Windows.
path.join()/path.resolve(), never hardcode/separatorsreadFileSync(0)breaks on Windowsos.tmpdir(), never hardcode/tmp