refactor(BA-5709): add main_access_key resolver helpers#11041
Closed
jopemachine wants to merge 5 commits into
Closed
refactor(BA-5709): add main_access_key resolver helpers#11041jopemachine wants to merge 5 commits into
jopemachine wants to merge 5 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds helper APIs to resolve a user’s main_access_key and rewires session access-key filters to resolve via the owning user’s main_access_key (preparatory work for dropping redundant sessions.access_key / kernels.access_key columns).
Changes:
- Add
UserRepository.get_main_access_key_by_idandUserDBSource.get_main_access_key_by_idfor single-query access-key resolution by user UUID. - Rewrite
SessionConditions.by_access_key_*filters to use aUserRow.main_access_keysubquery keyed bySessionRow.user_uuid. - Add a changelog entry describing the refactor groundwork.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/ai/backend/manager/repositories/user/repository.py | Adds repository helper for main_access_key lookup and adjusts endpoint ownership delegation call signature. |
| src/ai/backend/manager/repositories/user/db_source/db_source.py | Adds DBSource scalar query for main_access_key and updates endpoint ownership delegation call signature. |
| src/ai/backend/manager/models/session/conditions.py | Reworks access-key session filters to resolve via owner subquery; adds centralized helper. |
| changes/11041.misc.md | Documents the new helper + filter rewrite as groundwork for future column removal. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Apr 14, 2026
Two independent additions that other parts of the BA-5650 stack build on: - ``UserRepository.get_main_access_key_by_id`` (+ the matching ``UserDBSource`` method) returns ``main_access_key`` for a given user UUID with a single readonly query. Used by downstream refactors that need to resolve the keypair access_key on demand from the owner. - ``SessionConditions.by_access_key_*`` filters in ``models/session/conditions.py`` now resolve through a subquery on ``UserRow.main_access_key`` keyed by ``SessionRow.user_uuid``, instead of the ``sessions.access_key`` column. A new ``_owners_where_main_access_key`` staticmethod centralises the subquery shape. Behavior is unchanged on ``main`` where ``sessions.access_key`` still mirrors the owner's main_access_key; this change just lets us drop the redundant column later.
Slice A scope is only the new get_main_access_key_by_id helper and the SessionConditions rewrite. Accidentally dropping the target_main_access_key argument from delegate_endpoint_ownership belongs to a later slice that also updates EndpointRow and the user service; restoring the signature here so this PR builds standalone.
2d7d64e to
e66536b
Compare
jopemachine
commented
Apr 14, 2026
Drop the redundant UserRow.main_access_key IS NOT NULL guard inside SessionConditions._owners_where_main_access_key. The subquery selects users.uuid (non-null PK), so NOT IN is well-defined; NULL main_access_key fails the caller-supplied condition on its own. The behaviour is unchanged — this just makes the helper contract clearer. Also drop the stale misc news fragment (skip:changelog applies to this purely additive refactor).
Member
Author
|
Consolidated into the merged PR stack (A+B+C+D, E+F, G+H, I) |
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.
📚 Stack
mainMerge from top to bottom. Intermediate slices may not build standalone; the final refactor tip is #11051, and #11040 is the schema-drop follow-up on top of it.
Summary
Add
UserRepository.get_main_access_key_by_id(plus the matchingUserDBSourcemethod) and rewriteSessionConditions.by_access_key_*filters to resolve the owner'smain_access_keyvia a subquery._owners_where_main_access_keystaticmethod centralises the subquery shape. Behavior unchanged on main.Resolves BA-5709. Part of epic BA-5650.
📚 Documentation preview 📚: https://sorna--11041.org.readthedocs.build/en/11041/
📚 Documentation preview 📚: https://sorna-ko--11041.org.readthedocs.build/ko/11041/
BA-5650 Series: Split Rationale
Overall goal: migrate the session owner identifier from
access_key(keypair) toowner_id(user UUID), and drop thesessions.access_key/kernels.access_keycolumns.Split criteria: layer + dependency order. Bottom-up (DB helpers → service → API) so the destructive column drop can land safely at the end.
get_main_access_key_by_idand related resolver helpers (everything else depends on this)UserPermission.user_uuid → owner_id; addmain_access_keyfieldSessionData.user_uuid → owner_id; Row adapters; GQL nodeSessionRepository,SessionDBSource, creators signaturesowner_idfrom 21 read/control Actions; resolve viacurrent_user()owner_access_keyfrom REST v1 DTOs (breaking)Why this split
access_keyfromowner_id. BA-5653 (destructive) only runs once every reader has migrated off the dropped column.