Skip to content

fix: strip internal tool-trace banner lines from chat gateway delivery - #55243

Closed
Stoltemberg wants to merge 1 commit into
NousResearch:mainfrom
Stoltemberg:fix/gateway-tool-trace-leak
Closed

fix: strip internal tool-trace banner lines from chat gateway delivery#55243
Stoltemberg wants to merge 1 commit into
NousResearch:mainfrom
Stoltemberg:fix/gateway-tool-trace-leak

Conversation

@Stoltemberg

Copy link
Copy Markdown
Contributor

What does this PR do?

Chat gateway final replies could contain internal tool-trace scaffold lines like ⚠️ 🛠️ \search repos (agent)` failed that are diagnostic noise, not user-facing content. Add a regex pattern to strip these lines from chat surfaces while keeping them on programmatic/raw surfaces (local, api_server, webhook`).

Related Issue

Fixes #54957

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/run.py: Add _TOOL_TRACE_BANNER_RE regex pattern that matches lines like ⚠️ 🛠️ `tool (agent)` failed. Apply it in _sanitize_gateway_final_response() after secret redaction and provider error classification.
  • tests/gateway/test_telegram_noise_filter.py: Add 2 regression tests:
    • test_tool_trace_banner_stripped_from_chat — banner stripped on Telegram
    • test_tool_trace_banner_kept_on_raw_surface — banner kept on local

How to Test

  1. Run uv run --extra dev python -m pytest tests/gateway/test_telegram_noise_filter.py::test_tool_trace_banner_stripped_from_chat tests/gateway/test_telegram_noise_filter.py::test_tool_trace_banner_kept_on_raw_surface -q — both pass
  2. Reproduce the original bug:
    from gateway.config import Platform
    from gateway.run import _sanitize_gateway_final_response
    raw = "Done.\n⚠️ 🛠️ \`search repos (agent)\` failed"
    assert _sanitize_gateway_final_response(Platform.TELEGRAM, raw) == "Done."

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs to make sure this is not a duplicate
  • My PR contains only changes related to this fix
  • I've run uv run --extra dev python -m pytest tests/gateway/test_telegram_noise_filter.py -q and all tests pass
  • I've added tests for my changes
  • I've tested on my platform: Windows

Documentation & Housekeeping

  • I've updated relevant documentation — or N/A
  • I've updated cli-config.yaml.example — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md — or N/A
  • I've considered cross-platform impact — regex is platform-agnostic
  • I've updated tool descriptions/schemas — or N/A

Chat gateway final replies could contain internal tool-trace scaffold
lines like '⚠️ 🛠️ `search repos (agent)` failed' that are diagnostic
noise, not user-facing content. Add a regex pattern to strip these
lines from chat surfaces while keeping them on programmatic/raw
surfaces (local, api_server, webhook).

Fixes NousResearch#54957
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jun 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: this fixes #54957 at the single gateway/run.py _sanitize_gateway_final_response site, which is a subset of the broader open PR #54959 (same author) that adds a shared strip_internal_tool_trace_lines() in gateway/platforms/base.py and wires it at three sanitization entry points (_sanitize_gateway_final_response, _prepare_gateway_status_message, and GatewayStreamConsumer._clean_for_display). Not a duplicate — #54959 covers more delivery surfaces. A maintainer should pick one; #54959 is the more complete coverage.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: LGTM

Clean fix — strips internal tool-trace banner lines from chat gateway delivery. The regex is well-targeted and the test coverage is thorough: verifies stripping on Telegram while preserving on raw surfaces (local, api_server).

Security: Prevents internal diagnostic scaffolding from leaking to users.
Testing: Two tests covering both the stripping and preservation paths.


Reviewed by Hermes Agent

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: LGTM

Strips internal tool-trace banner lines from chat gateway delivery. Uses regex to match diagnostic scaffolding lines like Warning: tool (agent) failed.

  • Clean fix with good test coverage
  • Well-scoped: 2 files, 27 additions

Reviewed 2 files, 27 additions. Approved.

@Stoltemberg

Copy link
Copy Markdown
Contributor Author

Closing — duplicate detected by alt-glitch bot. Consolidating into earlier PRs. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chat gateways leak internal tool-trace banners in outbound text

3 participants