Skip to content

feat(BA-6827): add agent resource-group update service#12917

Open
fregataa wants to merge 3 commits into
mainfrom
feat/BA-6827-conflicting-session-cleanup
Open

feat(BA-6827): add agent resource-group update service#12917
fregataa wants to merge 3 commits into
mainfrom
feat/BA-6827-conflicting-session-cleanup

Conversation

@fregataa

@fregataa fregataa commented Jul 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Add AgentService.update_resource_group: change an agent's resource group and handle the sessions still running on it in a single flow.
  • The action carries the target resource_group_id (caller-resolved), a cleanup policy (TERMINATE / RESCHEDULE), and force.
  • AgentRepository.update_resource_group atomically gates on the agent's active kernels — it raises AgentHasConflictingSessions when they exist and force is unset (the admin drains first), otherwise commits the group change (both the id and name columns) and returns those kernels. The service then marks their sessions for termination (graceful → TERMINATING, cleanup proceeds asynchronously).
  • RESCHEDULE is design-only for now (depends on the RESCHEDULING state from the preemption work) and is rejected up front.

Test plan

  • pants test tests/unit/manager/services/agent/test_service.py — service unit: no-op commit / drain-first failure / force terminate / reschedule rejected
  • pants test tests/unit/manager/repositories/agent/test_repository.py — real-DB: no-kernel commit updates both columns; active-kernel force gate
  • CI: pants check / pants lint

Resolves BA-6827

@github-actions github-actions Bot added size:XL 500~ LoC comp:manager Related to Manager component labels Jul 16, 2026
fregataa added a commit that referenced this pull request Jul 16, 2026
@fregataa
fregataa marked this pull request as ready for review July 16, 2026 07:49
@fregataa
fregataa requested a review from a team as a code owner July 16, 2026 07:49
Copilot AI review requested due to automatic review settings July 16, 2026 07:49

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.

@fregataa
fregataa marked this pull request as draft July 16, 2026 08:12
fregataa and others added 2 commits July 16, 2026 18:00
Introduce a single agent-service method that cleans up the sessions running
on an agent whose resource group is changing.

- Policy enum {TERMINATE, RESCHEDULE} + force flag; v1/v2 call it identically.
- force unset: succeed if no active sessions, else fail (admin drains first).
- force set + TERMINATE: graceful transition to TERMINATING, async cleanup.
- RESCHEDULE is design-only for now (depends on the RESCHEDULING state).
- Conflict detection is a generic scheduler-repo search_kernels(querier)
  filtered by agent + active kernel statuses.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@fregataa
fregataa force-pushed the feat/BA-6827-conflicting-session-cleanup branch 2 times, most recently from 5b51fb0 to 47f371c Compare July 16, 2026 09:12
@fregataa
fregataa marked this pull request as ready for review July 16, 2026 11:24
Redefine the service as "update an agent's resource group" that checks and
applies the change in one flow, per the reworked BA-6827.

- Action now carries the target resource_group_id (caller-resolved), policy,
  and force. No name resolution in the repository.
- AgentRepository.update_resource_group atomically gates on the agent's active
  sessions (raises AgentHasConflictingSessions when present and force is unset),
  commits the group change (id + name columns), and returns the remaining
  sessions. The service marks those sessions for termination.
- Revert the scheduler-repo search_kernels generic; the kernel gate now lives in
  the agent db_source.
- Tests: service unit tests for the new flow; real-DB agent-repo tests for the
  no-kernel commit and the active-kernel force gate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@fregataa
fregataa force-pushed the feat/BA-6827-conflicting-session-cleanup branch from 47f371c to 079639d Compare July 16, 2026 11:35
@fregataa fregataa changed the title feat(BA-6827): add conflicting-session cleanup service path feat(BA-6827): add agent resource-group update service Jul 16, 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