Skip to content

refactor: drop persist_session plumbing + fix broken /btw mid-turn bypass - #16075

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-37175680
Apr 26, 2026
Merged

refactor: drop persist_session plumbing + fix broken /btw mid-turn bypass#16075
teknium1 merged 1 commit into
mainfrom
hermes/hermes-37175680

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Follow-up cleanup to PR #16053 (/btw as /background alias). Removes the `persist_session` kwarg that only existed for the old ephemeral /btw handler, and fixes a broken /btw mid-turn bypass (PR #16059) that called a method the refactor deleted.

Changes

  • `run_agent.py`: remove `persist_session: bool = True` kwarg, `self.persist_session` attr, and the `if not self.persist_session: return` short-circuit in `_persist_session`. Only the removed /btw handlers ever passed `False`; no other callers in production or tests.
  • `gateway/run.py`: remove the unreachable `if _cmd_def_inner.name == "btw"` block. Canonical name after alias resolution is always `background`, so the comparison could never match. It also called `_handle_btw_command`, which PR refactor: /btw is now an alias for /background #16053 deleted. The existing `name == "background"` branch above it already dispatches /btw correctly (via alias).
  • `tests/gateway/test_running_agent_session_toggles.py`: rewrite `test_btw_dispatches_mid_run` to mock `_handle_background_command` (the real dispatch target) instead of the deleted `_handle_btw_command`. Test still covers the same regression — /btw must not hit the "can't run mid-turn" catch-all — but against the current architecture.

Kept on purpose

  • `model_tools.py` `if enabled_toolsets is not None` (vs the previous truthy check) stays. PR refactor: /btw is now an alias for /background #16053 removed the only in-repo caller that passed `[]`, but the semantic is correct behavior and documented by a regression test (`test_no_tools_never_injects`). Reverting it would re-introduce the footgun where `enabled_toolsets=[]` silently means "all tools" instead of "no tools."

Validation

`scripts/run_tests.sh tests/gateway/test_running_agent_session_toggles.py tests/run_agent/test_run_agent.py tests/run_agent/test_413_compression.py tests/run_agent/test_860_dedup.py tests/tools/test_interrupt.py tests/cron/test_codex_execution_paths.py` — 339 passed.

Net: -25 / +13 lines.

Follow-up to PR #16053 (/btw as /background alias). Cleans up the
plumbing added exclusively for the old ephemeral /btw handler and
repairs a broken btw bypass that landed between my refactor and this
follow-up.

run_agent.py:
- Remove persist_session kwarg, instance attr, and _persist_session
  short-circuit. Only /btw ever passed persist_session=False; with
  /btw gone the default (always persist) is the only behavior anyone
  ever wanted.

