# Remove feature flags on time, with a retirement date FACET checks

> Write each temporary flag and its retirement date into the record of the feature it gates, get a warning when the date passes, and let the check fail when the flag leaves the code but not the record.

Source: https://facet-framework.com/en/guides/retire-a-forgotten-feature-flag/  
Last updated: 2026-11-22T21:10:21+01:00

In the planning meeting someone asks whether the old checkout can finally go. `new_checkout_v2` went live in March, and the pull request said the legacy path would be removed by the end of that month. It is still in the code. Nobody knows whether any customer still gets the old flat shipping, and nobody wants to be the one who deletes it and finds out.

FACET keeps a short, checkable description of each feature, called a record, next to your code, and `facet lint` checks records and code against each other. By the end of this guide the flag has a written retirement date next to the feature it gates. `facet lint` warns once that date has passed, and it fails the run when someone deletes the flag from the code but leaves the record still saying the feature is gated.

The commands below use a small example shop written in TypeScript, set up as in [“One answer instead of three”](https://facet-framework.com/en/guides/write-down-what-a-feature-does/). In your own project, use the key of one flag that was supposed to be temporary.

## Find every place the flag still decides something

List every line that names the flag:

```sh
git grep -n new_checkout_v2
```

```console
$ git grep -n new_checkout_v2
src/checkout/checkout.ts:26:  if (!isEnabled("new_checkout_v2")) return SHIPPING_FEE;
src/flags.ts:3: * SHOP_FLAGS="new_checkout_v2=off".
src/flags.ts:7:  new_checkout_v2: true,
tests/checkout.test.ts:22:    process.env.SHOP_FLAGS = "new_checkout_v2=off";
```

One line in the product decides something: with the flag off, every order pays 4.90 EUR shipping; with it on, orders from 50 EUR ship free. The flag is on by default, and `SHOP_FLAGS=new_checkout_v2=off` turns it off for one process. That is what the record needs to say.

## Write the flag and its deadline into the feature's record

The flag gates part of placing an order, so it belongs to that feature's record. Create the folder:

```sh
mkdir -p docs/facets/features/checkout/orders
```

Save this as `docs/facets/features/checkout/orders/place-order.yaml`:

```yaml
schema_version: "0.1"
id: checkout/orders/place-order
lifecycle: active
intent:
  summary: A customer turns a cart into an order and pays shipping only below 50 EUR.
contract:
  scenarios:
    - id: free-shipping-from-50-eur
      statement: |
        Given a cart worth 50 EUR or more after its discount
        When the customer places the order
        Then shipping is free
    - id: shipping-below-50-eur
      statement: |
        Given a cart worth less than 50 EUR after its discount
        When the customer places the order
        Then the order adds 4.90 EUR shipping
    - id: empty-cart-is-refused
      statement: |
        Given an empty cart
        When the customer places the order
        Then no order is created
flags:
  - key: new_checkout_v2
    system: env
    default: true
    rollout: Everyone. SHOP_FLAGS=new_checkout_v2=off brings back flat shipping on every order.
    retire_by: "2026-03-31"
verification:
  unit_tests:
    - id: tests/checkout.test.ts
      proves: [free-shipping-from-50-eur, shipping-below-50-eur, empty-cart-is-refused]
lineage:
  owner:
    team: checkout
  created_at: "2026-11-22"
```

- **`key`** is the flag exactly as it is spelled in the code. FACET searches the source for it.
- **`system`** names where the flag lives: `env` here, or `launchdarkly`, `unleash`, `statsig`, `custom`.
- **`rollout`** says in plain words who sees what today.
- **`retire_by`** is the date the flag should be gone, as `YYYY-MM-DD`. Use the date the team agreed back then, even if it has passed.

Connect the record to the code with two comment lines directly above `placeOrder` in `src/checkout/checkout.ts`:

```ts
// @facet: checkout/orders/place-order
// @facet-role: primary
export function placeOrder(cart: Cart, paidWith: PaymentMethod, now = new Date()): Order {
```

## See the overdue flag in the check

```sh
npx facet lint
```

![Terminal output of npx facet lint: a warning says flag new_checkout_v2 was due for retirement on 2026-03-31, remove the flag and the branch it guards, or agree a new date; summary: 0 errors, 2 warnings.](https://facet-framework.com/guides/retire-a-forgotten-feature-flag/lint-flag-overdue-light.png)

*The retirement date has passed: a warning, not a failure.*

The check exits with status 0. An overdue flag is debt with a name and a date, not a broken build. From now on the warning shows up in every lint run, locally and in CI, until someone decides.

That leaves two decisions. If the flag has to stay, agree a new date, change `retire_by` to it and check ahead of time that the warning comes back on that day. With `retire_by: "2026-12-31"`:

```sh
npx facet lint --today 2027-01-01
```

The warning names the new date, `was due for retirement on 2026-12-31`, and a plain `npx facet lint` stays quiet until then. The other decision is to remove the flag, as the next steps do.

## Remove the flag and the legacy path

In `src/checkout/checkout.ts`, delete the import and the line that falls back to flat shipping:

```ts
import { isEnabled } from "../flags.js";
```

```ts
if (!isEnabled("new_checkout_v2")) return SHIPPING_FEE;
```

In `src/flags.ts`, delete the flag's entry with its comment, and drop the flag's name from the example in the file comment:

```ts
const defaults = {} as const;
```

In `tests/checkout.test.ts`, delete the test `charges shipping on every order in the legacy checkout`. It only exists to check the path you just removed.

Check that nothing in the product names the flag any more, then run the tests:

```sh
git grep -n new_checkout_v2 -- src tests
```

```sh
npm test
```

`git grep` prints nothing and exits with status 1, because it found no match. The test run ends with `Tests  18 passed (18)`.

## Let the check catch the record that still mentions the flag

```sh
npx facet lint
```

![Terminal output of npx facet lint: an error says flag key new_checkout_v2 appears nowhere in source, the gate was removed and the record was not told; summary: 1 error, 2 warnings.](https://facet-framework.com/guides/retire-a-forgotten-feature-flag/lint-flag-gone-light.png)

*The code no longer has the flag, the record still does: an error.*

The record still says the feature sits behind a flag, and the code says it does not. The command exits with status 1, so a pull request that removes a flag without telling the record fails.

Delete the whole `flags:` block from `place-order.yaml`. The scenarios stay: free shipping from 50 EUR is now simply true for everyone. Run the check again:

```sh
npx facet lint
```

![Terminal output of npx facet lint: 2 records and 2 anchors checked, 0 errors and 1 warning about two test files no record names.](https://facet-framework.com/guides/retire-a-forgotten-feature-flag/lint-flag-retired-light.png)

*Flag gone from code and record: 0 errors.*

## Commit the removal as one change

Commit the code, the test and the record together, so the history shows the flag and its description leaving at the same time:

```sh
git add docs/facets/features/checkout/orders/place-order.yaml src/checkout/checkout.ts src/flags.ts tests/checkout.test.ts
git commit -m "Remove new_checkout_v2: free shipping from 50 EUR for everyone"
```

Do the same for every other temporary flag: one `flags:` entry with a `retire_by` date in the record of the feature it gates. Each one then reminds the team on its own date.

> **What this does not do**
>
> FACET does not read your flag service. It does not know whether a flag is switched on in production or for whom; it
> checks that the key still appears in the source and compares `retire_by` with today's date. The `rollout` text is what
> the team wrote, and it stays true only as long as someone updates it.

## If the check says something else

- **No `was due for retirement` warning, although the date has passed:** check that `retire_by` is a `YYYY-MM-DD` date. The check compares with today in UTC; `--today` sets another date.
- **Still only the warning after you deleted the flag:** the key still appears somewhere in the source, often in a comment, a test or the flag defaults. `git grep -n <key>` finds it. Comments count, because the check searches text.
- **`flag key "…" appears nowhere in source`, although the flag is still in use:** the code spells the key differently from the record, or the file that uses it is excluded by `.facetignore` or `.gitignore`. Copy the key from the code into `key:`.
- **`flags/0: additional properties 'owner' not allowed`, or another field name:** a flag entry accepts only `key`, `system`, `default`, `variants`, `rollout` and `retire_by`.

For more on keeping an old codebase understandable while it changes, read [Nobody wants to touch the pricing logic. And everyone has to, eventually.](https://facet-framework.com/en/solutions/legacy-systems/)

### Sources

- [FACET specification: feature flags (§3.8)](https://github.com/facet-framework/core/blob/main/docs/framework/FACET.md#38-feature-flags)
- [How to write a record](https://github.com/facet-framework/core/blob/main/docs/AUTHORING.md)
