human fight sequence fix

This commit is contained in:
Dorian
2026-03-11 10:34:08 +00:00
parent 29a0a48eb1
commit ea72c097c4
5 changed files with 80 additions and 37 deletions
+4 -2
View File
@@ -28,6 +28,8 @@ export function clearAllPending(): void {
}
const DEFAULT_HUMAN_TIMEOUT_MS = 8_000
// Extra time for humans: accounts for network latency, SSE/polling delivery delay, reading time
const HUMAN_EXTRA_MS = 5_000
export function isHumanPlayer(webhookUrl: string): boolean {
return webhookUrl === 'http://human.local/'
@@ -115,7 +117,7 @@ export function waitForHumanResponse(
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
const timeoutMs = (challenge.timeout_ms || DEFAULT_HUMAN_TIMEOUT_MS) + HUMAN_EXTRA_MS
const timeoutHandle = setTimeout(() => {
pending.delete(key)
@@ -174,7 +176,7 @@ export function getPendingChallenge(
const entry = pending.get(key)
if (!entry) return null
const timeoutMs = entry.challenge.timeout_ms || DEFAULT_HUMAN_TIMEOUT_MS
const timeoutMs = (entry.challenge.timeout_ms || DEFAULT_HUMAN_TIMEOUT_MS) + HUMAN_EXTRA_MS
const elapsed = Date.now() - entry.createdAt
const remaining = Math.max(0, timeoutMs - elapsed)