Skip to content

feat(BA-3947): Add sessions resolver to strawberry AgentV2 schema#9620

Open
jopemachine wants to merge 5 commits intomainfrom
BA-3647
Open

feat(BA-3947): Add sessions resolver to strawberry AgentV2 schema#9620
jopemachine wants to merge 5 commits intomainfrom
BA-3647

Conversation

@jopemachine
Copy link
Member

@jopemachine jopemachine commented Mar 4, 2026

resolves #8130 (BA-3947)

Checklist: (if applicable)

  • Milestone metadata specifying the target backport version
  • Mention to the original issue
  • Installer updates including:
    • Fixtures for db schema changes
    • New mandatory config options
  • Update of end-to-end CLI integration tests in ai.backend.test
  • API server-client counterparts (e.g., manager API -> client SDK)
  • Test case(s) to:
    • Demonstrate the difference of before/after
    • Demonstrate the flow of abstract/conceptual models with a concrete implementation
  • Documentation
    • Contents in the docs directory
    • docstrings in public interfaces and type annotations

📚 Documentation preview 📚: https://sorna--9620.org.readthedocs.build/en/9620/


📚 Documentation preview 📚: https://sorna-ko--9620.org.readthedocs.build/ko/9620/

@github-actions github-actions bot added size:M 30~100 LoC comp:manager Related to Manager component labels Mar 4, 2026
@jopemachine jopemachine changed the title feat(BA-3647): Implement session node resolver to Agent feat(BA-3947): Implement session node resolver to Agent Mar 4, 2026
@jopemachine jopemachine added this to the 26.3 milestone Mar 4, 2026
Co-authored-by: octodog <mu001@lablup.com>
@github-actions github-actions bot added the area:docs Documentations label Mar 4, 2026
@jopemachine jopemachine changed the title feat(BA-3947): Implement session node resolver to Agent feat(BA-3947): Add sessions resolver to strawberry AgentV2 schema Mar 4, 2026
Co-authored-by: octodog <mu001@lablup.com>
@jopemachine jopemachine marked this pull request as ready for review March 5, 2026 02:10
@jopemachine jopemachine requested review from a team and Copilot March 5, 2026 02:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds the missing AgentV2.sessions field to the Strawberry-based GraphQL schema so AgentV2 can expose session lists associated with a specific agent (parity step toward legacy AgentNode replacement).

Changes:

  • Add AgentV2.sessions field + resolver wiring to fetch_sessions() with pagination/filter/order support.
  • Add a scheduler query condition (SessionConditions.by_agent_id) to filter sessions by agent membership.
  • Update GraphQL reference schema docs and add a changelog entry.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/ai/backend/manager/repositories/scheduler/options.py Adds SessionConditions.by_agent_id() and updates kernel agent-id condition typing.
src/ai/backend/manager/api/gql/agent/types.py Adds Strawberry AgentV2.sessions field and passes agent-based base condition into session fetcher.
docs/manager/graphql-reference/v2-schema.graphql Documents the new AgentV2.sessions field in the v2 schema reference.
docs/manager/graphql-reference/supergraph.graphql Documents the new AgentV2.sessions field in the supergraph schema reference.
changes/9620.feature.md Records the feature addition in the changelog system.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +451 to 490
@strawberry.field( # type: ignore[misc]
description="Added in 26.3.0. List of sessions running on this agent with pagination support."
)
async def sessions(
self,
info: Info[StrawberryGQLContext],
filter: Annotated[
SessionV2FilterGQL, strawberry.lazy("ai.backend.manager.api.gql.session.types")
]
| None = None,
order_by: list[
Annotated[
SessionV2OrderByGQL, strawberry.lazy("ai.backend.manager.api.gql.session.types")
]
]
| None = None,
before: str | None = None,
after: str | None = None,
first: int | None = None,
last: int | None = None,
limit: int | None = None,
offset: int | None = None,
) -> Annotated[
SessionV2ConnectionGQL, strawberry.lazy("ai.backend.manager.api.gql.session.types")
]:
"""Fetch sessions associated with this agent."""
from ai.backend.manager.api.gql.session.fetcher.session import fetch_sessions

return await fetch_sessions(
info=info,
filter=filter,
order_by=order_by,
before=before,
after=after,
first=first,
last=last,
limit=limit,
offset=offset,
base_conditions=[SessionConditions.by_agent_id(self._agent_id)],
)
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

AgentV2GQL.sessions calls fetch_sessions() directly per agent instance. In queries that return a list/connection of agents and request sessions for each node, this will trigger one session-search per agent (N+1 pattern) and can become expensive. Consider introducing a batching approach (e.g., a DataLoader keyed by (agent_id, pagination/filter args) with internal grouping, or a dedicated processor/repository method that can fetch sessions for multiple agent IDs in one call when args match) to keep the number of DB/service calls bounded per GraphQL request.

Copilot uses AI. Check for mistakes.
Comment on lines +451 to 490
@strawberry.field( # type: ignore[misc]
description="Added in 26.3.0. List of sessions running on this agent with pagination support."
)
async def sessions(
self,
info: Info[StrawberryGQLContext],
filter: Annotated[
SessionV2FilterGQL, strawberry.lazy("ai.backend.manager.api.gql.session.types")
]
| None = None,
order_by: list[
Annotated[
SessionV2OrderByGQL, strawberry.lazy("ai.backend.manager.api.gql.session.types")
]
]
| None = None,
before: str | None = None,
after: str | None = None,
first: int | None = None,
last: int | None = None,
limit: int | None = None,
offset: int | None = None,
) -> Annotated[
SessionV2ConnectionGQL, strawberry.lazy("ai.backend.manager.api.gql.session.types")
]:
"""Fetch sessions associated with this agent."""
from ai.backend.manager.api.gql.session.fetcher.session import fetch_sessions

return await fetch_sessions(
info=info,
filter=filter,
order_by=order_by,
before=before,
after=after,
first=first,
last=last,
limit=limit,
offset=offset,
base_conditions=[SessionConditions.by_agent_id(self._agent_id)],
)
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

The new AgentV2GQL.sessions field introduces a new query surface and filtering/pagination wiring via base_conditions=[SessionConditions.by_agent_id(...)], but there are no unit tests covering this resolver behavior. Adding a resolver-level unit test (similar to other GraphQL resolver tests that patch the fetcher) would help ensure the agent-id condition is always applied and pagination args are forwarded correctly.

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added size:L 100~500 LoC and removed size:M 30~100 LoC labels Mar 5, 2026
@github-actions github-actions bot added size:M 30~100 LoC size:L 100~500 LoC and removed size:L 100~500 LoC size:M 30~100 LoC labels Mar 5, 2026
@github-actions github-actions bot added size:M 30~100 LoC and removed size:L 100~500 LoC labels Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:docs Documentations comp:manager Related to Manager component size:M 30~100 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement session node resolver

2 participants