From 1b934c43f48c566b168f4ed5652fd40183a47aa3 Mon Sep 17 00:00:00 2001 From: Ollie Agent Date: Tue, 18 Aug 2026 07:09:21 +0200 Subject: [PATCH] Release empty registry agent state --- cmd/toolsrv/internal/registry/registry.go | 5 +++++ doc/concurrency-resource-audit.md | 8 ++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/toolsrv/internal/registry/registry.go b/cmd/toolsrv/internal/registry/registry.go index 7ed0ff1..b616901 100644 --- a/cmd/toolsrv/internal/registry/registry.go +++ b/cmd/toolsrv/internal/registry/registry.go @@ -71,6 +71,11 @@ func (r *Registry) Unload(agentID, name string) error { } delete(agentTools, name) + if len(agentTools) == 0 { + delete(r.agents, agentID) + delete(r.revisions, agentID) + return nil + } r.revisions[agentID]++ return nil } diff --git a/doc/concurrency-resource-audit.md b/doc/concurrency-resource-audit.md index e59bf38..1816fc2 100644 --- a/doc/concurrency-resource-audit.md +++ b/doc/concurrency-resource-audit.md @@ -286,13 +286,9 @@ Completion notifications now use the toolsrv run context with a ten-second timeo ### M14. Toolsrv registry retains abandoned agent state -**Evidence:** `cmd/toolsrv/internal/registry/registry.go:15-19,47-75`. +**Status:** Fixed in the working tree. -`Load` creates per-agent tool and revision maps. `Unload` removes tools but never removes empty agent maps or revision entries. - -**Impact:** transient or deleted agent identifiers accumulate in long-lived toolsrv processes. - -**Remediation:** delete empty agent state when an agent is unloaded. +`Unload` now removes the per-agent tool map and revision entry when the final tool is removed. Empty agent state no longer accumulates in long-lived toolsrv processes. ### M15. `DismissProc` and process GC can lose cleanup ownership