Skip to content

fix(think): preserve attachment fetchMetadata through messenger serialization#1839

Merged
threepointone merged 1 commit into
mainfrom
fix/messenger-attachment-fetchmetadata
Jun 29, 2026
Merged

fix(think): preserve attachment fetchMetadata through messenger serialization#1839
threepointone merged 1 commit into
mainfrom
fix/messenger-attachment-fetchmetadata

Conversation

@threepointone

@threepointone threepointone commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1833.

When a conversation resolver routes a thread to a sub-agent Durable Object, the messenger event is run through serializableMessengerEvent() before crossing the DO boundary. That serialization dropped everything except id, mediaType, name, size, text, and url from each attachment — discarding fetch, raw, and the platform identifier.

For adapters like @chat-adapter/telegram, the file id lives exclusively in fetchMetadata.fileId and the top-level id is never populated, so photos became irretrievable inside a sub-agent (attachment.id and attachment.fetch were both missing).

This change:

  • Adds a serialization-safe fetchMetadata?: Record<string, string> field to MessengerAttachment.
  • Preserves fetchMetadata through serializableMessengerEvent (the exact spot identified in the issue), while still dropping the non-cloneable fetch/raw/data.
  • Carries fetchMetadata through toMessengerAttachment, and backfills the top-level id from a known, adapter-agnostic metadata key (id/fileId/mediaId/fileUniqueId).

This implements both options the issue suggested (preserve fetchMetadata and backfill id), so a downstream sub-agent has the data needed to re-fetch via the adapter's rehydrateAttachment().

Test plan

  • Extended the serialization-snapshot test to assert fetchMetadata survives JSON round-tripping while raw/fetch/data are still stripped.
  • Added focused toMessengerAttachment tests: id backfill from fetchMetadata.fileId, and id staying undefined when no known id key is present.
  • pnpm run check (sherif + export checks + format + lint + typecheck, all 114 projects) passes.
  • @cloudflare/think test suite passes (894 unit/integration + generated/vite/cli/react).
  • Added a @cloudflare/think patch changeset.

Made with Cursor


Open in Devin Review

…lization (#1833)

serializableMessengerEvent stripped everything except id/mediaType/name/
size/text/url from attachments before handing events to sub-agent DOs,
discarding fetch, raw, and the platform identifier. For adapters like
@chat-adapter/telegram the file id lives only in fetchMetadata.fileId and
the top-level id is never set, so attachments were irretrievable inside a
sub-agent.

Add a serialization-safe fetchMetadata field to MessengerAttachment,
preserve it through serializableMessengerEvent, and carry it through
toMessengerAttachment while backfilling the top-level id from a known
metadata key (id/fileId/mediaId/fileUniqueId).

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5995df3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/think Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Open in Devin Review

Comment thread packages/think/src/messengers/chat-sdk.ts
@pkg-pr-new

pkg-pr-new Bot commented Jun 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1839

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1839

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1839

create-think

npm i https://pkg.pr.new/create-think@1839

hono-agents

npm i https://pkg.pr.new/hono-agents@1839

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1839

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1839

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1839

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1839

commit: 5995df3

@threepointone threepointone merged commit 62b90eb into main Jun 29, 2026
7 checks passed
@threepointone threepointone deleted the fix/messenger-attachment-fetchmetadata branch June 29, 2026 22:37
@github-actions github-actions Bot mentioned this pull request Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serializableMessengerEvent strips fetchMetadata from attachments, breaking file access in sub-agent DOs

1 participant