Conversation
* Locate all child sub-processes (subagents) by searching in AgentProcessRepository * Ammend eviction algorithm by blocking eviction for running agents (including subagents)
|
The cascade kill implementation is clean. One suggestion worth considering: the hierarchy-aware eviction logic ( Extracting the eviction policy to its own class would keep the repository focused and make the policy independently testable: internal class HierarchyAwareEvictionPolicy(private val windowSize: Int) {
fun evictIfNeeded(accessOrder: ArrayDeque<String>, map: MutableMap<String, AgentProcess>) {
while (accessOrder.size > windowSize) {
val oldestRootId = accessOrder.first()
if (isHierarchyFinished(oldestRootId, map)) {
accessOrder.removeFirst()
evictHierarchy(oldestRootId, map)
} else break
}
}
private fun isHierarchyFinished(processId: String, map: Map<String, AgentProcess>): Boolean {
val process = map[processId] ?: return true
if (!process.finished) return false
return map.values.filter { it.parentId == processId }
.all { isHierarchyFinished(it.id, map) }
}
private fun evictHierarchy(processId: String, map: MutableMap<String, AgentProcess>) {
map.values.filter { it.parentId == processId }.forEach { evictHierarchy(it.id, map) }
map.remove(processId)
}
}
if (agentProcess.isRootProcess) {
accessOrder.offer(processId)
evictionPolicy.evictIfNeeded(accessOrder, map)
}As a further thought, eviction could eventually be applied as an aspect on |
|
@jasperblues: Refactored InMemory Agent Process Repo per recommendation. thanks |
|



Overview
Please refer to issue:
#1509
When killing a parent agent process, all child subagents are now automatically killed recursively.
Child Process Discovery: Uses AgentProcessRepository.findByParentId() to locate children. Each
child process stores its parentId (set during createChildProcess()), enabling repository queries to
find all descendants.
Why Repository vs Parent Collection: Repository is the single source of truth for process
lifecycle. This works consistently across repository
implementations (in-memory, database), and leverages existing parentId field without bi-directional
references.
Changes
File: AgentProcess.kt
Change: Add isRootProcess property
────────────────────────────────────────
File: AgentProcessRepository.kt
Change: Add findByParentId(parentId: String): List
────────────────────────────────────────
File: AbstractAgentProcess.kt
Change: kill() cascades to children via repository lookup
────────────────────────────────────────
File: DefaultAgentPlatform.kt
Change: killAgentProcess() delegates to process.kill()
────────────────────────────────────────
File: InMemoryAgentProcessRepository.kt
Change: Implement findByParentId() and hierarchy-aware eviction
────────────────────────────────────────
File: SubagentExecutionTest.kt
Change: Add tests for parentId, cascading kill via platform and direct kill()
────────────────────────────────────────
File: InMemoryAgentProcessRepositoryTest.kt
Change: Add tests for hierarchy eviction rules