Skip to content

agent: Fix a UTF-8 boundary panic in the agent streaming parser#58432

Merged
Anthony-Eid merged 1 commit into
mainfrom
anthony/fr-56-zed-8y1-start-byte-index-7811-is-not-a-char-boundary-it-is
Jun 3, 2026
Merged

agent: Fix a UTF-8 boundary panic in the agent streaming parser#58432
Anthony-Eid merged 1 commit into
mainfrom
anthony/fr-56-zed-8y1-start-byte-index-7811-is-not-a-char-boundary-it-is

Conversation

@Anthony-Eid

Copy link
Copy Markdown
Contributor

The parser stores emitted byte offsets between partial tool-call parses. Because partial JSON can be repaired differently as more bytes arrive, a byte offset that was valid in an earlier string can land inside a multibyte character in a later string. We now normalize those offsets with find_char_boundary before slicing.

Added property tests covering boundary-sensitive write/edit streaming sequences to prevent regressions.

Fixes Sentry ZED-8Y1 / 7523469866.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed a crash that could occur while streaming agent edits containing multibyte characters.

The parser stores emitted byte offsets between partial tool-call parses.
Because partial JSON can be repaired differently as more bytes arrive, a
byte offset that was valid in an earlier string can land inside a
multibyte character in a later string. We now normalize those offsets
with `find_char_boundary` before slicing.

Added property tests covering boundary-sensitive write/edit streaming
sequences to prevent regressions.

Fixes Sentry ZED-8Y1 / 7523469866.

Release Notes:

- Fixed a crash that could occur while streaming agent edits containing
  multibyte characters.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jun 3, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Jun 3, 2026
@maxdeviant maxdeviant changed the title agent: Fixes a UTF-8 boundary panic in the agent streaming parser agent: Fix a UTF-8 boundary panic in the agent streaming parser Jun 3, 2026
@Anthony-Eid Anthony-Eid added this pull request to the merge queue Jun 3, 2026
Merged via the queue into main with commit 19b7625 Jun 3, 2026
44 checks passed
@Anthony-Eid Anthony-Eid deleted the anthony/fr-56-zed-8y1-start-byte-index-7811-is-not-a-char-boundary-it-is branch June 3, 2026 15:51
@Anthony-Eid

Copy link
Copy Markdown
Contributor Author

/cherry-pick preview
/cherry-pick stable

zed-zippy Bot added a commit that referenced this pull request Jun 3, 2026
…) (cherry-pick to preview) (#58451)

Cherry-pick of #58432 to preview

----
The parser stores emitted byte offsets between partial tool-call parses.
Because partial JSON can be repaired differently as more bytes arrive, a
byte offset that was valid in an earlier string can land inside a
multibyte character in a later string. We now normalize those offsets
with `find_char_boundary` before slicing.

Added property tests covering boundary-sensitive write/edit streaming
sequences to prevent regressions.

Fixes Sentry ZED-8Y1 / 7523469866.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX

checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed a crash that could occur while streaming agent edits containing
multibyte characters.

Co-authored-by: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com>
zed-zippy Bot added a commit that referenced this pull request Jun 3, 2026
…) (cherry-pick to stable) (#58452)

Cherry-pick of #58432 to stable

----
The parser stores emitted byte offsets between partial tool-call parses.
Because partial JSON can be repaired differently as more bytes arrive, a
byte offset that was valid in an earlier string can land inside a
multibyte character in a later string. We now normalize those offsets
with `find_char_boundary` before slicing.

Added property tests covering boundary-sensitive write/edit streaming
sequences to prevent regressions.

Fixes Sentry ZED-8Y1 / 7523469866.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX

checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed a crash that could occur while streaming agent edits containing
multibyte characters.

Co-authored-by: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com>
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 8, 2026
…industries#58432)

The parser stores emitted byte offsets between partial tool-call parses.
Because partial JSON can be repaired differently as more bytes arrive, a
byte offset that was valid in an earlier string can land inside a
multibyte character in a later string. We now normalize those offsets
with `find_char_boundary` before slicing.

Added property tests covering boundary-sensitive write/edit streaming
sequences to prevent regressions.

Fixes Sentry ZED-8Y1 / 7523469866.

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed a crash that could occur while streaming agent edits containing
multibyte characters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants