Did an refactoring to enable snapshot for fetch_expanded_live_specs, … - #3210
Closed
bbartman wants to merge 13 commits into
Closed
Did an refactoring to enable snapshot for fetch_expanded_live_specs, …#3210bbartman wants to merge 13 commits into
bbartman wants to merge 13 commits into
Conversation
…I added the snapshot as a parameter and left the user_id as a parameter because I wasn't sure if we would need the user_id as part of the interface and I didn't want to remove it without consulting someone about it.
bbartman
marked this pull request as draft
July 21, 2026 11:50
…tests verifing correct behavior.
…data_plane function.
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.
Description:
This is a continuation of previous work to remove the old style of permissions, and replace it with the snapshot style of permissions.
Remaining uses of internal.user_roles
This PR relies on work previously done here.
Documentation links affected:
N/A
Notes for reviewers:
Change approach rationale:
fetch_expanded_live_specs
There was a cascading affect from this up to a trait called
Initialize. I did a refactoring on the initialize member of that trait and added the snapshot to the parameter list, I also left theuser_idin the parameter list. Here is the rationale for this, 1) The implementer of initialize, needs theuser_idto figure out permissions, and 2) not all implementers of the ``initialize` function actually use the snapshot. Leaving both pieces of information there means that those that don't need the permissions check don't use it and can just ignore the parameters.Here is the rationale for adding this as a function parameter instead of a member. The only caller of the
initializetrait had access to the snapshot already, so there was minimal change there, and there was more than one implementer of theinitializetrait, and I didn't want to figure out each one was created, add a member for initialization, then thread the snapshot through the rest of the related code. I figured this out after looking into the locations that the implementers of theInitializetrait were being built. The locations where those types were being initialized did not have access to the snapshot, there by spreading the snapshot dependency, and making implementation more difficult.resolve_specs
This function has no call sites that I can find. Did normal refactoring to remove the
user_id, and write the function in terms of a set of permissions. Did an outside of DB query optimization by adding a filter to the construction of the permissions list. In the original DB call we were filtering onadminso I moved the filter to before we sent the arrays to the query.user_has_admin_capability
This function was changed to use the snapshot. Because this uses a transaction I had claude do some additional verification on if there was any way that permissions could be modified during that time. TL;DR no path that leads to that function changes or modifies permissions so it's safe to use the snapshot.
Claude output.
There is no path that leads to user_can_admin_tenant where permissions are changed in the same transaction — or by any reachable function — before (or after) the check. The requirements for a read-your-writes bug (a caller mutating grants in the same txn and relying on the check seeing them) are not met:
create_data_plane & update_l2_reporting
Note both of these functions used identical code so I refactored to use the same funciton.
Here is what was done.
After a code review, I added support for a deny and retry permission structure.
Added improvements to test harness evaluation speed
This is to fix something I added in a previous MR. Basically, we ran into a problem where we had to wait on the refresh of the snapshot which cost about 20 seconds this eventually made tests runtime cost about 40 - 60 seconds per tests. This change reduces the runtime down to about 67s locally or just over a minute. Here is the claude description of what was fixed:
From claude
The harness no longer uses PgSnapshotSource's timer-gated polling loop. Instead it owns both halves of a tokens::manual() watch: