DEV Community

Cover image for I let Twitch chat break my game's code, then made Codex race them to fix it
Stephen Sookra
Stephen Sookra

Posted on Edited on AI-assisted

I let Twitch chat break my game's code, then made Codex race them to fix it

So on Sunday afternoon I was live on Twitch with my game on screen, and a viewer typed !break.

The game reloaded right there on stream with a real bug in it. One plus sign in the physics code had turned into a minus, so gravity was pointing the wrong way. Fourteen seconds after the break, that same viewer typed !guess gravity-sign and got it right. The overlay said CHAT WON. Codex still came in after its wait, found the line and had the fix passing in about 28 seconds, and the fixed code swapped into the running game without resetting the player.

The funny part is that the viewer was on another team in the same hackathon. That was honestly one of my favorite moments of the whole weekend.

Why I built this

On most streams chat just watches. You type something and it flies by. I wanted chat to have a real job, so I gave them the thing every developer hates the most, which is a bug showing up live.

Most AI streams I've seen put chat and the AI on the same team. Chat asks for a feature and the AI builds it. I flipped that. Chat breaks the game, and Codex has to clean it up, so chat finally has someone to beat.

I built it solo for the Codex x TwitchCon Hackathon and called it Chat vs Codex.

How a round works

  1. A viewer types !break, redeems the "Break the game" Channel Points reward, or whispers a bug type so nobody sees it coming.
  2. The server picks one real, pre-tested bug and splices it into the game's TypeScript. The game reloads broken on stream.
  3. Chat gets a 15 second head start to !guess what broke while a replay shows the symptom.
  4. Then Codex gets a short bug ticket. It says which replays failed, the first frame where things went off and what viewers saw. It never names the bug, but if chat guessed during the head start, the most popular guess rides along as a one-word hint.
  5. Replay tests decide. If they pass, the fixed code hot-swaps into the game.

Every fixed round leaves something behind too. There's an autopsy card with the real diff, a stream marker at the break and another at the fix, an auto clip with its link posted in chat, and the result pinned.

The hard part was making it fair

Getting an AI to fix a bug on stream is the easy part. Making it a fair race is where almost all the time went.

Codex runs in a sandbox under a custom permission profile. It can't read the original code, it can read the tests but can't edit them, and it has no network. A canary test checks all of that from inside the sandbox, so I'm not just trusting the config.

A fix only counts if the replays pass. The game runs at a fixed 60 Hz with integer physics, so the same inputs give the same frames every time. That's what lets a test actually prove a fix instead of just saying it compiles.

The bugs have to earn their spot too. Stryker suggests candidates and most of them don't make it. A bug has to compile, change how the game behaves, fail a replay, show up on screen within 600 frames and leave the player alive. 53 made the pool.

Then I needed to know if the race was even close. I ran 212 sandboxed trials over that pool, with no hints at all, and Codex fixed 211. The one miss was a dropped network connection, and I kept it in the count. GPT-6.1 Terra at low effort had a median of 14.5 seconds to a passing fix, which is about the same as chat's head start. So it's a real race, and chat can actually win it.

There's also a boss round where two Codex models race each other on the same bug while chat bets on who wins. On Sunday GPT-6.1 Terra beat GPT-6.1 Sol in 22.1 seconds.

Building it with Codex

Codex wrote almost all of the code. I ran one main Codex thread for the whole build. I decided what got built and in what order, Codex wrote it, and every turn had to pass CI before the next one started. That ended up being 17 turns, 99 commits on main and 787 tests running on every push. The phone app came from a second Codex thread.

Codex is also the opponent at runtime. Each round starts a fresh run through the Codex SDK, and its real steps stream to the overlay so chat can watch it work. During a round it can also call a small read-only MCP server I built called Game Inspector, which replays frames and finds the first frame where the broken game drifts from the good one.

On the Twitch side, EventSub brings in chat messages, Channel Points redemptions and whispers. Helix handles everything going back out, like chat messages, the reward, refunds, stream markers, clips and pins. I run it on my own regular channel, which isn't Affiliate or Partner, so you don't need either one.

I also made a phone app called Pit Wall. My phone buzzes the moment chat breaks the game, and I can veto a round or send Codex a one word hint. On iPhone there's a Live Activity on the lock screen with the score and the last result.

Stuff that went wrong

Going live kept wiping my channel. OBS's Twitch dock had old values saved, so every time I went live it overwrote my title, category and tags. Now I reset them from the API right after.

One live round took 1:14 because another Codex build was eating my laptop's CPU at the same time. I don't run builds during live rounds anymore.

Right before Sunday's stream my Twitch refresh token died and I had to redo the sign-in. And at one point my Mac was down to 384 MB of free space because an iPhone simulator download ate the rest. That was fun.

The biggest thing I learned is that a fair AI race is way harder to build than a flashy one. Hiding the answer from Codex, proving every fix with replays and giving chat a real head start took most of the work. That's also the part that makes it fun to watch.

Try it

If you stream and want to try it, setup is Node 22, pnpm and the Codex CLI on your computer, one OBS browser source and a one time Twitch sign-in.

What I really want to see next is a big chat, like a few hundred people all trying to break the same game at once. I wonder how long Codex holds up against a chat that actually works together.

Top comments (0)