Skip to content

fix(gateway): route /background through active-session bypass#6935

Closed
Tranquil-Flow wants to merge 6 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/background-command-active-session
Closed

fix(gateway): route /background through active-session bypass#6935
Tranquil-Flow wants to merge 6 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/background-command-active-session

Conversation

@Tranquil-Flow

Copy link
Copy Markdown
Contributor

Summary

Fixes #6827

When /background <prompt> is sent during an active run, it interrupts the active conversation instead of spawning a parallel background task. This is a two-layer missing guard:

  1. gateway/platforms/base.py:1297 — the active-session bypass list (approve, deny, status, stop, new, reset) does not include background, so the command falls through to the interrupt path at line 1331
  2. gateway/run.py:1920-2039 — the running-agent guard also has no special handling for /background, so it hits running_agent.interrupt(event.text) at line 2034

Changes

  • Add "background" to the bypass list in gateway/platforms/base.py
  • Add early dispatch to _handle_background_command() in gateway/run.py before the default interrupt logic
  • Add regression test in tests/gateway/test_command_bypass_active_session.py following the existing test pattern for other bypass commands

Test plan

  • All 121 relevant tests pass (including new /background bypass test)
  • Send /background <prompt> while a Telegram session is active — should return "Background task started" without interrupting the main session
  • Verify /background still works normally when no session is active

Platform

Tested on macOS (Darwin 24.6.0), Python 3.14.2

cli.py saves pasted screenshots to ~/.hermes/images/ but _CACHE_DIRS
in credential_files.py only listed cache/images (the processed image
cache).  The images/ directory had no mount entry, so vision_analyze
and any tool referencing a clipboard image path silently failed inside
the hermes-aegis Docker container.

Add ("images", "images") to _CACHE_DIRS.  docker.py already iterates
get_cache_directory_mounts() so no changes are needed there.

Fixes NousResearch#6004
After the initial call and one retry both return empty content,
vision_tools.py was returning {"success": true, "analysis": "There was
a problem..."}.  Callers that branch on success would treat this as a
valid analysis.

Return {"success": false, "error": "..."} instead, consistent with
how all other failure paths in the same function behave.
…g_tool

Both tools passed the full os.environ (including all provider API keys
and tokens) to child processes via {**os.environ}.  A crashing subprocess
or one that logs its environment would expose every secret in the session.

The existing _sanitize_subprocess_env() helper in tools/environments/local.py
(with its 130+ var blocklist) was already used by LocalEnvironment and
process_registry but not by these two tools.  This fix extends it to:

  - tools/browser_tool.py     browser_env = {**os.environ}
  - tools/rl_training_tool.py env={**os.environ, 'TINKER_API_KEY': ...}

The sanitizer blocklist targets terminal subprocesses (e.g. codex CLI) so
it strips credentials these tools legitimately need.  Re-allow the minimum
required set via the _HERMES_FORCE_ prefix:

  - browser_tool:  BROWSERBASE_API_KEY, BROWSERBASE_PROJECT_ID,
                   BROWSER_USE_API_KEY, FIRECRAWL_API_KEY,
                   FIRECRAWL_API_URL, FIRECRAWL_BROWSER_TTL
  - rl_training:   TINKER_API_KEY, WANDB_API_KEY

Provider keys (OPENAI_API_KEY, ANTHROPIC_TOKEN, GOOGLE_API_KEY, etc.) are
now blocked as intended.

Related: NousResearch#3628 (broader env-scoping feature)
Adds plugins/memory/mnemoria/ with MnemoriaMemoryProvider — a MemoryProvider
adapter backed by the mnemoria PyPI package (mnemoria>=0.1.0).

- plugin.yaml declares pip_dependencies so hermes memory setup auto-installs
- provider.py imports from mnemoria.* (not the old unified_memory module)
- pyproject.toml gains [mnemoria] optional extra

Enable with: pip install 'hermes-agent[mnemoria]'
Then set memory.provider: mnemoria in ~/.hermes/config.yaml
When /background was sent during an active run, it was not in the
platform adapter's bypass list and fell through to the interrupt path
instead of spawning a parallel background task.

Add "background" to the active-session command bypass in the platform
adapter, and add an early return in the gateway runner's running-agent
guard to route /background to _handle_background_command() before it
reaches the default interrupt logic.

Fixes NousResearch#6827
Adds a regression test verifying that /background bypasses the
active-session guard in the platform adapter, matching the existing
test pattern for /stop, /new, /approve, /deny, and /status.
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #7123. The /background bypass fix (3 files) was cherry-picked onto current main with your authorship preserved. The unrelated changes (Mnemoria plugin, browser/vision/RL fixes) were not included — please submit those as separate PRs if you'd like them reviewed. Thanks!

@teknium1 teknium1 closed this Apr 10, 2026
@Tranquil-Flow

Copy link
Copy Markdown
Contributor Author

Ah yeah apologies @teknium1 have been having some issues lately when running multiple agents at the same time, sometimes commits from another agent get caught up in another agent and seems like my final review run didn't catch this - will be sure to be diligent about pruning out unrelated stuff in future. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Telegram /background can interrupt an active run instead of starting a background task

2 participants