# `fix`

`fix` is the dual of [`upgrade`](https://romnn.github.io/cooldown/docs/commands/upgrade/): it **downgrades** each violating dependency to the newest version that has *already* matured past its cooldown, so [`check`](https://romnn.github.io/cooldown/docs/commands/check/) passes while the protection holds. It never moves a dependency forward, and it only touches dependencies that are actually in violation.

```sh
cooldown fix
```

When nothing is too fresh, `fix` is a no-op:

```text
Nothing to fix.

0 applied · 0 skipped · 0 errors · lock re-verified
```

When there are violations, each is rolled back to a matured version:

```text
 Package   From      To        Status        Reason
───────────────────────────────────────────────────
 left-pad  3.1.0     3.0.9     downgraded
```

A row that landed cleanly has an empty **Reason**: the status says it all. The summary line ends with what the run did to the lock, such as `lock re-verified`, or `dry-run (lock untouched)` under `--dry-run`.

## Rolling back a security bump

With the [advisory feed](https://romnn.github.io/cooldown/docs/configuration/advisories/) enabled, a pin that is itself an advisory's fix version resolves against the shorter security window — so most security bumps never reach `fix` at all. One that is younger than even *that* window still fails `check`, and `fix` still rolls it back to the newest matured version, which the same advisory may mark affected.

The verdict is deliberately unchanged: `fix` exists to make `check` pass, and `cooldown` is not a vulnerability gate. What the feed adds is that the trade is stated rather than made silently:

```text
warning [advisory_rollback] left-pad left-pad@3.1.0 is younger than its cooldown; rolling it back
to 3.0.9 re-enters GHSA-wcg3-cvx6-7396; the fix is no longer locked (pin or `baseline` it to keep it)
```

The warning describes a rollback that actually happened: it is attached to the batch that landed the downgrade, so a batch the apply rejects or the post-apply gate rolls back takes the warning down with it.

Whether the fix is gone is decided once the run is over, from the lock it leaves. One fixed version gets one warning naming every rollback off it, and none when the final lock still holds the fix through:

- **A later step or rerun** that locks the fixed version again.
- **Another copy** of the package that still binds it.

Where cooldown cannot read the final lock, the warning says it could not confirm whether that lock still holds the fixed version. That happens with:

- **A lock a build rewrote** after cooldown last checked it.
- **A lock whose versions cooldown cannot read yet.**

Under `--dry-run` and in `outdated` the warning speaks in the conditional (`would roll it back to 3.0.9, re-entering …`), like the rest of a dry run's report.

[`baseline`](https://romnn.github.io/cooldown/docs/commands/other/) is the way to keep the fix and still pass the gate: it acknowledges the young pin instead of undoing it.

## The whole-graph default

By default `fix` works on the **whole resolved graph** — the same surface `check` gates. A too-fresh **transitive** dependency is rolled back to the newest matured version the graph still allows, not just direct dependencies.

This is safe by construction: the graph floor *is* a version every requirer already accepts, and a mature direct dependency was built against versions from before the window anyway — so a fresh transitive it didn't ask for is the riskier state, not the rollback.

`--transitive` relaxes this, mirroring `check`:

- **`--transitive hide`** — direct-only: ignore transitive dependencies entirely.
- **`--transitive allow`** — report too-fresh transitives but leave them in place; still fix direct dependencies.

## What `fix` won't silently do

`fix` is conservative — it reports, rather than forces, the cases where a downgrade would be wrong or impossible:

- **A graph-pinned transitive.** If no lower version satisfies the dependency's requirers, it can't be rolled back on its own. `fix` reports it so you can address the dependency that forces the fresh pin, instead of breaking resolution.
- **An exact pin.** A pinned violation is left in place with a warning, since a pin is a deliberate choice. Pass `--downgrade-pinned` to downgrade and rewrite it too. On the npm family this includes a pin in one install field beside a range in another (`"devDependencies": { "chalk": "4.1.2" }` beside `"dependencies": { "chalk": "^4.1.0" }`): the downgrade is held as `pin_held`, with a row naming the pin and `--downgrade-pinned`, and fails `fix --strict`. On pnpm a pin beside another workspace member's range stays held even under `--downgrade-pinned`; edit the pin to move it.
- **No matured fallback.** A violation with no older matured version to fall back to is reported — [`baseline`](https://romnn.github.io/cooldown/docs/commands/other/) it or wait — rather than downgraded to nothing.

## Locks the run stales itself

A `fix` that rewrites a manifest another project in the run resolves against (a root workspace's
`[workspace.dependencies]` read by a cargo-fuzz crate) stales that project's lock. As under
[`upgrade`](https://romnn.github.io/cooldown/docs/commands/upgrade/#projects-that-resolve-against-each-other), the run refreshes
such a lock instead of failing on it, reports a `stale_lock` warning naming the cause, and fixes
the refreshed graph like any other; a lock that was stale before the run began keeps the ordinary
`stale_lock` error.

## Flags

| Flag | Effect |
|---|---|
| `--transitive <mode>` | `allow` or `hide` — how to treat too-fresh transitive dependencies (see above). |
| `--downgrade-pinned` | Downgrade and rewrite exact-pinned dependencies too (off by default). |
| `--cargo-edge-policy <policy>` | cargo: `preserve` (default), `canonicalize`, or `none` — how lock edge bindings are treated after the re-resolve (see [upgrade](https://romnn.github.io/cooldown/docs/commands/upgrade/#lock-edge-bindings-cargo)). Config: `[tool.cargo] edge-policy`. |
| `--strict` | Exit `1` if the fix cannot complete cleanly. |
| `--fail-on-new-duplicate` | Cargo and pnpm: refuse a resolve that gives *any* package a second resolved copy instead of committing it with a `duplicate_copy` warning (see [upgrade](https://romnn.github.io/cooldown/docs/commands/upgrade/#whole-workspace-landings-pnpm)). On a tool without Cargo or pnpm's settlement guard the flag has no effect and the run says so. |
| `-n, --dry-run` | Resolve and print the plan; never mutate (env `COOLDOWN_DRY_RUN`). |

## `fix` versus `baseline`

Both clear a red `check`, but they mean different things:

- **`fix`** removes the risk — you end up on an older, matured version.
- [**`baseline`**](https://romnn.github.io/cooldown/docs/commands/other/) accepts the risk — you stay on the fresh version but record it as acknowledged, so `check` adopts it cleanly. Reach for `baseline` when you have a reason to trust the specific release and can't (or won't) roll back.
