Skip to content

fix(platform): deny a corpus ref bound to neither document nor thread - #3192

Merged
Israeltheminer merged 1 commit into
mainfrom
fix/deny-unbound-corpus-ref-v2
Sep 4, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
fix/deny-unbound-corpus-ref-v2

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

A corpus row bound to neither a document nor a thread was retrievable by any
member of the organization. decideRetrievable's unbound-file loop ended in
return true, so a row that passed no scope check at all was admitted.

Rebase of #3177 onto current main; no content change.

The premise it was defended on is wrong

The module docstring called this "the 0.4 same-org posture DELIBERATELY",
citing video-link transcripts as the lane that needs it. That lane does not
need it: bindStorageIdsToThread in backend/domains/chat/shim.ts stamps
thread_id at send time (WHERE document_id IS NULL AND thread_id IS NULL),
so those rows arrive at the gate thread-bound and are served by the branch
directly above — the one that checks access.threadIds.

So nothing reaches the unbound arm by design. What reaches it is a row whose
binding never landed, and the corpus reads an unscoped row as org-wide. That
makes return true a fail-open default, not a same-org one. Changed to
continue, and the docstring now says that.

Tests

The suite had a test asserting the old behaviour. It is replaced, not
deleted — two assertions now pin the denial, one with an access scope and one
without, because the two arms return through different paths.

Mutation-tested: restoring return true fails both.

Mutation Went red
continue → return true denies a live row bound to neither a document nor a thread, denies it with no access scope either

Gate

retrievable.test.ts 12 passed, typecheck 0 errors, oxlint --type-aware
clean, oxfmt --check clean.

The retrieval gate admitted a file row with no document and no thread to
any member of the organization.

That shape is not obscure: the indexer stamps corpus scope only from a
bound document, so such a row carries no project and no team, and the SQL
half of the two-gate design reads exactly that as an org-wide hub row. The
SQL half fails open by design and names this function as the decider, so
both gates passed the ref. 0.4 denied it (documentId === undefined →
continue).

The previous posture was deliberate and documented, on the grounds that
video-link transcripts index without a document and a blanket quarantine
would dark that lane. The premise does not hold: a transcript row carries
thread_id, so it admits through the thread branch. A welcome-page paste
starts thread-less only because no thread exists yet, and the first send
stamps it via bindStorageIdsToThread, which updates exactly the rows with
no document and no thread. Before that send no turn can be scoped to it.

So the assertion that locked in the old behaviour is replaced rather than
deleted, and a new case proves the video-link lane still admits once its
thread is stamped.

Refs #3142.
@Israeltheminer
Israeltheminer force-pushed the fix/deny-unbound-corpus-ref-v2 branch from 5243478 to 602d986 Compare September 4, 2026 08:53
@Israeltheminer
Israeltheminer merged commit 1a59548 into main Sep 4, 2026
66 of 67 checks passed
@Israeltheminer
Israeltheminer deleted the fix/deny-unbound-corpus-ref-v2 branch September 4, 2026 10:00
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