Find the race condition hiding in Part 2's bid code with your own eyes, then ask Codex to prove it exists with a four-window “Bidding War” Playwright test before anyone touches the fix.
http://localhost:5102. Or you caught up from the reference project.Before we ask Codex anything, I want you to find the bug yourself. It is only a few lines and you already know the rules it enforces (guide 10). Open the Part 2 folder in VS Code with the command below. Then press Cmd+P (quick open), type server/src/app.ts and press Enter. In that file press Cmd+F and search for INSERT INTO bids.
code ~/codex-course/workshop/part-2-create-auction-and-bid
code <folder> opens that folder as a VS Code workspace, so the file tree on the left shows only Part 2. Now read the bid route from top to bottom. Notice the order of what it does: first it reads the auction and its current highest bid from the database, then it runs the checks, and only after that does it write the new bid.
A race condition is a bug that only appears when two things happen at almost the same time, and the result depends on who gets there first. Our bid route does “check, then insert”: it reads the current price, checks that the new bid beats it, then inserts. Imagine two bidders, Priya and Sam, both bidding $101 on an auction at $100, half a millisecond apart. Priya's request reads “$100”, Sam's request reads “$100” too (Priya has not inserted yet). Both pass the “at least $101” check. Both insert. Now the auction has two $101 bids and no clear highest bidder, and the second one should have been rejected. Nothing in the code is “wrong” line by line; the gap between the read and the write is the bug. Any system with many users and shared data (seats, stock, wallets, bids) has this problem unless you design against it.
The bid route, app.post('/api/auctions/:slug/bids', …). It does its checks first: sellers cannot bid on their own auction, the auction must not have ended (compared with Date.now(), the current time in milliseconds), and the bid must be at least $1 (100 cents) above the current price. Then, as a separate statement, it runs INSERT INTO bids (auction_id, bidder_user_id, amount_cents) VALUES ($1, $2, $3). The $1, $2, $3 are placeholders that the pg library fills in safely with the real values.
There is no BEGIN, no transaction and no lock anywhere near it. That gap is the bug. Your line numbers and variable names may differ, since your Codex wrote your copy, but the shape (read → check → insert, as separate database calls) will be the same.
Why it slipped through: every test Codex wrote in guide 10 sends one bid at a time, so “check, then insert” always worked. Tests only catch what they try. Sequential tests cannot find a concurrency bug; you need a test that deliberately sends bids at the same moment, which is exactly what we build next.
Go to the Codex app and open your Part 2 chat from the sidebar (Codex names chats automatically; mine was called “Add auctions and bidding”). Hover over the small circle just left of the model picker, under the message box. This is the context-window meter you switched on in guide 10.
A tooltip like Context window: 3% used (97% left) · 8k / 258k tokens used. Your numbers will differ. You may also see a line saying “Context compacted” in the chat itself. That is the compaction you ran at the end of guide 10: Codex summarised the older messages, which is why the chat that was 76% full is now almost empty.
Even with lots of room left, I start a new chat for each new piece of work. A clean context keeps Codex focused on one problem, and with an API key it also costs less per message, because less history is re-sent every time. The meter is for knowing when you must start fresh; good habit is to start fresh before you must.
Finding and fixing the concurrency bug is a new task, so it gets a new chat. In the Codex sidebar, under Projects, hover over workshop and click the small pencil (new chat) icon that appears next to it. Or click New chat at the top of the sidebar and make sure the project shown above the message box is workshop, not something else.
A chat is Codex's short-term memory. Everything in it is re-sent to the model on every message, so an old chat full of form-building details makes the model slower, costlier and more likely to mix old decisions into the new work. A new chat has none of that. Codex still knows your project because the durable facts live in files it reads on demand: the root AGENTS.md, Part 2's AGENTS.md and GRILL.md, and the code itself. This is why we write decisions down instead of keeping them only in a conversation. My rule: one task, one chat. Fixing a bug is a task. Adding a feature is a task.
An empty chat that says What should we build in workshop?, with workshop · Local · master above the message box. Local means Codex works on the files on your Mac; master is the Git branch. The model picker still reads 5.6 Sol Medium; settings carry over between chats.
Now let's see if Codex can spot what you just found. I ask it in a deliberately casual, slightly teasing way, without telling it where the bug is or what it is. If the agent can find the problem from a one-line hint, it understands the code; if it cannot, that tells you something too. Paste the message exactly and press Enter.
lol you don't see a problem with bid concurrency?
Codex's answer will mention two database ideas we have not met yet. Read these two callouts first so the reply makes sense.
A transaction groups several database statements into one all-or-nothing unit. You start it with BEGIN, run your reads and writes, and finish with COMMIT (make it permanent) or ROLLBACK (undo everything). If the server crashes halfway, the database throws the half-done work away, so you never end up with a bid inserted but the auction price not updated. Think of it as a bank transfer: debit one account and credit another must both happen or neither. A transaction on its own, though, does not stop two bidders reading the same price at the same time; for that you need the next idea.
SELECT … FOR UPDATE)Inside a transaction, SELECT … FOR UPDATE reads a row and locks it until the transaction ends. If a second transaction tries to lock the same row, it has to wait. Apply that to bids: Priya's request locks the auction row, reads $100, checks, inserts $101, commits. Only now does Sam's request get the row; it reads $101, checks its $101 bid, and correctly rejects it. The lock turns a race into a queue, one bidder at a time, but only for that one auction. Bids on other auctions are not slowed at all. This is the fix we will build in Part 3 (guide 14).
Within about 15 seconds, a reply similar to: “Lol, yes—you're right. I missed a real lost-race bug.” Codex explains that the bid endpoint does three separate steps (read the current max bid, validate the amount, insert the bid) with no transaction or auction-row lock in app.ts. It gives an example like two requests both reading $100 and both inserting $101. It suggests wrapping the bid in a transaction with SELECT … FOR UPDATE on the auction row, and may point out that GRILL.md records concurrency as deferred to Part 3.
What it means: Codex found the same gap you found in Step 1, and it proposes the same fix the two callouts describe. It has not changed any code yet; it only answered the question.
If Codex asks which folder you mean, answer part 2. The root AGENTS.md tells it to ask when the part is not clear from your message, which is good behaviour in a repo with eight parts.
Stay in the same chat. Codex has already offered the fix, and the temptation is to say “go ahead”. I do not. First I want a test that shows the bug happening, so that later we can run the same test and watch it stop happening. Read the prompt before you paste it. It is prescriptive on purpose: it names the tool (Playwright), the number of windows (4), the roles (one seller, three bidders), the auction length (20 seconds), the layout (tiled on screen) and the behaviour (bids at the same time and at different times). The more precisely you describe the scene, the less the agent has to guess.
you're to reproduce the issue first, and here's how you're going to do it: you're going to make a Bidding War playwright test. Basically, you will open 4 windows. First window will be the person creating the auction - you will create an auction with 20 seconds left before the auction ends. Then, you will open 3 other windows, have them be separate users, and all attempt to bid on the item up to and at the end of the auction. Tile the windows on the screen so we can see what's going on. You will reproduce this by making them attempt to bid at the same time, different times, etc. Really make it chaotic! Make it a fun visual! Ensure that the frontend shows the bidding process and bids while they're happening.
The tests Codex wrote so far are unit and API tests: they call a function or an endpoint directly and check the answer. An end-to-end (E2E) test instead drives a real browser like a user would: open the page, click Sell, type a price, press Place bid, read what appears on screen. Playwright is the library that does this driving; it can control Chrome, Edge, Firefox and WebKit from a script. Normally it runs headless, meaning the browser runs invisibly in the background, which is fast and fine for automation. Headed means the browser windows are actually shown on your screen. We want headed here because the point is to watch four users collide. Each Playwright “context” is like a separate browser profile with its own storage, which is how the three bidders become three different users.
In testing, red is a failing test and green is a passing one. “Red before green” means: write a test that fails because of the bug before you fix the bug. Two reasons. First, it proves the test actually detects the problem; a test that was never red might pass for the wrong reasons. Second, when you then apply the fix and the same test turns green, you have evidence the fix works, not just a feeling. With an agent this matters even more, because the agent will happily say “fixed” whether it is or not. The red test is how you hold it accountable.
Within a minute, a reply similar to: “I'll build this in part-2-create-auction-and-bid as a headed Playwright ‘Bidding War’ demonstration: one seller window, three bidder windows, a 20-second auction, coordinated and staggered bids, and live on-screen activity. I'll keep all four Chrome/Edge windows open in a 2×2 grid.” It then reads the part's AGENTS.md and the existing test setup before writing anything.
Caught up from the reference in guide 10? Your Part 2 already contains the finished test (tests/bidding-war.spec.ts). You can still send the prompt; Codex will probably find the test and simply run it. The catch-up box at the bottom of guide 12 shows how to run it yourself.
This is a long run: 10 or more minutes across this guide and the next. Codex writes the test, installs Playwright and a browser, launches windows and takes screenshots to check the layout. That costs a fair number of tokens on your API key. Let it finish rather than interrupting halfway.
Now just watch. Do not close Codex, the chat, or the Terminal running Part 2. While it works, I want to give you the idea behind all of this. Every time Codex finishes a change, something has to tell it whether the change is right. Type checks do that for shapes of data. Tests do that for behaviour. Code review does that for design. Each of these is back pressure: a force pushing back on the agent, catching mistakes before they reach you. The more back pressure you give an agent, the more it can correct itself without you, and the faster you can safely move. A test that reproduces this bug is back pressure we did not have before.
Over the next few minutes, in roughly this order:
playwright.config.ts (Playwright's settings: which browser, headed or headless, timeouts), a tests/bidding-war.spec.ts file (the test itself) and a test:bidding-war script in package.json so you can run it with npm run test:bidding-war.BIDDING_WAR_HOLD_MS=3600000 npm run test:bidding-war and browser windows start popping up on your screen. BIDDING_WAR_HOLD_MS=3600000 is an environment variable: a setting passed to the command through the shell. Here it tells the test to hold the windows open for 3,600,000 milliseconds (one hour) after the auction ends, so you can look at the result instead of the windows vanishing instantly.This guide ends while Codex is still working. Carry on in guide 12 in this same chat.
macOS may show a dialog asking whether Codex can control your browser or record the screen (Codex takes screenshots to check the window layout). Guide 12 tells you what to click for each of these prompts.
If your Part 2 is broken or very different from what this guide describes (no bid route, bids not accepted, the app will not start), replace it with the finished Part 2 from the reference project. Note: the reference folder is the end state of the whole part: all Part 2 slices plus the finished bidding-war test from guides 11 and 12. After this you can skip straight to running the test (see the catch-up box in guide 12).
cd ~/codex-course/workshop && rm -rf part-2-create-auction-and-bid && cp -R ../reference/part-2-create-auction-and-bid ./ && git add -A && git commit -m "Catch up: part 2 from reference"
The command deletes your Part 2 folder, copies the reference's Part 2 in its place, and commits the result so your Git history shows exactly when you caught up. Then run npm install && npm start inside the new Part 2 folder before you continue.
SELECT … FOR UPDATE), which makes bidders on one auction wait their turn.AGENTS.md and GRILL.md files beats a long chat every time.