Skip to content

The agent that grows with you

fix(agent): only relabel a prepared-batch abort as a batch timeout on timeout

kshitijk4poor15855870b269
diff --git a/agent/tool_executor.py b/agent/tool_executor.py
index 49e287eb30e..2595dbf7312 100644
--- a/agent/tool_executor.py
+++ b/agent/tool_executor.py
@@ -975,9 +975,12 @@ def _run_sequential_tool_execution_middleware(
# A timed-out shell may still be unwinding. Never release a later
# prepared command into overlapping execution.
prepared.batch.close()
- # Label the abort as the batch guard's own, not a user stop (#130207). No message:
- # ``_interrupt_message`` is what gateway/CLI re-queue as the user's next turn.
- agent.interrupt(tool_reason="terminal batch timeout")
+ if state == "timeout":
+ # Label the abort as the batch guard's own, not a user stop (#130207). No message:
+ # ``_interrupt_message`` is what gateway/CLI re-queue as the user's next turn. On the
+ # interrupted branch the stop is already published; re-interrupting would rebook it
+ # and null the user's queued message and redirect.
+ agent.interrupt(tool_reason="terminal batch timeout")
future.cancel()
if state == "timeout":
_interrupt_worker_tids(agent, worker_tid)
diff --git a/tests/agent/test_interrupt_issuer_attribution.py b/tests/agent/test_interrupt_issuer_attribution.py
index c47a649100e..6c35433bdbc 100644
--- a/tests/agent/test_interrupt_issuer_attribution.py
+++ b/tests/agent/test_interrupt_issuer_attribution.py
@@ -129,5 +129,25 @@ def test_soft_interrupt_with_tool_reason_is_attributed_to_the_system():
# Rendered verbatim: consumers substitute ``{name}`` with str.replace, never str.format.
agent._tool_interrupt_reason = "guard {x}"
assert interrupt_skip_wording(agent) == "Turn aborted — guard {x}"
+
+ # A USER stop that abandons the same wedged batch (grace elapsed) keeps its own attribution:
+ # the guard must not rebook it as a batch timeout nor drop the queued message / redirect.
+ set_interrupt(False)
+ agent.clear_interrupt()
+ agent.interrupt("fix the login bug")
+ agent._pending_redirect = "use the staging db"
+ prepared.future = concurrent.futures.Future()
+ with (
+ patch("agent.terminal_approval_batch.take_prepared_call", return_value=prepared),
+ patch.object(te, "_resolve_sequential_tool_timeout", return_value=60.0),
+ patch.object(te, "_emit_terminal_post_tool_call"),
+ patch.object(te.concurrent.futures, "wait", lambda fs, timeout=None: None),
+ ):
+ te._run_sequential_tool_execution_middleware(
+ agent, function_name="terminal", function_args={}, effective_task_id="t",
+ tool_call_id="c2", execute=lambda *_a, **_k: None)
+ assert interrupt_issuer(agent) is None
+ assert agent._interrupt_message == "fix the login bug"
+ assert agent._pending_redirect == "use the staging db"
finally:
set_interrupt(False)