Skip to content

fix(client): Join split surrogate pairs when encoding task parameters - #835

Merged
enochtangg merged 1 commit into
mainfrom
enochtang/stream-1999-handle-split-emoji-in-task-params
Oct 29, 2026
Merged

enochtangg merged 1 commit into
mainfrom
enochtang/stream-1999-handle-split-emoji-in-task-params

Conversation

@enochtangg

@enochtangg enochtangg commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

create_activation fails with UnicodeEncodeError when a string argument holds an emoji as two separate surrogate characters instead of one. This change catches that error, joins the pairs back into one character, and retries.

Python allows a string like "hi " + chr(0xD83D) + chr(0xDE00), for example after ast.literal_eval on escaped text. That isn't valid UTF-8, and msgpack encodes strings as strict UTF-8, so the producer raises before the task is sent. This caused SENTRY-5SB5 which caused the process_segment task to fail

Change:

  • Try to joined the split pair (e.g. "hi " + chr(0xD83D) + chr(0xDE00) becomes "hi 😀")
  • Try only runs after packb raises, so normal tasks encode exactly as before.
  • Each retry increments taskworker.producer.surrogates_repaired, tagged with namespace, taskname, and topic.

Refs STREAM-1999

A Python string can hold an emoji as two separate surrogate code points
(for example after `ast.literal_eval` on escaped text). msgpack encodes
strings as strict UTF-8, so `create_activation` raised
`UnicodeEncodeError` and the caller's task failed.

When msgpack raises `UnicodeEncodeError`, join the pairs back into one
character and retry. Lone halves can't be rebuilt, so they become
U+FFFD. The retry only runs after the error, so normal tasks are
unchanged. Each retry increments `taskworker.producer.surrogates_repaired`.

Refs STREAM-1999

Co-Authored-By: Claude <noreply@anthropic.com>
@enochtangg
enochtangg merged commit 6536a21 into main Oct 29, 2026
28 checks passed
@enochtangg
enochtangg deleted the enochtang/stream-1999-handle-split-emoji-in-task-params branch October 29, 2026 17:00
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.

2 participants