Skip to content

fix(channel): preserve UTF-8 across incremental event reads - #569

Open
cyq1017 wants to merge 1 commit into
mindfold-ai:mainfrom
cyq1017:codex/trellis-watch-utf8
Open

fix(channel): preserve UTF-8 across incremental event reads#569
cyq1017 wants to merge 1 commit into
mindfold-ai:mainfrom
cyq1017:codex/trellis-watch-utf8

Conversation

@cyq1017

@cyq1017 cyq1017 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Problem

The Core and CLI channel watchers decoded each appended buffer independently. A read boundary inside a multibyte UTF-8 character therefore produced replacement characters while leaving the JSON event parseable.

Change

Keep a streaming StringDecoder in each watcher's read state, reset it when the event file disappears or truncates, and cover both live implementations with split-byte regression tests.

Verification

  • Core focused watcher regression: 1 passed
  • CLI focused watcher regression: 1 passed
  • Core test suite: 347 passed, 1 skipped
  • CLI test suite: 1,709 passed
  • pnpm lint
  • pnpm typecheck
  • focused four-file Prettier check
  • git diff --check

Closes #568.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed channel event watching so multi-byte UTF-8 characters remain intact when data arrives in partial chunks.
    • Improved handling of event files that are truncated, rotated, replaced, or recreated.
  • Tests

    • Added coverage confirming complete message text is preserved across incremental reads in both CLI and core channel watchers.

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c4ed9fe9-06fd-4a55-b229-b2a658f8a8aa

📥 Commits

Reviewing files that changed from the base of the PR and between 64e6636 and df674eb.

📒 Files selected for processing (4)
  • packages/cli/src/commands/channel/store/watch.ts
  • packages/cli/test/commands/channel-watch.test.ts
  • packages/core/src/channel/internal/store/watch.ts
  • packages/core/test/channel/watch.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The Core and CLI channel watchers now preserve UTF-8 characters that span incremental file-read boundaries. New tests verify correct reconstruction of the character in both watchers.

Changes

Channel watcher UTF-8 handling

Layer / File(s) Summary
Core watcher decoding and validation
packages/core/src/channel/internal/store/watch.ts, packages/core/test/channel/watch.test.ts
The core watcher maintains a StringDecoder across reads, resets it when file state resets, and preserves split UTF-8 characters. Tests validate the complete character.
CLI watcher decoding and validation
packages/cli/src/commands/channel/store/watch.ts, packages/cli/test/commands/channel-watch.test.ts
The CLI watcher maintains and resets a StringDecoder during event-file changes. Tests validate split UTF-8 input across incremental writes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to df674

This change preserves UTF-8 characters across incremental event reads and includes regression coverage for both watchers. No actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: preserving UTF-8 characters across incremental event reads in channel watchers.
Linked Issues check ✅ Passed The changes satisfy issue #568. Both Core and CLI watchers use persistent StringDecoder state, reset it when required, and include regression tests for characters split across reads.
Out of Scope Changes check ✅ Passed All implementation and test changes directly support the UTF-8 watcher corruption fix in issue #568. No unrelated changes are identified.
✨ 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.

@cyq1017
cyq1017 marked this pull request as ready for review August 25, 2026 15:10
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.

Channel watchers corrupt UTF-8 characters split across incremental reads

1 participant