The 2026-09-26 audits and their fixes
This page is generated from the project corpus and rewritten on every docs build. Edit the source in corpus/, not here.
Two read-only passes on 2026-09-26 (the "Improvements audit" and a "Second
improvements pass" that also read vps-deploy) found 21 problems. All were
fixed on 2026-10-02, except the state move, which deployed on 2026-10-07. The
log has one entry per fix. This page keeps what is still true and easy to
undo by accident.
Not checked in Discord. No dev application token was on this machine, so every fix was verified with typecheck, tests or a scratch script, never live. The checks still owed are at the end.
Crashes and pings
- No reply in a listener can kill the bot. The
@mentionecho is deleted;MessageCreateonly routes Wordle and Hangman thread messages. The client logsEvents.Error, and a module-levelunhandledRejectionhandler logs instead of exiting. There is deliberately nouncaughtExceptionhandler: a genuine synchronous crash should still exit and be restarted (by pm2 locally, by the container'srestart: unless-stoppedin production). Seebots/discord/src/index.ts. - Mentions default to users only. The client option
allowedMentions: { parse: ['users'], repliedUser: true }covers every place user text is echoed (reminders,/ask, RPG duel proposals, the town crier), so no stored text can ping@everyoneor a role./givekeeps its own per-message override. Users were still pingable through RPG character names until 2026-11-02: names are now cleaned of mention syntax, crier posts parse no mentions, and a duel proposal pings only the defender.
Games
- Connect Four's 90 s timer is per turn (
armTurnTimer), cleared and re-armed after every move, the bot's reply move included. Before, a game longer than 90 s ended in a forfeit. - An RPG controller can't act mid-fight. With an encounter open, anything but fight, flee or a combat potion shows the combat screen ("You're in a fight!"). An older controller message could rest, explore or travel.
- Trades count copies.
executeTradefails when an inventory holds fewer copies than offered and gives the receiver only what the giver lost. The dupe was not reachable: the trade menu offers each item once. This is hardening for the day an offer can hold duplicates. - Mafia phases resolve once.
resolveDay/resolveNighttake an in-memory claim keyed per phase (guild:day,guild:night), not per guild: a night that ends while the day is still sending DMs must not be dropped.launchGametakes alaunchingclaim that both join paths respect. A lobby timer only expires the lobby it was armed for (createdAt), andrearmMafiaTimersre-arms every persisted game atClientReady, resolving at once if the deadline passed while the bot was down. A harness with the claims removed failed the race tests. - Hangman words are
^[a-z]+$("jalapeño" was unwinnable); a test holds it.
Persistence
shared/src/json-file.ts is the one way the bot writes JSON:
- Atomic. Each write goes to
<file>.<pid>.tmp, is fsynced, then renamed. The pid is in the name because a restart or deploy can briefly overlap two processes, and two writers on one temp name renamed each other's file away. - One chain per path, so a failed write rejects for its own caller only and later writes still land. The old chain stopped all writes after one failure.
- Shutdown flushes.
index.tsclears the timers, thendrainStores()runs the RPG worlds' flush andflushPendingWrites()side by side to the end (bounded at 3 s), logging each failure, then exits;ecosystem.config.cjsgives pm2kill_timeout: 5000. Since 2026-11-02 a world that fails to write stays dirty and the other stores still drain; before, one failed world skipped every queued write behind it. - Checked by
kill -9at random points on a 1.4 MB write loop, 20 times: the file always parsed.
Commands
/helpis built from the registry (setHelpCatalog), one line per subcommand, grouped by name with an "Other" catch-all, so a new command shows up without editinghelp.ts. A group spills into "(cont.)" fields past 1024 characters. Social was at 1005 of 1024 on 2026-10-02, so the next social command spills over by design.commands/help.test.tschecks every registered command appears./quote addonly saves what the invoker can read. The channel must give themViewChannelandReadMessageHistory; a missing channel, a DM, an uncached member and a refusal all get the same reply, so the check never confirms a hidden channel exists. A private thread also needs the member in it or Manage Threads (2026-11-02), since discord.js gives a thread its parent's permissions.- Dates must exist.
/birthdayrefuses a day past the month's length (February allows 29);/remindme's ISO form refuses 2026-02-30 instead of rolling it into March. - Reminder text is capped at 1000 characters on the slash command, and
reminderMessagetruncates on delivery so a message never passes 2000; the list clips each line to 80 characters and stops before 1900. /clockprints each zone's own UTC offset (getUtcOffsetMinutes); it printed the host's for every zone.- The trivia fetch times out after 5 s into the fallback bank. When
testing it in a script, keep the process alive:
AbortSignal.timeout's timer is unref'd, so a bare script exits before it fires.
Dependencies and tests
- discord.js is pinned at 14.27.0 and the
/imgrenderer exactly (satori 0.26.0, @resvg/resvg-js 2.6.2);npm auditwas clean on 2026-10-02. npm testruns zero-dependencynode:testfiles through tsx insharedandbots/discord: blackjack ace demotion, Wordle repeated letters, Connect Four wins and draws, reminder and date parsing, trade conservation, hangman words,/help, and since 2026-10-09 the Jukebox. 67 tests on 2026-11-02.
The container's state
The estate deploys the bot as a container only (since 2026-09-06). Before
2026-10-07 its state sat in the container's writable layer, the deploy's rsync
rewrote bots/data on every run, and the image baked in the builder's
reminders and birthdays. Now:
infrastructure/docker-compose.ymlbind-mountsJUST_A_BOT_DATAandJUST_A_BOT_DISCORD_DATA;vps-deploypoints them at/srv/just-a-bot/state/{shared,discord}, outside its mirror, and excludesbots/dataand/statefrom the rsync..dockerignorekeeps both data directories out of the image.- The owner purged the old state rather than reconcile two copies; the bot started fresh on 2026-10-07 (decisions.md).
Owed in Discord
On a dev application (never with production's token, see the root
CLAUDE.md): @mention the bot and /ping; a reminder with @everyone in
it; two 60 s Connect Four turns and one over 90 s; two RPG controllers mid-fight;
/clock show; /trivia; a long reminder and /remindme list; Mafia day and
night timers across a restart; /help; /quote add from a channel the member
can't read; /birthday set 04-31; /coins add 1, deploy, and the balance
survives.