Skip to content

fix(redis-session): preserve created_at across writes#3202

Merged
seratch merged 2 commits intoopenai:mainfrom
adityasingh2400:fix/session-redis-created-at
May 9, 2026
Merged

fix(redis-session): preserve created_at across writes#3202
seratch merged 2 commits intoopenai:mainfrom
adityasingh2400:fix/session-redis-created-at

Conversation

@adityasingh2400
Copy link
Copy Markdown
Contributor

Summary

RedisSession.add_items rewrites the session metadata hash with mapping={"created_at": str(int(time.time())), ...} on every call. Because HSET with a mapping overwrites every field, created_at is reset to the current timestamp on every subsequent write — making it indistinguishable from updated_at and useless as a session-creation timestamp.

This is the same class of metadata-integrity bug as #3173 (Dapr) and #3175 (encrypted-session counts), in a sibling backend.

Fix

Write session_id with HSET, created_at with HSETNX (set only if not present), and updated_at with HSET. Reuse a single now value for both writes so created_at == updated_at on the very first call.

Diff: 15 net lines in redis_session.py, plus a focused regression test.

Test plan

  • New regression test test_add_items_preserves_created_at_metadata fails on main, passes with the fix
  • Full tests/extensions/memory/ suite passes locally (83 passed, 4 skipped)
  • Pre-existing Redis tests unchanged

`add_items` rewrote the session metadata hash with a fresh
`created_at` value on every call, so the timestamp tracked the most
recent write rather than the actual session creation time. Use
`HSETNX` for `created_at` so it is written only on the first call.
@seratch
Copy link
Copy Markdown
Member

seratch commented May 8, 2026

@codex review

@seratch seratch marked this pull request as draft May 8, 2026 16:56
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@seratch seratch marked this pull request as ready for review May 9, 2026 03:46
@seratch seratch added this to the 0.17.x milestone May 9, 2026
@seratch seratch merged commit 4bb388c into openai:main May 9, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working feature:extensions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants