Skip to content

The agent that grows with you

fix(agent): render concurrent skip notices from the recorded reason

alrcatraze8a478d15530
diff --git a/agent/interrupt_control.py b/agent/interrupt_control.py
index f61cd493434..7918a3cea09 100644
--- a/agent/interrupt_control.py
+++ b/agent/interrupt_control.py
@@ -46,13 +46,16 @@ def interrupt_skip_wording(agent) -> str:
"""Reason a tool call was skipped/cancelled, in words safe for tool output.
Derived from the RECORDED reason rather than the call site, so a system-initiated
- abort reads as one instead of asserting a user message that never existed (#130207)."""
+ abort reads as one instead of asserting a user message that never existed (#130207).
+ Braces are escaped: the wording is interpolated into notice templates, and a caller-
+ supplied reason must never become a format field."""
reason = getattr(agent, "_tool_interrupt_reason", None)
if not reason:
return "Turn interrupted"
if reason in USER_INTERRUPT_REASONS:
return _USER_STOP_WORDING.get(reason, str(reason))
- return f"Turn aborted — {str(reason).replace('_', ' ')}"
+ wording = f"Turn aborted — {str(reason).replace('_', ' ')}"
+ return wording.replace("{", "{{").replace("}", "}}")
def interrupted_during_api_call_reason(agent) -> str:
diff --git a/agent/tool_executor.py b/agent/tool_executor.py
index bfb768e3898..c572b8d1c74 100644
--- a/agent/tool_executor.py
+++ b/agent/tool_executor.py
@@ -303,7 +303,7 @@ class _ToolCallRef:
def emit_cancelled(self, agent, start_time: float) -> str:
"""Synthesize the ``cancelled`` result for a KeyboardInterrupt mid-tool and emit its hook."""
- message = "Tool execution cancelled by user interrupt"
+ message = f"Tool execution cancelled. {interrupt_skip_wording(agent)}"
result = json.dumps({"error": message, "status": "cancelled"}, ensure_ascii=False)
self.emit_post(
agent, result, duration_ms=int((time.time() - start_time) * 1000),
@@ -337,12 +337,12 @@ def _append_skipped_tool_results(
append and returns False on the first failed flush when ``stop_on_flush_failure``."""
for tc in tool_calls:
name = _tc_name(tc)
- result = content.format(name=name)
+ result = content.replace("{name}", name)
messages.append(make_tool_result_message(name, result, _pairing_tool_call_id(tc), effect_disposition="none"))
if hook_error_type is not None:
_ToolCallRef(name, {}, effective_task_id, (hook_id or _pairing_tool_call_id)(tc), []).emit_post(
agent, result,
- status="cancelled", error_type=hook_error_type, error_message="Tool execution skipped due to user interrupt",
+ status="cancelled", error_type=hook_error_type, error_message=f"Tool execution skipped. {interrupt_skip_wording(agent)}",
)
if flush_stage is not None:
flushed = _flush_session_db_after_tool_progress(agent, messages, stage=f"{flush_stage} {name}")
@@ -1510,8 +1510,8 @@ def _unfinished_tool_result(agent, ref: _ToolCallRef, *, timed_out: bool, timeou
outcome = dict(duration_ms=int((timeout_s or 0.0) * 1000), status="timeout", error_type="tool_timeout", error_message=function_result)
tool_duration, effect_disposition = float(timeout_s or 0.0), "unknown"
elif agent._interrupt_requested:
- function_result = f"[Tool execution cancelled — {ref.name} was skipped due to user interrupt]"
- outcome = dict(status="cancelled", error_type="keyboard_interrupt", error_message="Tool execution cancelled by user interrupt")
+ function_result = f"[Tool execution cancelled — {ref.name} was skipped. {interrupt_skip_wording(agent)}]"
+ outcome = dict(status="cancelled", error_type="keyboard_interrupt", error_message=f"Tool execution cancelled. {interrupt_skip_wording(agent)}")
tool_duration, effect_disposition = 0.0, None
else:
function_result = f"Error executing tool '{ref.name}': thread did not return a result"
@@ -1570,7 +1570,7 @@ def execute_tool_calls_concurrent(agent, assistant_message, messages: list, effe
print(f"{agent.log_prefix}⚡ Interrupt: skipping {num_tools} tool call(s)")
_append_skipped_tool_results(
agent, messages, tool_calls, effective_task_id,
- content="[Tool execution cancelled — {name} was skipped due to user interrupt]",
+ content=f"[Tool execution cancelled — {{name}} was skipped. {interrupt_skip_wording(agent)}]",
hook_error_type="user_interrupt",
flush_stage="cancelled tool result",
stop_on_flush_failure=False,
@@ -1767,7 +1767,7 @@ def _run_sequential_call(
agent.interrupt("keyboard interrupt")
_append_skipped_tool_results(
agent, messages, remaining_calls, ref.task_id,
- content="[Tool execution cancelled — {name} was skipped due to keyboard interrupt]",
+ content=f"[Tool execution cancelled — {{name}} was skipped. {interrupt_skip_wording(agent)}]",
)
raise
except Exception as tool_error:
diff --git a/tests/agent/test_interrupt_issuer_attribution.py b/tests/agent/test_interrupt_issuer_attribution.py
index 3552fc9c0cc..3ccde808bea 100644
--- a/tests/agent/test_interrupt_issuer_attribution.py
+++ b/tests/agent/test_interrupt_issuer_attribution.py
@@ -146,3 +146,44 @@ def test_skip_wording_never_blames_the_user_for_a_system_stop():
assert interrupt_skip_wording(agent) == "Turn interrupted"
finally:
set_interrupt(False)
+
+
+def test_concurrent_skip_wording_follows_the_recorded_reason():
+ """The concurrent batch path renders its skipped-call notices from the RECORDED reason
+ like the sequential path does — a system abort must not read as a user stop (#130207)."""
+ import types as _types
+ from agent.tool_executor import execute_tool_calls_concurrent
+
+ class _Agent:
+ _interrupt_requested = True
+ _tool_interrupt_reason = "lease lost"
+ quiet_mode = False
+ log_prefix = ""
+ _incremental_persistence_failed = False
+ def _vprint(self, *a, **k): pass
+ def _safe_print(self, *a, **k): pass
+ def _should_emit_quiet_tool_messages(self): return False
+ def _touch_activity(self, *a): pass
+
+ tc = _types.SimpleNamespace(function=_types.SimpleNamespace(name="terminal", arguments="{}"), id="c1")
+ messages = []
+ execute_tool_calls_concurrent(_Agent(), _types.SimpleNamespace(tool_calls=[tc]), messages, "t")
+ notice = messages[-1]["content"]
+ assert "user" not in notice.lower(), notice
+ assert "lease lost" in notice, notice
+
+
+def test_skip_wording_escapes_braces_from_free_form_reasons():
+ """A caller-supplied ``tool_reason`` may contain braces; the wording feeds notice
+ templates, so braces must survive as literals and never become format fields."""
+ agent = _bare_agent()
+ try:
+ agent.interrupt("stop", tool_reason="bad {oops} reason")
+ wording = interrupt_skip_wording(agent)
+ assert "{{oops}}" in wording # escaped for template interpolation
+ # The shipped notice shape renders cleanly through replace-based substitution.
+ content = f"[Tool execution cancelled — {{name}} was skipped. {wording}]"
+ out = content.replace("{name}", "terminal")
+ assert "{oops}" in out and "KeyError" not in out
+ finally:
+ set_interrupt(False)