Part I · Foundations

02 The Working Loop

TutorWeek 1Lab: Watch a loop, then run two stepsMemory

What still holds

You answer for every line you submit.

The agent may: explain and quiz; you watch a full loop.

Learning objectives

After this chapter you should be able to:

Do unaided:

  1. Name the six steps of the working loop in order, who does each, and the five things never delegated.
  2. Describe the three phases and state what the agent may and may not do in each.
  3. Place any source of claims about your code on the trust ledger and say how to check it.
  4. Write a short Audit Report and a work-log entry, including a calibration line.
  5. Explain why exams and memory checkpoints stay AI-free, and what the oral defense asks.

May delegate:

  1. 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.

  1. 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?

  2. 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?

  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?

  4. 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?

  5. 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?

  6. 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?

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

  1. 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.2 The six steps
    • 2.2.1 The loop at a glance
    • 2.2.2 A worked example: averaging the valid readings
  3. 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
  4. 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
  5. 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
  6. 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.

See it on the map

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.