CS-11126: drop Realm visibility / worldReadable caches#4868
Open
lukemelia wants to merge 1 commit into
Open
Conversation
`Realm.visibility()` and `isWorldReadable()` were memoized per instance, so a `*: read` grant or revoke applied via the PATCH handler on replica A was silently ignored by every other replica until restart — the only audit finding in the multi-replica sweep that touches auth correctness, not just stale display data. Going with Option B from the ticket: drop the caches entirely. `realm_permissions` is indexed by `realm_url`, so each call is a single SELECT. `createRequestContext` is refactored to do that SELECT once per request and derive both the world-readable flag and the full permissions map from the same row set, so the non-world-readable read path is not double-fetching. Removes the boot-time `await this.isWorldReadable()` warmup (cache priming is now a no-op) and the cache-write inside `patchRealmPermissions` (no cache to update). The `visibility()` body collapses from a memoized IIFE into a straight-line read. Adds an integration test in `permissions-test.ts` that simulates a peer-replica DB write via direct `insertPermissions` and asserts `visibility()` reflects the new state on the next call without restart — the acceptance criterion from the ticket.
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
Removes the per-Realm memoization of visibility() and #worldReadable so that out-of-band changes to realm_permissions (e.g. a *: read grant/revoke applied on a peer replica) are observed without requiring a server restart. createRequestContext is refactored to do a single fetchRealmPermissions lookup per request and derive both the world-readable flag and the full permissions map from that one fetch.
Changes:
- Drop
#worldReadable/#worldReadablePromise/visibilityPromisecaches and the boot-time warmup; collapsevisibility()into a straight-line read. - Refactor
createRequestContextto fetchrealm_permissionsexactly once and deriveisWorldReadablefrom it. - Add an integration test that simulates a peer-replica DB write via
insertPermissionsand assertsvisibility()reflects the new state on the next call.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/runtime-common/realm.ts | Remove visibility/worldReadable caches; single-fetch request context; simplify visibility(). |
| packages/realm-server/tests/realm-endpoints/permissions-test.ts | Add integration test asserting visibility reflects out-of-band permission writes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
visibility()/#worldReadablememoization onRealmso a*: readgrant or revoke applied on one replica is observed by every other replica on the next call instead of requiring a restart. This is the only audit finding from CS-11126 that touches auth correctness (vs. stale display data).createRequestContextto fetchrealm_permissionsexactly once per request and derive both the world-readable flag and the full permissions map from the same row set, so the non-world-readable read path is not double-fetching.insertPermissionsand assertsvisibility()reflects the new state on the next call (the acceptance criterion from the ticket).This is Option B from the ticket — fetch fresh, no NOTIFY channel — chosen because
realm_permissionsis a single indexed lookup and the per-request overhead is one SELECT.Linear: CS-11126
Notes
await this.isWorldReadable()warmup — with no cache to prime, it was a wasted DB query.patchRealmPermissionsfor the same reason.visibility()body collapses from a memoized IIFE into a straight-line read.Test plan
visibility() reflects out-of-band realm_permissions changes without restartpasses inrealm-endpoints/permissions-test.ts_permissionsPATCH tests still pass🤖 Generated with Claude Code