Skip to content

Add outgoing-text sanitization before mdToMrkdwn - #8

Merged
TheGreatAxios merged 1 commit into
cl-5104-corbits-tag-add-loggerdebug-as-an-optional-diagnostic-onlyfrom
cl-5105-corbits-tag-outgoing-text-sanitization-sanitizets-before
Aug 2, 2026
Merged

Add outgoing-text sanitization before mdToMrkdwn#8
TheGreatAxios merged 1 commit into
cl-5104-corbits-tag-add-loggerdebug-as-an-optional-diagnostic-onlyfrom
cl-5105-corbits-tag-outgoing-text-sanitization-sanitizets-before

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Summary

  • New sanitize.ts: sanitizeOutgoingText cleans up known model-output artifacts before a reply is handed to mdToMrkdwn — a single wrapping HTML tag (<div dir="auto">...</div>), a leading leaked JSON/tool-call fence followed by real prose, a whole-reply fence wrapping plain prose that got mistakenly tagged as code, and backslash-escaped markdown punctuation (\_, \*, \`). Heuristic (regex/ratio checks, not a parser), deliberately biased toward "leave it alone" when ambiguous — see the module header comment for the full reasoning per heuristic.
  • detectInfraErrorReply recognizes when a reply IS a raw infra-error dump (not merely mentions one) — anchored full-dump signatures, or an error-shaped substring that dominates the trimmed text — so resolveOutgoingText can swap it for a neutral, user-actionable message before it reaches a Slack channel. The original is logged, not dropped, so the failure stays diagnosable.
  • Wired into tag-slack's toTagThread().post() ahead of the convertMarkdown branch added in Reconcile TagThread.post(): convertMarkdown opt-out + Block Kit blocks/unfurl suppression #6: sanitization targets text that should never have reached Slack in that shape at all (not markdown needing conversion), so it runs unconditionally — convertMarkdown: false still skips mdToMrkdwn, but not sanitization.

Test plan

  • CI: bun run typecheck && bun run test
  • packages/tag-slack/src/sanitize.test.ts: unit coverage for every heuristic (HTML unwrap, whole-fence unwrap, leading-fence drop, escape un-escaping, infra-error detection including the two "must NOT swallow" reviewer repros — prose that quotes or usefully reports a failure).
  • packages/tag-slack/src/wire.test.ts: new wireBot outgoing text sanitization suite covers the toTagThread().post() integration point — HTML-wrap stripped before mrkdwn conversion, an infra-error dump replaced with the neutral message (and logged), and sanitization still running when convertMarkdown: false.
  • Not run locally (sandboxed dev machine); tests will run in this repo's CI.

sanitizeOutgoingText strips a single wrapping HTML tag, drops a leading
leaked JSON/tool-call fence followed by real prose, unwraps a
whole-reply fence around plain prose, and un-escapes markdown escape
sequences. detectInfraErrorReply recognizes a raw infra-error dump (vs.
prose that merely mentions one) so resolveOutgoingText can swap in a
neutral, user-actionable message instead of letting it reach Slack
verbatim; the original is logged for diagnosis.

Wired into toTagThread's post() ahead of the convertMarkdown branch —
sanitization targets text that should never have reached Slack in that
shape at all, so it runs regardless of whether markdown conversion is
requested.
@TheGreatAxios
TheGreatAxios merged commit 62f8311 into cl-5104-corbits-tag-add-loggerdebug-as-an-optional-diagnostic-only Aug 2, 2026
1 check passed
@TheGreatAxios
TheGreatAxios deleted the cl-5105-corbits-tag-outgoing-text-sanitization-sanitizets-before branch August 2, 2026 20:42
TheGreatAxios added a commit that referenced this pull request Aug 2, 2026
sanitizeOutgoingText strips a single wrapping HTML tag, drops a leading
leaked JSON/tool-call fence followed by real prose, unwraps a
whole-reply fence around plain prose, and un-escapes markdown escape
sequences. detectInfraErrorReply recognizes a raw infra-error dump (vs.
prose that merely mentions one) so resolveOutgoingText can swap in a
neutral, user-actionable message instead of letting it reach Slack
verbatim; the original is logged for diagnosis.

Wired into toTagThread's post() ahead of the convertMarkdown branch —
sanitization targets text that should never have reached Slack in that
shape at all, so it runs regardless of whether markdown conversion is
requested.
TheGreatAxios added a commit that referenced this pull request Aug 2, 2026
…ion (#9)

* logger: add optional debug() as a diagnostic-only logging seam

warn() is for fail-soft conditions a host should see by default; debug()
is for diagnostic-only lines a host can opt into without adopting a full
log-level system. Optional so existing host loggers (which only
implement warn) keep working unchanged.

* Add outgoing-text sanitization before mdToMrkdwn (#8)

sanitizeOutgoingText strips a single wrapping HTML tag, drops a leading
leaked JSON/tool-call fence followed by real prose, unwraps a
whole-reply fence around plain prose, and un-escapes markdown escape
sequences. detectInfraErrorReply recognizes a raw infra-error dump (vs.
prose that merely mentions one) so resolveOutgoingText can swap in a
neutral, user-actionable message instead of letting it reach Slack
verbatim; the original is logged for diagnosis.

Wired into toTagThread's post() ahead of the convertMarkdown branch —
sanitization targets text that should never have reached Slack in that
shape at all, so it runs regardless of whether markdown conversion is
requested.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant