-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Bug Description
According to the documentation, the ShallowRedisSaver and AsyncShallowRedisSaver are intended to retain only the latest complete checkpoint, including associated blobs and write entries. However, this behavior does not hold due to two related issues:
-
Key Formatting Inconsistency:
The shallow saver classes do not use the same key formatting utilities (to_storage_safe_id,to_storage_safe_str) as the base classes, especially when handling emptycheckpoint_nsvalues. As a result, when searching for outdated keys, orphanedcheckpoint_blobandcheckpoint_writeentries are left undeleted because the key patterns do not match what was written (e.g., empty strings are not encoded to__empty__). -
Unsafe Channel Value Parsing:
Current logic does not encode channel values. If a channel value contains the delimiter character:, the split/parse logic (see shallow.py#L182-L186) misinterprets keys, causing it to miss the correct entries for cleanup.
Minimal Example
Given:
thread_id = "1234"
checkpoint_ns = ""
channel_values = {"messages": [], "branch:to:agent": None}
The following key would be produced:
checkpoint_blob:1234:__empty__:branch:to:agent:00000000000000000000000000000007.0.35094819908709574
Current behavior:
- The key pattern generated by
_make_shallow_redis_checkpoint_blob_key_pattern(ref) misses this blob because it doesn't encode empty strings the same way as _dump_blobs, so old blobs aren't deleted. - Even with key pattern issue fixed, channel values containing
:cause parsing errors. E.g., the parsing would incorrectly interpretchannel="branch"andversion="to"instead of the intended values.
Suggested Solutions
- Consistently apply encoding (e.g., base64) to all interpolated values (including
thread_id,checkpoint_ns, andchannel) to avoid delimiter collisions. - Ensure that key formatting (including handling empty strings) is unified across both base and shallow classes to avoid orphaned entries. An initial draft PR fix: cleanup blobs and writes for shallow classes #37 for this was created (not addressing the delimiter issue though)