perf(session-search): skip unused context enrichment via fields projection (salvage #63389) - #77637
Merged
kshitijk4poor merged 2 commits intoAug 3, 2026
Conversation
kshitijk4poor
enabled auto-merge (rebase)
August 3, 2026 12:06
kshitijk4poor
disabled auto-merge
August 3, 2026 12:06
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.
Salvage of #63389 by @frizikk — both commits cherry-picked verbatim (authorship preserved). No follow-up fixes needed: the verification pass came back clean.
What this does for users
Every session-search (the dashboard's search box AND the agent's session_search discovery tool) ran one extra SQL query PER MATCH to build a "surrounding context" window — which both consumers then threw away (the router copies only metadata/snippet fields; the tool hydrates its own windows via
get_anchored_view). With the router over-fetchingmax(limit*5, 50)matches and the tool scanning up to 300, that's up to hundreds of wasted queries per search.This adds an optional
fields=projection tosearch_messages(): the context-enrichment loop is skipped when the projection doesn't includecontext, and both discard-callers opt in. Omittingfieldspreserves the complete legacy result — no behavior change for any other caller (verified: the router and the tool are the only two production callers).Measured impact
Synthetic 50 sessions × 200 messages, FTS5 on, 15 reps, median:
Honest caveat: absolute numbers are from a small synthetic DB (~0.06ms/context query); the win scales with DB size and match count, but a single search is not a hot loop — this is per-user-search latency, not per-turn.
Verification
context_matches = matches(defeating the skip) failstest_search_projection_skips_context_enrichment_queries— the test counts context queries via sqlite trace callback, so it binds the mechanismmatch["context"]; both field tuples validated member-by-member against_SEARCH_MESSAGE_RESULT_FIELDS(a typo would 500 every dashboard search — none present); every field each consumer reads ⊆ its projection (idincluded in the tool's, excluded from the router's, matching actual usage)Closes #63389.