Skip to content

The agent that grows with you

fix(agent): hide only the placeholder close, keep caller banners visible

alrcatraz15015d7cfeb9
diff --git a/agent/message_sanitization.py b/agent/message_sanitization.py
index 7ea09a0ae2b..200f492395f 100644
--- a/agent/message_sanitization.py
+++ b/agent/message_sanitization.py
@@ -290,10 +290,13 @@ def close_interrupted_tool_sequence(messages: list, final_response: Any = None)
alternation violation strict providers (Gemini, Claude) answer by hallucinating a
continuation. Mutates in place; True if a closing turn was appended.
- The synthetic row is hidden from the user: ``api_content`` sidecar carries the LLM-visible
- text (substituted at API-build time by ``substitute_api_content``), while ``content=""`` +
- ``display_kind="hidden"`` keep it out of rendered transcripts. Matches the
- ``_INTERRUPTED_PLACEHOLDER`` shape in ``turn_api_call.py``."""
+ Only the placeholder closes silently: with no real text (or just the bare interrupt
+ placeholder) the row is hidden from the user — ``api_content`` carries the LLM-visible
+ text (substituted at API-build time by ``substitute_api_content``), ``content=""`` +
+ ``display_kind="hidden"`` keep it out of rendered transcripts, matching the
+ ``_INTERRUPTED_PLACEHOLDER`` shape in ``turn_api_call.py``. A caller-supplied banner
+ (truncation notices, partial-delivery text) stays visible: it is the turn's only
+ user-facing explanation."""
last = messages[-1] if messages else None
if not isinstance(last, dict) or last.get("role") != "tool":
return False
@@ -301,12 +304,16 @@ def close_interrupted_tool_sequence(messages: list, final_response: Any = None)
from agent.message_metadata import append_message
from agent.agent_runtime_helpers import _INTERRUPTED_PLACEHOLDER
- append_message(messages, {
- "role": "assistant",
- "content": "",
- "display_kind": "hidden",
- "api_content": text.strip() or _INTERRUPTED_PLACEHOLDER,
- })
+ stripped = text.strip()
+ if not stripped or stripped == _INTERRUPTED_PLACEHOLDER:
+ append_message(messages, {
+ "role": "assistant",
+ "content": "",
+ "display_kind": "hidden",
+ "api_content": stripped or _INTERRUPTED_PLACEHOLDER,
+ })
+ else:
+ append_message(messages, {"role": "assistant", "content": stripped})
return True
diff --git a/tests/agent/test_close_interrupted_tool_sequence.py b/tests/agent/test_close_interrupted_tool_sequence.py
index 23f7295c330..0b1ce90fa2e 100644
--- a/tests/agent/test_close_interrupted_tool_sequence.py
+++ b/tests/agent/test_close_interrupted_tool_sequence.py
@@ -66,3 +66,28 @@ def test_user_tail_is_left_untouched():
assert close_interrupted_tool_sequence(messages, None) is False
assert len(messages) == 1
+
+
+def test_placeholder_close_is_hidden_from_rendered_transcripts():
+ """No real text (or just the bare placeholder) closes silently: content empty,
+ display_kind hidden, LLM still sees the placeholder through api_content."""
+ from agent.agent_runtime_helpers import _INTERRUPTED_PLACEHOLDER
+ messages = _tool_tail()
+ close_interrupted_tool_sequence(messages, None)
+ row = messages[-1]
+ assert row["role"] == "assistant"
+ assert row["content"] == ""
+ assert row["display_kind"] == "hidden"
+ assert row["api_content"] == _INTERRUPTED_PLACEHOLDER
+
+
+def test_caller_supplied_banner_stays_visible():
+ """Truncation and partial-delivery paths pass a real user-facing banner — it is
+ the turn's only explanation and must NOT be swallowed by the hidden shape."""
+ banner = "Response truncated — tool call arguments were cut off."
+ messages = _tool_tail()
+ close_interrupted_tool_sequence(messages, banner)
+ row = messages[-1]
+ assert row["role"] == "assistant"
+ assert row.get("display_kind") != "hidden"
+ assert row["content"] == banner