Codex switch: translate settings-index ↔ rotation-index by auth path (#51)

settings-store lists codex accounts as
  index 0 = ~/.codex/auth.json (default)
  index N = ~/.codex-accounts/{N}/auth.json
but codex-token-rotation only loads ~/.codex-accounts/{N} when those
dirs exist (it ignores ~/.codex/auth.json in that mode), so the
rotation array's indices are off-by-one vs settings indices.

Old buggy behavior:
- "사용중" badge pointed at the wrong account.
- Clicking 전환 on UI #N called setCurrentCodexAccountIndex(N) which
  selected rotation array element N — typically a different
  ~/.codex-accounts/{N+1} entry. Effectively the UI told us a
  different account was now active than what the next codex spawn
  actually used.

Fix
- New findCodexAccountIndexByAuthPath(path) on the rotation module
  exposes a path-based lookup.
- New getActiveCodexSettingsIndex() / setActiveCodexSettingsIndex(idx)
  in settings-store translate via codexAuthPath() ↔
  findCodexAccountIndexByAuthPath().
- /api/settings/accounts.codexCurrentIndex and PUT
  /api/settings/accounts/codex/current both go through the
  settings-side translation, so UI indices are now authoritative.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Eyejoker
2026-04-27 22:47:40 +09:00
committed by GitHub
parent 4ed12332d4
commit e2dd12a235
3 changed files with 69 additions and 7 deletions

View File

@@ -48,6 +48,7 @@ import {
} from './web-dashboard-data.js';
import {
addClaudeAccountFromToken,
getActiveCodexSettingsIndex,
getFastMode,
getModelConfig,
listClaudeAccounts,
@@ -55,13 +56,10 @@ import {
refreshAllCodexAccounts,
refreshCodexAccount,
removeAccountDirectory,
setActiveCodexSettingsIndex,
updateFastMode,
updateModelConfig,
} from './settings-store.js';
import {
getCurrentCodexAccountIndex,
setCurrentCodexAccountIndex,
} from './codex-token-rotation.js';
const DEFAULT_STATUS_MAX_AGE_MS = 10 * 60 * 1000;
const ROOM_MESSAGE_ID_CACHE_LIMIT = 500;
@@ -1393,10 +1391,10 @@ export function createWebDashboardHandler(
);
}
try {
setCurrentCodexAccountIndex(idx);
setActiveCodexSettingsIndex(idx);
return jsonResponse({
ok: true,
codexCurrentIndex: getCurrentCodexAccountIndex(),
codexCurrentIndex: getActiveCodexSettingsIndex(),
});
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
@@ -1602,7 +1600,7 @@ export function createWebDashboardHandler(
return jsonResponse({
claude: listClaudeAccounts(),
codex: listCodexAccounts(),
codexCurrentIndex: getCurrentCodexAccountIndex(),
codexCurrentIndex: getActiveCodexSettingsIndex(),
});
}