fix(cliproxy): tighten session affinity status handling

This commit is contained in:
Tam Nhu Tran
2026-04-28 12:26:42 -04:00
parent 4309db89c3
commit 20f3916d55
2 changed files with 21 additions and 11 deletions
+3 -1
View File
@@ -99,6 +99,8 @@ const MIN_STALE_HIGH_ONLY_GEMINI_MINOR_VERSIONS = 3;
const MIN_STALE_GUESSED_GEMINI_AVERAGE_VARIANTS_PER_MINOR = 2;
const LEGACY_GEMINI_STALE_ALIAS_MIGRATION_VERSION = 16;
const MAX_LEGACY_MANUAL_GEMINI_MINOR_VERSION = 2;
const GO_DURATION_SEGMENT = String.raw`(?:\d+(?:\.\d+)?(?:ns|us|µs|μs|ms|s|m|h))`;
const GO_DURATION_PATTERN = new RegExp(`^${GO_DURATION_SEGMENT}+$`);
/**
* Get provider configuration
@@ -139,7 +141,7 @@ function getSessionAffinityEnabled(): boolean {
function getSessionAffinityTtl(): string {
const ttl = loadOrCreateUnifiedConfig().cliproxy?.routing?.session_affinity_ttl?.trim();
return ttl || '1h';
return ttl && GO_DURATION_PATTERN.test(ttl) ? ttl : '1h';
}
function sanitizeYamlScalar(rawValue: string): string {
@@ -168,12 +168,20 @@ export function ProxyStatusWidget() {
} = useCliproxySessionAffinity();
const updateSessionAffinity = useUpdateCliproxySessionAffinity();
const isSavingRoutingConfig = updateRouting.isPending || updateSessionAffinity.isPending;
const routingConfigError =
routingError instanceof Error
? routingError
: sessionAffinityError instanceof Error
? sessionAffinityError
: null;
const routingConfigError = routingError instanceof Error ? routingError : null;
const effectiveSessionAffinityState =
sessionAffinityState ??
(sessionAffinityError instanceof Error
? {
source: 'unsupported' as const,
target: (routingState?.target ?? (isRemoteMode ? 'remote' : 'local')) as
| 'local'
| 'remote',
reachable: false,
manageable: false,
message: sessionAffinityError.message,
}
: undefined);
const startProxy = useStartProxy();
const stopProxy = useStopProxy();
const restartProxy = useRestartProxy();
@@ -330,11 +338,11 @@ export function ProxyStatusWidget() {
</div>
<RoutingGuidanceCard
key={`remote:${routingState?.strategy ?? 'round-robin'}:${sessionAffinityState?.enabled ?? 'na'}:${sessionAffinityState?.ttl ?? 'na'}:${sessionAffinityState?.manageable ?? 'na'}`}
key={`remote:${routingState?.strategy ?? 'round-robin'}:${effectiveSessionAffinityState?.enabled ?? 'na'}:${effectiveSessionAffinityState?.ttl ?? 'na'}:${effectiveSessionAffinityState?.manageable ?? 'na'}`}
compact
className="mt-3"
state={routingState}
sessionAffinityState={sessionAffinityState}
sessionAffinityState={effectiveSessionAffinityState}
isLoading={routingLoading || sessionAffinityLoading}
isSaving={isSavingRoutingConfig}
error={routingConfigError}
@@ -488,11 +496,11 @@ export function ProxyStatusWidget() {
</div>
<RoutingGuidanceCard
key={`local:${routingState?.strategy ?? 'round-robin'}:${sessionAffinityState?.enabled ?? 'na'}:${sessionAffinityState?.ttl ?? 'na'}:${sessionAffinityState?.manageable ?? 'na'}`}
key={`local:${routingState?.strategy ?? 'round-robin'}:${effectiveSessionAffinityState?.enabled ?? 'na'}:${effectiveSessionAffinityState?.ttl ?? 'na'}:${effectiveSessionAffinityState?.manageable ?? 'na'}`}
compact
className="mt-3"
state={routingState}
sessionAffinityState={sessionAffinityState}
sessionAffinityState={effectiveSessionAffinityState}
isLoading={routingLoading || sessionAffinityLoading}
isSaving={isSavingRoutingConfig}
error={routingConfigError}