Add concurrency guards to harness.Run: single-flight, semaphore and timeouts
CI / ci (push) Successful in 1m34s
CI / ci (pull_request) Successful in 1m37s

harness.Run now takes a scope key. Concurrent runs of one skill with one
scope share a single in-flight run and its result, errors included, so
only one Generate call is made; different scopes run independently. A
process-wide Guard (NewGuard, DefaultMaxCalls = 2) bounds concurrent LLM
calls with a context-aware semaphore. Each skill declares Timeout()
(DefaultTimeout = 60 s), enforced via context over the whole run; a run
past it fails with an error matching llm.ErrTimeout. A caller whose
context ends gets the context error; the shared run is cancelled, and
its slot freed, once no caller waits for it.

llm.Fake results can now block (Release) and signal entry (Started), so
tests hold calls in flight.

Maestro task: 8f533721-32c9-4f73-af9f-9a9f0e94abf8

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-05 10:00:20 -04:00
co-authored by Claude Opus 5.5
parent 87316d8b70
commit d03068ace5
10 changed files with 591 additions and 17 deletions
+3
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"strings"
"time"
"code.cubecraftlabs.com/Maniacs_Mansion/Meal-Quest/internal/ai/llm"
)
@@ -53,3 +54,5 @@ func (echoSkill) PostProcess(out echoOutput) (echoOutput, error) {
out.Echo = strings.TrimSpace(out.Echo)
return out, nil
}
func (echoSkill) Timeout() time.Duration { return DefaultTimeout }