Restored rooms wake their automatons

The bot pump only ran when a command or join arrived, so a server
restart landing mid-bot-turn left the restored room waiting forever
for a human to poke it — room 928D sat exactly there, its automaton
holding a perfectly answerable stack. Boot now kicks the pump for
every restored still-running room, two seconds after restore.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Eric Wagoner
2026-08-17 18:07:33 -04:00
co-authored by Claude Fable 5
parent 2ac046611d
commit 4a75370de5
2 changed files with 11 additions and 0 deletions
+6
View File
@@ -35,6 +35,7 @@ import {
getRoom,
joinRoom,
loadPersistedRooms,
runningRooms,
addAutomaton,
addChat,
driveOneAutomaton,
@@ -70,6 +71,11 @@ const port = Number(process.env.PORT ?? 8787);
// is not reachable from the internet. Dev default stays LAN-friendly.
const host = process.env.HOST ?? "0.0.0.0";
loadPersistedRooms();
// A restart can land mid-bot-turn: without a kick, a restored room whose
// current actor is an automaton waits forever for a human to poke it.
setTimeout(() => {
for (const room of runningRooms()) runBots(room);
}, 2000);
// One process serves both the built client and the websocket, so production
// needs only a TLS proxy in front (or nothing, on a LAN).
+5
View File
@@ -91,6 +91,11 @@ export function roomCount(): number {
return rooms.size;
}
/** Every restored, still-running room — so boot can wake their bot pumps. */
export function runningRooms(): Room[] {
return [...rooms.values()].filter((r) => r.state && r.state.phase === "playing");
}
export function createRoom(hostId: PlayerId): { room: Room; token: string } {
const token = randomBytes(16).toString("hex");
const room: Room = {