Skip to content

fix(gateway): strip internal tool-trace banners from chat output - #54959

Open
ooiuuii wants to merge 1 commit into
NousResearch:mainfrom
ooiuuii:fix/chat-tool-trace-sanitize
Open

fix(gateway): strip internal tool-trace banners from chat output#54959
ooiuuii wants to merge 1 commit into
NousResearch:mainfrom
ooiuuii:fix/chat-tool-trace-sanitize

Conversation

@ooiuuii

@ooiuuii ooiuuii commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add a shared user-visible text sanitizer for internal tool-trace banner lines, for example:
\u26a0\ufe0f \U0001f6e0\ufe0f `search repos (agent)` failed
  • apply it to chat final-response/status sanitization while preserving raw programmatic surfaces
  • apply the same cleanup to GatewayStreamConsumer._clean_for_display() so streamed chat text gets the same backstop

Context

This ports the same outbound boundary covered by OpenClaw's recent Slack/Matrix fixes:

Fixes #54957.

Duplicate Audit

Related but not a duplicate of #38732: that PR blocks stale commentary after final delivery and fixes a Telegram duplicate-send path. This PR is a narrower outbound sanitizer for already-assembled chat text that contains internal tool-trace banner lines, and it applies to final responses, status messages, and streaming display cleanup across chat surfaces while preserving raw local/API/webhook diagnostics.

Also adjacent to #30574, #53334, and #54865, but those cover compression/status/error/runtime notices. This PR only strips the internal tool-trace banner shape shown above.

Tests

  • TMP=.tmp-pytest TEMP=.tmp-pytest TMPDIR=.tmp-pytest .\.venv\Scripts\python.exe -m pytest tests/gateway/test_telegram_noise_filter.py tests/gateway/test_stream_consumer.py -q (325 passed)
  • TMP=.tmp-pytest TEMP=.tmp-pytest TMPDIR=.tmp-pytest .\.venv\Scripts\python.exe -m ruff check gateway/platforms/base.py gateway/run.py gateway/stream_consumer.py tests/gateway/test_telegram_noise_filter.py tests/gateway/test_stream_consumer.py
  • git diff --check

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages P2 Medium — degraded but workaround exists labels Jun 29, 2026
@ooiuuii
ooiuuii force-pushed the fix/chat-tool-trace-sanitize branch from b88fb9e to 29b079c Compare June 29, 2026 18:20
@ooiuuii
ooiuuii force-pushed the fix/chat-tool-trace-sanitize branch from 29b079c to 7c20481 Compare July 6, 2026 01:53

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for covering both final and streamed output paths. The premise is still present on current main: gateway/run.py:434 only redacts secrets before returning final chat text, and gateway/stream_consumer.py:1647 reaches BasePlatformAdapter.strip_media_directives_for_display(), whose current implementation at gateway/platforms/base.py:3710-3718 only handles media directives.

Problems

  • gateway/run.py:445 adds banner stripping to _prepare_gateway_status_message(), but the PR adds no direct test for that status-delivery path. tests/gateway/test_telegram_noise_filter.py covers final responses; tests/gateway/test_stream_consumer.py covers streamed display.

Suggested changes

  • Add a status-helper regression test for a chat platform and a raw platform, using the same banner fixture and raw-surface contract as the final-response tests.

Automated hermes-sweeper review.

Comment thread gateway/run.py
@@ -443,7 +445,7 @@ def _prepare_gateway_status_message(platform: Any, event_type: str, message: str
if _gateway_surface_passes_raw_text(platform):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This adds a third sanitization boundary, but the new tests cover only final responses and streamed display. Please add a direct _prepare_gateway_status_message() regression test for both a chat surface and a raw surface.

@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 15, 2026
@ooiuuii
ooiuuii force-pushed the fix/chat-tool-trace-sanitize branch from 7c20481 to f07e002 Compare August 13, 2026 08:12
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:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform 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