hermes-agent/acp_adapter
teknium1 603a68b918
fix(acp): isolate per-session approval callback via ContextVar
Concurrent ACP sessions in one Hermes process previously shared
tools.terminal_tool._approval_callback as a module-global, so session B
overwriting the slot could route session A's dangerous-command prompt
through B's callback (and vice versa). Within a single OS user this was
UX confusion rather than a cross-principal boundary break, but the
shared state is genuine concurrency sloppiness worth fixing.

Store the callback (and the sibling sudo password callback) in
ContextVars. Each asyncio task gets its own copy, so per-session
set_approval_callback calls no longer stomp on each other. ACP's prompt
handler now wraps loop.run_in_executor in contextvars.copy_context().run
so the per-session callback survives the hop into the worker thread —
asyncio does not propagate contextvars across the executor boundary on
its own, and this was verified empirically.

Regression tests reproduce the original primitive (two overlapping
sessions, each asserts it observes its own callback) and document the
run_in_executor contextvar contract the ACP fix relies on.

Reported by @xeloxa in GHSA-qg5c-hvr5-hjgr.
2026-04-21 03:30:19 -07:00
..
__init__.py feat: restore ACP server implementation from PR #949 (#1254) 2026-03-14 00:09:05 -07:00
__main__.py feat: restore ACP server implementation from PR #949 (#1254) 2026-03-14 00:09:05 -07:00
auth.py feat: restore ACP server implementation from PR #949 (#1254) 2026-03-14 00:09:05 -07:00
entry.py fix(acp): silence 'Background task failed' noise on liveness-probe requests (#12855) 2026-04-20 00:10:27 -07:00
events.py fix(acp): improve zed integration 2026-04-17 13:29:26 -07:00
permissions.py chore: remove ~100 unused imports across 55 files (#3016) 2026-03-25 15:02:03 -07:00
server.py fix(acp): isolate per-session approval callback via ContextVar 2026-04-21 03:30:19 -07:00
session.py fix(acp): improve zed integration 2026-04-17 13:29:26 -07:00
tools.py fix(acp): improve zed integration 2026-04-17 13:29:26 -07:00