Repository navigation
feat(platform): record which conversation an email attachment arrived on - #3010
Merged
Merged
Conversation
An inbound attachment's bytes were stored with no record of the mail they came from. `fileMetadata` knew two bindings — a Document Hub row via `documentId` and a chat upload via `threadId` — and an email attachment had neither, so nothing downstream could get from the file back to its conversation. `conversationId` is that third binding, with an index on it. The point is derived visibility. An emailed file should be readable by whoever can currently read its conversation, and that needs a link to derive from. Stamping a team on the file instead would be wrong the moment somebody reassigns the conversation, and every missed rewrite would leave a file either hidden from its new owner or visible to the person who handed it off. It binds after ingest, not at storage time. Attachment bytes are drained per message inside `fetchBodies` so a page of mail never holds every base64 payload at once, and that runs before the conversation is resolved — there is no id to write yet. `createConversationFromEmail` collects each ingested email with the conversation it landed on, at all three sites that learn one, and binds in a single pass afterwards. The write is scoped and idempotent. A row must already belong to the organization doing the binding, so a storage id cannot re-point a foreign row, and an unchanged value writes nothing, so a re-poll of the same mail is a no-op. Best-effort: a failed binding logs and continues rather than failing a sync that has already landed the mail. The attachment is still stored and still shown; only the link is missing, and the next poll rebinds it. No migration: an optional field and a new index are data-safe. Groundwork for #2985. Indexing email attachments for RAG comes next and needs this link to derive its scope from.
This was referenced Aug 19, 2026
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.
An email attachment now records which conversation it arrived on. Nothing could get from a stored file back to its mail before this.
Why
fileMetadataknew two bindings, both documented in its schema: a Document Hub row viadocumentId, and a chat upload viathreadId. An email attachment had neither. Its bytes were stored, and what they arrived on was not recorded anywhere.The reason it matters is derived visibility. An emailed file should be readable by whoever can currently read its conversation. That needs a link to derive from.
The alternative — stamping a team on the file at ingest — is wrong the moment somebody reassigns the conversation. Every missed rewrite then leaves a file either hidden from its new owner or still visible to the person who handed it off. Deriving it means there is nothing to keep in sync.
What changed
fileMetadata.conversationId, withby_organizationId_and_conversationId.It binds after ingest, not at storage time. Attachment bytes are drained per message inside
fetchBodiesso a page of mail never holds every base64 payload at once, and that runs before the conversation is resolved — there is no id to write yet.createConversationFromEmailcollects each ingested email with the conversation it landed on, at all three sites that learn one, then binds in a single pass.Risk
The write is scoped: a row must already belong to the organization doing the binding, so a storage id cannot re-point a row in another org. A storage id is not a capability.
It is idempotent: an unchanged value writes nothing, so re-polling the same mail is a no-op rather than a write.
It is best-effort: a failure logs and continues rather than failing a sync that has already landed the mail. The attachment is still stored and still shown; only the link is missing, and the next poll rebinds it.
No migration. An optional field and a new index are data-safe, confirmed by
migrations:check.Tests
Five on the mutation — it records, refuses a foreign organization, writes nothing when unchanged, rebinds a changed value, and no-ops when no row exists. Five through the real ingest path — one attachment, several on one email, a metadata-only part with nothing stored, an email with none, and an ingest that still succeeds when a binding throws.
Mutations, all red: dropping the org scope, writing when unchanged, binding parts with no
storageId, letting a failure fail the ingest, and never binding at all.Scope
Groundwork for #2985, which is not closed by this. The duplicate re-ingestion that issue describes was addressed in #3000 by reusing stored pointers, and the display half was fixed in #3009. What remains there is retention reach over these rows, now that they can be found.
Does not index email attachments for RAG. That is the next change, and it needs this link to derive its scope from. One open question for it: the SQL pre-filter treats a row with all scope stamps NULL as an org-wide hub row, which is the outcome to avoid, so it likely needs a
conversation_idcolumn on the corpus table and a knowledge-DB migration.Gate: typecheck,
oxlint --type-aware, oxfmt, SAST 0 findings,migrations:check(no migration), platform 75,168 tests.