Skip to content

Commit 9a75d5a

Browse files
committed
docs(examples): correct JSONB hoist attribution; fix README result-message check
- postgres_session_store.py + README.md: the type-hoist lives in the *_from_store read helpers (_entries_to_jsonl) protecting the SDK's lite-parse tag scan, not in the resume materializer protecting a CLI prefix-scan. Reword so adapter authors debugging the read path aren't pointed at the wrong function. - README.md usage examples (S3/Redis/Postgres): query() yields dataclass instances with no .type attribute; message.type == 'result' raises AttributeError on the first iteration. Switch to isinstance(message, ResultMessage) like every other example in the repo. :house: Remote-Dev: homespace
1 parent c1158da commit 9a75d5a

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

examples/session_stores/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pip install claude-agent-sdk boto3
110110
import anyio
111111
import boto3
112112

113-
from claude_agent_sdk import ClaudeAgentOptions, query
113+
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, query
114114
from my_project.stores import S3SessionStore # your copy of this file
115115

116116
store = S3SessionStore(
@@ -126,7 +126,7 @@ async def main() -> None:
126126
options=ClaudeAgentOptions(session_store=store),
127127
):
128128
# Messages are mirrored to S3 automatically.
129-
if message.type == "result" and message.subtype == "success":
129+
if isinstance(message, ResultMessage) and message.subtype == "success":
130130
print(message.result)
131131

132132

@@ -210,7 +210,7 @@ pip install claude-agent-sdk redis
210210

211211
```python
212212
import redis.asyncio as redis
213-
from claude_agent_sdk import ClaudeAgentOptions, query
213+
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, query
214214

215215
from redis_session_store import RedisSessionStore
216216

@@ -223,7 +223,7 @@ async for message in query(
223223
prompt="Hello!",
224224
options=ClaudeAgentOptions(session_store=store),
225225
):
226-
if message.type == "result" and message.subtype == "success":
226+
if isinstance(message, ResultMessage) and message.subtype == "success":
227227
print(message.result)
228228
```
229229

@@ -311,7 +311,7 @@ pip install claude-agent-sdk asyncpg
311311

312312
```python
313313
import asyncpg
314-
from claude_agent_sdk import ClaudeAgentOptions, query
314+
from claude_agent_sdk import ClaudeAgentOptions, ResultMessage, query
315315

316316
from postgres_session_store import PostgresSessionStore
317317

@@ -323,7 +323,7 @@ async for message in query(
323323
prompt="Hello!",
324324
options=ClaudeAgentOptions(session_store=store),
325325
):
326-
if message.type == "result" and message.subtype == "success":
326+
if isinstance(message, ResultMessage) and message.subtype == "success":
327327
print(message.result)
328328
```
329329

@@ -354,9 +354,9 @@ CREATE INDEX IF NOT EXISTS claude_session_store_list_idx
354354
Entries are stored as `jsonb`, which **reorders object keys** on read-back
355355
(shorter keys first, then by byte order). This is explicitly allowed by the
356356
`SessionStore` contract — `load()` requires *deep-equal*, not *byte-equal*,
357-
returns. The SDK never byte-compares stored entries, and the resume
358-
materializer hoists `"type"` first when re-serializing so the CLI's
359-
prefix-scan still works. If you need byte-stable storage, switch the column
357+
returns. The SDK never byte-compares stored entries, and the `*_from_store`
358+
read helpers hoist `"type"` to the first key when re-serializing so the SDK's
359+
lite-parse tag scan still works. If you need byte-stable storage, switch the column
360360
to `json` (preserves text as-is) or `text`.
361361

362362
### Retention

examples/session_stores/postgres_session_store.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
explicitly allowed by the :class:`~claude_agent_sdk.SessionStore` contract:
5151
:meth:`~claude_agent_sdk.SessionStore.load` requires *deep-equal*, not
5252
*byte-equal*, returns. The SDK never hashes or byte-compares stored entries,
53-
and ``_entries_to_jsonl`` (the resume materializer) hoists ``"type"`` first
54-
when re-serializing so the CLI's prefix-scan still works. If you need
53+
and the ``*_from_store`` read helpers hoist ``"type"`` to the first key when
54+
re-serializing so the SDK's lite-parse tag scan still works. If you need
5555
byte-stable storage, switch the column to ``json`` (preserves text as-is) or
5656
``text`` and ``json.dumps`` yourself.
5757

0 commit comments

Comments
 (0)