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(responses): preserve literal spans in citation escaping - #8811
Streaming Responses deliveries pass provider text through the memory-citation escaper. Ordinary '<' characters previously created a new lookahead slice and output fragment for each character, so an otherwise admitted delta could allocate many temporary string objects before pending-tail accounting ran.
Preserve unchanged text as spans in the original input and move only the scan cursor across ordinary characters.
Flush the unchanged span only when escaping a real tag mention or retaining an unresolved suffix; inspect a bounded body only for complete opening-tag candidates.
Preserve split opening/closing tags, real and ids-only citation blocks, malformed and oversized candidates, and the existing 16,384 UTF-16-unit hold limit.
Add bounded operation-count regressions, mixed-span and hold-boundary controls, and production bridge delta/done checks.
Verification
Recorded local validation:
Independent prepatch source-to-sink inspection and bounded offline measurements confirmed the allocation amplification on the current runtime. The original report's 8 MiB/process-exhaustion scenario was not reproduced.
For 2,048 / 8,192 / 32,768 ordinary '<' characters, the original makes 4,096 / 16,384 / 65,536 slice calls; the candidate makes 19 / 19 / 19. The original fails the new bounded-slice assertions, while the candidate preserves the same output and pending suffix.
A separate 256 KiB observation reduced additional JSC string objects from 526,816 to 21, and the observed RSS increase from 28,258,304 to 5,173,248 bytes. These are observations, not fixed CI thresholds or peak-memory guarantees.
bun run test tests/responses/citation-markers.test.ts tests/web-search/web-search-memory-citation.test.ts: 53 passed / 366 assertions, covering the helper, production Responses bridge and mocked web-search sidecar.
Fresh independent review of the immutable final tree found no blocking issue; it checked the source, direct consumers, budget boundaries, span/partial-tag behavior and test cleanup. The focused test counts above are the author's execution evidence, not a duplicate reviewer run.
Upstream validation for f50d4ad43febb3db23406cd5e105c1942b3bf6a1 passed: Cross-platform CI, Catalog async contracts, and PR gates. The PR CI ran its changed-test subset; skipped native-platform jobs are not claimed as executed. A second read-only review of this exact commit found no blocking correctness or test-isolation issue; it did not rerun tests or performance measurements. Installed/live application validation and explicit maintainer security review before merge remain separate.
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.
The security checkbox records implementation review; explicit maintainer security review remains required before merge.
Summary by CodeRabbit
Bug Fixes
Improved handling of streamed memory citations so incomplete or invalid citation blocks are held until they can be safely processed.
Preserved consistent citation escaping across different stream chunk sizes, including around long runs of angle brackets.
Kept final responses consistent with streamed updates, whether citation escaping is enabled or disabled.
No actionable comments were generated in the recent review.
Walkthrough
The streaming memory-citation escaper now accumulates unchanged text spans and holds candidate blocks until their closing tag and body validate them. Tests cover slicing, chunk-size parity, hold-limit boundaries, and Responses bridge output parity.
Changes: Memory citation streaming
Layer / File(s)
Summary
Span buffering and validation src/responses/citation-markers.ts:218-291, structure/transports/byte-accounting.md:148-154, tests/responses/citation-markers.test.ts:1,288-337,399-409
The escaper accumulates unchanged text and releases a candidate block only after validation. Documentation describes bounded lookahead and the 16,384-unit hold limit. Tests cover slice counts, chunking, hold-limit boundaries, and bridge delta, done-event, and buffered-JSON parity.
lidge-jun/opencodex#8044: Introduces the Responses memory-citation escaper and its streaming hold behavior, which this change updates.
Merge Risk: Minimal · up to f50d4
This change reduces slicing overhead when escaping memory citations in streamed responses and keeps the output unchanged. The risk of merging is low, and the focused tests are reported as passing.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "fix(responses): preserve literal spans in citation escaping" matches the main change. The raw summary and objectives both show that the memory-citation escaper in src/responses/citation-mar…
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 "fix(responses): preserve literal spans in citation escaping" matches the main change. The raw summary and objectives both show that the memory-citation escaper in src/responses/citation-markers.ts now keeps unchanged ordinary text as input spans instead of creating a separate slice at each '<'. The title names the Responses area, the fix type, and the core concept. It is concise, specific, and has no file lists or vague terms. Its wording follows the PR objectives directly.
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.
Reviewing files that changed from the base of the PR and between 595de1e and f50d4ad.
Files selected for processing: 3
src/responses/citation-markers.ts
structure/transports/byte-accounting.md
tests/responses/citation-markers.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.
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
Streaming Responses deliveries pass provider text through the memory-citation escaper. Ordinary '<' characters previously created a new lookahead slice and output fragment for each character, so an otherwise admitted delta could allocate many temporary string objects before pending-tail accounting ran.
Verification
Recorded local validation:
bun run test tests/responses/citation-markers.test.ts tests/web-search/web-search-memory-citation.test.ts: 53 passed / 366 assertions, covering the helper, production Responses bridge and mocked web-search sidecar.Upstream validation for
f50d4ad43febb3db23406cd5e105c1942b3bf6a1passed: Cross-platform CI, Catalog async contracts, and PR gates. The PR CI ran its changed-test subset; skipped native-platform jobs are not claimed as executed. A second read-only review of this exact commit found no blocking correctness or test-isolation issue; it did not rerun tests or performance measurements. Installed/live application validation and explicit maintainer security review before merge remain separate.Checklist
The security checkbox records implementation review; explicit maintainer security review remains required before merge.
Summary by CodeRabbit