Skip to content

fix(tools): scope session_search to current gateway chat - #50030

Open
the3asic wants to merge 1 commit into
NousResearch:mainfrom
the3asic:abm/session-search-current-scope
Open

fix(tools): scope session_search to current gateway chat#50030
the3asic wants to merge 1 commit into
NousResearch:mainfrom
the3asic:abm/session-search-current-scope

Conversation

@the3asic

@the3asic the3asic commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix session_search gateway scoping so Discord/Telegram/etc. gateway turns default to the current chat/thread instead of profile-wide history.

Key pieces:

  • persist a gateway recall/search scope key on session rows (scope_key) plus minimal routing metadata (origin_json)
  • split recall scope from the in-memory gateway session_key, so group/channel sessions can remain per-user while recall searches the whole current channel/thread
  • pass HERMES_RECALL_SCOPE_KEY through gateway contextvars, cached agents, API server, and tool execution paths
  • make gateway current-scope failures fail closed instead of silently falling back to global search
  • add schema v18 data migration to backfill v17 rows that accidentally stored the full per-user session key
  • keep scope='all' as the explicit opt-out for profile-wide/global history
  • hide internal routing metadata from dashboard session APIs

Verification

python -m py_compile hermes_state.py gateway/session.py tools/session_search_tool.py agent/tool_executor.py agent/agent_runtime_helpers.py run_agent.py gateway/run.py gateway/session_context.py

/home/the3asic/.hermes/hermes-agent/.venv/bin/python -m pytest \
  tests/test_hermes_state.py::TestSessionLifecycle::test_v18_migration_backfills_recall_scope_keys \
  tests/tools/test_session_search.py \
  tests/gateway/test_session_scope_persistence.py \
  tests/agent/test_session_search_scope_executor.py \
  tests/gateway/test_session_env.py \
  -q -o 'addopts='
# 80 passed, 7 warnings

/home/the3asic/.hermes/hermes-agent/.venv/bin/python -m pytest \
  tests/test_hermes_state.py \
  tests/hermes_state/test_get_anchored_view.py \
  tests/hermes_state/test_get_messages_around.py \
  -q -o 'addopts='
# 302 passed

git diff --check
/home/the3asic/.hermes/hermes-agent/.venv/bin/python scripts/check-windows-footguns.py --diff origin/main
# ✓ No Windows footguns found

Notes

A live dogfood DB was backed up before running the v18 migration, then migrated successfully:

  • backup: ~/.hermes/backups/state-before-recall-scope-v18-20260621T214508.db
  • migrated candidates: 3
  • remaining unmigrated candidates: 0

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists labels Jun 21, 2026
@the3asic
the3asic force-pushed the abm/session-search-current-scope branch from 6614e42 to 831d493 Compare June 21, 2026 13:52
@the3asic the3asic changed the title fix(tools): scope session search to current gateway chat fix(tools): scope session_search to current gateway chat Jun 21, 2026
@alt-glitch alt-glitch added comp/dashboard Web dashboard / control panel UI (dashboard/, landing) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state labels Jun 26, 2026
@lkz-de

lkz-de commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

One overlap note from rechecking nearby work: PR #57981 (fix(compression): preserve gateway origin on child sessions) looks like a distinct narrow bug fix rather than a duplicate of this PR.

My current read is:

  • #57981 fixes metadata preservation for compression-created child sessions on the rotation fallback path in agent/conversation_compression.py
  • #50030 handles broader current-chat / session_search recall scoping

The meaningful overlap looks operational rather than conceptual: both PRs currently add tests/gateway/test_session_scope_persistence.py.

So if both lanes move forward, I would expect a manual merge on that shared test file — the two versions cover different scenarios and should both survive intact — rather than a duplication issue in the production logic.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform area/sessions Session lifecycle, resume, persistence, history labels Jul 14, 2026
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/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/dashboard Web dashboard / control panel UI (dashboard/, landing) comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants