fix(responses): assign monotonic sequence_number to all synthetic events

Several Responses API event types now declare sequence_number with a
default of 0. The native synthetic streaming path constructed many
events without explicitly passing sequence_number, which caused them
to serialize as 0 and break the strict monotonic ordering guarantee
expected by some clients (e.g. Grok Build CLI).

Assign sequence_number to every event after the list is built so the
stream is guaranteed monotonic regardless of which helper produced
each event.

Co-authored-by: Yassin Kortam <yassin@berri.ai>
This commit is contained in:
Cursor Agent 2026-05-27 00:48:23 +00:00
parent f1c33c4d1c
commit 3b3da793da
No known key found for this signature in database

View file

@ -1212,6 +1212,18 @@ def _build_synthetic_response_events(
response=transformed,
)
)
# Assign monotonic sequence_number to every event. The helpers above
# build events without consistently passing sequence_number, and several
# event types now declare `sequence_number: int = 0` (default), which
# would otherwise serialize as 0 for most events and break the strict
# monotonic ordering guarantee expected by some Responses API clients.
for idx, event in enumerate(events):
try:
event.sequence_number = idx
except (AttributeError, ValueError):
pass
return events