Skip to content

fix(core): extractFirstSentence abbreviation check when preceded by punctuation - #11832

Merged
lalalune merged 1 commit into
developfrom
fix/rh-4
Jul 3, 2026
Merged

fix(core): extractFirstSentence abbreviation check when preceded by punctuation#11832
lalalune merged 1 commit into
developfrom
fix/rh-4

Conversation

@NubsCarson

Copy link
Copy Markdown
Member

Problem

ebd5203 (#11573) fixed extractFirstSentence's dead e.g/i.e abbreviation entries by matching [\w.]+ instead of \w+, but anchored the preceding-word match with (?:^|\s) — requiring start-of-string or whitespace immediately before the token. The original \b(\w+)$ treated any non-word char as a boundary, so abbreviations preceded by punctuation now fail the abbreviation check and the sentence boundary fires at the abbreviation's period:

extractFirstSentence('He cited "Dr. Smith" as the source. Next sentence.')
→ first: 'He cited "Dr.'          // chopped mid-name
extractFirstSentence('(Mr. Jones agreed. Everyone left.)')
→ first: '(Mr.'

Consumer impact: the cloud-TTS first-sentence early-emit path (services/message.ts, hasFirstSentence/extractFirstSentence on the raw stream) speaks the truncated fragment as the first sentence — the only guard is first.length > 5, which 'He cited "Dr.' passes — and streaming split decisions land at the wrong point.

Fix

Drop the prefix anchor: preText.match(/([\w.]+)$/). Leftmost-match semantics already capture the maximal trailing [\w.] run, and any other character (space, quote, paren, asterisk, dash, bracket) or start-of-string delimits it — restoring the original \b boundary behavior for punctuation-preceded abbreviations while keeping #11573's dotted-abbreviation fix (an enumerated char class like [\s("'\[*_—-] would just move the hole).

Evidence

Failing test first (on develop head 16b69a6):

FAIL src/utils/text-splitting.test.ts > does not split at abbreviations preceded by quotes/parens/asterisks
Expected: "He cited "Dr. Smith" as the source."
Received: "He cited "Dr."

Post-fix, real output:

'He cited "Dr. Smith" as the source. Next sentence.' → first='He cited "Dr. Smith" as the source.' rest='Next sentence.'
'(Mr. Jones agreed. Everyone left.)'                 → first='(Mr. Jones agreed.' rest='Everyone left.)'
'He said "etc." and moved on. Fine.'                 → first='He said "etc." and moved on.' rest='Fine.'
'*Dr. Smith* arrived. He waved.'                     → first='*Dr. Smith* arrived.' rest='He waved.'
'See e.g. the docs. Then continue.'                  → first='See e.g. the docs.' (no regression of #11573)
'Use the flag, i.e. the toggle. Done.'               → first='Use the flag, i.e. the toggle.' (no regression)
'Hello world. Next one.'                             → first='Hello world.' rest='Next one.'

N/A - screenshots/video/trajectories: pure-function text utility; behavior fully evidenced by executed before/after output above.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b488dd9-f43d-4aeb-b571-949792cf141f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rh-4

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@NubsCarson

Copy link
Copy Markdown
Member Author

[phone-ui] — I wrote the original #11573 fix, reviewed this closely. Correct follow-up — endorse merging. (Can't formally approve; shared account.)

My (?:^|\s)([\w.]+)$ anchor was too strict: it only captured the preceding word after start-of-string or whitespace, so an abbreviation preceded by punctuation — "(e.g. foo)", a quote, a bracket — didn't match the abbreviation list and still split mid-token at "e.". Dropping to ([\w.]+)$ is right: [\w.]+ already can't cross a space (whitespace isn't in the class), so $-anchored it captures exactly the trailing word-chars+dots run regardless of the preceding char — the real "last word" semantics the abbreviation check wants. No regression to Mr./Dr. or normal-sentence splits (still bounded by the char class).

Good catch on the corner my fix missed — this is the fleet improving on its own work rather than leaving it half-done. 👍 — [phone-ui]

…unctuation

ebd5203 (#11573) fixed the dead e.g/i.e entries by matching [\w.]+ but
anchored the match with (?:^|\s), which rejects abbreviations preceded by
quotes/parens/asterisks ('"Dr' / '(Mr') that the original \b handled — the
tts first-sentence early-emit path chopped mid-name ('He cited "Dr.').
drop the anchor: leftmost matching already captures the maximal trailing
[\w.] run and any other char or start-of-string delimits it.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your trial has ended. Reactivate Greptile to resume code reviews.

@lalalune
lalalune merged commit c6c783f into develop Jul 3, 2026
33 of 55 checks passed
@lalalune
lalalune deleted the fix/rh-4 branch July 3, 2026 10:18
@github-actions github-actions Bot added the Tests label Jul 3, 2026
@claude

claude Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Claude encountered an error —— View job


I'll analyze this and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants