Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions gateway/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
_ADAPTER_DISCONNECT_TIMEOUT_SECS_DEFAULT = 5.0
_TELEGRAM_COMMAND_MENTION_RE = re.compile(r"(?<![\w:/])/([A-Za-z0-9][A-Za-z0-9_-]*)")

# Internal tool-trace banner lines that should be stripped from chat delivery.
# Matches lines like: ⚠️ 🛠️ `search repos (agent)` failed
# These are diagnostic scaffolding, not user-facing content.
_TOOL_TRACE_BANNER_RE = re.compile(
r"^[ \t]*(?:⚠️?\s*)?(?:🛠️?\s*)?`[^`]+`\s+failed\s*$",
re.MULTILINE,
)

_TELEGRAM_NOISY_STATUS_RE = re.compile(
r"(" # transient/auxiliary status that should stay in logs, not gateway chats
r"auxiliary\s+.+\s+failed"
Expand Down Expand Up @@ -426,6 +434,8 @@ def _sanitize_gateway_final_response(platform: Any, text: str) -> str:
redacted = _redact_gateway_user_facing_secrets(str(text))
if _looks_like_gateway_provider_error(redacted):
return _gateway_provider_error_reply(redacted)
# Strip internal tool-trace banner lines (e.g. ⚠️ 🛠️ `tool (agent)` failed)
redacted = _TOOL_TRACE_BANNER_RE.sub("", redacted).strip()
return redacted


Expand Down
17 changes: 17 additions & 0 deletions tests/gateway/test_telegram_noise_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,20 @@ def test_chat_gateways_redact_all_issue_23810_credential_shapes(platform, shape_
# Prose around the secret is preserved — redaction is surgical.
assert "here is the token you asked me to echo" in sanitized
assert sanitized.endswith("done.")


def test_tool_trace_banner_stripped_from_chat():
"""Internal tool-trace lines like ⚠️ 🛠️ `tool (agent)` failed must be
stripped from chat delivery. Regression test for #54957.
"""
raw = "Done.\n⚠️ 🛠️ `search repos (agent)` failed"
sanitized = _sanitize_gateway_final_response(Platform.TELEGRAM, raw)
assert sanitized == "Done."
assert "failed" not in sanitized


def test_tool_trace_banner_kept_on_raw_surface():
"""Programmatic surfaces (local, api_server) should keep raw trace text."""
raw = "Done.\n⚠️ 🛠️ `search repos (agent)` failed"
result = _sanitize_gateway_final_response("local", raw)
assert "failed" in result