Skip to content

feat(platform): decide retrievability for an emailed attachment - #3220

Merged
Israeltheminer merged 1 commit into
mainfrom
feat/conversation-retrievable-branch
Sep 4, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
feat/conversation-retrievable-branch

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

Step 1 of #3121 — the piece the issue says must ship first.

What was missing

The corpus write already carries conversation_id
(core/knowledge/indexing.ts stamps it, and its comment says why: "to keep
the row out of the hub clause"). The retrievability gate never read it. The
SELECT fetched thread_id only, and decideRetrievable branched on a
document or a thread.

So a conversation-scoped row fell through — and every scope column NULL reads
as an org-wide hub row in the SQL pre-filter. That is the posture #3011 was
written to prevent.

Nothing indexes these files yet, so no such row exists and the fallback is
unreachable today. It becomes reachable the moment queue-on-bind lands, which
is why the gate goes in before it rather than with it.

The decision is assignment privacy, not org scope

Conversations are scoped more narrowly than anything else the platform
retrieves: an unassigned inbox row is admin-triage only, not org-readable. So
the caller supplies the conversations it may read and decideRetrievable never
derives them. A second copy of that rule is how a reader ends up subtly wider
than the rule it mirrors, and the failure mode is publishing an entire inbox
into a chat answer.

allowedConversationIds delegates to conversationAssignmentAllows — the one
definition — and is bounded by the candidates, not the caller. An admin may
read every conversation, so enumerating theirs would ship thousands of ids into
every dispatch's scope. One read of the candidates' assignment stamps, then the
shared predicate per row. The team lookup that predicate defers costs nothing
here, because the document branches have already resolved the caller's teams.

No caller identity means nothing is allowed, so an emailed attachment stays
denied on any path that doesn't supply one.

Verification

Mutation Went red
admit any conversation-bound row denies one whose conversation the caller may not read, denies when the caller has no conversations at all, is not widened by team or project scope
ignore the conversation-scoped opt-out honours the conversation-scoped opt-out
let a folder filter reach an attachment never surfaces an attachment under a folder filter

is not widened by team or project scope is the one worth having: a member of
every team and every project still sees only their own conversations. The
document branches' scope says nothing about an inbox row.

Also

Two docstrings in knowledge/service.ts still claimed the conversation branch
returns deny; both corrected. The MIGRATION.md PENDING note now names what
actually remains — msg: refs and queue-on-bind — rather than the branch that
just landed. Verified additive: +211 characters, main's text intact.

Gate

typecheck 0 errors, oxlint --type-aware clean, oxfmt --check clean,
knowledge suites 278 passed (18 files).

What's left on #3121

Step 2 (queue on bind, in the bind's own transaction) and step 3 (msg: refs)
are unblocked by this and belong in their own changes — step 2 is where #2995's
lesson about splitting that promise across a boundary applies.

Step 1 of #3121, and the one that has to ship first.

The corpus write already carries `conversation_id`
(`core/knowledge/indexing.ts`), but the retrievability gate never read it:
the SELECT fetched `thread_id` only, and `decideRetrievable` branched on a
document or a thread. A conversation-scoped row would therefore fall
through — and every scope column NULL reads as an ORG-WIDE hub row in the
SQL pre-filter, which is exactly the posture #3011 was written to prevent.

Nothing indexes these files yet, so no such row exists and the fallback is
unreachable today. It becomes reachable the moment queue-on-bind lands,
which is why the gate goes in before it rather than with it.

## The decision

`decideRetrievable` gains a conversation branch, and it is ASSIGNMENT
privacy, not org scope. Conversations are scoped more narrowly than
anything else the platform retrieves: an unassigned inbox row is
admin-triage only. So the caller supplies the conversations it may read and
this file never derives them — a second copy of that rule is how a reader
ends up publishing an inbox.

`allowedConversationIds` resolves them through
`conversationAssignmentAllows`, the one definition, and is bounded by the
CANDIDATES rather than the caller: an admin may read every conversation, so
enumerating theirs would ship thousands of ids into every dispatch. One
read of the candidates' assignment stamps, then the shared predicate.

Without a caller identity nothing is allowed, so an emailed attachment
stays denied on any path that does not supply one.

## Tests

| Mutation | Went red |
| --- | --- |
| admit any conversation-bound row | `denies one whose conversation the caller may not read`, `denies when the caller has no conversations at all`, `is not widened by team or project scope` |
| ignore the conversation-scoped opt-out | `honours the conversation-scoped opt-out` |
| let a folder filter reach an attachment | `never surfaces an attachment under a folder filter` |

`is not widened by team or project scope` is the one worth having: a member
of every team and project still sees only their own conversations.

Corrects two docstrings that claimed the conversation branch denies, and
the MIGRATION.md `PENDING` note, which now names what actually remains —
`msg:` refs and queue-on-bind.
@Israeltheminer
Israeltheminer merged commit ce5be11 into main Sep 4, 2026
66 of 67 checks passed
@Israeltheminer
Israeltheminer deleted the feat/conversation-retrievable-branch branch September 4, 2026 14:53
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