Repository navigation
perf(server): shell resume filters visibility once, not per thread - #228
Merged
Merged
Conversation
On every team-mode shell resume the fork emitted an execution frame for every thread in the unfiltered shell, and each frame then re-read its thread (getThreadShellById, 5 statements) to decide visibility: ~980 statements per resume in prod, plus execution lookups for threads the user could not see. The shell is now filtered with the same owner/member rule (filterShellSnapshot) before execution snapshots are read, so only visible threads are looked up and frames need no per-frame check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
When a client resumes its shell subscription (every reconnect, and every wake from sleep), the fork's
currentShellExecutionStreaminws.tsdid three things:applyShellItemVisibility.For a team-mode connection, and in prod every Clerk connection has an actor, step 3 ran
getThreadShellById(5 statements) per frame, just to check owner/member. That's about 980 statements per resume, before the "synchronized" marker, even when the client missed no events.Fix
Inside the existing
T3-CUSTOM(expbkt3)block inws.ts: the shell is filtered once withfilterShellSnapshot(shell, actorUserId), the same owner/member rule the per-frame check applied to the same active-shell rows. Execution snapshots are then read only for visible threads, and the frames need no per-frame check. Unrestricted connections (actorUserId === null) are unchanged.The live execution-frame path (
wsVisibility.ts"execution"case) is deliberately left alone: the cheapercanAccessThreadwould also pass archived threads, which changes behaviour.Evidence
Statements per shell resume on the prod copy (196 active threads). Prod users see 147, 32, 15, 15 and 1 of them.
Tests:
server.test.ts -t "subscribeShell|shell": 16 pass.wsVisibility.test.ts+accessRules.test.ts(the rule): 13 pass.vp run typecheckinapps/serveris clean, and the fork-marker check passes.Model/harness: Claude Opus 5.5 via Claude Code in T3 Code.
🤖 Generated with Claude Code