Mayling Bot and AK Guesser: three bugs
EngineeringDec 4, 2026Updated Dec 5, 20265 min read
The Mayling Bot and AK Guesser run for a friend's Discord server of 500+ members. In July and August 2026 one mistake took the game offline for about 17 hours, one left a command unclickable, and one was caught in review before it reached the live database.
~17 h AK Guesser offline Jul 13, 2026
1.5 s refetch deadline inside a 3 s reply window Aug 2, 2026
13 invalid-header test cases added Aug 29, 2026
How this was builtClaude Code and OpenAI Codex wrote the code and the fixes described here, under my direction and verification.
01A private bot and a daily game
The Mayling Bot is a private TypeScript Discord bot for a creator friend's server of 500+ members. It runs on Fly.io with Supabase Postgres and Cloudflare R2. The name is an unofficial fan reference to Mayling from Girls' Frontline 2.
AK Guesser is a daily Arknights guessing game that members start from the bot with a slash command. It runs as its own Cloudflare Worker and opens inside Discord as a verified Activity. It launched on Jul 10, 2026 and grew on Sep 14, 2026 to 436 operators across two modes, Artwork and Skill icons. By my estimate in Sep 2026 it had about 10 players a week and about 15 a month.
The same media library feeds Priestess. Priestess started as planning docs inside the Mayling project, was built as separate services, and indexes Mayling's shared R2 reaction-media catalogue.
| Date | What happened | Reached members |
|---|---|---|
| Jul 13, 2026 | Live game built with the dev Discord app ID | Yes, offline for about 17 hours |
| Aug 2, 2026 | A new command showed as plain text in /help | Yes, one unclickable command |
| Aug 29, 2026 | SQL and JavaScript disagreed on whitespace | No, caught in review |
02Jul 13: the live game shipped with the dev app ID
On Jul 13, 2026 the live AK Guesser stopped loading. Members saw a screen that said "Open this activity inside Discord" while they were already inside Discord. The dev copy worked.
The live bundle had been built without its app ID variable. The code fell back to the dev ID, so the live and dev Workers were serving the same bundle. Inside the live Activity the Discord SDK started with the wrong client ID and its handshake never finished. After a 10 s timeout the app concluded it was not inside Discord at all.
By the build stamp, the game was down for about 17 hours, from a build shortly before 01:00 ET until 18:03 ET. I reported it to the agent with a screenshot, and the root cause was logged at 17:36 ET.
- Test inputA deliberately wrong build
- Layer 1BuildA build with no app ID fails
- Layer 2DeployEach environment verifies its own bundle
- Layer 3RuntimeBuilt-in ID compared with the Discord origin
- Build
- The fallback to the dev ID is gone and a build with no app ID fails. Dev and live builds write to separate output folders, and a script (verify-bundle-app-id.mjs) checks the bundle for the right ID and for the absence of the other one.
- Deploy
- Each environment rebuilds and verifies its own bundle as part of the deploy command. A bare deploy command can no longer overwrite the live Worker.
- Runtime
- The app compares its built-in ID with the Discord origin it is running on and shows a specific wrong-app error.
03Aug 2: a command that would not turn into a link
In /help, command names render as clickable mentions when the bot knows each command's ID. On Aug 2, 2026 I noticed the AK Guesser command showing as plain text.
The bot took one snapshot of command IDs when it started. A release boots the bot first and registers new commands second, so a newly added command always missed the snapshot and stayed plain text until some later restart.
The first fix refetched the command list whenever /help found a command with no ID. The reviewing agent rejected it. The refetch ran before the reply, inside the 3 seconds Discord allows for acknowledging an interaction, so a slow refetch would have failed the whole command.
The shipped version races the refetch against a 1.5 s deadline. If the refetch loses, /help answers from the cache it has and the refresh finishes in the background for the next call. Refetches are limited to one per 60 s, and a failed refetch no longer wipes the cache.
A second mistake in the same hourThe agent piped its deploy command into tail, and the pipe reported success while the deploy had failed on expired credentials. The fix sat in git for about 20 minutes until I logged in again and it went live.
04Aug 29: a whitespace mismatch caught in review
This one never reached members. A database migration added a webhook: when a media file is changed or deleted in Mayling, Postgres notifies Priestess so her index stays in sync. The webhook sends a Bearer token that an operator saves in a settings table.
The table had a CHECK constraint to reject tokens with stray whitespace, written with the PostgreSQL class [[:space:]]. The receiver did its own check in JavaScript with trim(). The two disagree. JavaScript trims 25 whitespace code points, and [[:space:]] did not match several of the non-ASCII ones, such as U+00A0, U+1680, U+2007, U+202F, and U+FEFF.
A token pasted with one of those characters would have passed the database check and switched the webhook on. The receiver would then have rejected every delete notification with HTTP 401. The webhook would have looked enabled while deletes stopped syncing.
A review round caught it before the migration was applied. The SQL now strips an explicit list of 26 code points: the 25 that JavaScript trims, plus U+0085. An integration test covers 13 invalid headers, including 6 of those characters at both the start and the end of the token.
05How each one was found
- I found the outage and the /help bug by using the bot myself.
- An agent reviewing another agent's work caught two more problems before they shipped: the reply-window risk in the first /help fix, and the whitespace mismatch.