Skip to content

feat(platform): let a message ref pass the retrieval gate - #3062

Merged
Israeltheminer merged 1 commit into
mainfrom
feat/message-corpus-refs
Aug 25, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
feat/message-corpus-refs

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

An email message can now pass the retrieval gate. Nothing writes such a ref yet, so no search result changes.

This is the mechanism half of #3015, the way #3011 preceded #3012.

Why

Every corpus ref today resolves through fileMetadata.by_storageId, and the gate skips a ref whose row is missing. A message is not a blob and has no such row, so a message hit is denied before reaching any access branch.

That is why this ships first. Index bodies without it and the rows are admitted by SQL, then silently dropped.

What changed

msg:<messageId> is a corpus ref for a message, in a new lib/knowledge/message-ref.ts.

The gate gains one branch, decided before the blob lookup. A message is retrievable only when the caller can currently read the conversation it arrived on — conversationAssignmentAllows, the same predicate emailed attachments use, so reassigning a conversation moves its messages with it. Scope exclusions and the folder filter are honoured exactly as the attachment branch honours them.

The branch keys on the msg: prefix rather than on a successful parse. A malformed ref is denied there instead of falling through to the blob path, where parseBlobRef would coerce it into a Convex storage id rather than reject it. A test pins that.

One branch covers both readers: knowledge/search.ts filters hits through this gate, and knowledge/fetch.ts returns null unless the ref comes back retrievable.

Risk

msg: is deliberately not part of BlobRef. parseBlobRef treats any non-s3: string as a storage id, and six modules call it or convexStorageId, including blob_delete.ts and erase_document_blobs.ts. That is safe only because every one of them reads its ref from a Convex row — documents.fileId, documents.historyFiles, fileMetadata.storageId — and a message has none of those. eraseDocumentBlobs was checked specifically: it walks doc.fileId and doc.historyFiles, never a corpus ref.

If a message ever gains a documents or fileMetadata row, that reasoning expires and msg: must join ParsedBlobRef so the compiler forces all six to handle it. The module says so.

Tests

Thirteen cases in a new suite: the individual assignee, a member of the assigned team, another team's mail, unassigned mail, an admin, a cross-org message, a cross-org conversation, a missing message, a missing conversation, a ref that is not a message id, a bare prefix, a scope excluding conversations, a folder-scoped search, and an absent caller.

The suite's ctx has no fileMetadata at all and throws if queried, so every passing case also proves the decision happened before the blob lookup.

Eight deliberate breakages were introduced one at a time to confirm each is caught: always-allow, both org checks, the scope exclusion, the folder filter, the absent caller, the id check, and the malformed prefix. All eight were caught. The malformed-prefix case found a real flaw during development — the branch originally keyed on a successful parse, so a bare msg: fell through to the blob path.

Scope

Nothing writes a msg: ref. Bodies are not indexed, and no erasure cascade exists for them; both belong to #3015's second half, which must ship the cascade in the same change so message text is not left behind after an erasure request.

No SQL or DDL change. The corpus pre-filter already admits any row carrying a conversation, deliberately, because enumerating a caller's readable conversations is unbounded under assignment privacy.

Gate: typecheck, oxlint --type-aware, oxfmt, knip, SAST 0 findings, platform suite 75,716 passing.

@Israeltheminer
Israeltheminer merged commit f613349 into main Aug 25, 2026
51 checks passed
@Israeltheminer
Israeltheminer deleted the feat/message-corpus-refs branch August 25, 2026 15:32
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