## TL;DR

The wrong key is rotated and production may be breaking. Stabilize first: restore production to a working credential, then fix the process so environment confusion cannot recur.

## Error

```text
agent rotated the production key instead of the staging one: deploy error
```

## Steps

1. Assess production impact now: which services use the rotated key and are they failing. Expected: the blast radius known.
2. Restore a working production credential immediately (revert the rotation or issue a fresh key and deploy it). Expected: production stable.
3. Rotate the intended staging key correctly. Expected: the original goal achieved.
4. Find how the confusion happened: shared names, missing labels, or a skipped check. Expected: the root cause.
5. Add the environment assertion gate so it cannot recur. Expected: structural fix.

## When to use

- Production keys rotated by mistake.
- Incident response for wrong-environment actions.

## When not to use

- Planned production rotations.
- Staging-only mistakes (lower urgency, same fix).

## Tool compatibility

- Incident response; environment gates.

## Variant phrasings

### rotated prod instead of staging

Stabilize, then fix.

### wrong environment rotation

Same containment.

## Why it happens

Without environment checks, a staging task and a production credential look identical to the agent.

## Edge cases

- Production may need the old key restored, not a new one, to match deployed config; check first.
- Communicate the incident; silent fixes hide systemic risk.
- The gate must be tested against adversarial confusion, not just the happy path.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_I0dUx3EDKwXqziISqpOPqg
