Skip to content

Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.

refactor(httpapi): simplify runner waiter notify with runnerWaiter.accepts (#321)

fx-kurumi35e4989a0bd2
diff --git a/internal/httpapi/runners.go b/internal/httpapi/runners.go
index 6be12d42..10e7e0d6 100644
--- a/internal/httpapi/runners.go
+++ b/internal/httpapi/runners.go
@@ -10,6 +10,7 @@ import (
"io"
"net/http"
"os"
+ "slices"
"strings"
stdsync "sync"
"time"
@@ -131,25 +132,22 @@ func (r *runnerWaiterRegistry) notify(providers []string) {
r.mu.Lock()
defer r.mu.Unlock()
for _, w := range r.waiters {
- for _, p := range providers {
- if containsStringFold(w.providers, p) {
- select {
- case w.ch <- struct{}{}:
- default:
- }
- break
- }
+ if !w.accepts(providers) {
+ continue
+ }
+ select {
+ case w.ch <- struct{}{}:
+ default:
}
}
}
-func containsStringFold(values []string, want string) bool {
- for _, v := range values {
- if strings.EqualFold(v, want) {
- return true
- }
- }
- return false
+// accepts reports whether any of providers matches one the waiter is polling
+// for, compared case-insensitively.
+func (w *runnerWaiter) accepts(providers []string) bool {
+ return slices.ContainsFunc(providers, func(p string) bool {
+ return slices.ContainsFunc(w.providers, func(v string) bool { return strings.EqualFold(v, p) })
+ })
}
// ---------- background sweeper ----------
diff --git a/internal/httpapi/runners_cases_test.go b/internal/httpapi/runners_cases_test.go
index a7b435e5..54605bab 100644
--- a/internal/httpapi/runners_cases_test.go
+++ b/internal/httpapi/runners_cases_test.go
@@ -300,9 +300,19 @@ func TestRunnerInternalHelperBranches(t *testing.T) {
waiters.notify([]string{"mock"})
waiters.notify([]string{"mock"})
waiters.unregister(w)
- if !containsStringFold([]string{"A"}, "a") || containsStringFold([]string{"A"}, "b") {
- t.Fatal("containsStringFold")
+ accepting := &runnerWaiter{providers: []string{"A", "Codex"}}
+ if !accepting.accepts([]string{"x", "a"}) || !accepting.accepts([]string{"CODEX"}) ||
+ accepting.accepts([]string{"b"}) || accepting.accepts(nil) {
+ t.Fatal("runnerWaiter.accepts")
}
+ other := waiters.register([]string{"codex"})
+ waiters.notify([]string{"mock"})
+ select {
+ case <-other.ch:
+ t.Fatal("waiter notified for a provider it does not poll")
+ default:
+ }
+ waiters.unregister(other)
for path, want := range map[string]bool{
"/runners/x": true, "/api/runners/register": true, "/api/runners/tasks/id": true,
"/api/runners/tasks/id/start": true, "/api/runners/tasks/id/cancel": false,