Finish Part 4. Read the architecture diagram Codex drew, question it, approve Slice 1, then watch two browser windows update live without a reload. Run the four-window bidding war and use a screenshot to make Codex fix the cramped layout and the leftover page reloads.
npm start starts two containers, PostgreSQL and Redis, and then the API and the web app. If Docker is not running, the start fails on the very first line.~/codex-course/workshop folder.Until now our auction page only knew about a new bid when you reloaded it. In Part 4 we flip that around: the server tells every open page the moment something changes. The pipe for this is a WebSocket, a connection that stays open between the browser and the server so the server can push a message down at any time, unlike a normal request where the browser must ask first. When a bid is saved, the server sends one small event, “auction 42 changed”, to every browser that is looking at auction 42. Sending one event to many listeners is called fan-out. Think of a classroom notice board versus a teacher who walks to each desk: fan-out is the notice board, everyone sees it at once. Socket.IO is the library we use; it wraps WebSockets and adds rooms (“everyone watching auction 42”) and automatic reconnects.
Open the grill chat from guide 17. Codex has finished and printed something like “The grilling session is complete and documented in GRILL.md.” Below that message there is a diagram and a numbered list of proposed slices. Click the diagram once to open it in a larger view. Read the boxes and the arrows slowly, left to right, and then read the slice list. Do not approve anything yet. This step is reading only.
Why this matters: Codex is about to write a lot of code based on this picture. If the picture has one extra box in it, you will get one extra piece of software you never asked for. It is far cheaper to question a diagram than to delete a service.
Mermaid is a way of drawing diagrams with plain text. Instead of dragging shapes in a drawing tool, you write lines like Browser --> API --> Database and a renderer turns them into boxes and arrows. Codex likes Mermaid because it can write the text itself, and the Codex app renders it as a picture for you. The important part for you: every box is a component (a browser, a server, a database) and every arrow is a message or call between two components. If you can follow the arrows, you understand the design.
Imagine we later run two copies of our API server to handle more users. Browser A is connected to server 1, Browser B to server 2. A bid arrives at server 1. Server 1 can tell Browser A, but it has no idea Browser B exists. A backplane fixes this: every server publishes its events to one shared place, and every server listens to that place. We use Redis for it, a very fast in-memory data store that also offers Pub/Sub (publish/subscribe): one side publishes a message on a channel, every subscriber gets it instantly. So server 1 publishes “auction 42 changed” to Redis, server 2 hears it, and Browser B gets the update. With one server you would not strictly need this, but we build it in now so the design is ready for more than one.
A diagram with emoji service labels similar to: Bidder and Auction Watcher (🌐 browsers) → POST bid → ⚡ Fastify API → 🐘 PostgreSQL. After the database commit, an auction:changed event goes to 🔌 Socket.IO, which uses 🔴 Redis Pub/Sub as its backplane, then a WebSocket notification reaches both browsers and each browser refetches the auction (asks the API for the latest data).
Two slices are proposed, similar to:
And a closing line like: “Please confirm these two slices. Once confirmed, I'll implement and verify Slice 1 only, then stop for your browser review.”
Some words in Slice 1 that I want you to understand before you approve it:
A question I get asked a lot: do I limit the grill to 8–10 questions on real projects too? No. That limit in our AGENTS.md exists only to keep this course moving. On real work I let the grill run, and when it crosses roughly 50 questions I say “can we wrap this up?” or “this doesn't matter, cut this.” You control the depth, not the tool.
In my run, one box in the diagram worried me: “Auction Watcher”. It sat next to “Bidder” as if it were a separate thing. Was Codex planning to build a second program that watches auctions? That would be a whole new service to run, deploy and debug. Before approving, I asked. This is exactly how you catch an agent adding complexity you never requested. If your diagram has a different unclear box, ask the same kind of question about that box instead, using the same shape: “is X a logical idea, or a real separate service?”
is Auction Watcher represented here as a logical separation, or is it physically meant to be a separate service?
Notice the wording. “Logical separation” means “just a role or a label in the picture”. “Physically a separate service” means “a separate process with its own port and its own code”. Giving Codex both options makes it answer precisely instead of guessing what you are worried about.
Similar to: “It's a logical role, not a separate service. ‘Bidder’ and ‘Auction Watcher’ are two browser windows running the same React/Vite frontend; one submits a bid while both receive updates. I'll relabel the diagram to make that explicit before implementation.” That is the answer we want: two windows of the same website, no new service.
Make this a habit. Every time a diagram shows a box you did not ask for, ask “is this a new service?” before you say go. Agents love adding infrastructure. Your job is to keep the design as small as it can be.
Now send the approval. The prompt is short on purpose: Codex already has the full design in GRILL.md and in this chat, so all it needs is a clear yes and a clear scope. “Go for slice 1” tells it to build the first slice only and then stop, which is what it offered to do.
the implementation looks great, go for slice 1
Then wait. This is a long run. You will see Codex work through roughly these stages, in order: install the socket.io packages and the Redis adapter with npm; start a Redis container through Docker; edit the server code (a new realtime.ts file and changes in app.ts); edit the web code (a new liveAuction.ts file and the auction detail page); write tests; run the test suite and the TypeScript typecheck; and finally open a headless browser, load the same auction in two pages, bid in one and confirm the other updates.
A long run that ends with “Slice 1 is complete and verified. I stopped before Slice 2.” and a list of key changes similar to:
realtime.tsauction:changed events in app.tsliveAuction.ts3104, web 5104, database auction_part_4GRILL.mdThe “isolated on” line matters: Part 4 has its own port numbers and its own database name, so it never collides with Parts 1–3 if you run them side by side.
I never build Slice 2 in this course. The reference copy's GRILL.md still marks it “proposed”. You can skip it too; the app works without it. If you want extra practice later, say “go for slice 2” after step 10 and review the result the same way.
This is a big build run, often 10–20 minutes, and one of the more expensive steps on your API key. Do not interrupt it unless it is clearly going wrong. If you want to save money, this is not the step to switch to a smaller model; a weak model makes more mistakes in exactly this kind of multi-file change.
In my run I had to quit Codex in the middle of the slice. When I reopened the app and the same chat, I sent one word and Codex picked up where it had left off. Do this step only if your run was interrupted: you quit the app, your Mac went to sleep, or the run stopped with no final summary. If step 3 ended cleanly with “Slice 1 is complete and verified”, skip to step 5.
continue
Why this works: the chat history is Codex's memory. On “continue” it re-reads the last messages and the files on disk, works out what is already done and what is not, and resumes the same slice. You do not need to repeat the plan.
Codex re-reads where it was and keeps going with the same slice, ending with the same “Slice 1 is complete and verified” summary. One quirk: after a restart the “Edited N files” card may list fewer files than were really changed, because the card only counts changes made in the current run. The earlier work is still on disk. Step 6 shows you how to see the full picture with Git.
“Continue” is for interruptions, not for bad runs. If a run is clearly heading the wrong way, I stop it and restart from a good point instead of continuing. The next step shows the clean way to do that.
My tip for when Codex does something you don't like. Do not argue in the same thread (“no, you did it wrong, redo it”). Every wrong turn stays in the chat's context, and the model keeps getting pulled back towards it. Instead, go back to the last message before things went wrong and branch from there, so the bad part never existed in the new thread:
Nothing to send right now. Just find the icon on any message so you know where it is when you need it under pressure.
The “Fork chat from here” box with the two options. Press Esc to close it without forking.
If your Codex version has no branch icon, the fallback is: start a New chat, paste a three-line summary of the decisions so far, add your correction, and continue there. The idea is the same: a clean context with no wrong turn in it.
This slice adds new architecture to the project, a second data store and a push channel, so I read the diff. I do not read every line of every slice, but I always read the first slice that introduces a new technology. Click Review on the “Edited N files” card, or open the review panel from the icon at the top right of the Codex window. A side panel opens with one entry per changed file. Look specifically at:
auction:changed is published only after a successful bid. A rejected bid (too low, or from the seller) must not trigger an event.tests/realtime-bid.spec.ts, the browser test. It waits for a websocket connection to be established and then opens two pages on the same auction.web/src/liveAuction.ts, the browser side. Find io(..., { transports: ['websocket'] }), which is the “WebSocket-only” decision from the slice list, and the auction:changed handler, which is the code that runs when the server pushes an event.GRILL.md: Slice 1 now says Status: implemented and verified. The design document and the code moved together.A diff shows only what changed between two versions of a file. Lines with a red background (and a minus sign) were removed; lines with a green background (and a plus sign) were added; unchanged lines around them are shown in grey for context. You do not need to understand every line. Ask three questions per file: Is this file one I expected to change? Does anything get deleted that should not be? Does the new code match what the slice promised? If the answer to all three is yes, move on.
A side panel with green and red diff lines per file. In Codex's summary, the Mermaid diagram has been relabelled (that was the promise from step 2): it now shows Browser A · submits bid and Browser B · watches auction as two browsers, not two services.
Prefer VS Code? Run code ~/codex-course/workshop in Terminal and click the Source Control icon in the left bar (the one with three connected dots). It lists every changed file since your last commit, which is the full picture even if the Codex card lost count after a restart.
Codex ended its summary with browser review steps: run npm start in Part 4, open the same auction in two windows, bid as a non-seller in one, and watch both update. The built-in browser preview is not available with an API-key sign-in, so we do it by hand in Chrome. First start the servers:
cd ~/codex-course/workshop/part-4-realtime-socketio-redis npm install npm start
Line by line:
cd …/part-4-realtime-socketio-redis moves into the Part 4 folder. Each part is its own small project with its own package.json.npm install downloads the packages this part depends on, including the new socket.io and Redis adapter packages Codex added. The first run takes a minute.npm start runs the start script: it brings up the Postgres and Redis containers, runs the database migrations for auction_part_4, then starts the API on port 3104 and the web app on port 5104. Leave this Terminal window open; closing it stops the servers.Now the manual test:
A page reload (pressing refresh, or code calling location.reload()) throws the whole page away and asks the server for everything again: the HTML, the scripts, the data. You see a white flash, scroll position is lost, and every reload is a full round of requests. A live update keeps the page as it is and changes only the numbers that changed, because the server pushed a tiny “something changed” message and the page fetched just the auction data. For the user it feels instant and smooth. For the server it is far less work. From now on, a reload on the auction page is a bug, not a feature. Keep that in mind for step 8.
Terminal shows the Postgres and Redis containers as healthy, the migrations running, then [server] and [web] log lines. In the browser, the bid appears in both windows within about a second, with no reload and no flash: current price, highest bidder, bid count, minimum next bid and the bid history all change in the window you did not touch. That is the fan-out working end to end.
If the second window does not change: open Docker Desktop and check that a redis container is running (the root docker-compose.yml maps it to localhost:56379). If Redis is down, the backplane is down, and no events get through. If Redis is fine, ask Codex in the same chat “the second window is not updating, what's wrong?” and let it debug.
When you are done, press Ctrl+C in Terminal to stop the servers. The Redis and Postgres containers keep running in Docker, which is fine and saves start-up time later.
My rule since Part 3: it isn't verified until bidding wars. Two windows and one bid is a demo. Four users bidding against each other under a countdown is a test. First make sure your npm start from step 7 is stopped (Ctrl+C in Terminal), because the test starts its own servers on the same ports and will fail if they are already taken. Then send the prompt. The silly wording is mine, keep it; Codex knows from Part 3 exactly what “bidding wars” means in this project.
well you know what I'ma say (or maybe not...) TIME FOR BIDDING WARSS!!!!!!!
Playwright is a tool that drives a real browser from code: open this page, type here, click there, wait for this text. Normally it runs headless, with no visible window, which is fast and good for automated checks. A headed run opens real browser windows so a human can watch. Our bidding-war test is deliberately headed: it opens four windows, logs in four different users, fires bids on a timer and leaves the windows open at the end. The computer checks the final prices; you check what it looks and feels like. That second check is the one that catches layout problems and unwanted reloads, which no assertion in the code would notice.
Codex runs the headed Playwright test tests/bidding-war.spec.ts. Four Edge windows open in a 2×2 grid: SELLER · AVERY, BIDDER 1 · MAYA, BIDDER 2 · THEO, BIDDER 3 · PRIYA, each with a countdown badge (T-…s). Bids fly in, every window shows ENDED at the deadline, and Codex reports something like: “BIDDING WAR PROTECTED! Accepted bids: $101 → $102 → $106 → $107. All four tiled Edge windows are open and will remain open for inspection.”
Now watch closely, because in my run two things were wrong even though the test passed. First, the bids did show up live, but the pages also refreshed, a visible flash on every bid. Second, the layout wasted space: a big search bar at the top pushed the price and the bid form below the visible area, so in a quarter-screen window you could not see what mattered without scrolling. Look for both in your windows. You fix them in the next two steps.
No Edge? The test's Playwright project is set to Edge (channel: 'msedge'). Either install Microsoft Edge, or tell Codex: “run the headed bidding war in Google Chrome instead”. The root AGENTS.md allows Chrome or Edge, so Codex will change the channel without complaint.
Leave the four Edge windows open exactly as they are. Press Cmd+Shift+3 to capture the whole screen. A small thumbnail appears at the bottom-right corner of your screen for a few seconds, and the image is also saved to your Desktop. Bring Codex to the front and drag the thumbnail (or the file from your Desktop) into the Codex message box. You can also click the + button in the message box and pick the image file.
Why a screenshot: a layout problem is hard to describe in words (“there is too much space above the price and the form is cut off at the bottom in a half-height window…”). A picture says it in one glance, and Codex can read images. For anything visual, this is the fastest way to be understood.
A small image thumbnail sits above your text in the Codex message box. Do not send yet; step 10 adds the text.
Want to capture only part of the screen? Cmd+Shift+4 gives you a crosshair to drag a rectangle. For this step the full screen is better, because Codex needs to see all four windows together to understand the 2×2 layout.
With the screenshot attached, send my two-point fix. Two separate points, numbered, so Codex treats them as two separate tasks and reports on each. “Above the fold” is a newspaper term: the part of a folded newspaper you see without unfolding it, so on a web page it means visible without scrolling. “Vestigial” means a leftover that no longer has a purpose, like the test helper that still reloads pages from the Part 3 days. My typo “vestigal” stays in the prompt, because it comes back in step 11.
1. the tiled view is not ideal for the resolution. can you condense the page a little bit so that the demo looks better? see screenshot - lots of wasted space and stuff is not "above the fold" 2. we noticed page refreshes - those should not be there in these tests anymore. vestigal!
Point 2 is the important one for a backend engineer. The reloads were not a bug in the app; they came from the test. In Part 3 the test had to reload each window to see new bids, because there were no live updates then. Codex copied that test into Part 4 and the reload helper came along. With real-time updates in place, the helper is now hiding the very thing we built. Removing it proves the live updates work on their own.
Similar to: “You're right on both counts. The screenshot shows the search bar consuming nearly an entire viewport row, and the test still calls its old syncAuction helper, which reloads every live window…” Codex then compacts the page layout, removes the reload helper from the test, and reruns the headed war. This time the four windows are compact, the price and bid form are visible without scrolling, bids arrive without any reload (no flash), and the final report is again similar to “$101 → $102 → $106 → $107”, with the windows left open for you.
Codex may run the war twice: once headless to check its fix, once headed to leave the final windows open for you. That is normal. If it only ran headless, say “run it headed and leave the windows open”.
While Codex was working on the fix, I started doubting my spelling. I did not want to add noise to the main thread, so I used a side chat. Select the word vestigal in your sent message (click and drag over it). A Side chat panel opens on the right with a label “1 selection”. The panel has its own message box. Type there:
did i spell it right
Why this matters: everything you type in the main thread becomes part of its context and costs tokens on every later turn. A side chat is a throwaway: you get your answer, the main thread never sees it.
“Almost—it's spelled vestigial.” The panel also notes that side chats are temporary and disappear when you close the app. The main chat keeps working in the background the whole time.
If your Codex version has no side chat, skip this step. It is only a convenience for quick questions that have nothing to do with the task at hand.
Part 4 is done: Slice 1 plus the layout and test fixes. Save it as a commit now, before Part 5 copies from it. If you forget, Part 5's copy still works, but your Git history will show Part 4 and Part 5 changes mixed in one commit, which makes reviewing much harder.
cd ~/codex-course/workshop && git add -A && git commit -m "Part 4: real-time bid updates"
What the three parts do: cd ~/codex-course/workshop goes to the root of your practice copy (the commit must happen at the root, not inside Part 4). git add -A stages every added, changed and deleted file. git commit -m "…" saves that snapshot with a message. The && between them means “only run the next command if the previous one succeeded”.
A commit summary listing new files such as part-4-realtime-socketio-redis/server/src/realtime.ts, web/src/liveAuction.ts and tests/realtime-bid.spec.ts, plus the changed GRILL.md. If it says “nothing to commit”, you already committed, which is fine.
Slice 1 refuses to work, or you want to skip ahead? Replace your Part 4 with the finished reference version. The reference folder is the end state of the whole part: Slice 1 plus the layout and test fixes; Slice 2 was never built there either. After copying, run it with npm install && npm start inside the Part 4 folder and open http://localhost:5104 to confirm it works.
cd ~/codex-course/workshop && rm -rf part-4-realtime-socketio-redis && cp -R ../reference/part-4-realtime-socketio-redis ./ && git add -A && git commit -m "Catch up: part 4 from reference"
What it does: deletes your Part 4 folder (rm -rf), copies the reference Part 4 in its place (cp -R, where -R means copy the folder and everything inside it), and commits the result so your history records the catch-up.
Other common problems: if npm start fails immediately, Docker Desktop is probably not running. If the API complains that port 3104 is in use, a previous run is still alive; press Ctrl+C in that Terminal or quit it. If the bidding war cannot open Edge, see the tip in step 8.
auction:changed event over WebSockets to every page watching that auction; the pages refetch. Redis is the backplane that lets several servers share those events.realtime.ts) and in the browser (liveAuction.ts).