feat(BA-6827): add agent resource-group update service#12917
Open
fregataa wants to merge 3 commits into
Open
Conversation
fregataa
added a commit
that referenced
this pull request
Jul 16, 2026
fregataa
marked this pull request as ready for review
July 16, 2026 07:49
fregataa
marked this pull request as draft
July 16, 2026 08:12
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
force-pushed
the
feat/BA-6827-conflicting-session-cleanup
branch
2 times, most recently
from
July 16, 2026 09:12
5b51fb0 to
47f371c
Compare
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
force-pushed
the
feat/BA-6827-conflicting-session-cleanup
branch
from
July 16, 2026 11:35
47f371c to
079639d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AgentService.update_resource_group: change an agent's resource group and handle the sessions still running on it in a single flow.resource_group_id(caller-resolved), a cleanup policy (TERMINATE/RESCHEDULE), andforce.AgentRepository.update_resource_groupatomically gates on the agent's active kernels — it raisesAgentHasConflictingSessionswhen they exist andforceis 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).RESCHEDULEis 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 rejectedpants test tests/unit/manager/repositories/agent/test_repository.py— real-DB: no-kernel commit updates both columns; active-kernel force gatepants check/pants lintResolves BA-6827