fix(router): bind fallback_kwargs before try for each iteration

Greptile: except used fallback_kwargs assigned only inside try, risking
UnboundLocalError or a stale dict from a prior loop iteration. Set
fallback_kwargs = kwargs before each try; first line in try remains
safe_deep_copy(kwargs).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Milan 2026-05-08 15:42:09 +03:00
parent 23c27fc305
commit eba6cc16ee
No known key found for this signature in database

View file

@ -123,6 +123,10 @@ async def run_async_fallback(
for mg in fallback_model_group:
if mg == original_model_group:
continue
# Bind before try so except always has a defined dict; reset each
# iteration so we never log a stale copy from a prior attempt. Until
# safe_deep_copy runs, this aliases the caller kwargs (same as legacy).
fallback_kwargs = kwargs
try:
# Keep each fallback attempt isolated from mutations made while
# preparing or sending a previous attempt.