Skip to content

feat(platform): record which conversation an email attachment arrived on - #3010

Merged
Israeltheminer merged 2 commits into
mainfrom
feat/bind-attachment-to-conversation
Aug 19, 2026
Merged

Israeltheminer merged 2 commits into
mainfrom
feat/bind-attachment-to-conversation

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

An email attachment now records which conversation it arrived on. Nothing could get from a stored file back to its mail before this.

Why

fileMetadata knew two bindings, both documented in its schema: a Document Hub row via documentId, and a chat upload via threadId. 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, with by_organizationId_and_conversationId.

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, 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_id column 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.

Israeltheminer and others added 2 commits August 19, 2026 10:15
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.
@Israeltheminer
Israeltheminer merged commit 992ed85 into main Aug 19, 2026
49 of 50 checks passed
@Israeltheminer
Israeltheminer deleted the feat/bind-attachment-to-conversation branch August 19, 2026 10:12
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.

1 participant