Skip to content

🏠 Index | ⬅️ Prev (Ch.05) | ➡️ Next (Ch.07) | 🌐 中文版

Ch.06 Inspect Progress and Correct Course ​

Problem: An incorrect assumption can expand the scope of a running task.

Practice: Inspect visible plans, commands, and diffs; interrupt and restate a concrete constraint when needed.

In traditional software development, when managing a junior engineer, your biggest fear is having them work in isolation for a week, only to deliver code that completely deviates from business goals or breaks the main branch.

With any model, an incorrect assumption or task boundary can lead to unnecessary edits. Check visible plans, tool calls, and diffs during long tasks.

This chapter uses observable execution records to spot drift and restate concrete constraints.


A Way to Think About It: An "Exam Proctor Window" into AI's Mind ​

Never treat AI reasoning as a black box:

text
[Passive Blind Waiting] ──> Like waiting outside an exam hall for 2 hours, only to discover the student misremembered the fundamental formula on Question 1, failing the entire exam.
[Proctor Supervision]   ──> Like standing right behind the student, observing their draft scratchpad (Reasoning Summary):
                            - The student drafts: "Assume we need to rewrite the entire database schema..."
                            - You tap their shoulder immediately: "Don't touch the schema, just add a query index!"
                            - The student strikes out the wrong idea and returns to the right track.

Reading the Reasoning Summary gives you real-time visibility into that draft scratchpad.


Practice: Start with Three Steps ​

Learn to supervise and correct the AI like a tech lead in 3 simple steps:

  1. Step 1: Launch the Interactive TUI and Monitor Reasoning
    Run codex directly in your terminal and observe the rolling thought summary in the split pane.
  2. Step 2: Press Ctrl + C the Instant an Assumption Derails
    The moment you see the AI planning to pull in unfamiliar external packages or refactor core untouched files, hit Ctrl + C immediately.
  3. Step 3: Correct with One Precise Sentence and Resume
    Type your constraint directly: "Do not rewrite existing tables; solve this with in-memory caching." Ask the agent to restate the new constraint before it continues editing.

6.1 Why Inspect the Model's Reasoning Process? ​

The biggest difference between deep-reasoning models (such as GPT-5.6 Terra) and traditional models is that before producing final code, the reasoning model conducts in-depth internal hypothesis testing and simulation. The Codex TUI displays this process in real time as a Reasoning Summary.

text
[User Request] ──> 1. Parse Goals & Constraints ──> 2. Plan Steps ──> 3. Run Tests ──> 4. Self-Correct ──> [Final Output]
                     └──────(Displayed in TUI as Reasoning Summary: Your Proctor Viewport)──────┘

⚠️ Note: The full internal Chain of Thought (CoT) is guarded for safety; what you see in the TUI is a high-fidelity reasoning summary generated by the model. This summary is more than sufficient to evaluate technical decisions and architectural directions.


6.2 How to Observe and Interpret Reasoning in the TUI ​

1. Interactive Mode (TUI) ​

Launch codex to enter the interactive terminal interface, where the main pane streams the reasoning summary. Essential inspection and control commands:

bash
# Common TUI shortcut commands
/diff       # Review actual code modifications in the current session
/review     # Summon a reviewer subagent to audit recent changes
/copy       # Quickly copy the last generated response or code snippet

2. Non-Interactive Mode (Scripted Pipelines) ​

When running background tasks or long scripts, stream structured JSONL logs:

bash
# Non-interactive execution, streaming structured JSONL
codex exec --json "Refactor auth middleware" > task.jsonl

Healthy Reasoning Stream Example ​

When Codex receives the task "Fix connection timeout in the Redis rate limiter," a healthy reasoning stream looks like this:

text
[Reasoning Summary - Normal Flow]
- User wants to fix Redis rate limiter connection timeout.
- Checking existing implementation in src/lib/redis.ts...
- Found `redis = new Redis()` without retryStrategy.
- If Redis is unreachable, this hangs the Node process, violating the 3000ms SLA in AGENTS.md.
- Action Plan:
  1. Add `maxRetriesPerRequest: null` and explicit connectTimeout: 2000.
  2. Implement custom retryStrategy up to 3 attempts.
  3. Run `npm run test:redis` to verify behavior.

6.3 Identifying Typical AI "Death Loops" ​

Stay alert for these two classic self-spinning traps during daily development:

1. The Dependency Loop ​

  • Symptom: The AI attempts to install an unvetted library. When installation fails, it tries three different versions or switches to another even more obscure library.
  • Signal: Repeated occurrences of npm install --legacy-peer-deps more than twice in the terminal.

2. The Regression Loop (Whack-a-Mole) ​

  • Symptom: Editing file A breaks test B; it modifies test B, triggering errors in module C; it edits C, which breaks file A again.
  • Signal: Test pass rates fluctuating between 80% and 90%, with repeated edits to the exact same set of files.

6.4 The Three-Step Intervention: Interrupt, Correct, and Take Over ​

Step 1: Decisive Interruption (Ctrl + C) ​

Press Ctrl + C to stop the current run immediately and avoid token waste.

Step 2: Point-to-Point Correction (Direct Dialogue) ​

Directly point out the blind spot:

text
You were trying to install axios-retry, but this project strictly forbids external HTTP retry libraries. Use native AbortController for timeout handling and replan.

Step 3: Human Takeover and Git Rollback ​

If the edit is wrong, inspect the diff and confirm there are no human changes to keep before restoring only the target file:

bash
git diff -- src/lib/redis.ts
git restore -- src/lib/redis.ts

Append a guardrail into AGENTS.md: "Strictly prohibit external retry libraries."


6.5 Companion Hands-on Sandbox: Codex Web Copilot (Chrome Extension) ​

To experience how to steer reasoning chains and enforce anti-loop guardrails during browser extension development, this repository provides a ready-to-run sandbox:

👉 Source Sandbox Directory: examples/ch06-chrome-extension

Core Highlights: ​

  1. Pure Native Manifest V3: Zero build bundling dependencies. Load unpacked in Chrome Developer Mode in under 1 minute;
  2. Strict CSP Guardrails: AGENTS.md forbids inline scripts and eval(), showing how AI agents write compliant code under strict browser sandboxes;
  3. Automated Guard Tests: Run npm test to automatically validate MV3 specs and script syntax.

🛡️ Troubleshooting & Pitfall Cheat Sheet ​

Common PitfallRoot CauseRapid Diagnosis & Fix Guide
AI stuck in an endless loop of self-editsPrompt lacks an explicit retry capHit Ctrl + C immediately, then instruct: "Retry threshold reached. Stop spinning and output your diagnostic findings."
Interrupting and re-prompting loses previous contextSession context was droppedUse codex resume to restore the original session thread and preserve reasoning context
AI broke multiple legacy core filesChanges were not isolatedInspect git status and git diff, preserve any human edits, then restore only confirmed unwanted changes; use a separate branch or worktree next time

🏠 Index | ⬅️ Prev (Ch.05) | ➡️ Next (Ch.07) | 🌐 中文版