Skip to content

refactor(BA-7226): replace session/kernel/agent ORM relationship usages with explicit queries - #13786

Open
fregataa wants to merge 5 commits into
mainfrom
refactor/BA-7226-remove-session-kernel-agent-relationships
Open

refactor(BA-7226): replace session/kernel/agent ORM relationship usages with explicit queries#13786
fregataa wants to merge 5 commits into
mainfrom
refactor/BA-7226-remove-session-kernel-agent-relationships

Conversation

@fregataa

Copy link
Copy Markdown
Member

Summary

  • Replace the remaining usages of the session, kernel and agent ORM relationships with explicit queries and batched assembly, then remove the relationship definitions and every loader option that depended on them (8 of the 9 relationships listed in BA-7226).
  • ComputeContainer.imageObject and ComputeSessionNode.owner now resolve through id/uuid-keyed dataloaders instead of eager-loaded joins; the GraphQL schema itself is unchanged. gql_legacy joins users/groups explicitly so the full_name / user_email / group_name filters keep working, and the resource-usage report runs one explicit join returning ResourceUsageRecord.
  • SessionRow.kernels and the row helpers built on it (main_kernel, resource_opts, get_kernel_by_id, delegate_ownership) are intentionally left for a follow-up PR — converging them onto the sokovan-style dataclass accessors touches ~100 consumer sites and is a separate change.

Test plan

  • pants test --changed-since=origin/main passes
  • Agent list/detail (REST v2 + agents GQL) reports the same occupied_slots as before, with slots still ordered by resource_slot_types.rank
  • computeContainerList / computeContainer still return imageObject, and computeSessionNode.owner still resolves
  • Session list filtering and ordering by full_name, user_email, group_name still work
  • usage_per_period / usage_per_month project usage reports return the same figures
  • get_direct_access_info on a SYSTEM session returns the agent public host, and raises KernelNotReady when no agent is assigned
  • convert_session_to_image still resolves the project container registry

Resolves BA-7226

🤖 Generated with Claude Code

fregataa and others added 4 commits August 16, 2026 02:48
… queries

Add fetch_actual_occupied_slots() to the agent repository query module and
pass the resolved slots into AgentRow.to_data(), so agent occupancy no longer
depends on the agent_resource_rows relationship or its slot_type_row chain.
The scheduler db_source loads per-slot capacity/reserved/used through its own
batched query.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…explicit queries

- ComputeContainer.imageObject resolves through a new id-keyed ImageNode
  dataloader instead of the KernelRow.image_row join; group_row/user_row were
  eager-loaded but never read, so those loader options are gone.
- KernelRow.get_kernel() filters live agents with an explicit join on agents.
- get_direct_access_info() reads the agent public host through the session
  repository rather than walking main_kernel.agent_row.
- Drop the now-dead agent_row eager loads in the registry, the stream/session
  db_sources and the session kernel loading strategies.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… queries

- ComputeSessionNode.owner resolves through a uuid-keyed UserNode dataloader.
- gql_legacy session queries join users/groups explicitly so the
  full_name/user_email/group_name filters keep working.
- The resource-usage report runs one explicit join and returns
  ResourceUsageRecord instead of walking kernel -> session -> user/group.
- convert_session_to_image reads the project container registry through the
  session repository; get_session_with_group is gone.
- join_by_related_field had no callers left and is removed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ype_row

Both relationships are now unreferenced: slot_type_row lost its last reader
when agent occupancy moved to an explicit join, and nothing reads
KernelRow.session. SessionRow.kernels drops its back_populates and becomes
one-directional; no code writes through the relationship, so delete behaviour
still comes from the database foreign keys.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@fregataa
fregataa requested a review from a team as a code owner August 15, 2026 17:54
Copilot AI balanced review requested due to automatic review settings August 15, 2026 17:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added size:XL 500~ LoC comp:manager Related to Manager component labels Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants