refactor(codex): align continuity helpers with review feedback

Align websocket continuity resolution with the HTTP Codex path, make auth-affinity principal keys use a stable string representation, and extract small helpers that remove duplicated continuity and affinity logic without changing the validated cache-hit behavior.
This commit is contained in:
VooDisss
2026-03-27 18:11:57 +02:00
parent 511b8a992e
commit 62b17f40a1
5 changed files with 86 additions and 98 deletions

View File

@@ -216,13 +216,31 @@ func requestExecutionMetadata(ctx context.Context) map[string]any {
} else if ctx != nil {
if ginCtx, ok := ctx.Value("gin").(*gin.Context); ok && ginCtx != nil {
if apiKey, exists := ginCtx.Get("apiKey"); exists && apiKey != nil {
meta[authAffinityMetadataKey] = fmt.Sprintf("principal:%v", apiKey)
if principal := stablePrincipalMetadataKey(apiKey); principal != "" {
meta[authAffinityMetadataKey] = principal
}
}
}
}
return meta
}
func stablePrincipalMetadataKey(raw any) string {
var keyStr string
switch v := raw.(type) {
case string:
keyStr = v
case fmt.Stringer:
keyStr = v.String()
default:
keyStr = fmt.Sprintf("%v", raw)
}
if trimmed := strings.TrimSpace(keyStr); trimmed != "" {
return "principal:" + trimmed
}
return ""
}
func pinnedAuthIDFromContext(ctx context.Context) string {
if ctx == nil {
return ""