Add outgoing-text sanitization before mdToMrkdwn - #8
Merged
TheGreatAxios merged 1 commit intoAug 2, 2026
Conversation
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
merged commit Aug 2, 2026
62f8311
into
cl-5104-corbits-tag-add-loggerdebug-as-an-optional-diagnostic-only
1 check passed
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sanitize.ts:sanitizeOutgoingTextcleans up known model-output artifacts before a reply is handed tomdToMrkdwn— 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.detectInfraErrorReplyrecognizes 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 — soresolveOutgoingTextcan 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.tag-slack'stoTagThread().post()ahead of theconvertMarkdownbranch 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: falsestill skipsmdToMrkdwn, but not sanitization.Test plan
bun run typecheck && bun run testpackages/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: newwireBot outgoing text sanitizationsuite covers thetoTagThread().post()integration point — HTML-wrap stripped before mrkdwn conversion, an infra-error dump replaced with the neutral message (and logged), and sanitization still running whenconvertMarkdown: false.