From a8a27eeb7d18e07bab8186b40d5fe019d5b01eae Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Fri, 15 May 2026 19:05:37 +0000 Subject: [PATCH] =?UTF-8?q?stage-360:=20Opus=20follow-up=20=E2=80=94=20upd?= =?UTF-8?q?ate=20=5FENV=5FLOCK=20docstring=20to=20reflect=20narrow-lock=20?= =?UTF-8?q?semantics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Opus stage-360 review caught that the docstring at api/streaming.py:40-43 said 'around the entire agent run' which is no longer accurate after the narrow-lock refactor. The lock is now held only briefly for the env-mutation critical section; the agent runs outside the lock and the finally block re-acquires to atomically restore env vars. Docstring now points to both narrow-lock implementations as references: - _run_agent_streaming at line ~2719 (the original pattern) - profile_env_for_background_worker at api/profiles.py:715 (added stage-360) --- api/streaming.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/streaming.py b/api/streaming.py index 64825168..391c245a 100644 --- a/api/streaming.py +++ b/api/streaming.py @@ -40,7 +40,11 @@ from api.turn_journal import append_turn_journal_event_for_stream # Global lock for os.environ writes. Per-session locks (_agent_lock) prevent # concurrent runs of the SAME session, but two DIFFERENT sessions can still # interleave their os.environ writes. This global lock serializes the env -# save/restore around the entire agent run. +# save/restore — held only briefly across the env-mutation critical section, +# NOT for the entire agent run. The agent runs outside the lock; the finally +# block re-acquires to atomically restore env vars. See narrow-lock pattern +# in _run_agent_streaming (line ~2719) and profile_env_for_background_worker +# (api/profiles.py:715). _ENV_LOCK = threading.Lock()