mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
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:
parent
f1c33c4d1c
commit
3b3da793da
1 changed files with 12 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue