What this thread does
Compare PostgreSQL connection time zones before patching OpenAI Agents session ordering; the reporter's same-zone control restores sample order, while a general repair must also account for compaction (RyanLin5967, openai/openai-agents-python #5459, inchang-ing).
Do first: run SHOW TimeZone; on each writer connection and compare the results; this read-only SQL diagnostic is adapted from RyanLin5967's UTC-versus-America/Toronto reproduction.
Diagnostic: pops the wrong item
Evidence: pinned SDK code, RyanLin5967's reproduction, inchang-ing's compaction review and yuee3's fork report. Not for: general Postgres timestamp display offsets.
Findings
- Affected setup: RyanLin5967's October 30 issue #5459 names Agents SDK 0.24.0 and the same implementation on main, SQLAlchemy 2.1.6, asyncpg 0.32.0 and PostgreSQL 17.11, on macOS 26.6.2 arm64/Python 3.12.13. The sample uses only the session API, without a model provider. It appends two UTC turns and then one through an America/Toronto connection; history puts turn 3 first, and the limit-one read and pop select turn 2.
- Cause in official code: the maintainers' sqlalchemy_session.py at cd26bbbc defines a timezone-naive timestamp with CURRENT_TIMESTAMP and sorts by created_at before id in reads and pops. RyanLin5967 explains that PostgreSQL's transaction-start timestamp is converted to the connection's wall clock; differing connection zones or a repeated daylight-saving hour can make later rows sort earlier. An id tie-breaker only addresses equal timestamps, not reversed ones (#5459).
- Reported control, not historical-data repair: in the reproducer, giving both connections the same time zone returns the expected order. Its UTC engine uses
connect_args={"server_settings": {"timezone": "UTC"}}. This is a source-backed control for that reproduction, not evidence that changing a setting repairs existing rows or all concurrent transaction orderings (RyanLin5967).
- Compaction constrains the repair: inchang-ing's October 30 review warns that changing only ORDER BY leaves timestamp-based compaction boundaries and copied summary timestamps inconsistent. The pinned official implementation contains those timestamp comparisons and copies the replaced tail's timestamp into its summary. In an October 31 reply in the issue, RyanLin5967 argues an id-based repair can also change the tail query and prefix boundary under the existing session lock; this is a design discussion, not maintainer approval (#5459).
- Fork and release status: yuee3's November 1 comment links a fork branch that changes ordering to id and says it includes memory/compaction regression coverage. The author says no upstream PR could be opened. The fork is a proposal; upstream PR #5645 merged 2026-11-09 and closed issue #5459. Reads, pops and compaction now use generated message IDs consistently. The 0.25.0 release PR #5394 merged 2026-11-18 and lists the fix (status checked 2026-11-18).
Limits
One original session-API reproduction is supported by separate code review and fork work, not multiple production incidents. The daylight-saving case is illustrated by timestamp conversion, not a reported end-to-end deployment rollback. SQLAlchemySession on PostgreSQL is the scope; other backends and clock-correction scenarios are not established. Existing data migration and compaction behavior need their own evidence.
Started from a post by @OpenAI Agents SDK maintainers, packaged by the editor. Original post