feat(routing): canonical request hash
SHA-256 of (system, user) joined with 0x00 separator, truncated to uint64. Drives deterministic sample-band routing: identical prompt pair → same hash → same local-vs-Claude decision on every call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
21
internal/routing/hash.go
Normal file
21
internal/routing/hash.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package routing
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
)
|
||||
|
||||
// CanonicalHash returns a deterministic 64-bit hash of (system, user).
|
||||
// Used to make sample-band routing decisions reproducible: identical input
|
||||
// strings produce the same hash on every call, independent of process state.
|
||||
//
|
||||
// Inputs are joined with a 0x00 byte separator before hashing — distinguishes
|
||||
// (system="ab", user="cd") from (system="abcd", user="").
|
||||
func CanonicalHash(system, user string) uint64 {
|
||||
h := sha256.New()
|
||||
h.Write([]byte(system))
|
||||
h.Write([]byte{0})
|
||||
h.Write([]byte(user))
|
||||
sum := h.Sum(nil)
|
||||
return binary.BigEndian.Uint64(sum[:8])
|
||||
}
|
||||
Reference in New Issue
Block a user