fix(agent): ensure turns are sorted (#2854)

# What does this PR do?

Ensures that session turns retrieved from the agent persistence layer
are sorted by their `started_at` timestamp, as the key-value store does
not guarantee order.

Closes #2852

## Test Plan

- [ ] Add unit tests
This commit is contained in:
Omer Tuchfeld 2025-07-22 19:24:51 +02:00 committed by GitHub
parent b5a6ecc331
commit 5e18d4d097
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -128,6 +128,11 @@ class AgentPersistence:
except Exception as e:
log.error(f"Error parsing turn: {e}")
continue
# The kvstore does not guarantee order, so we sort by started_at
# to ensure consistent ordering of turns.
turns.sort(key=lambda t: t.started_at)
return turns
async def get_session_turn(self, session_id: str, turn_id: str) -> Turn | None: