-
Notifications
You must be signed in to change notification settings - Fork 164
fix(BA-4167): Use joinedload instead of selectinload in AgentDBSource.get_by_id
#8472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Fixes MissingGreenlet raised by AgentDBSource.get_by_id() when actual_occupied_slots computation touches the kernels relationship in async contexts.
Changes:
- Switch eager-loading strategy in
AgentDBSource.get_by_id()fromselectinloadtojoinedloadforAgentRow.kernels. - Add unit test coverage to validate
get_by_id()can computeactual_occupied_slotswithout triggering async lazy-loading. - Add changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/ai/backend/manager/repositories/agent/db_source/db_source.py |
Changes eager-loading option used by get_by_id() for kernels. |
tests/unit/manager/repositories/agent/test_repository.py |
Adds a new test ensuring get_by_id() loads kernels and computes actual_occupied_slots. |
changes/8472.fix.md |
Adds a changelog note for the MissingGreenlet fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c60831c to
5775c15
Compare
| async def test_get_by_id_loads_kernels_and_computes_actual_occupied_slots( | ||
| self, | ||
| db_source: AgentDBSource, | ||
| agent_with_kernels: KernelFilteringTestCase, | ||
| ) -> None: | ||
| # Act - This should not raise MissingGreenlet error | ||
| agent_data = await db_source.get_by_id(agent_with_kernels.agent_id) | ||
|
|
||
| # Assert - Verify actual_occupied_slots is computed correctly | ||
| actual_cpu = agent_data.actual_occupied_slots.get("cpu", 0) | ||
| assert Decimal(str(actual_cpu)) == agent_with_kernels.expected_actual_occupied_cpu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to test the repository, but you are only testing the database source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified it to test the repository. Since test_search_agents_validates_actual_occupied_slots was also testing DBSource, changed it to test the repository as well.
…d of AgentDBSource
resolves #8468 (BA-4167)
Checklist: (if applicable)
ai.backend.testdocsdirectory