lablup / lablup/backend.ai

Apply the virtual scope chain to the session entity

Open
#14,071 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
15h 13m
Merged PRs (30d)
368

Description

Settle every scope operation of the `session` entity on the virtual scope chain. The wiring declares 13 scope operations for it; each one is accounted for below. Resolve ownership through `entity_memberships` joined to `virtual_scopes`; helpers live in `src/ai/backend/manager/models/virtual_scope/queries.py`.

## Convert

- `search_sessions_in_project` — `SessionRow.group_id == :project_id` (`models/session/scopes.py:22`)
- `search_sessions` — declares a user scope for the permission gate but applies no scope condition of its own; `SessionService.search()` passes the querier straight through and the predicate lives as adapter lambdas (`api/adapters/session/adapter.py:666` and three further call sites). Gather it into one OperationScope.
- `export_sessions_by_project_c_s_v` and `export_my_sessions_c_s_v` — the same two relations as service lambdas (`services/export/service.py:243`, `:311`)

## Already settled

- `create_cluster`, `create_from_params`, `create_from_template`, `enqueue_session` — the create path records both the owning user and the project

## Out of scope

- `search_kernels` — returns kernel rows, and `kernel` appears in the catalogue as neither an entity type nor a field type
- `match_sessions` — matches on `owner_access_key`, which reaches the session through keypair, a field type
- `search_session_scoped_history`, `search_kernel_scoped_history` — parent-keyed history reads
- `get_domain_resource_overview`, `get_project_resource_overview` — GROUP BY aggregates over kernels, not scoped lists
- `get_effective_allocation` — computes a policy for one (user, project) pair

## Write side

Present. `models/session/creators.py:53` declares `member_of() -> [UserID, ProjectID]`.

## Done when

- No adapter call site is left writing its own session ownership lambda.
- Each converted read has a test proving it returns the same rows as the column-based query on backfilled data.

JIRA Issue: BA-7548

Contributor guide

Open the contributing guide

Research direction

Start with the virtual-scope helpers in src/ai/backend/manager/models/virtual_scope/queries.py, then trace the session scopes and service/adapter call sites named in the issue, including models/session/scopes.py, api/adapters/session/adapter.py, services/export/service.py, and models/session/creators.py. Done means no adapter site owns its own session lambda and each converted read has a test showing the same rows as the column-based query on backfilled data.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, databases
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.