Skip to content

Commit e45069f

Browse files
committed
fix(chat): null out SentMessage.raw before persisting to history
Post-merge review of PR #117 caught that _MessageHistoryCache.append in chat.py did not null out raw before persisting (unlike its sibling MessageHistoryCache.append in message_history.py, which already does). Without this, the platform raw payload (Slack team_id/user_id, Discord guild IDs, etc.) that #117 now correctly populates on SentMessage.raw would persist to Redis/Postgres-backed state on every reply, inflating storage size and PII surface. Mirrors the null-out in message_history.py:62.
1 parent 918a0e6 commit e45069f

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Python-only patch on the 0.4.27 line. No upstream version change; does NOT inclu
77
### Fixes
88

99
- **Slack now surfaces `files_upload_v2` confirmation through `post()`** — `SlackAdapter._upload_files` already computed the list of Slack-confirmed file IDs but `post_message` discarded the return, and `ThreadImpl._create_sent_message` hardcoded `raw=None`, so the confirmation never reached `SentMessage.raw`. Slack was the only file-capable adapter to drop this; discord/telegram upload inline and expose the platform response naturally. `post_message` now augments `RawMessage.raw` with `"uploaded_file_ids"` on every return path that can carry files (file-only, card, table, text), and `ThreadImpl._create_sent_message` accepts and propagates the adapter's `raw` into `SentMessage.raw`. `None` means no upload occurred; an empty list signals Slack confirmed zero attachments. The `raw` payload is augmented, not replaced, so existing consumers are unaffected. Backported from #117 (which targets the 0.4.29 line). Unblocks chinchill gating UX on actual delivery success. Upstream convergence tracked in vercel/chat#564.
10+
- **`chat._MessageHistoryCache` now nulls `raw` before persisting to history** — mirror of the existing null-out in `message_history.MessageHistoryCache.append`. Without this, the platform payload that the above fix populates on `SentMessage.raw` (Slack `team_id`/`user_id`, Discord `guildId`, etc.) would persist on every reply to Redis/Postgres-backed state, inflating storage and PII surface. Caught by post-merge review of #117.
1011

1112
### Test quality
1213

src/chat_sdk/chat.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,7 +2454,13 @@ def __init__(self, state: StateAdapter, config: dict[str, Any] | None = None) ->
24542454

24552455
async def append(self, thread_id: str, message: Message) -> None:
24562456
key = f"msg-history:{thread_id}"
2457+
# Serialize with raw nulled out to save storage (matches
2458+
# MessageHistoryCache.append in message_history.py). Without this,
2459+
# SentMessage.raw — now populated post-#117 with platform payloads
2460+
# like Slack team_id/user_id, Discord guild IDs — would persist to
2461+
# the state adapter on every reply, inflating storage and PII surface.
24572462
data = message.to_json()
2463+
data["raw"] = None
24582464
await self._state.append_to_list(key, data, max_length=self._max_messages, ttl_ms=self._ttl_ms)
24592465

24602466
async def get_messages(self, thread_id: str, limit: int | None = None) -> list[Message]:

0 commit comments

Comments
 (0)