Skip to content

Prevent color bleed and stale prefix on mid-message new entries#1680

Merged
bdraco merged 1 commit into
esphome:mainfrom
bluetoothbot:koan/log-parser-mid-message-reset
May 20, 2026
Merged

Prevent color bleed and stale prefix on mid-message new entries#1680
bdraco merged 1 commit into
esphome:mainfrom
bluetoothbot:koan/log-parser-mid-message-reset

Conversation

@bluetoothbot
Copy link
Copy Markdown
Contributor

@bluetoothbot bluetoothbot commented May 20, 2026

What does this implement/fix?

parse_log_message already appends an ANSI reset to the first line of a multi-line message when it carries color but no inline reset, so the color cannot bleed past that one line. A second log entry that appears later inside the same message did not get the same treatment — it was emitted as f"{timestamp}{line}" with no reset, even when its own color code had no closing terminator. Color could then leak into subsequent output.

The same branch also left the cached prefix / color_code from the first line in place. Any continuation lines that followed the mid-message new entry were rendered with the first entry's prefix and the first entry's color, not the new one's.

Apply the same _needs_reset / re-extract treatment to mid-message new entries so they behave like first-line entries.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

  • n/a

Pull request in esphome (if applicable):

  • n/a (client-only)

Checklist:

  • The code change is tested and works locally.
  • If api.proto was modified, a linked pull request has been made to esphome with the same changes.
  • Tests have been added to verify that the new code works (under tests/ folder).

Quality Report

Changes: 2 files changed, 63 insertions(+), 2 deletions(-)

Code scan: clean

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

parse_log_message gave the first line of a multi-line message a
trailing ANSI reset when it carried color but no inline reset, so
the color could not bleed past that one line. A second log entry
that appeared inside the same message got no such protection — it
was emitted as f"{timestamp}{line}" with no reset, even when its
own color code had no closing terminator.

The same branch also left the cached prefix and color from the
first line in place, so any continuation lines that followed the
mid-message entry were rendered with the wrong prefix and the
wrong color.

Apply the same _needs_reset / re-extract treatment to that branch
so mid-message new entries (and any continuations they own)
behave like first-line entries.
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 20, 2026

Merging this PR will not alter performance

✅ 40 untouched benchmarks


Comparing bluetoothbot:koan/log-parser-mid-message-reset (637d38f) with main (f544437)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ea8cc90) to head (637d38f).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1680   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines         4143      4156   +13     
=========================================
+ Hits          4143      4156   +13     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bdraco bdraco marked this pull request as ready for review May 20, 2026 12:20
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

Warning

Rate limit exceeded

@bdraco has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 44 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a517591b-6f6c-4374-b794-7f707e7c23bd

📥 Commits

Reviewing files that changed from the base of the PR and between f544437 and 637d38f.

📒 Files selected for processing (2)
  • aioesphomeapi/log_parser.py
  • tests/test_log_parser.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@bdraco bdraco merged commit fd12cf3 into esphome:main May 20, 2026
18 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes parse_log_message handling of “mid-message new entries” so they (1) get an ANSI reset appended when needed (preventing color bleed) and (2) refresh the cached prefix/color so subsequent continuation lines inherit from the correct entry.

Changes:

  • Append ANSI_RESET for mid-message new entries when _needs_reset(...) indicates it’s required.
  • Re-extract prefix / color_code for mid-message new entries so later continuation lines use the new entry’s context.
  • Add focused regression tests covering color-bleed prevention, prefix/color refresh, and strip_ansi_escapes=True.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
aioesphomeapi/log_parser.py Fix mid-message new-entry handling by adding reset-when-needed and updating cached prefix/color for subsequent continuation lines.
tests/test_log_parser.py Adds regression tests covering mid-message new-entry reset behavior and correct prefix/color inheritance (including strip-ANSI mode).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@bluetoothbot bluetoothbot deleted the koan/log-parser-mid-message-reset branch May 20, 2026 12:22
bluetoothbot added a commit to bluetoothbot/aioesphomeapi that referenced this pull request May 20, 2026
The single-line fast path returned the text with timestamp but skipped
the trailing-reset check applied on the multi-line first-line path
and in LogParser.parse_line. A single chunk like "\x1b[31mhello"
(color without inline reset) therefore left the terminal in red, so
the next print would inherit the colour — the same bleed bug fixed
by esphome#1680 for multi-line first lines.
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.

3 participants