feat: add ValkeySession provider for session memory#3583
Conversation
Adds ValkeySession session provider using valkey-glide client library. Valkey is the Linux Foundation's BSD-licensed, Redis-compatible key-value store. - Implement ValkeySession class following the same patterns as RedisSession - Uses valkey-glide (>=2.1) with GlideClient for async operations - Supports from_url factory method (valkey://, valkeys://, redis://, rediss://) - Supports TTL-based session expiration - Supports injecting an existing GlideClient for connection reuse - Uses Batch API for efficient pipelined writes - Includes comprehensive test suite using testcontainers or local Valkey - Registered as lazy import in extensions.memory with optional 'valkey' extra Closes openai#3017 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eb5c6e6ae2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| import shutil | ||
| import sys | ||
| import time | ||
|
|
There was a problem hiding this comment.
Skip Valkey tests when no server is provisioned
Because CI runs make sync with --all-extras in .github/workflows/tests.yml, the new valkey-glide extra is installed and this import skip no longer skips the file. The workflow does not start a Valkey service or set VALKEY_URL, and the helpers call GlideClient.create/ValkeySession.from_url before any pytest.skip, so the serial test suite will try to connect to localhost and fail instead of skipping on every CI job without a Valkey server. Gate these tests on an explicit server/container being available or catch client-creation failures and skip before attempting operations.
Useful? React with 👍 / 👎.
Adds a
ValkeySessionsession provider that uses the valkey-glide client library.Valkey is the Linux Foundation's open-source, BSD-licensed, high-performance key-value store, forked from Redis 7.2.5. It is wire-compatible with Redis, but organizations using Valkey deserve a first-class session provider that uses the dedicated Valkey-GLIDE client, which is optimized for Valkey and will diverge from redis-py as Valkey adds its own features.
Changes
src/agents/extensions/memory/valkey_session.py—ValkeySessionclass implementing theSessionprotocolsrc/agents/extensions/memory/__init__.py— lazy-import registration with optionalvalkeyextrapyproject.toml—valkey = ["valkey-glide>=2.1"]optional dependency + dev dependency + mypy overridetests/extensions/memory/test_valkey_session.py— comprehensive test suite (27 tests covering direct ops, runner integration, isolation, limits, unicode, concurrency, TTL, key prefix isolation, client ownership, counter, metadata, settings, and more)API
Direct construction with an existing client
URL-based construction
Supported URL schemes:
valkey://,valkeys://,redis://,rediss://Testing
Tests require a running Valkey/Redis instance (set via
VALKEY_URLenv var, defaults tovalkey://localhost:6379/15).Run with:
Closes #3017