Skip to content

Port rehydrate_attachment to Adapter protocol + _rehydrate_message #52

@patrick-chinchill

Description

@patrick-chinchill

Missing capability — queued/debounced messages lose attachment fetch callbacks.

The gap

Upstream `Adapter` interface exposes an optional `rehydrateAttachment(attachment)` hook. When `Chat` dequeues a message (in `"queue"` / `"debounce"` concurrency strategies), it calls `adapter.rehydrateAttachment()` on each attachment to restore the `fetchData` callback, which was dropped during JSON serialization.

Python has:

  • No `rehydrate_attachment` on any adapter
  • `Chat._rehydrate_message` takes no `adapter` parameter (see `src/chat_sdk/chat.py:1911`)
  • Rehydrated attachments are plain dicts with no `fetch_data` callable

Downstream effect: handlers in queue/debounce mode can't fetch attachment bytes, because the callback is gone.

Upstream references

  • `vercel-chat/packages/chat/src/chat.ts:2313-2365` — `rehydrateMessage(raw, adapter?)` calls `adapter?.rehydrateAttachment?.(att)`
  • `vercel-chat/packages/chat/src/types.ts` — `rehydrateAttachment?(attachment: Attachment): Attachment` on `Adapter` interface
  • Individual adapter implementations (Slack, Teams, Discord, GitHub, etc.) — each re-attaches the platform-specific fetch callback

Fix (two PRs, can be parallelized)

Part A — protocol

  1. Add `rehydrate_attachment?: Callable[[Attachment], Attachment]` to the `Adapter` protocol in `src/chat_sdk/types.py`
  2. Update `_rehydrate_message` signature in `chat.py:1911` to accept `adapter: Adapter | None = None`
  3. Update callers (`chat.py:1685`, `chat.py:1715`) to pass the active adapter
  4. After reconstructing the message, call `adapter.rehydrate_attachment(att)` on each attachment if the method exists

Part B — per-adapter implementations

Slack, Teams, Discord, GitHub, Google Chat, Telegram, WhatsApp, Linear — each implements `rehydrate_attachment` to re-attach platform-specific download logic.

Impact

  • chinchill-api uses `concurrency="drop"`, unaffected today
  • Any consumer switching to `"queue"` or `"debounce"` with attachment-handling handlers will find attachments unreadable post-dequeue

Acceptance

  • `Adapter` protocol exposes `rehydrate_attachment`
  • `_rehydrate_message` accepts adapter + calls hook
  • At least Slack + Teams implementations (the two most likely to receive file attachments)
  • Regression test: queue a message with an attachment, dequeue, verify `fetch_data()` returns the bytes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions