fix: ACP set_model no longer runs queued prompts inside the RPC (review follow-up)

set_session_model's `finally` awaited _drain_queued_prompts, so a prompt queued
during a failed (or slow) switch_model ran a whole agent turn inside the
session/set_model request; the client received the RequestError only after
that turn ended, and the drained turn streamed with no open prompt request.
Schedule the drain via _schedule_soon so it runs right after the response is
queued, on both the success and the error path.
This commit is contained in:
teknium1
2026-09-20 01:10:10 -07:00
committed by Teknium
parent 0b98de9af2
commit a23984887a
2 changed files with 43 additions and 1 deletions

View File

@@ -1041,7 +1041,10 @@ class HermesACPAgent(SlashCommandsMixin, acp.Agent):
finally:
with state.runtime_lock:
state.command_op = False
await self._drain_queued_prompts(state, session_id, self._conn)
# Drain AFTER this response is queued, never inside it: a prompt that arrived
# mid-switch would otherwise run a whole turn before the client sees the
# (possibly failed) switch result.
self._schedule_soon(lambda: self._drain_queued_prompts(state, session_id, self._conn))
logger.info(
"Session %s: model switched to %s via provider %s", session_id, resolved_model, requested_provider
)