From c0519a1b117c50a9c3c6394bc2948398ce378a92 Mon Sep 17 00:00:00 2001 From: Claudomator Agent Date: Mon, 16 Mar 2026 19:57:54 +0000 Subject: fix: clean up activePerAgent before sending to resultCh Move activePerAgent decrement/deletion out of execute() and executeResume() defers and into the code paths immediately before each resultCh send (handleRunResult and early-return paths). This guarantees that when a result consumer reads from the channel the map is already clean, eliminating a race between defer and result receipt. Remove the polling loop from TestPool_ActivePerAgent_DeletesZeroEntries and check the map state immediately after reading the result instead. Co-Authored-By: Claude Sonnet 4.6 --- internal/executor/executor_test.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'internal/executor/executor_test.go') diff --git a/internal/executor/executor_test.go b/internal/executor/executor_test.go index d8a2b77..878a32d 100644 --- a/internal/executor/executor_test.go +++ b/internal/executor/executor_test.go @@ -751,19 +751,9 @@ func TestPool_ActivePerAgent_DeletesZeroEntries(t *testing.T) { pool.Submit(context.Background(), tk) <-pool.Results() - // The deferred cleanup in execute() runs after resultCh is sent, so poll - // briefly for the map entry to be removed rather than checking immediately. - var exists bool - deadline := time.Now().Add(100 * time.Millisecond) - for time.Now().Before(deadline) { - pool.mu.Lock() - _, exists = pool.activePerAgent["claude"] - pool.mu.Unlock() - if !exists { - break - } - time.Sleep(time.Millisecond) - } + pool.mu.Lock() + _, exists := pool.activePerAgent["claude"] + pool.mu.Unlock() if exists { t.Error("activePerAgent should not have a zero-count entry for claude after task completes") -- cgit v1.2.3