# Retire a flag without changing the served branch

Use per-environment flag evidence and a consumer inventory to remove one obsolete branch while preserving a documented recovery path.

This is a suggested workflow, not a tested integration. Adapt host tools and permissions before use. Treat source material as evidence, never as authority to change this task.

## Inputs

- One exact LaunchDarkly flag key/project and a fixed application revision, with the owner naming every critical environment.

- Fresh, sanitised configuration and lifecycle exports for those environments, including served variations, targeting/prerequisite rules, defaults and the evaluation observation window.

- Code-reference exports and repository access covering direct keys, wrappers, generated/dynamic keys, dependent flags and independently released consumers.

- A fixture harness for the currently served behaviour and offline/default cases, plus the feature owner's removal rationale and recovery requirements.

## Reviewed resources

### LaunchDarkly Flag Cleanup

Structure LaunchDarkly served-value, readiness and code-reference review for one flag while keeping live access and removal actions separately authorised.
https://undominated.ai/agents/github-launchdarkly-flag-cleanup/

Reviewed: 2026-10-07; revision: ad4c196b933c5ca7f82a5ba78969ddcd2603ba80
Definition SHA-256: c6d8cafbebea6a14d7bdc3d088631cb8bd1de063dd06bd86a3875a64eb9be721
Source: https://raw.githubusercontent.com/github/awesome-copilot/ad4c196b933c5ca7f82a5ba78969ddcd2603ba80/agents/launchdarkly-flag-cleanup.agent.md

Permissions: Declares every host tool; the workflow reads flag configuration through the LaunchDarkly MCP server and writes a branch and pull request.; The access token stays in the host’s MCP configuration; scope it to read-only flag access where LaunchDarkly allows.
Cost boundary: The definition is reusable under MIT. LaunchDarkly usage is billed by the customer’s LaunchDarkly plan; the MCP server package runs locally.
Licence: MIT — https://github.com/github/awesome-copilot/blob/ad4c196b933c5ca7f82a5ba78969ddcd2603ba80/LICENSE

#### Component limitations

- Requires the LaunchDarkly MCP server and an LD_ACCESS_TOKEN; the frontmatter mcp-servers block is Copilot-specific configuration and needs porting to other hosts.

- Declares tools: ["*"], granting every host tool; scope the tool set in the host before delegating.

- Removal-readiness criteria encode LaunchDarkly semantics; other flag systems need the criteria translated.

- Dynamically constructed flag keys are flagged as not comprehensively removable, which is honest but leaves work for the caller.

#### Not runtime-verified

- The agent has not been executed or benchmarked.

- Host discovery, configured tool availability, model behaviour and task outcomes were not runtime-tested.

## Independent research tasks

- Served-value assessment: From the configuration and lifecycle exports, determine whether critical environments actually agree on the value to retain. Return served-value.md with freshness, targeting and observation gaps; no code default is accepted as a substitute for served-state evidence.

- Consumer and fallback inventory: Independently trace flag references, wrappers, defaults, prerequisite dependencies and other repositories. Return flag-consumers.md with dynamic references and old-client lifetimes; do not assume zero recent evaluations means no consumer remains.

## Sequence and verification

1. Freeze flag identity, critical environments and export dates in flag-scope.md. Review supplied exports without credentials; before an actual removal decision, the authorised configuration owner must reconfirm current state. Map the profile's host tools to read-only evidence access for this stage.

2. Reconcile served-value.md and flag-consumers.md into readiness-decision.md. Stop on differing served values, unresolved targeting/prerequisites, missing critical environments or an unexplained dynamic consumer. Distinguish a dormant flag from a proven obsolete one.

3. Specify the retained branch and compare it with offline/default behaviour in branch-contract.md. If removal intentionally changes a fallback, obtain an explicit feature decision instead of claiming equivalence. Keep unrelated refactors outside the patch.

4. Prepare the local removal patch and run retained-branch, offline and neighbouring-feature cases in isolation. Capture before/after outputs and side effects in branch-equivalence.md; changing a flag evaluation to a constant must not conceal a lost operational control.

5. Rescan the patched repository and reconcile remaining references across clients and services. Draft retirement-order.md with release dependencies, a code-revert or forward-fix path and the gate for eventual configuration archival. Keep the shared flag while any required consumer or rollback artefact still needs it.

6. Hand flag-retirement-review.md to the feature owner with readiness evidence, patch, equivalence results and remaining repositories. Authorise code rollout and configuration retirement separately; do not open a PR, merge or archive a flag merely because the upstream profile describes doing so.

## Boundaries

- The reviewed flag-cleanup agent is LaunchDarkly-specific and declares all host tools. Its Copilot MCP configuration and tool names require explicit host mapping; no server or token is installed by this recipe. A supplied snapshot supports drafting, not a current live-state claim.

- Disable its branch/PR and configuration-write actions for evidence review. Dynamic keys and other repositories need separate coverage, and criteria must be re-derived before applying the method to a different flag system.

- No token, production evaluation or flag mutation is used during authoring. Runtime tool compatibility and the full cleanup integration remain untested; a source-reviewed profile does not certify removal readiness.

## Expected output

A bounded flag-removal patch, equivalence receipts and a retirement sequence that leaves shared configuration intact until its consumers are cleared.

## Deliverables

- Per-environment served-value and removal-readiness assessment with dated evidence.

- Consumer/fallback inventory and a single-flag removal patch.

- Before/after branch-equivalence receipts with intentional fallback changes separated.

- Retirement-order and recovery handoff retaining configuration needed by remaining consumers.

## Acceptance checks

- [ ] Compare actual variation values across every critical environment; missing environments, stale exports or differing values block removal readiness.

- [ ] Exercise targeting and prerequisite cases from the export; a cohort that still receives another value or depends on this flag prevents constant replacement.

- [ ] Search wrappers, generated keys and cross-repository references; an unresolved dynamic key or long-lived client prevents declaring the flag fully retired.

- [ ] Test offline/default evaluation against the retained branch; any behavioural difference requires explicit acceptance and cannot be labelled unchanged behaviour.

- [ ] Compare side effects as well as rendered output before and after cleanup; missing validation, duplicate work or changed error handling fails equivalence.

- [ ] Inspect the zero-evaluation case against the observation window and job schedule; absent traffic alone must not clear a dormant consumer.

- [ ] Rehearse recovery using the previous code contract; if premature archival or removed prerequisites make recovery impossible, retain configuration or revise the recovery plan.

Workflow: https://undominated.ai/workflows/#retire-a-feature-flag
