Skip to content

fix: prevent leading slash in S3 keys when prefix is empty (#1863)#1894

Open
mango766 wants to merge 1 commit intostrands-agents:mainfrom
mango766:fix/s3-session-empty-prefix-leading-slash
Open

fix: prevent leading slash in S3 keys when prefix is empty (#1863)#1894
mango766 wants to merge 1 commit intostrands-agents:mainfrom
mango766:fix/s3-session-empty-prefix-leading-slash

Conversation

@mango766
Copy link

Summary

Fix S3SessionManager._get_session_path() producing S3 keys with a leading slash when prefix="" (the default), causing session restore to silently fail on MinIO and S3-compatible backends.

Root cause

# Before: prefix="" produces "/session_<id>/..."
return f"{self.prefix}/{SESSION_PREFIX}{session_id}/"

MinIO strips the leading / on write, storing session_<id>/..., but reads use /session_<id>/... which never matches. read_agent() returns None, initialize() takes the new-session branch, and the agent starts fresh every time.

Fix

session_key = f"{SESSION_PREFIX}{session_id}/"
if self.prefix:
    return f"{self.prefix}/{session_key}"
return session_key

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 slash
  • S3SessionManager(prefix="my-prefix") → keys are my-prefix/session_<id>/...
  • Session restore works on MinIO with empty prefix

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] S3SessionManager with empty prefix produces leading slash in S3 keys causing session restore failure on MinIO and S3-compatible backends

1 participant