fix(think): preserve attachment fetchMetadata through messenger serialization#1839
Merged
Merged
Conversation
…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 detectedLatest commit: 5995df3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 exceptid,mediaType,name,size,text, andurlfrom each attachment — discardingfetch,raw, and the platform identifier.For adapters like
@chat-adapter/telegram, the file id lives exclusively infetchMetadata.fileIdand the top-levelidis never populated, so photos became irretrievable inside a sub-agent (attachment.idandattachment.fetchwere both missing).This change:
fetchMetadata?: Record<string, string>field toMessengerAttachment.fetchMetadatathroughserializableMessengerEvent(the exact spot identified in the issue), while still dropping the non-cloneablefetch/raw/data.fetchMetadatathroughtoMessengerAttachment, and backfills the top-levelidfrom a known, adapter-agnostic metadata key (id/fileId/mediaId/fileUniqueId).This implements both options the issue suggested (preserve
fetchMetadataand backfillid), so a downstream sub-agent has the data needed to re-fetch via the adapter'srehydrateAttachment().Test plan
fetchMetadatasurvives JSON round-tripping whileraw/fetch/dataare still stripped.toMessengerAttachmenttests: id backfill fromfetchMetadata.fileId, and id stayingundefinedwhen no known id key is present.pnpm run check(sherif + export checks + format + lint + typecheck, all 114 projects) passes.@cloudflare/thinktest suite passes (894 unit/integration + generated/vite/cli/react).@cloudflare/thinkpatch changeset.Made with Cursor