Feature flags that overstay: what happens when a flag lives longer than it should
A feature flag is almost always born with a clear intent: turn something new on for a slice of users, confirm nothing breaks, then flip it on for everyone or off for good once the rollout is done. That healthy lifecycle has three phases: introducing the flag, the progressive rollout, and cleanup. The phase almost nobody plans with the same care as the other two is the third one.
The result, months later, is a codebase full of conditional branches nobody dares touch because nobody remembers for certain whether the flag is still live, and a test suite that stays green without testing the path that actually runs in production.
The temporary flag that became part of the domain language
The distinction that matters is not "flag" versus "no flag" — it is temporary flag versus permanent flag. A temporary flag exists to control a rollout: it has a birth date and it should have a death date. A permanent flag controls a real operational decision — a kill switch for a third-party provider, a flag that splits behavior by subscription plan — and it can live in the code indefinitely because it represents a legitimate business branch, not a transient deployment state.
The problem shows up when a temporary flag never gets reclassified. It gets introduced for a two-week rollout:
function calculateShipping(order) {
if (featureFlags.isEnabled('new-shipping-calc', order.userId)) {
return calculateShippingV2(order);
}
return calculateShippingV1(order);
}
The rollout finishes, the flag sits at 100%, nobody reports issues, and it just stays there. Six months later, a new developer on the team reads this function and has no way to know, just by looking at the code, whether calculateShippingV1 still runs for any real user or is a dead branch nobody dared delete. The only way to know for sure is to go to the flag system's dashboard and confirm the value is pinned at 100% across every segment — which means understanding the system's real behavior is no longer possible from the source code alone; it requires checking an external system whose configuration can change without leaving any trace in version control.
What degrades is not just readability
The most visible symptom of a temporary flag that overstays is the conditional nobody cleans up. The most expensive symptom, and the least visible one, is what happens to the tests.
When the flag is introduced, it is common to write tests for both paths:
describe('calculateShipping', () => {
it('uses V1 when the flag is off', () => {
featureFlags.mock('new-shipping-calc', false);
expect(calculateShipping(testOrder)).toEqual(expectedResultV1);
});
it('uses V2 when the flag is on', () => {
featureFlags.mock('new-shipping-calc', true);
expect(calculateShipping(testOrder)).toEqual(expectedResultV2);
});
});
Both tests are correct the day they are written. The problem is that they keep being correct — they keep passing — long after one of the two paths stops ever running in production. The suite reports coverage on calculateShippingV1, and that coverage is real in the sense that the test executes the function, but it is coverage that does not correspond to anything a real user will ever trigger. If someone, trusting that a green test means the path is still alive, decides calculateShippingV1 is safe to keep "just in case," that code keeps absorbing review time on every related change, without that time buying any real protection.
This gets worse when flags nest. A second flag gets introduced months later, also inside calculateShipping, also meant to be temporary:
function calculateShipping(order) {
if (featureFlags.isEnabled('new-shipping-calc', order.userId)) {
if (featureFlags.isEnabled('free-shipping-first-order', order.userId)) {
return calculateShippingV2WithPromo(order);
}
return calculateShippingV2(order);
}
return calculateShippingV1(order);
}
With two boolean flags there are four possible state combinations, and each one is, in theory, a distinct code path someone should have tested. In practice, almost nobody tests all four, because by the time the second flag gets added, the first one is already assumed "done" and stops being treated as a live variable of the system. The combination nobody tests — first flag off, second flag on — can be literally unreachable in production if the first flag is already at 100% for everyone, but the code still allows that combination, and nothing in the repository records that it is unreachable.
Cleanup is not the job of whoever wrote the flag
The pattern we keep seeing is that the person who introduces the flag is not the same person who decides when to retire it, and that is where ownership falls through the cracks. Whoever wrote the flag has already moved on to the next task by the time the rollout finishes; nobody explicitly inherited the job of coming back, confirming the 100% state is stable, and deleting the dead branch. The result is that cleanup competes for priority against new features, and it almost always loses, because deleting code that already works feels urgent to no one — until someone needs to modify that function and runs into three levels of nested conditionals they are not sure they can safely touch.
What worked for us was treating the flag's retirement date as part of the flag's definition, not as a separate task someone would remember later. When a temporary flag is created, it gets registered together with a target retirement date — not a "rollout complete" date, a "code deleted" date — and an owner explicitly assigned for that date, not just the person who created it by default.
featureFlags.register('new-shipping-calc', {
type: 'temporary',
targetRetirementDate: '2026-11-15',
retirementOwner: 'checkout-team',
});
That alone does not delete any code. What actually changed things was adding a CI check that fails — not silently, but with an explicit error in the pipeline — when a flag marked temporary passes its target date without having been retired. We do not block the deploy over this — an overdue flag is not a bug that should stop production — but we do make it visible somewhere it cannot be ignored, instead of leaving it as one more entry in a backlog nobody prioritizes.
What didn't work on the first try
The first thing we tried was simply putting an expiration date in a comment next to the flag in the code:
// TODO: delete this flag after 2026-10-01
if (featureFlags.isEnabled('new-shipping-calc', order.userId)) {
It didn't work, because a comment generates no active signal. Nobody searches for overdue TODO comments unless someone explicitly decides to run that search, and that search never turned into a team habit. The comment just sat there, correct and completely ignored, exactly like the flag it described. The real difference came when we moved that information out of a comment and into something an automated system could read and act on — the flag registry, checked by CI — instead of a place that depended on a human remembering it on their own.
What we check before introducing a new flag
Before adding a temporary flag, we first confirm it has a target retirement date and an assigned owner from the moment it is created, not afterward. We check that the tests for both paths carry a mark or comment that explicitly ties them to the flag, so we can find and delete them together when the time comes, instead of leaving orphaned tests that keep passing without protecting anything real. And when a second flag needs to nest inside a function that already has one, we stop and ask whether the first one should have already been retired, because a flag nested inside another flag is almost always the clearest sign that cleanup got postponed one time too many.