← All guidesCodex for Backend Engineering · Future with Shivank
Hands-on guide

15. Closing the Auction

Build Slice 2 (an injected app clock, and auction pages that switch to “Ended” exactly on time), use two side chats to learn isolation levels and to find your blind spots, then commit Part 3 and run one last, fully protected bidding war.

Part 3 · slice 2 + commit≈ 25–35 min hands-onTwo side chatsPart 3 done

What you'll do

Before you start

⚙ Codex settings for this guide
Project / folderworkshop
ModelGPT-5.6 Sol
ReasoningMedium
ApprovalsApprove for me
📘 Concept: what “closing” an auction really means

Every auction has an endsAt time. After that moment, no bid may be accepted. That sounds trivial, but there are two separate problems hidden inside it. First, the backend must decide, for every bid, “did this arrive before or after the deadline?”, and it must make that decision with a clock it controls and can test. Second, the frontend must show the user that bidding is over at the right moment, even if they have had the tab open for ten minutes and never refreshed. Slice 2 solves both. The backend is the authority: whatever the browser shows, the server's decision is final.

1

Ask what the next slice is

We are back in the Part 3 chat (the one that started with grilling in guide 13). The plan for Slice 2 is somewhere far up in the conversation. Instead of scrolling, ask Codex. The chat still has the whole plan in its context, so it can restate the slice in a few lines, and you get a fresh summary to check against what you decided in grilling.

✦Paste into CodexPart 3 chat
what's the next slice again I don't wanna scroll up

Read the list it gives you carefully, because every line maps to a grilling answer you gave. “Inject an app clock” was your answer to question 3. “Check the clock after acquiring the lock” and “store that reading as createdAt” were question 11. “Switch to Ended at endsAt” and “recheck when a backgrounded tab becomes visible” were questions 7 and 16. If something in the list is not what you agreed to, say so now, before any code is written. Changing a plan costs one sentence; changing built code costs a lot more.

📘 Concept: injected app clock (why we don't call Date.now() directly)

The obvious way to get the current time in JavaScript is Date.now(). The problem is that it always returns the real current time, so a test can never say “pretend it is one second before closing and send a bid”. The fix is to put the clock behind a tiny object, for example clock.now(), and inject it (pass it in from outside) when the app is created. In production we pass a real clock. In tests we pass a fake clock that we can set to any moment and move forward by hand. The bid-checking code calls clock.now() either way and never knows which one it got. This is why your tests can prove the closing rule exactly at the boundary, deterministically, every time.

📘 Concept: polling

Polling means the browser asks the server “anything new?” again and again on a timer, for example every two seconds. It is simple, and it is wasteful: a thousand open tabs mean a thousand requests every two seconds, most of them returning “nothing changed”. For the “Ended” switch we do not need polling at all. The page already knows endsAt, so it can set a timer in the browser that fires at that moment, and re-check once if the tab wakes up after sleeping. The server is still the authority on whether a bid is accepted; the timer only updates what the user sees.

✓ You should see

Similar to: “Next is Slice 2: authoritative auction closing and live page transitions.”

  • Inject an app clock so backend time is mockable.
  • After acquiring the auction lock, check that clock before accepting the bid.
  • Store that same clock reading as the bid's createdAt.
  • Reject bids whose serialized decision occurs at or after closing.
  • Automatically change an open page to “Ended” and disable bidding at endsAt.
  • Recheck the deadline when a backgrounded tab becomes visible.
  • Add deterministic clock-boundary and frontend timer tests.

“No continuous polling—the backend remains authoritative.” (“Deterministic” means the test gives the same result every run, because the fake clock removes all timing luck.)

2

Start Slice 2

If the summary matches your decisions, give the go-ahead. Two words are enough; the plan is already in GRILL.md and in this chat.

✦Paste into CodexPart 3 chat
go for it

Notice the phrase “as independently testable pieces” in Codex's reply. The backend clock and the frontend deadline watcher are two separate changes, each with its own tests. That is good engineering: if the “Ended” switch misbehaves later, you know the backend clock is not the suspect.

✓ You should see

Similar to: “I'm starting Slice 2 now. I'll close the finished bidding-war windows before changing the app, then add the injected backend clock and the frontend deadline watcher as independently testable pieces…” A step counter (Step 1 / 4) and a growing file count appear, just like in guide 14. If your Edge windows from guide 14 were still open, Codex closes them first.

⚠ Heads up

This is another multi-minute build: code, backend tests, frontend tests, a typecheck and a headed browser run. Let it work. Use the time for Steps 3 and 4, which is exactly how I use it in class.

3

Side chat: isolation levels in plain words

In guide 14, “READ COMMITTED isolation” appeared in the list of things to Google. Let's actually learn it now. Open a fresh side chat (right-panel button at the top-right → Side chat, or ⌥⌘S; close any old side chat first). The trick in this prompt is the last sentence: tell Codex what you already know. Without it, the answer is either too basic or too advanced. With it, Codex pitches the explanation at your level and skips what you already understand.

✦Paste into CodexSide chat
tbh, I thought postgres was a type of plant, and I don't understand isolation level at all. please explain it to me in basic terms. I know the basics of SQL.
📘 Concept: transaction isolation levels

When two transactions run at the same time, the database has to decide how much each one is allowed to see of the other's unfinished work. The isolation level is that setting. Picture two accountants working on the same ledger at the same desk. At the weakest level they can read each other's pencil notes before the ink is dry (“dirty reads”). At Read Committed, PostgreSQL's default, you only see what the other person has finished and signed off; but if you read a value, then they commit a change, then you read again, you may see two different values inside one transaction. At Repeatable Read you work from a fixed photocopy taken when your transaction began. At Serializable, the strictest, the database guarantees the result is as if the transactions ran one after another, and it cancels one of them if that is impossible, so your code must be ready to retry. Stricter levels cost performance and add retry logic. Our auction keeps the default Read Committed and adds one explicit row lock on the auction. That gives us the exact serialisation we need, only where we need it, and nothing has to be retried.

✓ You should see

Similar to: “PostgreSQL—usually called Postgres—is a database system, not a plant.” An isolation level answers “When two database transactions happen at the same time, how much are they allowed to see and interfere with each other?” Then the levels from weakest to strongest:

  • Read Uncommitted: could see unfinished changes (“dirty reads”); Postgres treats it as Read Committed
  • Read Committed: the Postgres default; each statement sees data committed before it began. It does not by itself protect a read-validate-write sequence
  • Repeatable Read: a stable snapshot for the whole transaction
  • Serializable: strongest; Postgres may cancel a transaction, so the app must retry

And “What our auction uses”: the default Read Committed plus a row lock, like a single checkout lane per auction.

💡 Tip

“I know the basics of SQL” is still vague. Being specific (“I know SELECT, UPDATE and what a transaction is, but I have never used locks”) gets you a better-fitted answer. The more precisely you describe your starting point, the less time the model wastes.

4

Second side chat: what am I not thinking about?

Click the + next to the side-chat tab at the top of the panel. A second tab, Side chat 2, opens with its own empty context. Now ask a different kind of question. So far you have asked Codex to explain things you knew you did not understand. This prompt asks about the things you do not even know to ask about. When you are new to a domain, this is the single most useful question you can put to an AI, because your own list of worries is limited by your experience.

✦Paste into CodexSide chat 2
in the work that we're doing right now, what am I NOT thinking about? what's important or risky that should be surfaced?

Read the answer as a senior engineer's review notes, not as a to-do list. I read it, I nod at a few points, and I do not act on it today. The slice we agreed on is the slice we build; everything else goes into a mental “later” pile. This is scope discipline, and it is the reason Part 3 gets finished in this guide instead of growing for another week. Some items (no authentication, identity controlled by the client) are real gaps that we knowingly accept in a course project.

✓ You should see

A numbered list of about 10 risks, similar to: app clocks can disagree across servers; define the exact acceptance moment; injected timestamps can break history ordering; browser time vs backend time; sleeping tabs and clock changes; a failed refresh can leave contradictory UI; lost responses (no idempotency); identity is completely client-controlled (no auth). It ends with something like “My strongest ‘fix now’ recommendations are #2, #3, #5, and #8.”
Your list will differ in order and wording. The clock-related items should dominate, for the reason in the tip below.

💡 Tip

A side chat can see the main chat, so its answer is biased by that conversation. Here the main chat is deep in clock work, so the risks it lists are mostly about clocks. For an unbiased review, ask the same question in a brand-new chat in the workshop project and tell it which folder to look at; it will read the code cold and often raise different points.

5

Read the Slice 2 handoff

Go back to the main chat and wait for Slice 2 to finish. Edge windows will open and close on their own while Codex runs the headed test. When it is done you get a handoff like the one in guide 14: a summary, a list of changes, the test counts, a Mermaid diagram and a URL. Click the diagram to zoom in if you like.

Match each change to the concept behind it. buildApp accepting a Clock is the injection: the function that creates the server now takes the clock as an input, so tests can hand it a fake one. Reading the time after acquiring the lock matters because the lock is the moment the bid is actually judged; reading it before the lock could stamp a bid with a time from before it waited in line. AUCTION_CLOSED is the typed 409 error code the frontend uses to show “Bidding has ended” instead of a generic failure. And “recheck when a tab comes back” handles a laptop that went to sleep: the browser timer may have been paused, so the page checks the deadline again as soon as it becomes visible.

✓ You should see

Similar to: “Slice 2 is complete. The app clock is officially in charge—no database-clock funny business.” What changed:

  • buildApp accepts an injected Clock
  • bid time is read after acquiring the auction lock and stored as createdAt
  • bids at or after the deadline return AUCTION_CLOSED
  • open pages transition to “Ended” at the deadline and recheck when a tab comes back

Tests: about 8 backend and 8 frontend pass, plus the headed Edge run. A Mermaid diagram (Bid request → Fastify API → Lock auction → PostgreSQL; Read time after lock → Injected App Clock; 201 or AUCTION_CLOSED back to the web app). “Both planned slices are now implemented and verified.” The app stays running at the URL Codex gives (in my run http://localhost:5103).

6

Optional: watch an auction close in Chrome

I trust the tests here, and the bidding war in Step 8 shows the “Ended” switch anyway. But if you want to see it happen on a page you created yourself, it takes three minutes:

  1. Open the Part 3 URL in Chrome (in my run http://localhost:5103). The app should still be running from Codex's handoff; if the page does not load, ask Codex in the main chat to start the Part 3 app.
  2. Click Sell in the top navigation and post a new auction whose closing time is about 2 minutes from now. The form insists on a closing time at least one minute in the future, so do not try to make it close immediately.
  3. Leave the auction's page open and watch the countdown reach zero. Do not refresh the page; the whole point is that the switch happens without a reload.
✓ You should see

At the deadline, without a reload, the page switches to Ended, the Place bid button is disabled, and the guidance text reads “Bidding has ended.” If you switch to another tab before the deadline and come back after it, the page shows Ended immediately: that is the “recheck when the tab becomes visible” behaviour from the handoff.

7

Commit Part 3

Part 3 is functionally done, so we save a snapshot of it in Git. You can commit from any Git tool you like (VS Code's Source Control panel, for example), but I do it from the Terminal because it is the same two commands every time and the message is explicit. Run this in the Terminal app, or in Codex's bottom-panel terminal.

❯Run in TerminalTerminal app · workshop folder
cd ~/codex-course/workshop && git add -A && git commit -m "Part 3: bid concurrency protection and auction closing"

Piece by piece: cd ~/codex-course/workshop moves to the root of your workshop, where the Git history lives. git add -A stages every new, changed or deleted file under it, which right now is everything Codex created in Part 3. git commit -m "…" saves that staged set as one snapshot with the message in quotes. Write messages that say what the snapshot contains, like this one; “done” or “fixes” tells future-you nothing.

📘 Concept: git commit and git diff

A commit is a saved snapshot of the whole project at one moment, with a message. Git stores the chain of commits, so you can always go back to any snapshot. A diff is the difference between two snapshots (or between the last commit and your current files): which lines were added, which were removed, in which files. This is what makes AI-assisted work reviewable. Because you committed at the end of Part 2, the diff since then is exactly “what Codex did in Part 3”, no more, no less. In guide 16 we hand that diff to two different reviewers and ask them to find problems in it. Without a clean commit boundary, there would be no clean diff to review.

Why this matters: commit at the end of every part, before the next one starts. It costs five seconds, it gives you an undo point, and it gives the code review in guide 16 a precise scope.

✓ You should see

A new commit containing the files in part-3-business-rules-concurrency (AGENTS.md, GRILL.md, package.json, server/…, web/…, tests/…). Git prints a line like [main abc1234] Part 3: bid concurrency protection and auction closing followed by N files changed. In my run it was 34 files; your count will differ. Guide 16 reviews this commit.

8

BIDDING WARS!!!!!

My rule: it is not done until I have seen it done. Codex has told us twice that the tests pass. Now we watch the complete Part 3 behaviour, both slices together, in real browser windows. The prompt is silly on purpose; Codex knows exactly what it means from the context of this chat.

✦Paste into CodexMain chat
BIDDING WARS!!!!!

Watch for two things this time. First, the bid history: every accepted amount must be higher than the one before it (Slice 1). Second, the ending: when the auction's closing time arrives, all four windows must flip to Ended by themselves, with no reload, and any bid sent after that must be rejected (Slice 2).

✓ You should see

Four tiled Edge windows on the Part 3 app. Near the end, every window flips to ENDED on its own, Place bid is disabled, and late bids show “$108 rejected: This auction has ended.” Codex reports similar to:
BIDDING WAR PROTECTED. Accepted history: $101 → $102 → $103 → $104 → $106 → $107. No duplicate bids; $106 won the mixed stale wave; every page transitioned to Ended, disabled bidding, and rejected post-close attempts.

💡 Tip

If the seller's window looks oddly laid out when you resize it, that is CSS injected by the test to squeeze the auction into a quarter of the screen, not a bug in your app. Open the same URL in a normal Chrome window and it looks fine.

Stuck or got a very different result?

If the “what am I not thinking about?” list sends Codex off on fixes you did not ask for, that is because you asked in the main chat by mistake. Tell it “stop, do not implement any of that, finish Slice 2 only”. Side questions always go in a side chat or a separate new chat.

If Slice 2 or the final bidding war fails, replace your Part 3 with the finished reference version. The command deletes your Part 3 folder (cannot be undone), copies the reference Part 3 in, and commits. The reference folder is the end state of the whole part: both slices done, which is exactly where this guide ends. Because it commits for you, skip Step 7 afterwards and go on to Step 8 or straight to guide 16.

❯Run in TerminalTerminal app
cd ~/codex-course/workshop && rm -rf part-3-business-rules-concurrency && cp -R ../reference/part-3-business-rules-concurrency ./ && git add -A && git commit -m "Catch up: part 3 from reference"

Key takeaways