Facet
DeutschInstall
Legacy code

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

Write each temporary flag and its retirement date into the FACET recordA FACET record is a short, checkable description of one feature, kept as a YAML file next to the code. It states why the feature exists, the behaviour it promises as scenarios, and the tests that check it.In the glossary 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.

  • 8 min read
  • 7 steps
  • npmGit
  • Your coding agent

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”. In your own project, use the key of one flag that was supposed to be temporary.

Step 1Find 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.

Step 2Write 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-orderlifecycle: activeintent:  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 createdflags:  - 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: primaryexport function placeOrder(cart: Cart, paidWith: PaymentMethod, now = new Date()): Order {

Step 3See 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.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.
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 LintLint is FACET's check that records and code still point at each other: every record matches its schema, every anchor names an existing record, and every active record has an anchor. It runs locally and in CI on every pull request.In the glossary 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.

Step 4Remove 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).

Step 5Let 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.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.
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 ScenarioA scenario is one behaviour a feature promises, written in a record as Given/When/Then steps. Each scenario has an id that tests and other records can refer to.Read more here 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.Terminal output of npx facet lint: 2 records and 2 anchors checked, 0 errors and 1 warning about two test files no record names.
Flag gone from code and record: 0 errors.

Step 6Commit 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.

Step 7If 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.

Sources