feat(routing): decision policy
Pure-function Policy{Floor,Ceil} with Decide(*float64, uint64) Decision.
Rules in priority order: nil → local; ≥floor → local; <ceil → claude;
sample band → low bit of requestHash.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
47
internal/routing/policy.go
Normal file
47
internal/routing/policy.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package routing
|
||||
|
||||
// Decision is the route picked for a single skill call.
|
||||
type Decision int
|
||||
|
||||
const (
|
||||
DecideLocal Decision = iota
|
||||
DecideClaude
|
||||
)
|
||||
|
||||
func (d Decision) String() string {
|
||||
if d == DecideLocal {
|
||||
return "local"
|
||||
}
|
||||
return "claude"
|
||||
}
|
||||
|
||||
// Policy holds the floor/ceil thresholds for routing decisions.
|
||||
//
|
||||
// Rules (in order):
|
||||
//
|
||||
// 1. passRate == nil → DecideLocal (default-to-local for cost-routable skills)
|
||||
// 2. *passRate >= Floor → DecideLocal (trust local)
|
||||
// 3. *passRate < Ceil → DecideClaude (don't trust local)
|
||||
// 4. otherwise (sample band) → requestHash low bit picks: 0=local, 1=claude
|
||||
type Policy struct {
|
||||
Floor float64
|
||||
Ceil float64
|
||||
}
|
||||
|
||||
// Decide returns the routing decision for a single call.
|
||||
// requestHash is consulted only when passRate is in the sample band [Ceil, Floor).
|
||||
func (p Policy) Decide(passRate *float64, requestHash uint64) Decision {
|
||||
if passRate == nil {
|
||||
return DecideLocal
|
||||
}
|
||||
if *passRate >= p.Floor {
|
||||
return DecideLocal
|
||||
}
|
||||
if *passRate < p.Ceil {
|
||||
return DecideClaude
|
||||
}
|
||||
if requestHash&1 == 0 {
|
||||
return DecideLocal
|
||||
}
|
||||
return DecideClaude
|
||||
}
|
||||
Reference in New Issue
Block a user