Repository navigation
fix(python): escape glob characters in Redis session key scan (AI-4255) - #2675
Conversation
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
Reviewed at 601aceb, merged onto current main in a scratch tree. The fix is correct: keys() is the only SCAN/KEYS/MATCH call in the SDK (grep of scan_iter and .keys( over sdks, plugins, examples), and its only caller is SessionRegistry.get_for_call. The escape set (\, *, ?, [, ]) is the full set of Redis glob specials. Ids without those characters give the same pattern as before: the escape returns the string unchanged for vision_agents:sessions/call-123/, test: and similar. The Redis container tests pass (83 passed in the session_registry dir), ruff, ruff format and mypy are clean on the touched files, and the PR's CI checks are green.
Mutation checks against a real Redis: with no escape (the base behaviour) the 5 new tests fail, and with only * escaped 2 fail. With \ dropped from the escape class everything still passes, which is the one follow-up (R1.1, inline). It does not block: the code is right, only the test is loose.
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
[security R1] The escape is correct and complete. keys() is the only pattern scan in the session registry, and its result is never used to delete keys. The escape covers every Redis glob character: once [ is escaped no character class can open, so ^, - and ] stay literal. Ids without glob characters match exactly as before. I checked this against a real Redis with the PR merged onto current main, at the registry level as well as the store level, and on the base the same checks fail.
One follow-up that does not block: the backslash escape has no test that fails without it (S1.1, inline).
What I checked
| Check | Result |
|---|---|
Other SCAN, KEYS or pattern DEL in session_registry/ or the SDK |
none |
| Delete driven by scan results | none; delete() and remove() take exact keys |
| Mutations on the escape class | *, ?, [ caught; ] is equivalent (literal in Redis); \ survives |
| CI | all checks pass |
kanat
left a comment
There was a problem hiding this comment.
Approving on the reviewers' GO (main and security GO; the backslash-escape test row is a follow-up; text review clear).
RedisSessionKVStore.keys() put the prefix in the SCAN MATCH pattern as is. A call_id with *, ?, [ or ] matched the session keys of other calls. The store now escapes these characters and the backslash.
601aceb to
994ad72
Compare
AI-4255
Why
RedisSessionKVStore.keys()put the key prefix in the RedisSCAN MATCHpattern without an escape. The prefix holds thecall_idfrom the HTTP routes ofRunner.serve(). Acall_idwith*,?,[or]matched the session keys of other calls. Thenget_for_call()returned sessions of other calls, and themax_sessions_per_callcheck counted them.Changes
keys()escapes\,*,?,[and]in the prefix. The pattern now matches the prefix as literal text, the same asInMemorySessionKVStore.Validation
test_redis_store.py(real Redis container): a prefix with*,?,[ab]or\returns only keys that start with that literal text. All 5 tests failed onmainbefore the fix: each returned keys of other calls.uv run --no-sync pytest tests/test_agents/test_session_registry/: 62 passed.ruff check,ruff format --checkandmypyon the changed files: clean.