another fix for human choices

This commit is contained in:
Dorian
2026-03-11 00:13:31 +00:00
parent 112bcde515
commit bbe656929c
7 changed files with 42 additions and 22 deletions
+9 -4
View File
@@ -190,6 +190,11 @@ const CREATIVE_POOLS: Record<string, { good: string[]; medium: string[]; bad: st
}
function generateChoices(challenge: Challenge): string[] {
// Use pre-built choices from templateToChallenge if available (hand-picked distractors)
if (challenge.choices && challenge.choices.length >= 2) {
return shuffle([...challenge.choices])
}
if (challenge.scoring === 'factual' && challenge.answers && challenge.answers.length > 0) {
const correct = challenge.answers[0]
const num = Number(correct)
@@ -237,8 +242,9 @@ export function waitForHumanResponse(
botId: string,
challenge: Challenge,
roundNumber: number,
): Promise<{ answer: string | null; trashTalk?: string; timedOut: boolean }> {
return new Promise((resolve) => {
): { promise: Promise<{ answer: string | null; trashTalk?: string; timedOut: boolean }>; choices: string[] } {
const choices = generateChoices(challenge)
const promise = new Promise<{ answer: string | null; trashTalk?: string; timedOut: boolean }>((resolve) => {
const key = `${fightId}:${botId}`
const timeoutMs = challenge.timeout_ms || DEFAULT_HUMAN_TIMEOUT_MS
@@ -248,8 +254,6 @@ export function waitForHumanResponse(
resolve({ answer: null, timedOut: true })
}, timeoutMs)
const choices = generateChoices(challenge)
pending.set(key, {
fightId,
botId,
@@ -267,6 +271,7 @@ export function waitForHumanResponse(
logger.info('human', `waiting: ${key} round=${roundNumber} type=${challenge.type} choices=${choices.length}`)
})
return { promise, choices }
}
export function submitHumanResponse(
+3 -1
View File
@@ -269,7 +269,8 @@ async function getBotResponse(
// 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)
const { promise: resultPromise, choices } = waitForHumanResponse(fightId, bot.id, challenge, roundNumber)
// Include choices directly in SSE so frontend never depends on a secondary fetch
emit(fightId, 'human_challenge', {
botId: bot.id,
round: roundNumber,
@@ -278,6 +279,7 @@ async function getBotResponse(
prompt: challenge.prompt,
timeoutMs: challenge.timeout_ms,
scoring: challenge.scoring,
choices,
})
const result = await resultPromise
const elapsed = Date.now() - start