human fight non multiple choice fix

This commit is contained in:
Dorian
2026-03-10 23:26:36 +00:00
parent 68e292183a
commit 112bcde515
3 changed files with 11 additions and 4 deletions
+7 -3
View File
@@ -265,6 +265,11 @@ async function getBotResponse(
): Promise<WebhookResponse> {
if (isHumanPlayer(bot.webhookUrl)) {
logger.info('fight', `${bot.name} is human player, waiting for browser response`)
// Start waitForHumanResponse FIRST so the pending challenge is stored
// before the SSE event tells the frontend to fetch it (fixes race condition
// where frontend fetched before pending was set → no choices shown)
const start = Date.now()
const resultPromise = waitForHumanResponse(fightId, bot.id, challenge, roundNumber)
emit(fightId, 'human_challenge', {
botId: bot.id,
round: roundNumber,
@@ -274,8 +279,7 @@ async function getBotResponse(
timeoutMs: challenge.timeout_ms,
scoring: challenge.scoring,
})
const start = Date.now()
const result = await waitForHumanResponse(fightId, bot.id, challenge, roundNumber)
const result = await resultPromise
const elapsed = Date.now() - start
return { answer: result.answer, trashTalk: result.trashTalk, timeMs: elapsed, timedOut: result.timedOut, error: false }
}
@@ -389,7 +393,7 @@ async function executeFightRounds(fightId: string, botA: BotRecord, botB: BotRec
for (let round = 1; round <= MAX_ROUNDS; round++) {
lastRound = round
const challenge = round === retroRound
const challenge = (round === retroRound && !hasHuman)
? generateRetroChallenge()
: pickChallenge(usedTypes, arena.modifier, undefined, round, hasHuman)
usedTypes.add(challenge.type)