Fix draft timer missing after rollback causing draft to freeze

The rollback endpoint was deleting all timers but only recreating one
for the team currently on the clock. After that team made their pick,
the next team had no timer row, causing the timer system to log
"No timer found" and skip indefinitely, freezing the draft.

Fix: recreate timers for ALL teams after a rollback, each starting at
draftInitialTime.

Also add a defensive fallback in the timer system: if a timer row is
missing for the current team during an active draft, create it at
draftInitialTime instead of skipping, so the draft can never get
permanently stuck due to a missing timer.

https://claude.ai/code/session_01YPxgcQywG57KiXj7m46gLV
This commit is contained in:
Claude 2026-02-23 00:45:30 +00:00
parent b35791e76a
commit cb2fd1f031
No known key found for this signature in database
2 changed files with 27 additions and 7 deletions

View file

@ -75,20 +75,20 @@ export async function action(args: any) {
)
);
// Clear all timers and create a fresh one for the team now on the clock
// Clear all timers and recreate them for every team so no team is left without a timer
await db
.delete(schema.draftTimers)
.where(eq(schema.draftTimers.seasonId, seasonId));
const initialTime = season.draftInitialTime || 120;
if (rollbackSlot) {
await db.insert(schema.draftTimers).values({
await db.insert(schema.draftTimers).values(
draftSlots.map((slot) => ({
seasonId,
teamId: rollbackSlot.teamId,
teamId: slot.teamId,
timeRemaining: initialTime,
});
}
}))
);
// Update season: reset pick number and unpause
await db

View file

@ -111,7 +111,27 @@ async function updateDraftTimers(): Promise<void> {
});
if (!timer) {
console.warn(`[Timer] No timer found for team ${currentTeamId} in season ${season.id}`);
console.warn(
`[Timer] No timer found for team ${currentTeamId} in season ${season.id}, creating with initial time`
);
const initialTime = season.draftInitialTime || 120;
await db
.insert(schema.draftTimers)
.values({
seasonId: season.id,
teamId: currentTeamId,
timeRemaining: initialTime,
});
// Emit timer update so clients are aware of the new timer
io.to(`draft-${season.id}`).emit("timer-update", {
seasonId: season.id,
teamId: currentTeamId,
timeRemaining: initialTime,
currentPickNumber,
});
// Continue processing with the newly created timer on the next tick
continue;
}