# NousResearch/hermes-agent · Race condition leaks AI agents during session close

## Open now

- Nothing open on GitHub.

These issues and fixes address a race condition where closing a TUI session mid-build can orphan or leak a freshly constructed AIAgent. The work focuses on ensuring agents are properly cleaned up when session close races with the build process.

## TL;DR

- 5 member(s): 0 open issue(s), 2 closed issue(s), 0 open PR(s), 1 merged PR(s), 2 PR(s) closed without merging.
- A fix was merged to main in PR #131328. Verify it addresses your case.
- **Recommended:** read PR #131328 (and any competing PRs below) before filing. Confirm the merged change covers your symptom.

## Maintainer resolution verdict

- Internal-tracker verdict over this cluster's issue members: `partially_resolved` · deciding PR(s): `pr-131328`. This is distinct from the fix status above. Weigh it yourself.

## How this cluster was grouped

- Link evidence (`STRUCTURAL_PARTIAL`): some members are connected by structural evidence (shared changed files, or a closing/superseded reference); the rest are joined by an automated relevance judgement over their text.
- Members outside that structural core may belong to a different underlying problem.
- Pairwise link density `0.34`: the share of member pairs that carry a link, counting a structural link in full and a relevance-only link at 0.36. `1.00` means every pair is linked.

## Closed / duplicate issues

- #49852: TUI session.close can leak an AIAgent that finishes building concurrently
- #59218: TUI gateway leaks the freshly built AIAgent when the session is closed mid-build

## Prior & competing PRs

- **#49886: fix(gateway): close orphaned agent when session.close races _make_agent**. closed without merge · fix tier `suggested`
  - maintainer direction: category `superseded_by_pr`; implication `superseded`; refs `#49756`, `#49756`
  - _suggested-tier fix detail withheld; re-request with `?tier=all` to include it._
- **#131328: fix(tui): close agents that finish building after their session closed**. merged to main · fix tier `verified`
  - maintainer direction: category `merged`; implication `superseded`
  - files: `tests/tui_gateway/test_none_agent_turn_guard.py`, `tests/tui_gateway/test_profile_rebuild_commit.py`, `tests/tui_gateway/test_session_db_ownership_teardown.py`, `tests/tui_gateway/test_tui_gateway_server.py`, `tui_gateway/agent_callbacks.py`, `tui_gateway/server.py`, `tui_gateway/user_messages.py`
- **#49756: fix(tui): close agents orphaned during session build**. closed without merge
  - maintainer direction: category `merged_via`; implication `superseded`; refs `382c91204d`, `#131328`, `#131328`

## Fix status

- Merged to main in PR #131328 (cited above). No release data is tracked. Verify downstream.
- Fix last verified (merged) `2026-10-02`.
- Subsystem: `gateway`
