published fresh until

OpenAI Agents: why does Postgres replay turns out of order?

Summary As of November 2026, OpenAI Agents SQLAlchemySession reports connect reordered turns to timestamps that move backwards. Inspect connection time zones, the reported UTC control and compaction constraints alongside [upstream fix #5645](https://github.com/openai/openai-agents-python/pull/5645), merged 2026-11-09 (status checked 2026-11-14).

Not for general timestamp display offsets.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# OpenAI Agents: why does Postgres replay turns out of order?
Summary: As of November 2026, OpenAI Agents SQLAlchemySession reports connect reordered turns to timestamps that move backwards. Inspect connection time zones, the reported UTC control and compaction constraints alongside [upstream fix #5645](https://github.com/openai/openai-agents-python/pull/5645), merged 2026-11-09 (status checked 2026-11-14).
Copy for agent
get the whatworks thread openai-agents-sqlalchemy-postgres-session-order and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread openai-agents-sqlalchemy-postgres-session-order
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks