From 3aac71ee5d14007eafc66b98205d178c7ba3fa57 Mon Sep 17 00:00:00 2001 From: easonysliu Date: Fri, 13 Mar 2026 11:09:44 +0800 Subject: [PATCH] fix: prevent leading slash in S3 keys when prefix is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When S3SessionManager is created with the default empty prefix, `_get_session_path()` produced keys like `/session_/...` 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_/...`. Fixes #1863 --- src/strands/session/s3_session_manager.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/strands/session/s3_session_manager.py b/src/strands/session/s3_session_manager.py index 8d557e81c..74fdfe357 100644 --- a/src/strands/session/s3_session_manager.py +++ b/src/strands/session/s3_session_manager.py @@ -95,7 +95,10 @@ def _get_session_path(self, session_id: str) -> str: ValueError: If session id contains a path separator. """ session_id = _identifier.validate(session_id, _identifier.Identifier.SESSION) - return f"{self.prefix}/{SESSION_PREFIX}{session_id}/" + session_key = f"{SESSION_PREFIX}{session_id}/" + if self.prefix: + return f"{self.prefix}/{session_key}" + return session_key def _get_agent_path(self, session_id: str, agent_id: str) -> str: """Get agent S3 prefix.