gateway/run.py:
- Remove the unreachable 'if _cmd_def_inner.name == "btw"' block
  (PR #16059). Canonical name for a /btw message is 'background' after
  alias resolution — the comparison could never be true, and it called
  _handle_btw_command which no longer exists. The /background branch
  above it already dispatches /btw correctly.

tests/gateway/test_running_agent_session_toggles.py:
- Fix test_btw_dispatches_mid_run to mock _handle_background_command
  (the real dispatch target for /btw) instead of the deleted
  _handle_btw_command.
@teknium1
teknium1 merged commit 454d883 into main Apr 26, 2026
4 checks passed
@teknium1
teknium1 deleted the hermes/hermes-37175680 branch April 26, 2026 14:15
@alt-glitch alt-glitch added type/refactor Code restructuring, no behavior change P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery labels Apr 26, 2026
donald131 pushed a commit to donald131/hermes-agent that referenced this pull request May 2, 2026
…ass (NousResearch#16075)

Follow-up to PR NousResearch#16053 (/btw as /background alias). Cleans up the
plumbing added exclusively for the old ephemeral /btw handler and
repairs a broken btw bypass that landed between my refactor and this
follow-up.

run_agent.py:
- Remove persist_session kwarg, instance attr, and _persist_session
  short-circuit. Only /btw ever passed persist_session=False; with
  /btw gone the default (always persist) is the only behavior anyone
  ever wanted.

gateway/run.py:
- Remove the unreachable 'if _cmd_def_inner.name == "btw"' block
  (PR NousResearch#16059). Canonical name for a /btw message is 'background' after
  alias resolution — the comparison could never be true, and it called
  _handle_btw_command which no longer exists. The /background branch
  above it already dispatches /btw correctly.

tests/gateway/test_running_agent_session_toggles.py:
- Fix test_btw_dispatches_mid_run to mock _handle_background_command
  (the real dispatch target for /btw) instead of the deleted
  _handle_btw_command.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…ass (NousResearch#16075)

Follow-up to PR NousResearch#16053 (/btw as /background alias). Cleans up the
plumbing added exclusively for the old ephemeral /btw handler and
repairs a broken btw bypass that landed between my refactor and this
follow-up.

run_agent.py:
- Remove persist_session kwarg, instance attr, and _persist_session
  short-circuit. Only /btw ever passed persist_session=False; with
  /btw gone the default (always persist) is the only behavior anyone
  ever wanted.

gateway/run.py:
- Remove the unreachable 'if _cmd_def_inner.name == "btw"' block
  (PR NousResearch#16059). Canonical name for a /btw message is 'background' after
  alias resolution — the comparison could never be true, and it called
  _handle_btw_command which no longer exists. The /background branch
  above it already dispatches /btw correctly.

tests/gateway/test_running_agent_session_toggles.py:
- Fix test_btw_dispatches_mid_run to mock _handle_background_command
  (the real dispatch target for /btw) instead of the deleted
  _handle_btw_command.
dannyJ848 pushed a commit to dannyJ848/hermes-agent that referenced this pull request May 17, 2026
…ass (NousResearch#16075)

Follow-up to PR NousResearch#16053 (/btw as /background alias). Cleans up the
plumbing added exclusively for the old ephemeral /btw handler and
repairs a broken btw bypass that landed between my refactor and this
follow-up.

run_agent.py:
- Remove persist_session kwarg, instance attr, and _persist_session
  short-circuit. Only /btw ever passed persist_session=False; with
  /btw gone the default (always persist) is the only behavior anyone
  ever wanted.

gateway/run.py:
- Remove the unreachable 'if _cmd_def_inner.name == "btw"' block
  (PR NousResearch#16059). Canonical name for a /btw message is 'background' after
  alias resolution — the comparison could never be true, and it called
  _handle_btw_command which no longer exists. The /background branch
  above it already dispatches /btw correctly.

tests/gateway/test_running_agent_session_toggles.py:
- Fix test_btw_dispatches_mid_run to mock _handle_background_command
  (the real dispatch target for /btw) instead of the deleted
  _handle_btw_command.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…ass (NousResearch#16075)

Follow-up to PR NousResearch#16053 (/btw as /background alias). Cleans up the
plumbing added exclusively for the old ephemeral /btw handler and
repairs a broken btw bypass that landed between my refactor and this
follow-up.

run_agent.py:
- Remove persist_session kwarg, instance attr, and _persist_session
  short-circuit. Only /btw ever passed persist_session=False; with
  /btw gone the default (always persist) is the only behavior anyone
  ever wanted.

gateway/run.py:
- Remove the unreachable 'if _cmd_def_inner.name == "btw"' block
  (PR NousResearch#16059). Canonical name for a /btw message is 'background' after
  alias resolution — the comparison could never be true, and it called
  _handle_btw_command which no longer exists. The /background branch
  above it already dispatches /btw correctly.

tests/gateway/test_running_agent_session_toggles.py:
- Fix test_btw_dispatches_mid_run to mock _handle_background_command
  (the real dispatch target for /btw) instead of the deleted
  _handle_btw_command.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…ass (NousResearch#16075)

Follow-up to PR NousResearch#16053 (/btw as /background alias). Cleans up the
plumbing added exclusively for the old ephemeral /btw handler and
repairs a broken btw bypass that landed between my refactor and this
follow-up.

run_agent.py:
- Remove persist_session kwarg, instance attr, and _persist_session
  short-circuit. Only /btw ever passed persist_session=False; with
  /btw gone the default (always persist) is the only behavior anyone
  ever wanted.

gateway/run.py:
- Remove the unreachable 'if _cmd_def_inner.name == "btw"' block
  (PR NousResearch#16059). Canonical name for a /btw message is 'background' after
  alias resolution — the comparison could never be true, and it called
  _handle_btw_command which no longer exists. The /background branch
  above it already dispatches /btw correctly.

tests/gateway/test_running_agent_session_toggles.py:
- Fix test_btw_dispatches_mid_run to mock _handle_background_command
  (the real dispatch target for /btw) instead of the deleted
  _handle_btw_command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have type/refactor Code restructuring, no behavior change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants