Skip to content

feat: unify agent isolation (--ignore-rules / --safe-mode) across TUI, messaging gateway, and API server - #88360

Draft
YuYigeng wants to merge 10 commits into
NousResearch:mainfrom
YuYigeng:agent/isolation-contract
Draft

feat: unify agent isolation (--ignore-rules / --safe-mode) across TUI, messaging gateway, and API server#88360
YuYigeng wants to merge 10 commits into
NousResearch:mainfrom
YuYigeng:agent/isolation-contract

Conversation

@YuYigeng

@YuYigeng YuYigeng commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Problem

--ignore-rules / HERMES_IGNORE_RULES and --safe-mode / HERMES_SAFE_MODE are honored by CLI chat and -z oneshot sessions, but not consistently by the other agent session entry points. On current main:

  • TUI session agents read only HERMES_IGNORE_RULES; HERMES_SAFE_MODE is ignored for the skip flags, and TUI background turns do not inherit the parent session's isolation.
  • The messaging gateway only supports an opt-in per-platform gateway.platforms.<platform>.skip_context_files config; both env vars are ignored on foreground turns and background tasks.
  • The API server constructs AIAgent without either skip flag and never reads the env vars.
  • CLI background tasks and ACP (Agent Client Protocol) sessions construct AIAgent without the skip flags.

Root cause

Isolation intent is resolved per entry point instead of once. --ignore-rules and --safe-mode are normalized to HERMES_IGNORE_RULES / HERMES_SAFE_MODE at CLI startup, but the other agent construction sites never resolve them, so AIAgent receives default False skip flags and injects rules/memory even when isolation was requested.

Scope

Included:

  • agent/isolation.py: one private resolver, precedence = explicit flag > env (HERMES_IGNORE_RULES, HERMES_SAFE_MODE; safe mode implies ignore-rules) > default False; returns (skip_context_files, skip_memory).
  • TUI session agent construction (tui_gateway/server.py, _make_agent) and TUI background/preview turns (_background_agent_kwargs).
  • Messaging gateway foreground turns and background tasks (gateway/run.py), including the agent cache signature so a cached AIAgent is never reused across an isolation change.
  • API server agent construction (gateway/platforms/api_server.py).
  • CLI background tasks (hermes_cli/cli_commands_mixin.py).
  • ACP session agents (acp_adapter/session.py).
  • Docs and per-entry behavior tests.

Not included (follow-ups): -z oneshot / Termux wiring (tracked in #72075, kept independent; can be refactored onto the shared resolver after it merges); cron / batch / curator / delegate worker policies (deliberate internal contracts); new config.yaml keys (public config surface, only if maintainers want it).

Design

One resolver as the single source of truth. For the gateway, isolation composes with the existing per-platform latency opt-out: skip_context_files = isolation OR platform config, skip_memory = isolation. Default behavior is unchanged everywhere.

Coverage matrix

Entry Before After Test
CLI chat env honored unchanged existing
CLI oneshot / Termux #72075 unchanged (merged separately) #72075
CLI background task neither both resolver contract + review
TUI session HERMES_IGNORE_RULES only both env vars test_make_agent_forwards_isolation_env
TUI background turn no inheritance inherits parent session test_background_agent_kwargs_inherits_isolation
Messaging gateway foreground per-platform config only config OR isolation; cache signature includes both skip flags test_skip_context_files_change_different_signature, test_skip_memory_change_different_signature, test_resolve_gateway_isolation_skip_flags
Messaging gateway background task neither both test_resolve_gateway_isolation_skip_flags
API server neither both test_create_agent_honors_isolation_env
ACP session neither both test_make_agent_forwards_isolation_env, test_make_agent_defaults_isolation_off

Compatibility

  • Default behavior: unchanged (resolver returns False when no flag/env is set).
  • Existing config: the gateway per-platform skip_context_files key keeps working and composes with isolation.
  • Public API: no public interface or config format changes.
  • Session cache: skip_memory now participates in the gateway agent cache signature, so an isolation toggle rebuilds the agent instead of silently reusing a stale one.

Related / competing work

Validation

Command Result
scripts/run_tests.sh tests/agent/test_isolation.py tests/gateway/test_isolation_skip_flags.py tests/gateway/test_agent_cache.py tests/acp/test_session.py passed
scripts/run_tests.sh tests/test_tui_gateway_server.py 573+ passed
scripts/run_tests.sh tests/gateway/test_api_server.py passed
ruff check on changed files passed
git diff --check clean

@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 comp/tui Terminal UI (ui-tui/ + tui_gateway/) area/config Config system, migrations, profiles P2 Medium — degraded but workaround exists needs-decision Awaiting maintainer decision before any implementation sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Aug 17, 2026
Single source of truth for --ignore-rules / --safe-mode (and their
HERMES_IGNORE_RULES / HERMES_SAFE_MODE env forms) across every agent
session entry point. Explicit flags win over env, safe mode implies
ignore-rules, default stays False, and both AIAgent skip flags always
move together.
TUI sessions previously read only HERMES_IGNORE_RULES for the skip
flags; safe mode (--safe-mode / HERMES_SAFE_MODE=1) now resolves to the
same skip_context_files + skip_memory contract via the shared resolver.
The messaging gateway only supported an opt-in per-platform
skip_context_files config. Isolation now composes with that config
(resolver OR platform opt-out for context files, resolver for memory),
and skip_memory joins skip_context_files in the agent cache signature so
a cached AIAgent is never reused across an isolation change.
API server agents now resolve HERMES_IGNORE_RULES / HERMES_SAFE_MODE
and pass skip_context_files + skip_memory to AIAgent, matching CLI, TUI,
and messaging gateway behavior.
State that HERMES_IGNORE_RULES and the agent-level effect of
HERMES_SAFE_MODE are honored by CLI, TUI, messaging gateway, and API
server sessions.
Background gateway tasks constructed AIAgent without the isolation skip
flags, so --ignore-rules / --safe-mode applied to foreground turns but
not to /background-style work. Extract _resolve_gateway_isolation_skip_flags
(shared by foreground and background paths) so both honor
HERMES_IGNORE_RULES / HERMES_SAFE_MODE and compose with the per-platform
context-file opt-out.
TUI background turns and preview restarts rebuild AIAgent from scratch;
the kwargs helpers now carry the parent session's skip_context_files /
skip_memory so an isolated session stays isolated in its background work.
CLI background tasks (/background) now resolve HERMES_IGNORE_RULES /
HERMES_SAFE_MODE through the shared isolation resolver, matching the
foreground chat agent.
ACP (Agent Client Protocol) sessions now pass skip_context_files and
skip_memory from the shared isolation resolver, so a daemon started with
--ignore-rules / --safe-mode applies the same contract to IDE/editor
sessions.
@YuYigeng
YuYigeng force-pushed the agent/isolation-contract branch from 0b99bbb to cc4fc38 Compare August 18, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants