fix(gateway): restore MoA one-shot model override on failed turns - #53523
fix(gateway): restore MoA one-shot model override on failed turns#53523srojk34 wants to merge 1 commit into
Conversation
The MoA one-shot restore ran inside the try block after _handle_message_with_agent returned. When that call raised an exception (agent init failure, interpreter shutdown, OOM), the restore was skipped and the MoA model override stayed permanently on _session_model_overrides — silently routing all subsequent messages through the MoA reference fan-out with no user-visible indication. Move the restore to the finally block so it fires on every exit path (success, exception, interrupt). The restore data lives on the per-turn event object and would be lost if not consumed here.
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Moves the MoA one-shot model restore logic from the success path into the finally block so a failed turn (exception) still reverts the model override. Complements PR #53548 (which makes /moa one-shot only).
Looks Good
- The restore logic in
finallyis idempotent (pop-on-absent is harmless) - Placed before
_release_running_agent_stateto ensure cleanup ordering - Comprehensive test suite: tests for success, exception, None restore, and non-MoA turns
- The 4 test cases in
test_moa_one_shot_restore.pycover the key scenarios clearly
Reviewed by Hermes Agent
|
Merged via #53559 — your commit was cherry-picked onto current |
Summary
Root cause
The MoA one-shot restore ran inside the `try` block (line ~9032), after `_handle_message_with_agent` returns. When that call raises an exception (agent init failure, interpreter shutdown, OOM), execution jumps to the `finally` block which only calls `_release_running_agent_state` — the restore is skipped.
Since `_moa_restore_override` lives on the event object (not on the runner or session), it is permanently lost when the event goes out of scope. The next message creates a new event with no restore data, so the MoA override persists silently.
Impact
Changes
Test plan