Skip to content

fix(browseros-agent): strip leaked model scaffold tokens from chat output#1782

Open
GriggsRice wants to merge 1 commit into
browseros-ai:mainfrom
GriggsRice:fix/strip-leaked-model-scaffold-tokens
Open

fix(browseros-agent): strip leaked model scaffold tokens from chat output#1782
GriggsRice wants to merge 1 commit into
browseros-ai:mainfrom
GriggsRice:fix/strip-leaked-model-scaffold-tokens

Conversation

@GriggsRice

Copy link
Copy Markdown

Summary

  • Some local models (observed via LM Studio) embed their own thinking-scaffold markers, e.g. <|channel|> or the malformed <channel|>, directly in regular text/reasoning output instead of a structured field. Nothing sanitized this before rendering, so raw protocol tokens showed up verbatim in the chat UI.
  • Add stripScaffoldTokens(), a regex-based sanitizer matching only bracket+pipe token shapes (<|word|>, <|word>, <word|>), so real HTML-like text and markdown tables are untouched.
  • Applied to both text and reasoning segments in getMessageSegments; segments that become empty after stripping are dropped entirely.

Test plan

  • bun run typecheck, bun run lint, bun run fallow — clean
  • bun test (app package) — clean, 11 new tests
  • Verified against the actual persisted conversation that showed the leak — tokens gone after the fix, re-rendered from the same stored (unfixed) data

🤖 Generated with Claude Code

…tput

Some local models (observed via LM Studio) embed their own
thinking-scaffold markers, e.g. "<|channel|>" or the malformed
"<channel|>", directly in regular text/reasoning output instead of a
structured field. Nothing sanitized this before rendering, so raw
protocol tokens showed up verbatim in the chat UI.

Add stripScaffoldTokens(), a regex-based sanitizer matching only
bracket+pipe token shapes ("<|word|>", "<|word>", "<word|>"), so real
HTML-like text and markdown tables are untouched. Applied to both
text and reasoning segments in getMessageSegments; segments that
become empty after stripping are dropped entirely.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

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