#19113: fix: prevent duplicated text after tag stripping
agents
size: S
trusted-contributor
Cluster:
Tool Execution and Error Handling
When HTML-like tags are stripped from assistant output, the remaining text could be duplicated on the same line.
Fix: Improve the deduplication logic to handle tag-stripped content correctly.
Recreated from #16813 with only relevant files.
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds same-line duplicate text detection to prevent duplicated assistant output after HTML-like tags (e.g., `</final>`) are stripped. The fix introduces a new `collapseSameLineDuplicates` function that uses a regex pattern to detect and remove sentence-level duplicates that occur on the same line.
**Key changes:**
- New `collapseSameLineDuplicates` function with regex `/(.{10,}?[.!?])\1/g` to detect duplicated sentences (minimum 10 characters, ending in `.`, `!`, or `?`)
- Modified `collapseConsecutiveDuplicateBlocks` to apply same-line deduplication before paragraph-level deduplication
- Updated return statements to preserve same-line deduplication results
- Added comprehensive test coverage for the new behavior
- Minor import reordering (type imports before regular imports)
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is well-designed with appropriate safeguards (10-char minimum to avoid false positives), comprehensive test coverage, and correct integration into the existing deduplication pipeline. The regex pattern correctly uses non-greedy matching and backreferences, and the changes preserve the original text when no duplicates are found
- No files require special attention
<sub>Last reviewed commit: 5981e3d</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#21695: fix(edit): include line numbers in duplicate match errors
by lbo728 · 2026-02-20
73.4%
#12325: fix: trim leading/trailing whitespace from outbound messages
by jordanstern · 2026-02-09
72.8%
#17244: fix: strip TTS tags from agent replies before delivery (#14652)
by robbyczgw-cla · 2026-02-15
72.5%
#13318: fix(agents): prevent sanitizeUserFacingText from rewriting conversa...
by hleliofficiel · 2026-02-10
71.9%
#16733: fix(ui): avoid injected newlines when tool output is hidden
by jp117 · 2026-02-15
71.9%
#10612: fix: trim leading blank lines on first emitted chunk only (#5530)
by 1kuna · 2026-02-06
71.5%
#13501: fix: extend assistant text dedup across message boundaries
by shakir-abdo · 2026-02-10
71.3%
#6094: auto-reply: ignore HTML comments in heartbeat check
by rudrapanchal81 · 2026-02-01
71.3%
#23073: fix(ui): strip reply directive tags from assistant messages in WebC...
by x4v13r1120 · 2026-02-22
70.9%
#12974: fix: intermittent (no output) reported by users
by vincentkoc · 2026-02-10
70.7%