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
@@ -113,6 +113,9 @@ export function useHumanChallenge(
} }
if (!humanChallenge.value || humanChallenge.value.roundNumber !== data.roundNumber) { if (!humanChallenge.value || humanChallenge.value.roundNumber !== data.roundNumber) {
applyChallenge(data) applyChallenge(data)
} else if (data.choices?.length && humanChoices.value.length === 0) {
// SSE fallback had no choices, polling found them — update
humanChoices.value = data.choices
} }
} else if (data.fightStatus === 'finished') { } else if (data.fightStatus === 'finished') {
humanChallenge.value = null humanChallenge.value = null
+1 -1
View File
@@ -553,7 +553,6 @@ async function fightAgain(botId: string) {
window.history.replaceState({}, '', `/arena/${data.fightId}`) window.history.replaceState({}, '', `/arena/${data.fightId}`)
startPolling({ onFinished: () => stopHumanPolling(), onTimeout: () => stopHumanPolling() }) startPolling({ onFinished: () => stopHumanPolling(), onTimeout: () => stopHumanPolling() })
if (isHumanFight.value) { if (isHumanFight.value) {
startHumanPolling()
wireSSE() wireSSE()
for (let i = 0; i < 20; i++) { for (let i = 0; i < 20; i++) {
await loadFight() await loadFight()
@@ -563,6 +562,7 @@ async function fightAgain(botId: string) {
await nextTick() await nextTick()
await nextTick() await nextTick()
if (liveFightData.value) await initLiveScene() if (liveFightData.value) await initLiveScene()
startHumanPolling()
} }
} else { } else {
fightError.value = `Failed to start fight (${res.status})` fightError.value = `Failed to start fight (${res.status})`
+7 -3
View File
@@ -265,6 +265,11 @@ async function getBotResponse(
): Promise<WebhookResponse> { ): Promise<WebhookResponse> {
if (isHumanPlayer(bot.webhookUrl)) { if (isHumanPlayer(bot.webhookUrl)) {
logger.info('fight', `${bot.name} is human player, waiting for browser response`) 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', { emit(fightId, 'human_challenge', {
botId: bot.id, botId: bot.id,
round: roundNumber, round: roundNumber,
@@ -274,8 +279,7 @@ async function getBotResponse(
timeoutMs: challenge.timeout_ms, timeoutMs: challenge.timeout_ms,
scoring: challenge.scoring, scoring: challenge.scoring,
}) })
const start = Date.now() const result = await resultPromise
const result = await waitForHumanResponse(fightId, bot.id, challenge, roundNumber)
const elapsed = Date.now() - start const elapsed = Date.now() - start
return { answer: result.answer, trashTalk: result.trashTalk, timeMs: elapsed, timedOut: result.timedOut, error: false } 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++) { for (let round = 1; round <= MAX_ROUNDS; round++) {
lastRound = round lastRound = round
const challenge = round === retroRound const challenge = (round === retroRound && !hasHuman)
? generateRetroChallenge() ? generateRetroChallenge()
: pickChallenge(usedTypes, arena.modifier, undefined, round, hasHuman) : pickChallenge(usedTypes, arena.modifier, undefined, round, hasHuman)
usedTypes.add(challenge.type) usedTypes.add(challenge.type)