fix: prevent leading slash in S3 keys when prefix is empty (#1863)#1894
Open
mango766 wants to merge 1 commit intostrands-agents:mainfrom
Open
fix: prevent leading slash in S3 keys when prefix is empty (#1863)#1894mango766 wants to merge 1 commit intostrands-agents:mainfrom
mango766 wants to merge 1 commit intostrands-agents:mainfrom
Conversation
When S3SessionManager is created with the default empty prefix, `_get_session_path()` produced keys like `/session_<id>/...` with a leading slash. MinIO and some S3-compatible backends strip the leading slash on write but not on read, causing session restore to silently fail — `read_agent()` returned None and the agent started fresh. Now conditionally prepend the prefix only when it is non-empty, producing clean keys like `session_<id>/...`. Fixes strands-agents#1863
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
S3SessionManager._get_session_path()producing S3 keys with a leading slash whenprefix=""(the default), causing session restore to silently fail on MinIO and S3-compatible backends.Root cause
MinIO strips the leading
/on write, storingsession_<id>/..., but reads use/session_<id>/...which never matches.read_agent()returnsNone,initialize()takes the new-session branch, and the agent starts fresh every time.Fix
Only prepend
prefix/when prefix is non-empty. All downstream methods (_get_agent_path,_get_message_path) call_get_session_path, so they are all fixed.Fixes #1863
Test plan
S3SessionManager(prefix="")→ keys have no leading slashS3SessionManager(prefix="my-prefix")→ keys aremy-prefix/session_<id>/...