Bug Description
SMG reconstructs conversation item order using ORDER BY added_at, item_id in the normalized conversation item link table.
This is unsafe because added_at is not guaranteed to be unique for items in the same conversation:
the manual conversation-items API assigns the same added_at to every item in a batch
response persistence uses wall-clock time but does not guarantee uniqueness
some backends reduce timestamp precision further (for example, in-memory uses seconds, Redis uses milliseconds)
When added_at ties occur, ordering falls back to item_id, but item_id is not a deterministic sequence field and may be randomly generated.
As a result, /v1/conversations/{id}/items and next-turn conversation reconstruction can return items in an order that does not match production order.
Steps to Reproduce
N/A
Expected Behavior
Conversation items should be returned in the exact order they were produced.
Actual Behavior
Ordering depends on timestamp uniqueness and arbitrary item_id tie-breaking.
Component
model-gateway (core routing)
Routing Policy (if applicable)
None
Connection Mode
None
Configuration
Logs / Error Output
Environment
Cargo
Deployment Environment
Local development
Streaming Context
Additional Context
Provide 2 full test files, one is openai, one is smg
Testing flow: create a conv => response 1 with conv_id => response 2 with conv_id => get conv items => mcp call => get conv items
Pre-submission Checklist
Bug Description
SMG reconstructs conversation item order using ORDER BY added_at, item_id in the normalized conversation item link table.
This is unsafe because added_at is not guaranteed to be unique for items in the same conversation:
the manual conversation-items API assigns the same added_at to every item in a batch
response persistence uses wall-clock time but does not guarantee uniqueness
some backends reduce timestamp precision further (for example, in-memory uses seconds, Redis uses milliseconds)
When added_at ties occur, ordering falls back to item_id, but item_id is not a deterministic sequence field and may be randomly generated.
As a result, /v1/conversations/{id}/items and next-turn conversation reconstruction can return items in an order that does not match production order.
Steps to Reproduce
N/A
Expected Behavior
Conversation items should be returned in the exact order they were produced.
Actual Behavior
Ordering depends on timestamp uniqueness and arbitrary item_id tie-breaking.
Component
model-gateway (core routing)
Routing Policy (if applicable)
None
Connection Mode
None
Configuration
Logs / Error Output
Environment
Cargo
Deployment Environment
Local development
Streaming Context
Additional Context
Provide 2 full test files, one is openai, one is smg
Testing flow: create a conv => response 1 with conv_id => response 2 with conv_id => get conv items => mcp call => get conv items
Pre-submission Checklist