From 8a5166f81ec886d88822dc74fa245fd6a84cbd6a Mon Sep 17 00:00:00 2001 From: Jeremy Schoemaker Date: Wed, 5 Aug 2026 13:23:38 -0500 Subject: [PATCH] fix(sessions): reject session IDs with a trailing newline `_validate_uuid` documents itself as "Returns the string if it is a valid UUID, else None", but `re.match` with a `$` anchor accepts one more string than that: Python's `$` also matches immediately before a trailing newline. _validate_uuid("3f2504e0-4f89-11d3-9a0c-0305e82c3301\n") -> '3f2504e0-4f89-11d3-9a0c-0305e82c3301\n' The newline is preserved in the returned value and flows into the nine call sites, where it becomes part of a filename: file_name = f"{uuid}.jsonl" # sessions.py:781 That path never exists, so `get_session_info` returns None and `get_session_messages` / `list_subagents` return [] -- indistinguishable from a session that genuinely is not there. A session ID read from a file or captured from command output is the common way to acquire the trailing byte. Switch to `fullmatch`, which anchors both ends with no newline exemption, and drop the now-redundant `^`/`$`. --- src/claude_agent_sdk/_internal/sessions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/claude_agent_sdk/_internal/sessions.py b/src/claude_agent_sdk/_internal/sessions.py index cb1cb1342..23cb630ee 100644 --- a/src/claude_agent_sdk/_internal/sessions.py +++ b/src/claude_agent_sdk/_internal/sessions.py @@ -43,7 +43,7 @@ MAX_SANITIZED_LENGTH = 200 _UUID_RE = re.compile( - r"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", + r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", re.IGNORECASE, ) @@ -68,7 +68,7 @@ def _validate_uuid(maybe_uuid: str) -> str | None: """Returns the string if it is a valid UUID, else None.""" - if _UUID_RE.match(maybe_uuid): + if _UUID_RE.fullmatch(maybe_uuid): return maybe_uuid return None