Skip to content

fix(delegation): keep child sessions out of parent env - #37368

Closed
BROCCOLO1D wants to merge 1 commit into
NousResearch:mainfrom
BROCCOLO1D:fix/37356-delegate-session-env
Closed

fix(delegation): keep child sessions out of parent env#37368
BROCCOLO1D wants to merge 1 commit into
NousResearch:mainfrom
BROCCOLO1D:fix/37356-delegate-session-env

Conversation

@BROCCOLO1D

Copy link
Copy Markdown
Contributor

Summary

Why

  • Child agents already have their own session_id for session logging, but mutating os.environ is process-global.
  • After a delegate_task call, later parent tools can inherit the child's HERMES_SESSION_ID even though the parent agent's session_id is unchanged.

Changes

  • gateway/session_context.py: add an update_environ switch to set_current_session_id while keeping the ContextVar update.
  • agent/agent_init.py: use child-local ContextVar session IDs for agents with parent_session_id without changing process env.
  • tests/run_agent/test_session_env.py: cover top-level env publication and subagent env preservation.

Validation

  • python -m pytest tests/run_agent/test_session_env.py -q -o 'addopts='
  • python -m pytest tests/gateway/test_session_env.py -q -o 'addopts='
  • python -m ruff check gateway/session_context.py agent/agent_init.py tests/run_agent/test_session_env.py
  • git diff --check

Scope

  • In scope: avoiding process-global session env clobbering for child agents while preserving ContextVar session identity.
  • Out of scope: migrating every existing os.environ reader to get_session_env().

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery tool/delegate Subagent delegation labels Jun 2, 2026
@BROCCOLO1D

Copy link
Copy Markdown
Contributor Author

Closing this as stale: there has been no activity or maintainer follow-up for over a week, and I don't want to leave inactive work open. Happy to reopen/rework if this becomes useful.

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 P2 Medium — degraded but workaround exists tool/delegate Subagent delegation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

delegate_task subagent overwrites os.environ["HERMES_SESSION_ID"] in parent process

2 participants