refactor(agent): one builder for the interrupted_during_api_call exit reason

The summary-interrupt path added a second copy of the string the loop's
interrupt path builds; turn_explainers matches its prefix, so both now
share interrupted_during_api_call_reason().
This commit is contained in:
kshitijk4poor
2026-09-27 01:34:02 +05:30
committed by kshitij
parent 578bcd2349
commit 429f319d45
3 changed files with 13 additions and 13 deletions

View File

@@ -32,6 +32,12 @@ def interrupt_issuer(agent) -> Optional[str]:
return str(reason).strip().replace(" ", "_")
def interrupted_during_api_call_reason(agent) -> str:
"""Turn exit reason for an API call cut short by an interrupt (``turn_explainers`` matches the prefix)."""
issuer = interrupt_issuer(agent)
return f"interrupted_during_api_call({issuer})" if issuer else "interrupted_during_api_call"
def _fence_cancel_before_commit(fence, *, when_in_flight: bool, failure_log: str) -> None:
"""Call ``type(fence).cancel_before_commit(fence)`` when ``commit_in_flight`` matches.

View File

@@ -14,7 +14,7 @@ from typing import Any, Callable, List, Optional, Tuple
from agent.codex_responses_adapter import _summarize_user_message_for_log
from agent.delegation_context import is_dispatcher_owned_worker_context
from agent.interrupt_control import interrupt_issuer
from agent.interrupt_control import interrupted_during_api_call_reason
from agent.turn_failure_copy import exit_reason_failure, stamp_failure
from agent.context_compressor import _DB_PERSISTED_MARKER
from agent.message_content import flatten_message_text
@@ -160,15 +160,12 @@ def _resolve_budget_fallback(
try:
final_response = agent._handle_max_iterations(messages, api_call_count)
except InterruptedError:
# Same surfacing as an interrupted loop API call (handle_api_interrupt):
# the turn is interrupted, so the pending interrupt message is returned
# for requeue instead of being cleared behind a fallback summary.
# The turn ends interrupted, so the pending interrupt message is returned
# for requeue instead of being cleared behind a fallback summary. A redirect
# also ends it: the budget is spent, so there is no loop to restart into.
from agent.conversation_loop import INTERRUPT_WAITING_FOR_MODEL_PREFIX
interrupted = True
_issuer = interrupt_issuer(agent)
_turn_exit_reason = (
f"interrupted_during_api_call({_issuer})" if _issuer else "interrupted_during_api_call"
)
_turn_exit_reason = interrupted_during_api_call_reason(agent)
final_response = f"{INTERRUPT_WAITING_FOR_MODEL_PREFIX}{time.time() - _summary_start:.1f}s elapsed)."
# A kanban worker must record a terminal outcome whether or not a fallback path

View File

@@ -17,7 +17,7 @@ from dataclasses import dataclass
from typing import Any, Dict
from agent.display import KawaiiSpinner
from agent.interrupt_control import interrupt_issuer
from agent.interrupt_control import interrupt_issuer, interrupted_during_api_call_reason
from agent.turn_context_compaction import _reanchor
from agent.turn_truncation import boosted_output_cap
@@ -471,10 +471,7 @@ def apply_retry_restarts(
return _verdict("continue")
if interrupted:
_issuer = interrupt_issuer(agent)
_turn_exit_reason = (
f"interrupted_during_api_call({_issuer})" if _issuer else "interrupted_during_api_call"
)
_turn_exit_reason = interrupted_during_api_call_reason(agent)
return _verdict("break")
if _retry.restart_with_compressed_messages: