Files
goclaw/internal/agent
Bruno ClermontandBruno Clermont cde8940501 fix(agent): fix race in TestMaybeSummarize_LogsTriggerDecisionOverThreshold (#1347)
maybeSummarize spawns a background goroutine that logs via slog.Info
before calling the LLM provider -- correct, intentional async design,
not a bug. The test read the shared log buffer (buf.String(), inside
captureSlog) immediately after maybeSummarize returned, i.e. right
after the goroutine was merely spawned, not after it finished logging
-- an unsynchronized concurrent read/write on bytes.Buffer, caught by
go test -race. This was surfaced by an unrelated PR's CI run
(nextlevelbuilder/goclaw#1346), confirmed unrelated to that PR's
actual changes.

Moved the existing done-channel wait inside captureSlog's closure, so
the buffer read only happens after the background goroutine has
signalled it reached provider.Chat -- which happens strictly after
the slog.Info write on this path. Proper happens-before via the
channel, no sleep/poll, no production code changed.

Verified 10/10 passes under go test -race -count=10, plus full
package regression run clean.

Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
2026-07-04 23:57:30 +07:00
..
2026-05-31 12:24:00 +07:00