← Spec-driven workflows guides

How to recover from spec-code drift

How-To Spec-driven workflows Intermediate 1081004HOWTO-1081004

HOWTO-1081004Spec-driven workflowsIntermediate

This guide shows you how to recover when SpecDD specs and implementation have drifted apart in a spec-driven development workflow.

Drift means the repository has two competing stories: the .sdd spec says one thing, while code, tests, docs, or task status say another. The recovery goal is not to make the diff quiet. The goal is to decide what should be true and make the spec, code, checks, and tasks agree again.

Short answer

Pause new behavior, compare the effective spec chain with the current implementation, classify the disagreement, decide whether the spec or code is wrong, then update code, specs, tasks, and checks in the same reviewed change. Do not let an agent or contributor silently choose the new contract when the behavior is ambiguous.

When to use this guide

Use this guide when:

Steps

1. Stop adding new behavior

Do not build more on top of drift. First get the local contract back into a trustworthy state.

Use a narrow prompt if an agent is helping:

Compare the Itinerary behavior with its spec.

Then, after reviewing the comparison:

Draft a drift recovery plan for Itinerary.

Keep comparison, planning, and implementation as separate steps. If the contract is already unclear, combining those actions makes the disagreement harder to review.

2. Identify the drift type

Most drift falls into one of these groups:

Name the drift before fixing it. Different drift types need different corrections.

3. Compare the spec chain to the code

Do not compare only the nearest file. SpecDD uses inherited context.

For example, work on:

src/trips/itinerary.js

might inherit:

travel-planner.sdd
src/trips/trips.sdd
src/trips/itinerary.sdd

Check:

If a child spec appears to loosen a parent rule, treat that as a conflict. Parent constraints remain active unless the operator explicitly resolves the change safely.

4. Choose the intended contract

For each disagreement, decide which side should change:

Do not preserve accidental behavior just because it exists. Do not delete a spec rule just because the code violates it. The recovery decision should come from product, design, architecture, security, or ownership review as appropriate.

5. Update code or specs deliberately

If code is wrong, make the smallest implementation change that restores the spec contract.

If the spec is stale, update the durable sections:

Must:
  Reject itinerary items without a place name.

Done when:
  Missing-place validation is covered by a check.

Scenario: missing place name
  Given the place name is empty
  When the person adds the itinerary item
  Then validation fails

If the issue is authority drift, move the change back inside the authorized boundary or create a reviewed spec change that grants the needed authority.

6. Add checks for the recovered behavior

Drift often returns when the recovered behavior is not checked. Add or update tests, validation, linting, documentation checks, or review gates that prove the selected contract.

Checks should cover:

7. Prevent the drift from returning

After recovery, improve the local workflow:

Drift prevention is usually a small spec improvement, not a large process change.

Example

Drift:

Must not:
  Change destination search behavior.

Tasks:
  [x] Add missing-place validation.

But the implementation changed:

src/destinations/destination-search.js

Recovery:

Common mistakes

How to verify the result

Drift has been recovered when:

← Spec-driven workflows guides