Skip to content

The agent that grows with you

test(agent): trim the soft-interrupt salvage tests to two invariants

kshitijk4poor5d8523e1e507
diff --git a/tests/agent/test_close_interrupted_tool_sequence.py b/tests/agent/test_close_interrupted_tool_sequence.py
index 0b1ce90fa2e..23f7295c330 100644
--- a/tests/agent/test_close_interrupted_tool_sequence.py
+++ b/tests/agent/test_close_interrupted_tool_sequence.py
@@ -66,28 +66,3 @@ 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
diff --git a/tests/agent/test_interrupt_issuer_attribution.py b/tests/agent/test_interrupt_issuer_attribution.py
index 0702aad6898..1db2b27eb9f 100644
--- a/tests/agent/test_interrupt_issuer_attribution.py
+++ b/tests/agent/test_interrupt_issuer_attribution.py
@@ -10,7 +10,7 @@ import logging
import threading
from agent.interrupt_compat import request_hard_interrupt
-from agent.interrupt_control import interrupt_issuer, interrupt_skip_wording
+from agent.interrupt_control import interrupt_issuer
from tools.interrupt import set_interrupt
@@ -111,81 +111,3 @@ def test_soft_interrupt_with_tool_reason_is_attributed_to_the_system():
assert agent._interrupt_message is None
finally:
set_interrupt(False)
-
-
-def test_soft_interrupt_message_without_tool_reason_stays_a_user_stop():
- """Regression guard for the heuristic itself: a steer/new-message soft interrupt carries no
- system reason and must keep reading as a human stop."""
- agent = _bare_agent()
- try:
- agent.interrupt("what about the other file?")
- assert interrupt_issuer(agent) is None
- agent.clear_interrupt()
- agent.interrupt()
- assert interrupt_issuer(agent) is None
- finally:
- set_interrupt(False)
-
-
-def test_skip_wording_never_blames_the_user_for_a_system_stop():
- """The skipped-call notice is rendered from the RECORDED reason. A system abort must describe
- itself; only the genuinely user-initiated reasons may say the user did it (#130207)."""
- agent = _bare_agent()
- try:
- # System abort: the batch guard with its own reason.
- agent.interrupt("terminal batch tool did not complete", tool_reason="terminal batch aborted")
- wording = interrupt_skip_wording(agent)
- assert "user" not in wording.lower(), wording
- assert "terminal batch aborted" in wording
-
- # Genuine user stop keeps the user-facing wording.
- agent.clear_interrupt()
- agent.interrupt("next message")
- assert interrupt_skip_wording(agent) == "User sent a new message"
-
- # Reason-less turn where nothing was recorded at all.
- agent.clear_interrupt()
- 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)
diff --git a/tests/agent/test_replay_echo_retirement.py b/tests/agent/test_replay_echo_retirement.py
index 28ee5cb64ec..4eaa151b875 100644
--- a/tests/agent/test_replay_echo_retirement.py
+++ b/tests/agent/test_replay_echo_retirement.py
@@ -9,11 +9,7 @@ while keeping the row whenever removing it would form ``tool -> user`` — the s
provider failure ``close_interrupted_tool_sequence`` exists to prevent (#48879).
"""
-import pytest
-
-
LEGACY = "[response interrupted]"
-SCAFFOLD = "[This response was interrupted by a user correction.]"
NEW_PLACEHOLDER = "[interrupt: no assistant output for this turn]"
@@ -51,43 +47,6 @@ def _hidden_row(text, *, content="", api_content=None):
return row
-# ---------------------------------------------------------------------------
-# 1. Role-safe removal: the row is dropped outright.
-# ---------------------------------------------------------------------------
-
-def test_role_safe_legacy_row_is_dropped(tmp_path, monkeypatch):
- """assistant -> hidden(legacy) -> user: removal leaves a valid alternation,
- so the poisoned row must leave the replay entirely."""
- messages = [
- {"role": "user", "content": "do the thing"},
- _hidden_row(LEGACY),
- {"role": "user", "content": "continue"},
- ]
- out = _prepare(tmp_path, monkeypatch, messages)
- assert not any(
- m.get("role") == "assistant" and m.get("display_kind") == "hidden"
- for m in out
- ), f"legacy hidden row survived: {out}"
-
-
-def test_role_safe_scaffold_row_is_dropped(tmp_path, monkeypatch):
- """The pre-existing #81841 path keeps working under the widened filter."""
- messages = [
- {"role": "user", "content": "hi"},
- _hidden_row(SCAFFOLD),
- {"role": "user", "content": "continue"},
- ]
- out = _prepare(tmp_path, monkeypatch, messages)
- assert not any(
- m.get("role") == "assistant" and m.get("display_kind") == "hidden"
- for m in out
- ), f"scaffold ghost survived: {out}"
-
-
-# ---------------------------------------------------------------------------
-# 2. tool -> user protection: keep the row, neutralise the text.
-# ---------------------------------------------------------------------------
-
def test_tool_tail_row_is_kept_and_neutralised(tmp_path, monkeypatch):
"""assistant(tool_calls) -> tool -> hidden(legacy) -> user: dropping would
recreate tool -> user (#48879). The row stays, but its echoable text is
@@ -101,6 +60,7 @@ def test_tool_tail_row_is_kept_and_neutralised(tmp_path, monkeypatch):
{"role": "user", "content": "they do! increase the timing"},
]
out = _prepare(tmp_path, monkeypatch, messages)
+ assert messages[3]["api_content"] == LEGACY # durable row dict is never rewritten in place
hidden = [m for m in out
if m.get("role") == "assistant" and m.get("display_kind") == "hidden"]
@@ -116,39 +76,3 @@ def test_tool_tail_row_is_kept_and_neutralised(tmp_path, monkeypatch):
assert out[i + 1].get("role") != "user", (
f"role-alternation violation: tool -> user at index {i}: {out}"
)
-
-
-# ---------------------------------------------------------------------------
-# 3. Rows already carrying the post-fix placeholder are untouched.
-# ---------------------------------------------------------------------------
-
-def test_post_fix_placeholder_row_is_untouched(tmp_path, monkeypatch):
- """The current placeholder is not a hazard: a freshly written hidden row must
- not be retired or rewritten on every request."""
- messages = [
- {"role": "user", "content": "hi"},
- {"role": "assistant", "content": "", "display_kind": "hidden",
- "api_content": NEW_PLACEHOLDER},
- {"role": "user", "content": "continue"},
- ]
- out = _prepare(tmp_path, monkeypatch, messages)
- hidden = [m for m in out
- if m.get("role") == "assistant" and m.get("display_kind") == "hidden"]
- assert len(hidden) == 1, f"post-fix placeholder row was retired: {out}"
- assert hidden[0].get("api_content") == NEW_PLACEHOLDER
-
-
-def test_visible_interrupt_banner_is_kept(tmp_path, monkeypatch):
- """Caller-supplied banners (real diagnostic text) are not hidden and never
- match the filter — they stay exactly as written."""
- messages = [
- {"role": "user", "content": "hi"},
- {"role": "assistant",
- "content": "Operation interrupted: waiting for model response (4.9s elapsed)."},
- {"role": "user", "content": "continue"},
- ]
- out = _prepare(tmp_path, monkeypatch, messages)
- assert any(
- m.get("content", "").startswith("Operation interrupted: waiting")
- for m in out
- ), f"visible banner lost: {out}"