Learning objectives
After this chapter you should be able to:
Do unaided:
- Name the six steps of the working loop in order, who does each, and the five things never delegated.
- Describe the three phases and state what the agent may and may not do in each.
- Place any source of claims about your code on the trust ledger and say how to check it.
- Write a short Audit Report and a work-log entry, including a calibration line.
- Explain why exams and memory checkpoints stay AI-free, and what the oral defense asks.
May delegate:
- Nothing new yet. You watch a full loop; as in Chapter 1, you may ask the tutor to explain a compiler message after writing your own guess.
Opening case
A composite case, not a real student or course.
This scene is a preview. It takes place in week 10, later in the course, when an agent may write code from a specification you wrote first (Section 2.3). You are in week 1 and will not delegate code for weeks; read it to see what the loop is preparing you for.
The chapter continues from here.
The loop in this chapter
Open a step to see what it asks of you and how it plays out in the Tutor phase.
Predictyou write the output of Listing 2.4, your confidence and a time estimate.
Step 1 of 6 · You, no AI
What you hand in: A written prediction: the output, the memory state, the operation count, and how sure you are.
Why this step: A prediction written before the run is the only way to learn whether your model of the machine is right. A miss is the most useful result there is, because it shows exactly where the model is wrong.
The first prediction is never delegated.
Ask yourself: What will this print, what will memory look like when it ends, and how many operations will it take?
Log the prediction in your work log · Predict in every chapter · ← Predict in Chapter 1 · Predict in Chapter 3 →
Writethe instructor writes a short function by hand; you write your fix to Listing 2.4.
Step 2 of 6 · You, no AI
What you hand in: One small piece written by hand, to build the mental model.
Why this step: You can only check what you could have built. Writing a small piece yourself gives you the model you will need to judge the agent's version later.
Ask yourself: Could I write this piece again tomorrow without notes?
Browse the companion code · Write in every chapter · ← Write in Chapter 1 · Write in Chapter 3 →
Specifythe instructor, then you, write a question for the tutor with a hypothesis.
Step 3 of 6 · You
What you hand in: The header or class interface, unit tests, a complexity budget and the ownership rules.
Why this step: The specification is the contract the code will be held to. Tests written first, a cost budget and ownership rules turn "looks right" into something you can check.
Tutor In the Tutor phase you specify a question instead of code: what you want explained, quizzed or drilled.
The ownership and lifetime section of a specification is never delegated.
Ask yourself: Who allocates, who frees, what does it cost, and what input would break it?
Prompt and specification templates · Specify in every chapter · ← Specify in Chapter 1 · Specify in Chapter 3 →
Delegatethe tutor explains; it writes no code anyone submits.
Step 4 of 6 · The agent
What you hand in: The implementation from your specification, or an explanation in the Tutor phase, with the prompts and transcript saved.
Why this step: The agent does the typing; you keep the judgment. Saving the prompts and the transcript makes the delegation something you can audit afterward.
Tutor Tutor phase: the agent explains, quizzes and makes practice problems. It writes no code you submit.
Ask yourself: Did I hand over my specification and tests, and did I save what the agent said?
Prompt templates · Delegate in every chapter · ← Delegate in Chapter 1 · Delegate in Chapter 3 →
Auditthe instructor checks the tutor's claims with a rebuild, a sanitizer and a test; you check the claims about Listing 2.4.
Step 5 of 6 · You and the tools
What you hand in: The Audit Report: tests, sanitizer and Valgrind output, your own cost derivation against a timing plot, the defects found, and a keep-or-rewrite decision.
Why this step: What the agent says is testimony until an instrument confirms it. Tests, sanitizers, Valgrind and a timing plot are evidence.
Tutor In the Tutor phase the audit checks the tutor's claims as well as your own code.
The final judgment that the code is correct is never delegated.
Ask yourself: What did the sanitizer report, does the timing plot match my derivation, and would I keep this code or rewrite it?
The Audit Report template · Audit in every chapter · ← Audit in Chapter 1 · Audit in Chapter 3 →
Defendyou answer one Defend it question aloud in under two minutes.
Step 6 of 6 · You, live
What you hand in: A five-minute oral defense.
Why this step: If you can explain it live, you own it. The oral checks that the understanding is yours and not the agent's.
Ask yourself: Why this bound, what input breaks it, and where is this memory freed?
How the loop works · Defend in every chapter · ← Defend in Chapter 1 · Defend in Chapter 3 →
What agents get wrong here
Patterns observed in agent-written code, to test for, not guarantees. If the agent no longer makes the mistake, your job is to prove it got it right, with the same instrument.
Calls a degenerate result "a safe default" (a mean of no valid readings "returns 0.0")
How to catch it Write the all-missing test; the run prints -nan while the sanitizers stay silent
Section 2.2.2 · Tests
Predicts output without checking integer division or a < boundary
How to catch it Build and run; place each claim on the trust ledger
Section 2 Lab · Your own trace
Calls a read one past the end of an array harmless because the output looks right
How to catch it Standard build line; ASan reports stack-buffer-overflow
Section Ex. 2.8 · AddressSanitizer
What the chapter covers
- 2.1 Why a loop
- 2.1.1 What working code used to prove
- 2.1.2 What the studies found
- 2.1.3 How much weight to put on this
- 2.1.4 What a loop is for
- 2.2 The six steps
- 2.2.1 The loop at a glance
- 2.2.2 A worked example: averaging the valid readings
- 2.3 The three phases
- 2.3.1 How the agent is earned
- 2.3.2 Agent roles
- 2.3.3 A suggested AI policy
- 2.4 How we know: testimony, evidence and the trust ledger
- 2.4.1 Testimony and evidence
- 2.4.2 The trust ledger
- 2.4.3 Calibration
- 2.5 From "the agent said so" to "ASan and my trace agree"
- 2.5.1 Three ways to answer the tutor
- 2.5.2 The stance behind the loop
- 2.6 The Audit Report, the work log and the oral defense
- 2.6.1 The Audit Report
- 2.6.2 The work log
- 2.6.3 The oral defense
- 2.6.4 Why the exams stay AI-free
Cost thread
This chapter's cost is your own time. Before your next session on the Chapter 1 lab, estimate the hours; afterward, record the actual. Early estimates usually run low; the gap is information, not failure.
Summary
- Working code no longer shows understanding: AI help while learning lowered later unassisted scores (50% against 67%; 17% lower once access ended), and people misjudged their progress.
- The working loop: Predict, Write, Specify, Delegate, Audit, Defend. In the Tutor phase you specify a question and the agent writes no code you submit.
- The agent is earned by phase (Tutor, Pair, Team) and works in named roles with limits; some work stays AI-free in every phase.
- Agent output is testimony; compiler, sanitizer, Valgrind and test results are evidence, each with blind spots. The trust ledger says how to check each.
- Calibration, confidence against hit rate, is measured from the work log.
- The Audit Report, work log and oral defense make your understanding visible.
Key terms
- working loop: Predict, Write, Specify, Delegate, Audit, Defend.
- phase: a course stage (Tutor, Pair, Team) that sets what an agent may do.
- agent role: a job given to an agent for a session, with a stated limit.
- testimony: a claim accepted because a source said it.
- evidence: an observation from a process that could have contradicted you.
- conjecture: your own claim before checking, such as a written prediction.
- trust ledger: the table ranking sources of claims about code, with how to check each.
- calibration: how well your stated confidence matches your hit rate.
- Audit Report: the seven-part written record of the Audit step.
- work log: one row per session: estimate, hours, prediction, result, defects, prompts.
- oral defense: five minutes explaining and answering for submitted work.
Connections
Where this chapter and another point to each other most often.
- Chapter 1: From Python to C: What Python Was Hiding
You watch a full loop; as in Chapter 1, you may ask the tutor to explain a compiler message after writing your own guess. ## Opening case A composite case, not a real student or course. This scene is a preview. - Chapter 5: Arrays, Strings, and Matrices: n, n², n³
(Arrays are taught in Chapter 5; here you only read a loop over one.) Step 1, Predict. For21.5, missing,22.5,23.0, Maya writes: "67.0 over three valid readings: 22.333333. 90% sure." The prediction is her first instrument. - Chapter 6: The Stack and the Heap: Dynamic Memory and Ownership
(mallocandfreeare taught in Chapter 6.) When an agent can produce a working program for you, what counts as evidence that you understand it? - Chapter 9: Files, Bits, and Function Pointers: ADTs Behind a Header
Defend | Student, live | Five-minute oral: why this bound, what input breaks it, where this memory is freed | In the Tutor phase (Chapters 1 to 9), steps 3 and 4 change shape: you specify a question, and the agent explains or quizzes but writes no code you submit. - Chapter 10: Complexity and Sorting: Your First Delegation
Chapters 10 to 15 (Pair): an agent may implement units from your specification. - Chapter 19: Directing a Team of Agents
The "safe default" is also wrong about the station: 0 °C is a real reading, and a frost warning (Chapter 19) could not tell a dead sensor from a freezing night.
Further reading
- Shen and Tamkin (2026): the trial behind the debugging gap; read how the way people used the assistant changed what they kept.
- Bastani et al. (2025): practice gains that vanish when access is removed, and a tutor design that avoided it.
- Lee and See (2004): why trust should match a tool's reliability; older than agents and still apt.