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:
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user