Skip to content

fix(gateway): bind session context for plugin slash commands - #108704

Closed
KoNit-K wants to merge 1 commit into
NousResearch:mainfrom
KoNit-K:fix/plugin-command-session-context
Closed

KoNit-K wants to merge 1 commit into
NousResearch:mainfrom
KoNit-K:fix/plugin-command-session-context

Conversation

@KoNit-K

@KoNit-K KoNit-K commented Sep 12, 2026 •

Copy link
Copy Markdown

What does this PR do?

Plugin-registered gateway slash commands ran before the normal agent-turn session binding, so handlers saw empty HERMES_SESSION_* values. This change binds the inbound session context only while a resolved plugin handler runs, using the same source and canonical session key as the gateway turn path.

The binding covers synchronous and asynchronous handlers and restores the exact prior ContextVar state, including runtime cwd, in a finally block. Existing turn-level clear semantics and non-plugin command routing are unchanged.

Related Issue

Fixes #108698

Type of Change

  • ✅ Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/run_inbound.py — scopes session context around plugin slash-command invocation.
  • gateway/session_context.py — adds token-based restoration for nested session scopes while preserving explicit-clear behavior.
  • tests/gateway/test_plugin_command_session_context.py — covers sync, async, exception, and outer-context restoration behavior.

How to Test

  • scripts/run_tests.sh on the files in Changes Made — focused verification
  • scripts/run_tests.sh tests/gateway/test_plugin_command_session_context.py -q
  • scripts/run_tests.sh \
  • Result: 3 passed

Evidence

  • BEFORE: the focused probe was RED on origin/main before this change
  • AFTER: - [x] scripts/run_tests.sh on the files in Changes Made — focused verification — 3 passed
  • CONTROL: neighboring paths listed in How to Test still pass

Checklist

Code

  • ✅ I've read the Contributing Guide
  • ✅ My commit messages follow Conventional Commits
  • ✅ I searched for existing PRs to make sure this isn't a duplicate
  • ✅ My PR contains only changes related to this fix
  • ✅ I've run relevant tests locally (see How to Test)
  • ✅ I've added tests for my changes
  • ✅ I've tested on my platform: macOS

Documentation & Housekeeping

  • ✅ Documentation update: N/A unless noted in Changes Made
  • ✅ cli-config.yaml.example: N/A
  • ✅ CONTRIBUTING.md or AGENTS.md: N/A
  • ✅ Cross-platform impact considered
  • ✅ Tool descriptions/schemas: N/A

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state duplicate This issue or pull request already exists labels Sep 12, 2026
@alt-glitch

Copy link
Copy Markdown

This was generated by AI during triage.

Duplicate of #108703 — same fix for #108698 (bind the inbound session context around the plugin slash-command handler, restore in finally), filed a few minutes later. Earlier open #82776 also targets this path. Leaving open for a maintainer to pick; the ContextVar token-restore in session_context.py here is the main delta.

@teknium1

Copy link
Copy Markdown
Collaborator

Closing as superseded by #118845 (#118845), commit 35fdb4608a, which fixes the same defect (you are credited there as a co-author / in the PR body).

Thanks for the contribution — the underlying problem this PR addresses has been resolved on current main. If you believe this was closed in error, please comment and we'll reopen.

@teknium1 teknium1 closed this Sep 22, 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/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have 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.

Plugin slash commands run without session context (get_session_env('HERMES_SESSION_KEY') empty in command handlers)

3 participants