diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.py index 691d796273f..b3a9cf5321c 100644 --- a/agent/agent_runtime_helpers.py +++ b/agent/agent_runtime_helpers.py @@ -729,7 +729,14 @@ def recover_with_credential_pool( # that seeded the pool. current_provider = (getattr(agent, "provider", "") or "").strip().lower() pool_provider = (getattr(pool, "provider", "") or "").strip().lower() - if current_provider and pool_provider and current_provider != pool_provider: + # Guard: skip credential pool recovery when the pool is scoped to a + # different provider than the agent. Only guard when the pool has a + # known provider — an empty pool provider means "unscoped" (applies to + # any provider). An empty agent provider is treated as a mismatch + # because swapping the pool's credentials would set base_url/api_key + # without fixing the empty provider field, leaving the agent in a + # corrupted state (provider="" model=""). + if pool_provider and current_provider != pool_provider: # Custom endpoints use two naming conventions for the SAME provider: # the agent carries the generic ``custom`` label while the pool is # keyed ``custom:`` (see CUSTOM_POOL_PREFIX). A literal string diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py index d2dc4745c03..0c4968b5fc6 100644 --- a/agent/chat_completion_helpers.py +++ b/agent/chat_completion_helpers.py @@ -2902,6 +2902,13 @@ def interruptible_streaming_api_call(agent, api_kwargs: dict, *, on_first_delta= except Exception: pass raise InterruptedError("Agent interrupted during streaming API call") + # Worker thread exited before the main thread's poll loop could check + # the interrupt flag. If the worker returned early due to an interrupt + # (e.g. _call_anthropic() detected _interrupt_requested and returned + # None), the InterruptedError above was never raised. Re-check the + # flag here so /stop is not silently swallowed. (#59999 area) + if agent._interrupt_requested: + raise InterruptedError("Agent interrupted during streaming API call (post-worker)") if result["error"] is not None: if deltas_were_sent["yes"]: # Streaming failed AFTER some tokens were already delivered to