fix: wait for a busy Codex lease instead of skipping the review

The Codex auth lease is exclusive per account so two Codex processes never
rotate the same refresh token at once. With the single configured account that
also serializes every Codex run, and claimCodexAuthLease() failed immediately
while another room's Codex run held it: the turn errored with "Codex rotation
pool unavailable", the task closed as reviewer_codex_unavailable and the
review was silently skipped.

All three such failures on 2026-09-28 coincided exactly with another room's
Codex run holding the lease (10:25:55, 18:08:25, 18:22:50 KST).

runAgentProcess now waits (up to 15 min, polling every 2s) when the only
obstacle is a lease held by a live run. A dead or rate-limited pool still
fails fast, and the normal path adds no async hop because the wait is only
entered when the lease is actually busy. The exclusivity itself is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-01 14:25:14 +09:00
parent 8b688853cc
commit 30ba51016a
3 changed files with 187 additions and 1 deletions

View File

@@ -16,7 +16,11 @@ import {
prepareGroupEnvironment,
type PreparedCodexSessionAuth,
} from './agent-runner-environment.js';
import { syncCodexSessionAuthBack } from './codex-token-rotation.js';
import {
isCodexAuthLeaseAvailable,
syncCodexSessionAuthBack,
waitForCodexAuthLease,
} from './codex-token-rotation.js';
import { syncClaudeSessionAuthBack } from './token-refresh.js';
import { runSpawnedAgentProcess } from './agent-runner-process.js';
import { getStoredRoomSkillOverrides } from './db.js';
@@ -161,6 +165,15 @@ export async function runAgentProcess(
// ── Host process mode (owner) ───────────────────────────────────
const startTime = Date.now();
const skillOverrides = readRoomSkillOverridesForRunner(input.chatJid);
if (
(group.agentType || 'claude-code') === 'codex' &&
!isCodexAuthLeaseAvailable()
) {
// A concurrent Codex run in another room may hold the account lease.
// Wait for it instead of failing the turn outright; if the pool is dead or
// rate-limited this returns at once and the prepare step below fails fast.
await waitForCodexAuthLease();
}
const prepared = prepareGroupEnvironment(group, input.isMain, input.chatJid, {
memoryBriefing: input.memoryBriefing,
runtimeTaskId: input.runtimeTaskId,