5 min read
Resolving live API drift
Drift means the deployed API no longer matches the declared spec. StateAnchor detects this in two ways: spec drift (the YAML file changed since the last sync) and runtime drift (the live API scanner observed behavior that differs from the canonical IR). This guide covers what to do when drift is detected.
What drift detection means
The scanner fetches the OpenAPI document from your running service and compares it against the IR built from stateanchor.yaml. When it finds a difference -- a field missing from a response, a type that changed, an endpoint that behaves differently -- it flags the project as drifted.
Drift is not an error. It is an operational signal. It means the spec and reality are out of sync, and someone needs to decide which one is correct.
How to find drift in the dashboard
- Project list: The dashboard shows a yellow "Drift detected" indicator next to any project where the current file SHA differs from the last synced SHA.
- Project detail: Click into the project. The status strip at the top shows the drift state. If drifted, you will see which fields or endpoints diverged in the latest sync run detail.
- Sync run detail: Click a sync run in the history section. The gate findings show exactly which operations were detected -- endpoint added, field removed, type changed, etc.
Resolution path A: Update the spec
When to use: The API changed intentionally. A developer shipped a new field, deprecated an endpoint, or modified a response shape -- and the spec was not updated. The deployed API is correct; the spec is stale.
- Edit
stateanchor.yamlin your repo to match the current API behavior. - Commit and push. StateAnchor will run a new sync.
- The gate evaluates the diff. If the changes are additive (INFO lane), the sync proceeds and artifacts regenerate.
- The project returns to "In sync" once the sync completes.
This is the most common resolution. Most drift comes from spec staleness, not from deployment errors.
Resolution path B: Fix the deployed API
When to use: The API drifted unintentionally. A hotfix changed a response shape, a migration altered a column type, or a feature flag modified behavior in production. The spec is correct; the deployed API needs to be reverted or fixed.
- Identify the root cause from the drift findings (which field, which endpoint).
- Deploy a fix to the API that restores the expected behavior.
- Run a manual sync or wait for the next push. The scanner will confirm the API matches the spec again.
Resolution path C: Temporary exception
When to use: The team needs time to align. The drift is known, the fix is in progress, but you do not want the gate to block other changes in the meantime.
- In project settings, create a drift exception for the specific endpoint and change kind.
- Provide a named approver and set an expiration (maximum 90 days).
- The excepted finding is suppressed from gate evaluation until the exception expires.
- When the underlying issue is fixed, the exception can be deleted early or left to expire.
Exceptions are scoped. They suppress one specific finding, not the entire gate. If a new breaking change is pushed alongside an excepted one, the gate still blocks.
How to verify drift is resolved
After applying your fix (spec update, API fix, or exception), trigger a new sync -- either by pushing a commit or clicking the Sync button on the project detail page. When the sync completes:
- The project status changes from "Drift detected" to "In sync".
- The latest sync run shows gate action: proceed.
- The drift indicator on the dashboard disappears.
Common causes of drift
| Cause | What happens | Typical fix |
|---|---|---|
| Hotfix deployed without spec update | Production API has a field or endpoint the spec does not declare | Update the spec (path A) |
| Database migration changed a column type | Response field type differs from spec (e.g., integer became string) | Fix the API or update the spec |
| Feature flag affecting response shape | Some users see a different response than the spec declares | Ensure the default response matches the spec |
| Environment differences (staging vs production) | Scanner runs against one environment but spec was synced from another | Ensure server.base_url points to the environment you want to monitor |
| Third-party API dependency changed upstream | Your API proxies or transforms an upstream response that changed | Update your API to handle the upstream change, then update spec if needed |