You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(messages): preserve split CRLF through the empty-tool guard - #8968
Follow up on the post-merge finding on #8883. With tools: [], a CRLF comment delimiter split after its last CR can leave one LF in the guard's frame buffer. A subsequent model-echo frame with construction metadata then fails the guard's empty-buffer check, settling as 502 and losing message_stop.
Relay the pending LF as part of the preceding delimiter before scanning the next frame. Keep the origin check and tool inspection on the complete frame.
Windows x64, Bun 1.4.4, tested on upstream dev6a4ae9d6e 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 dev6a4ae9d6e 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.
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.
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: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tools: [], a CRLF comment delimiter split after its last CR can leave one LF in the guard's frame buffer. A subsequent model-echo frame with construction metadata then fails the guard's empty-buffer check, settling as 502 and losingmessage_stop.Verification
dev6a4ae9d6eand fixed head7399cc929.bun run test -- --parallel=1 --test-name-pattern 'empty-tool guard settles' tests/claude-integration/messages-sse-guard-errors.test.tsondevwith 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.tson the fix: 150 passed, 0 failed, 1,735 assertions. All three layouts preserve the heartbeat andmessage_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, andgit diff --checkpassed.Additional review on
7399cc929message_stop, and settled at 200.dev6a4ae9d6eat 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
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