## TL;DR

The sweep tried to stop or modify an RDS instance that was already stopping, and RDS rejects actions on instances in transitional states. Filter the sweep to instances in the available state before acting, and re-check state immediately before the action call. Transitional states are temporary; the sweep should wait them out, not fight them.

## Error

```text
agent's idle-rds sweep failed with "InvalidDBInstanceState" on a stopping instance
```

## Steps

1. Confirm the failure: the log shows InvalidDBInstanceState on an instance whose status was stopping or starting. Expected: the transitional state is visible.
2. Add a state filter to the sweep: only target instances with DBInstanceStatus of available. Expected: transitional instances are excluded from the action list.
3. Add a just-in-time state check right before the stop or modify call. Expected: instances that transitioned since the scan are skipped.
4. Log skipped transitional instances and retry them on the next sweep cycle. Expected: they are handled when they settle.
5. Re-run the sweep. Expected: no InvalidDBInstanceState errors; available idle instances are actioned.

## When to use

- An RDS sweep fails with InvalidDBInstanceState.
- Instances are mid-transition when the sweep runs.
- The sweep acts on stale inventory.

## When not to use

- The error is a permission denial.
- The instance is in a failed state needing manual recovery.
- The sweep should never touch the instance at all.

## Tool compatibility

AWS RDS (current 2026 releases). Applies to cost agents managing RDS instances.

### Variant phrasings

### "instance is not in available state" during a sweep

Same transitional-state rejection. Filter to available.

### sweep crashed on a stopping database

Skip transitional instances and retry next cycle.

### rds stop failed mid-transition

Re-check state just before acting.

## Why it happens

RDS is a state machine: stop, start, modify, and delete are only valid from certain states, and transitions take minutes. A sweep that scans and then acts minutes later operates on stale state, so some targets have moved. Filtering to available plus a just-in-time check closes the staleness window to seconds, which is enough for a sweep cadence.

## Provenance

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