fix: avoid Claude token refresh races across services

This commit is contained in:
Eyejoker
2026-03-26 10:25:09 +09:00
parent 2b74e6fe40
commit f79baf1ff8
3 changed files with 31 additions and 2 deletions

View File

@@ -66,6 +66,7 @@ import { normalizeStoredSeqCursor } from './message-cursor.js';
import { initCodexTokenRotation } from './codex-token-rotation.js';
import { initTokenRotation } from './token-rotation.js';
import {
shouldStartTokenRefreshLoop,
startTokenRefreshLoop,
stopTokenRefreshLoop,
} from './token-refresh.js';
@@ -300,8 +301,16 @@ async function main(): Promise<void> {
initTokenRotation();
initCodexTokenRotation();
// Start OAuth token auto-refresh (before subsystems that spawn agents)
startTokenRefreshLoop();
// Only the Claude service owns Claude OAuth refresh to avoid
// cross-service refresh-token races on shared credentials.
if (shouldStartTokenRefreshLoop(SERVICE_AGENT_TYPE)) {
startTokenRefreshLoop();
} else {
logger.info(
{ serviceAgentType: SERVICE_AGENT_TYPE },
'Skipping Claude OAuth token auto-refresh for non-Claude service',
);
}
loadState();