Skip to content

Feature: optionally preserve newlines in system-event previews (avoid flattening multi-line Markdown) #12850

@echo931

Description

@echo931

Summary

Today the Mattermost channel (and possibly other channels) emits an inbound activity systemEvent preview computed as:

preview = bodyText.replace(/\s+/g, " ").slice(0, 160)

This collapses all whitespace including \n, so multi-line Markdown appears as a single line in the system-event preview.

Importantly: the full inbound envelope body forwarded to the agent still preserves \n — this is only about the preview string.

Why this matters

When debugging or scanning inbound context, the system-event preview is often the most visible/compact representation. Flattening newlines makes it harder to see Markdown block structure (lists, quotes, code fences), and can be misinterpreted as “newlines were lost in ingestion”.

Proposal

Add an option (config or per-channel setting) to generate previews that preserve newlines, e.g.:

  • keep \n and normalize only spaces/tabs within each line
  • or produce a multi-line preview capped by max lines + max chars

Keep current behavior as default (compact 1-line preview), but allow opting into a “faithful preview” mode.

Evidence

Instrumented logs show rawText and bodyText preserve \n; only preview flattens due to /\s+/g.

Related

Closed as not-a-bug: #12247 (root cause was preview flattening, not inbound newline loss)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions