Skip to content

fix: balance Telegram HTML chunks - #42

Merged
IceCodeNew merged 1 commit into
masterfrom
codex/balance-telegram-html-chunks
Jul 16, 2026
Merged

fix: balance Telegram HTML chunks#42
IceCodeNew merged 1 commit into
masterfrom
codex/balance-telegram-html-chunks

Conversation

@IceCodeNew

@IceCodeNew IceCodeNew commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • split Telegram HTML by parsed visible characters instead of raw payload offsets
  • close and reopen active formatting tags so every chunk is independently valid HTML
  • preserve newline characters at preferred split boundaries
  • cover nested tags, entities, adjacent tags, and line boundaries with regression tests

Root cause

The previous splitter only avoided cutting inside the text of a tag or entity. It did not track open tags across chunk boundaries, so long formatted content could produce an unclosed tag in one request and an orphaned closing tag in the next, causing Telegram Bot API rejection.

Validation

  • mise exec -- uv run --with pytest --with pytest-cov -- pytest --cov --cov-branch --cov-report=xml (546 passed; misses and partials unchanged)
  • prek run --all-files
  • CodeRabbit CLI review against master (0 findings after one valid newline-preservation fix)

Summary by CodeRabbit

  • Bug Fixes

    • Improved Telegram message splitting to respect visible-character limits while preserving valid HTML formatting in every message.
    • Prevented messages from being split inside HTML tags or entities.
    • Preserved leading line breaks when content is divided.
    • Daily briefings exceeding Telegram’s limit now fail instead of being split.
    • Authority forecasts are delivered independently and may be safely split across multiple formatted messages.
  • Documentation

    • Clarified Telegram delivery and message-sizing behavior.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@IceCodeNew, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2246050b-fc31-4c4b-8418-63098568d821

📥 Commits

Reviewing files that changed from the base of the PR and between 65ce112 and db6d2a8.

📒 Files selected for processing (3)
  • docs/design.md
  • tests/test_publishers.py
  • weather_briefing/publishers.py
📝 Walkthrough

Walkthrough

Telegram publisher message splitting now uses an HTML parser to enforce visible-character limits and produce independently valid HTML chunks. Tests cover tags, entities, nesting, and newlines, while design documentation specifies the delivery behavior.

Changes

Telegram HTML chunking

Layer / File(s) Summary
Parser-driven HTML chunking
weather_briefing/publishers.py
_split_message now delegates to _TelegramHTMLChunker, which counts visible characters, tracks open tags, and closes formatting tags in each chunk.
Chunking validation and delivery contract
tests/test_publishers.py, docs/design.md
Tests validate balanced HTML and entity splitting, and the design documentation describes visible-character counting and independently valid Telegram requests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly captures the main change: making Telegram HTML chunks balanced and valid.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/balance-telegram-html-chunks

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.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.63%. Comparing base (04fa7be) to head (db6d2a8).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #42   +/-   ##
=======================================
  Coverage   99.62%   99.63%           
=======================================
  Files          38       38           
  Lines        5944     5980   +36     
  Branches      323      325    +2     
=======================================
+ Hits         5922     5958   +36     
  Misses         15       15           
  Partials        7        7           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@IceCodeNew
IceCodeNew requested a review from Copilot July 16, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@IceCodeNew
IceCodeNew force-pushed the codex/balance-telegram-html-chunks branch from e0c877b to 65ce112 Compare July 16, 2026 15:04
@IceCodeNew
IceCodeNew marked this pull request as ready for review July 16, 2026 15:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@weather_briefing/publishers.py`:
- Around line 269-273: Update _finish_chunk to avoid appending or emitting a
chunk when the accumulated content has zero visible characters, including
trailing empty markup such as an empty nested tag. Preserve the existing
closing-tag and open-tag state handling for chunks containing visible text, and
ensure empty markup is not sent as a separate request.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 67b7debc-4b8f-4f02-b291-99c2dba6cd40

📥 Commits

Reviewing files that changed from the base of the PR and between 04fa7be and 65ce112.

📒 Files selected for processing (3)
  • docs/design.md
  • tests/test_publishers.py
  • weather_briefing/publishers.py

Comment thread weather_briefing/publishers.py
@IceCodeNew
IceCodeNew force-pushed the codex/balance-telegram-html-chunks branch from 65ce112 to db6d2a8 Compare July 16, 2026 16:00
@IceCodeNew
IceCodeNew merged commit 2cacd43 into master Jul 16, 2026
22 of 24 checks passed
@IceCodeNew
IceCodeNew deleted the codex/balance-telegram-html-chunks branch July 16, 2026 16:06
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.

2 participants