fix(platform): scope chat thread reads to the active org#2170
Merged
Conversation
Switching org while a thread was open kept rendering the previous org's chat. The thread by-id queries authorized against the thread's OWN org (any org the user still belonged to), never the org the user was acting in, and their query keys weren't org-scoped so stale data survived the switch. canAccessThread now enforces the supplied active org: a thread that does not belong to it returns null instead of falling back to membership of the thread's own org. The eight by-id thread queries (getThreadMeta, getThreadMessages, getThreadMessagesStreaming, isThreadGenerating, getThreadShareStatus, getThreadForkInfo, getArenaThreadPair, getFailedMessageErrors) and setThreadCanvasState now take the active organizationId, and every caller threads it through (route $id via useOrganizationId or in-scope props). That also makes the query keys org-scoped, so the org-switch cache purge catches them. Callers that omit the hint (internal/system) keep prior behaviour, so tenant isolation is unchanged - this only closes the active-org coherence gap for members of multiple orgs.
f032485 to
374f14f
Compare
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.
Problem
Switching organizations while a chat thread was open kept rendering the previous org's chat. Two causes compounded:
switching.tsxcouldn't drop them and stale data lingered.A context/correctness bug for multi-org members — tenant isolation was never broken (non-members could not read the data).
Fix
canAccessThreadnow enforces the supplied active org: a thread that doesn't belong to it returnsnullinstead of falling back to membership of the thread's own org. Callers that omit the hint (internal/system) keep prior behaviour.getThreadMeta,getThreadMessages,getThreadMessagesStreaming,isThreadGenerating,getThreadShareStatus,getThreadForkInfo,getArenaThreadPair,getFailedMessageErrors) andsetThreadCanvasStatetake the activeorganizationId; every caller threads it through (route$idviauseOrganizationId, or in-scope props). This also makes the query keys org-scoped, so the switch-time cache purge catches them.Verification
tsc --noEmit(whole platform): 0 errorscanAccessThreadunits: 21/21 (incl. a rewritten test that previously locked in the buggy behaviour + a new shared-branch denial test)use-message-processing,share/export-chat): 68/68Scope
First of a sequenced set: the same active-org-coherence gap exists for projects, tasks, automations, documents/knowledge/prompts/conversations (their by-id detail queries authorize against the entity's own org too). Those follow as separate focused PRs, plus a frontend
switching.tsxchange to reset resource-detail subpaths on switch.