Skip to content

perf(session-search): skip unused context enrichment via fields projection (salvage #63389) - #77637

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/63389-search-projection
Aug 3, 2026
Merged

perf(session-search): skip unused context enrichment via fields projection (salvage #63389)#77637
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/63389-search-projection

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

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-fetching max(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 to search_messages(): the context-enrichment loop is skipped when the projection doesn't include context, and both discard-callers opt in. Omitting fields preserves 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:

Case FULL PROJECTED Δ context queries
~20 matches, limit=100 1.44 ms 0.29 ms −79.6% 20 → 0
~100 matches, limit=100 7.20 ms 1.18 ms −83.6% 100 → 0
~100 matches, limit=20 1.69 ms 0.48 ms −71.4% 20 → 0

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

  • 204 passed (base 201 + 3 new); trivial auto-merge cherry-pick
  • Mutation check: forcing context_matches = matches (defeating the skip) fails test_search_projection_skips_context_enrichment_queries — the test counts context queries via sqlite trace callback, so it binds the mechanism
  • Adversarial: context loop mutates nothing but match["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 (id included in the tool's, excluded from the router's, matching actual usage)
  • Attribution chore chore: add frizikk to AUTHOR_MAP #77636 merged (frizikk → AUTHOR_MAP)

Closes #63389.

@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 3, 2026 12:06
@kshitijk4poor
kshitijk4poor disabled auto-merge August 3, 2026 12:06
@kshitijk4poor
kshitijk4poor merged commit f795d54 into NousResearch:main Aug 3, 2026
38 checks passed
@alt-glitch alt-glitch added type/perf Performance improvement or optimization P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard comp/dashboard Web dashboard / control panel UI (dashboard/, landing) area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Aug 3, 2026
@kshitijk4poor
kshitijk4poor deleted the salvage/63389-search-projection branch August 5, 2026 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/cli CLI entry point, hermes_cli/, setup wizard comp/dashboard Web dashboard / control panel UI (dashboard/, landing) P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/perf Performance improvement or optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants