Skip to content

fix(messages): preserve split CRLF through the empty-tool guard - #8968

Open
0disoft wants to merge 1 commit into
lidge-jun:devfrom
0disoft:task/messages-guard-lf-continuation
Open

0disoft wants to merge 1 commit into
lidge-jun:devfrom
0disoft:task/messages-guard-lf-continuation

Conversation

@0disoft

@0disoft 0disoft commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Verification

  • Windows x64, Bun 1.4.4, tested on upstream dev 6a4ae9d6e and fixed head 7399cc929.
  • bun run test -- --parallel=1 --test-name-pattern 'empty-tool guard settles' tests/claude-integration/messages-sse-guard-errors.test.ts on dev with the new regression: the coalesced case passed at status 200, and both split cases failed with a 502 settlement.
  • bun run test -- --parallel=1 tests/claude-integration/messages-sse-guard-errors.test.ts tests/server/messages-sse-error-filter.test.ts tests/server/messages-sse-error-lifecycle.test.ts tests/claude-integration/messages-native-combo-framing.test.ts on the fix: 150 passed, 0 failed, 1,735 assertions. All three layouts preserve the heartbeat and message_stop, settle at 200, and keep the upstream diagnostic out of client output.
  • bun run typecheck, bun run structure:check, bun run privacy:scan, bun scripts/file-size-ratchet.ts, and git diff --check passed.
  • Full-suite scope exception: local verification was scoped to framing, guard and lifecycle coverage because the full suite is disproportionately expensive on this Windows host. Required hosted checks still need to complete.

Additional review on 7399cc929

  • A local byte comparison covered 1,078 split positions across four line-ending layouts and both native stream paths (direct tap and payload rewrite). Every output matched its coalesced control byte for byte, preserved message_stop, and settled at 200.
  • Cancelling after the guard relayed the standalone LF invoked upstream cancellation once and returned the guard's retained-byte count to zero.
  • GitHub compared this head with dev 6a4ae9d6e at readiness submission. The branch was one commit ahead and zero behind. The original PR gates passed. Cross-platform CI and Catalog async contracts were awaiting maintainer authorization.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • Required local validation passed; commands, results, and any full-suite exception are documented.

  • I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of streamed Messages responses when carriage-return and line-feed delimiters arrive in separate chunks, preventing the line feed from being mistaken for part of the next frame.
    • Corrected model-echo behavior for error-event responses, preserving expected output and stream termination.
  • Tests
    • Added coverage for coalesced, split, and standalone line-ending scenarios, including heartbeat and terminal-message handling.
  • Documentation
    • Clarified how split delimiters and frame-origin tracking are handled.

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Messages native tool guard now preserves explicit frame origins and handles an LF that arrives after a CR delimiter in a later chunk. Integration tests cover coalesced, split-CRLF, and standalone-LF framing.

Changes: Messages SSE guard framing

Layer / File(s) Summary
Frame origin and split-CRLF handling
src/server/messages-native-tool-guard.ts, tests/claude-integration/messages-sse-guard-errors.test.ts, structure/data-planes/error-detail.md
enqueue calls hooks.output only when an original frame is supplied. The reader tracks a pending CR and relays a following LF separately. Integration tests cover three chunk-framing patterns, and the documentation describes the late-LF behavior.

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

Change: Bug fix

Merge Risk: Minimal · up to 7399c

This fixes a case where a CRLF delimiter split across chunks could make the empty-tool guard settle a response as 502 and lose the final message_stop. The change is narrow and has regression tests for the affected framing layouts. No merge-blocking risk is identified, though the full suite and hosted CI had not run.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix (preserving split CRLF through the empty-tool guard) and the affected area (messages). The changeset matches it: the guard now relays a pending LF after a split CRLF delimiter,…
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.
Full details: Title check

Explanation

The title names the fix (preserving split CRLF through the empty-tool guard) and the affected area (messages). The changeset matches it: the guard now relays a pending LF after a split CRLF delimiter, the stream reader tracks trailing CR across chunks, and regression tests cover split-CRLF framing for the empty-tool guard. The title is specific and concise, and it names the main change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 6a4ae9d and 7399cc9.

Files selected for processing: 3

  • src/server/messages-native-tool-guard.ts
  • structure/data-planes/error-detail.md
  • tests/claude-integration/messages-sse-guard-errors.test.ts

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ Required local validation passed; commands, results, and any full-suite exception are documented.
  • ✅ I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

✅ 4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently.
Maintainers: @lidge-jun @Ingwannu

Hygiene

✅ Deterministic PR hygiene checks passed.

@github-actions
github-actions Bot marked this pull request as ready for review November 19, 2026 18:05

This branch has not been deployed

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

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant