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
@@ -42,6 +42,7 @@ export function useFightPolling(fightId: Ref<string>) {
async function loadFight(): Promise<string | null> {
try {
const res = await fetch(`/api/fights/${fightId.value}`)
if (res.status === 429) return null // Rate limited, skip this poll
if (res.ok) {
const data = await res.json()
liveRounds.value = data.rounds?.length || 0
+13 -1
View File
@@ -97,11 +97,19 @@ export function useHumanChallenge(
}
}
let pollBackoff = 0
async function pollForChallenge() {
if (!myBotId.value) return
try {
const res = await fetch(`/api/fights/${fightId.value}/challenge/${myBotId.value}`)
if (res.status === 429) {
// Back off on rate limit — skip next few polls
pollBackoff = Math.min(pollBackoff + 2, 8)
return
}
if (!res.ok) return
pollBackoff = Math.max(0, pollBackoff - 1) // Recover gradually
const data = await res.json()
if (data.pending) {
@@ -130,8 +138,12 @@ export function useHumanChallenge(
function startHumanPolling() {
if (!myBotId.value) return
pollBackoff = 0
void pollForChallenge()
humanPollHandle = setInterval(() => { void pollForChallenge() }, 400)
humanPollHandle = setInterval(() => {
if (pollBackoff > 0) { pollBackoff--; return }
void pollForChallenge()
}, 800)
}
function stopHumanPolling() {