Sub topic 2
Why Prompts Alone Drift
This chapter assumes you have basic software development experience, use Git, have prompted an AI coding assistant before, and know what an automated test is. It explains why open-ended prompts give inconsistent results. The next chapters cover the fix.
What drift looks like
Drift is the gap between what you meant and what the agent builds. It grows over repeated prompts. You ask for a feature, get something close, correct it, and get something close again. After several rounds, the code matches the latest message more than your original intent.
Drift shows up in three ways:
- Between runs. The same prompt produces different behavior on different days.
- Within a session. A decision made early gets forgotten or contradicted later.
- Between sessions. A new session starts with none of the earlier decisions.
Why it happens
A coding agent builds its answer from the text in its context: your prompt, the files it reads, and the conversation so far. Several properties of that setup cause drift.
- Gaps get filled with guesses. A prompt like "add password reset by email" leaves out the token lifetime, the response for unknown emails, and whether a link can be reused. The agent must pick values, and different runs pick different ones.
- Output is not deterministic. Models sample their output, so two runs of one prompt can make different choices even when the prompt is complete.
- Context is limited and gets compressed. Long sessions are truncated or summarized. A constraint stated 40 messages ago may no longer be in view.
- Nothing records the decisions. Chat history is not a durable, reviewable artifact. It is not versioned with the code, and a teammate cannot easily read it.
- Nothing checks the result. Without a stated definition of done, the agent decides when it is finished. You find the mismatch by reading the code.
A worked example
Suppose you give two runs the same prompt: "Add password reset by email." Both runs produce working code, but they make different choices.
| Decision | Run A | Run B |
|---|---|---|
| Link lifetime | 24 hours | 30 minutes |
| Unknown email | Returns "no such account" | Returns the same response as for known emails |
| Reused link | Still works until it expires | Rejected after first use |
Neither run is wrong given the prompt. Run A leaks which emails are registered, which is a security problem you may not notice in review. The prompt never ruled it out.
The diagram shows how one vague prompt leads to different outputs.
Why correcting in chat does not fix it
The usual response to drift is another prompt: "make the link expire in 30 minutes." This fixes one detail. It does not record the detail anywhere durable, and it does not check the other details. Each correction costs a review pass. The decision exists only in the conversation, so the next session can undo it.
What a spec changes
A specification is a written, versioned description of what to build and how to tell it is done. It addresses each cause above:
| Cause of drift | What a spec provides |
|---|---|
| Guessed gaps | Explicit requirements for the values and behaviors that matter |
| Non-determinism | A fixed target, so varying output can be checked against the same criteria |
| Lost context | Files the agent can re-read in any session |
| No record of decisions | Documents in Git, reviewed like code |
| No check on the result | Acceptance criteria that can become tests |
A spec does not make the agent deterministic. It makes variation visible and cheap to catch. If two runs differ, you compare both against the criteria instead of against your memory of what you meant.
The remaining chapters build this up in order: the workflow, then requirements, design, tasks, and tests that verify the result.
Exercise
A teammate says, "Our agent's code for the same feature differs every run, so we should write a longer, more detailed prompt." Give two reasons a longer prompt alone does not solve the problem, and name one thing a spec adds.
Show answer
First, the agent's output is sampled, so even a complete prompt can produce different choices. Second, the prompt lives in a single conversation, so it can be truncated, forgotten in a new session, and not reviewed or versioned like code. A spec adds acceptance criteria stored in the repository, which give a fixed target that tests and reviewers can check any run against.