Repository navigation
fix(platform): scope project files to their owning project - #2549
Merged
Merged
Conversation
Project documents (projectId set, teamId cleared by the attach invariant) read as org-wide to hasTeamAccess, so every Knowledge Hub surface leaked them to the whole org while project-chat RAG never searched them. Give the scope decision one owner, documents/access.ts, and enforce it everywhere: - Knowledge read paths (list/paginated/cursor/mention/accessible-ids/ document_find) filter via hasKnowledgeHubDocumentAccess; by-ID reads use canReadDocument so project members can still open their files. - rag_search: list_indexed org bucket excludes project docs and gains a project bucket; retrieve/search verify project files against the thread's project scope (verify_thread_scoped_access). - @-pins (extracted resolve_referenced_files): a project doc is pinable only in its own project's thread by a sender with project access. - updateDocument/deleteDocument require project edit access; teamId(s) assignment on a project doc is rejected at both update helpers (mutual-exclusivity invariant). - generate_response resolves the thread's project once, re-verifies the sender's CURRENT access (revoked members lose project scope), and unions it into agentProjectIds for context injection + rag_search; document_retrieve honors the same scope. chat_turn validates args.projectId before the prewarm branch so an unvalidated prewarm can never bind a thread to a foreign project. - REST /api/v1/documents is hub-only: project docs filtered from list, opaque 404 on GET/PATCH/DELETE. - RLS documents rules deny project docs (defense-in-depth). WebDAV exclusion tracked in #2545; attach-lifecycle gaps in #2546.
larryro
force-pushed
the
fix/project-file-scope
branch
from
July 8, 2026 05:08
828bafb to
3337986
Compare
larryro
added a commit
that referenced
this pull request
Jul 8, 2026
Folders extended to project scope but single files did not — you could pin @contracts yet not the contract inside it. searchDocumentsForMention gains a projectId (access re-verified in the wrapper, mirroring the folders search): a bounded index scan ranks the thread project's RAG-indexed files ahead of the hub results, with the project folder path as the subtitle. The send path already permitted these pins (resolveReferencedFiles, #2549), so retrieval scoping, sandbox delivery on both paths, chips, and the toast exclusion all apply unchanged. Org threads see exactly the previous behavior.
larryro
added a commit
that referenced
this pull request
Jul 8, 2026
Folders extended to project scope but single files did not — you could pin @contracts yet not the contract inside it. searchDocumentsForMention gains a projectId (access re-verified in the wrapper, mirroring the folders search): a bounded index scan ranks the thread project's RAG-indexed files ahead of the hub results, with the project folder path as the subtitle. The send path already permitted these pins (resolveReferencedFiles, #2549), so retrieval scoping, sandbox delivery on both paths, chips, and the toast exclusion all apply unchanged. Org threads see exactly the previous behavior.
10 tasks done
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.
Summary
Documents attached to a project (
projectIdset,teamIdcleared by the attach invariant) read as org-wide tohasTeamAccess, so every Knowledge surface leaked them to the whole org — hub lists, the@mention picker and pin path, therag_search/document_find/document_retrieveagent tools, the per-user-key REST API, and update/delete mutations — while project-chat RAG never searched them (nothing mapped the thread's project intoagentProjectIds). This PR gives the scope decision one owner (convex/documents/access.ts) and enforces it at every surface, and wires the thread's project into RAG scope after re-verifying the sender's current project access.Follow-ups: WebDAV exclusion #2545, attach-lifecycle gaps #2546.
What changed
documents/access.ts:isProjectScopedDocument,hasKnowledgeHubDocumentAccess(sync, list-safe: project docs are never hub-visible),checkProjectDocumentAccess/canReadDocument(async: project docs resolve viacheckProjectAccesson the owning project).listDocuments,listDocumentsPaginated,getDocumentsCursor,searchDocumentsForMention,getAccessibleDocumentIds,listDocumentsForAgentfilter through the hub helper;getDocumentByIdusescanReadDocumentso project members can still open their files by ID.list_indexedorg bucket excludes project docs and gains a project bucket (agentProjectIds);retrieve/searchstorage-id verification (verify_thread_scoped_access) loads the backing hub doc and requires the caller's project scope to cover it.document_retrievehonors the same scope for parity.@pins —resolveReferencedFilesextracted toagents/resolve_referenced_files.ts: a project doc is pinable only when the thread belongs to that project and the sender can read it; thread metadata is read before reference resolution to supply the scope.updateDocument/deleteDocumentrequire project edit access (the attach/detach standard) for project docs;teamId(s)assignment on a project doc is rejected in both update helpers (projectId/teamId mutual exclusivity, all callers incl. REST/sync).generate_responseresolvesgetProjectIdForThreadonce, re-verifies the sender's current access viaassertProjectAccessForChat(a revoked member's old project threads no longer grant scope), and unions the project intoagentProjectIdsfor context injection and therag_searchtool context.chat_turnvalidatesargs.projectIdbefore the prewarm branch, so an unvalidated prewarm can never bind a thread to a foreign project./api/v1/documents— hub-only (keys are per-user sessions): list filters project docs post-pagination; GET/PATCH/DELETE answer an opaque 404. Shared internals stay open for sync/retention/erasure callers.Independent adversarial review of the initial six-path fix found the
rag_searchbucket and the prewarm/stale-binding holes; both are closed here rather than deferred.Checklist
bun run checkpasses — 42/47 tasks green in the worktree; the sole failure (@tale/uiapp-shell.test.tsx) is a git-worktree artifact (Vite denies the hoistednode_modulesfont path outside the worktree root) and the same file passes 5/5 in the main checkout. This diff touches nopackages/uicode.bun run lint:sastpasses — 0 findings on this diff; the repo-wide scan's single finding is pre-existing inservices/sandbox-runtime(untouched).PROJECT_FORBIDDEN,DOCUMENT_SCOPE_CONFLICT) and the REST handlers reuse the existing "Document not found" wording.docs/en/platform/projects/manage-files.mdalready documents exactly this behaviour ("The Files tab is not a knowledge base…", project chat sees project files); this fix makes the docs true.Test plan
Every leak class carries a red→green regression test (watched failing on the pre-fix code):
documents/access.test.ts— hub/project split,canReadDocument,checkProjectDocumentAccessrole matrix (15 cases).agents/resolve_referenced_files.test.ts— pin gate: own-project thread allowed; global chat / foreign project / no project access rejected (8 cases).list_documents_paginated,get_accessible_document_ids,search_documents_for_mention,list_documents_for_agent,list_indexed_documents_for_agent(org bucket + project bucket),update_document_internal(teamId-on-project-doc invariant).convex/documents/+convex/agents/+convex/agent_tools/— 937 tests green; typecheck/oxlint/oxfmt clean.Manual verification for a reviewer (dev stack, two users, one team-scoped project):
rag_search {operation:'list_indexed'}in a global chat does not list it.@picker never offers it; sending a craftedreferencedDocumentIdspin fails withKB_REF_INVALID.tool) retrieves the file's content viarag_search;document_retrieveof the same fileId also succeeds.getDocumentByIdreturns null; update/delete throwPROJECT_FORBIDDEN; RESTGET/PATCH/DELETE /api/v1/documents/:idreturn 404 and the list omits it.Not live-observed end-to-end: project-chat RAG retrieval on a seeded stack (step 3) — the unit tests pin every decision point and the wiring is typecheck-verified, but I could not run a full RAG corpus in this environment; step 3 is the one to smoke first.