fix(router): decision call skips settled requests and ignores client cancels

Live mode no longer calls the decision model when a floor or keyword rule already fixes the tier. A client cancel during the call no longer counts toward the breaker.
This commit is contained in:
2026-11-25 14:15:20 +00:00
parent 8c01f15ee5
commit 2cd828c162
4 changed files with 53 additions and 2 deletions
+34
View File
@@ -324,6 +324,40 @@ func TestRouterDecisionTimeout(t *testing.T) {
}
}
func TestRouterDecisionClientCancelSkipsBreaker(t *testing.T) {
started := make(chan struct{}, 8)
release := make(chan struct{})
var slow atomic.Bool
slow.Store(true)
f := newDecisionFixture(t, 3, "2s", func(w http.ResponseWriter, r *http.Request) {
if slow.Load() {
started <- struct{}{}
select {
case <-r.Context().Done():
case <-release:
}
return
}
okHandler(w, r)
})
t.Cleanup(func() { close(release) })
for i := 0; i < 3; i++ {
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-started
cancel()
}()
if a := f.g.askDecisionModel(ctx, f.rt, "c"+strconv.Itoa(i)); a.outcome != decisionError {
t.Fatalf("cancel %d outcome %q", i, a.outcome)
}
}
slow.Store(false)
before := f.hitCount()
if a := f.g.askDecisionModel(context.Background(), f.rt, "after"); a.outcome != "" || f.hitCount() != before+1 {
t.Fatalf("breaker opened by client cancels: outcome %q", a.outcome)
}
}
func TestRouterDecisionBreaker(t *testing.T) {
var fail atomic.Bool
fail.Store(true)