Applied AI
Agents SDK session history can reorder on PostgreSQL
Test conversation order when Agents SDK SQLAlchemySession writers use different PostgreSQL time zones.
October 31, 2026
An agent needs conversation turns in the order they were added, especially when a later message depends on an earlier reasoning or tool item. An Agents SDK issue reports that SQLAlchemySession on PostgreSQL orders items by a created_at column before the row ID. The column is a timestamp without time zone. The reporter demonstrates two writers with different PostgreSQL TimeZone settings adding three turns, then reading them back out of order; pop_item() removes a turn other than the last one added.
Know the session promise
The Agents SDK session guide describes automatic conversation history and defines pop_item() as removing the most recent item. Its SQLAlchemy session guide presents PostgreSQL as a production backend. An ordering defect at that boundary is not cosmetic: it can change the input assembled for the next run or undo the wrong turn during a correction.
Reproduce across writers
In a staging database, create one session ID and append numbered turns through two connection pools. Record each pool's PostgreSQL time zone, the row IDs and timestamps, get_items() order, get_items(limit=1), and pop_item() result. Test both a common UTC setting and a deliberately mixed setting. Around daylight-saving transitions, also test the repeated local hour if the database and driver configuration can produce it. Use no live customer conversation data for this probe.
Contain the risk before rollout
Standardize connection time zones and verify append order in integration tests. If existing rows may have mixed timestamp semantics, do not rewrite history blindly; assess affected sessions and a supported migration path. Keep the issue and installed SDK version in the release gate, and retest after a vendor fix. The proposed remedies in the issue are options for maintainers, not a shipped patch.
Adovo’s view
Memory has an order, not just a collection of messages. When that order drifts, the agent can sound coherent while reasoning from the wrong past. Test the storage contract at the same boundary where users expect continuity.
