Skip to content

Attachment fetchData lost after debounce/queue serialization #323

@steven-moneyforward

Description

@steven-moneyforward

Bug Description

When using the debounce or queue concurrency strategy, Attachment.fetchData closures are lost during message serialization. enqueue
calls JSON.stringify(entry) which strips functions. After rehydrateMessage, all attachments have fetchData: undefined — handlers cannot
download files/images.

Steps to Reproduce

  1. Create a Chat instance with concurrency: { strategy: 'debounce', debounceMs: 2000 }
  2. Register an onSubscribedMessage handler that accesses message.attachments[0].fetchData
  3. Send a message with an image attachment from Slack
  4. Message enters handleQueueOrDebounce → enqueue → JSON.stringify strips fetchData
  5. After debounce delay, dequeue → rehydrateMessage → attachments[].fetchData is undefined
  6. Handler throws: TypeError: fetchData is not a function

Expected Behavior

After dequeue + rehydrate, attachment.fetchData should be a working function. The attachment's url, name, mimeType survive serialization — only
fetchData (a closure) is lost. rehydrateMessage should recreate fetchData from the adapter using att.url.

Actual Behavior

attachment.fetchData is undefined after rehydration. All file/image downloads fail for debounced messages. Works correctly with 'drop' and
'concurrent' strategies (no serialization).

Code Sample

import { Chat } from 'chat';
  import { SlackAdapter } from '@chat-adapter/slack';

  const chat = new Chat({
    adapters: [new SlackAdapter({ botToken: '...' })],
    concurrency: { strategy: 'debounce', debounceMs: 2000 },
  });

  chat.onSubscribedMessage(async (thread, message) => {
    const att = message.attachments.find(a => a.type === 'image');
    if (att) {
      console.log(att.url);       // ✅ "https://files.slack.com/..." (survives serialization)
      console.log(att.fetchData); // ❌ undefined (closure lost after JSON.stringify)
      await att.fetchData();      // 💥 TypeError: fetchData is not a function
    }
  });

Chat SDK Version

latest

Node.js Version

4.23.0

Platform Adapter

No response

Operating System

None

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions