feat: show rejoin link when bot is already in a fight

- Track active fight IDs per bot in orchestrator (Set → Map)
- Return fightId in "already in fight" error responses (409)
- Frontend shows "REJOIN FIGHT" link instead of generic error

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-09 09:27:48 +00:00
co-authored by Claude Opus 4.6
parent 64273cf145
commit e31d49898b
5 changed files with 49 additions and 21 deletions
+13 -9
View File
@@ -47,7 +47,8 @@ interface WebhookResponse {
import { MAX_ROUNDS, KO_THRESHOLD, MAX_RESPONSE_BYTES, STARTING_HP, ELO_K_FACTOR, ELO_K_FACTOR_MOCK, MAX_ANSWER_LENGTH, MAX_TRASH_TALK_LENGTH } from '../lib/constants.js'
// Track bots currently in a fight to prevent concurrent fights
const activeFighters = new Set<string>()
// Maps botId → fightId so we can direct users to their active fight
const activeFighters = new Map<string, string>()
export function getActiveFighterCount(): number {
return activeFighters.size
@@ -57,6 +58,10 @@ export function isInFight(botId: string): boolean {
return activeFighters.has(botId)
}
export function getActiveFightId(botId: string): string | undefined {
return activeFighters.get(botId)
}
function emit(fightId: string, type: string, data: Record<string, unknown>) {
fightEvents.emit({
fightId,
@@ -621,13 +626,13 @@ export async function runFight(botAId: string, botBId: string, mode: 'free' | 'r
if (activeFighters.has(botAId)) throw new Error(`Bot ${botAId} is already in a fight`)
if (activeFighters.has(botBId)) throw new Error(`Bot ${botBId} is already in a fight`)
activeFighters.add(botAId)
activeFighters.add(botBId)
const [botA, botB] = await loadBots(botAId, botBId)
const arena = randomArena()
const fightId = await createFightRecord(botA, botB, arena, mode)
activeFighters.set(botAId, fightId)
activeFighters.set(botBId, fightId)
try {
const [botA, botB] = await loadBots(botAId, botBId)
const arena = randomArena()
const fightId = await createFightRecord(botA, botB, arena, mode)
await executeFightRounds(fightId, botA, botB, arena, mode)
return fightId
} finally {
@@ -644,12 +649,11 @@ export async function runFightAsync(botAId: string, botBId: string, mode: 'free'
if (activeFighters.has(botAId)) throw new Error(`Bot ${botAId} is already in a fight`)
if (activeFighters.has(botBId)) throw new Error(`Bot ${botBId} is already in a fight`)
activeFighters.add(botAId)
activeFighters.add(botBId)
const [botA, botB] = await loadBots(botAId, botBId)
const arena = randomArena()
const fightId = await createFightRecord(botA, botB, arena, mode)
activeFighters.set(botAId, fightId)
activeFighters.set(botBId, fightId)
executeFightRounds(fightId, botA, botB, arena, mode)
.catch(err => {