From a748e93fd959e688e7e79d83643327dc6ac8ada6 Mon Sep 17 00:00:00 2001 From: Luis Pater Date: Sun, 30 Nov 2025 16:56:29 +0800 Subject: [PATCH] **fix(executor, auth): ensure index assignment consistency for auth objects** - Updated `usage_helpers.go` to call `EnsureIndex()` for proper index assignment in reporter initialization. - Adjusted `auth/manager.go` to assign auth indices inside a locked section when they are unassigned, ensuring thread safety and consistency. --- internal/runtime/executor/usage_helpers.go | 2 +- sdk/cliproxy/auth/manager.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/runtime/executor/usage_helpers.go b/internal/runtime/executor/usage_helpers.go index 266a300e..5669d9bc 100644 --- a/internal/runtime/executor/usage_helpers.go +++ b/internal/runtime/executor/usage_helpers.go @@ -37,7 +37,7 @@ func newUsageReporter(ctx context.Context, provider, model string, auth *cliprox } if auth != nil { reporter.authID = auth.ID - reporter.authIndex = auth.Index + reporter.authIndex = auth.EnsureIndex() } return reporter } diff --git a/sdk/cliproxy/auth/manager.go b/sdk/cliproxy/auth/manager.go index eef70ee5..dc7887e7 100644 --- a/sdk/cliproxy/auth/manager.go +++ b/sdk/cliproxy/auth/manager.go @@ -1118,6 +1118,14 @@ func (m *Manager) pickNext(ctx context.Context, provider, model string, opts cli } authCopy := selected.Clone() m.mu.RUnlock() + if !selected.indexAssigned { + m.mu.Lock() + if current := m.auths[authCopy.ID]; current != nil && !current.indexAssigned { + current.EnsureIndex() + authCopy = current.Clone() + } + m.mu.Unlock() + } return authCopy, executor, nil }