AI / ML

Uber Uses AI Agents to Remove 16,000 Stale Feature Flags and Clean 1 Million Lines of Code

Uber's AutoClean pairs AI agents with deterministic code tools, CI repair, and CodeCourt checks to clear stale feature flags before humans review the change.

Uber AutoClean AI agents removing stale feature flags from large codebases
Uber AutoClean turns stale feature-flag cleanup into a continuous, review-ready workflow.

Uber says its internal system AutoClean uses AI agents to delete stale production code left behind by finished feature rollouts. According to Uber, the system has cleaned more than 16,000 feature flags and more than 1,000,000 lines of code. Those figures come from Uber's own announcement, not from an independent audit.

AutoClean is not described as a public product for every developer. It is Uber's engineering workflow for continuous technical-debt cleanup across monorepos, with automated checks preparing a diff and a human engineer making the final call.

Why stale feature flags become technical debt

A feature flag is usually a dynamic true/false switch in code. Teams use flags to roll out a change gradually, run experiments, and roll back quickly if something breaks. Uber says flags power experiences across mobile apps and backend services.

After a flag is fully rolled out and always true (or always false), the temporary scaffolding often stays: old if branches, helper parameters, config fields, and tests for both paths. That leftover code is hard to read and test. Uber also notes that AI coding agents waste time parsing dead paths, which can make agent sessions longer and more expensive.

Cleanup often loses to new product work. At Uber's scale, many teams create flags continuously, so small delays become a large backlog. AutoClean is Uber's answer: make cleanup a scalable automated workflow with safety checks, validation, and review points.

Why removing one flag is harder than search and delete

Finding a flag name and deleting the call looks easy. Real cleanup is a chain of decisions. Uber's illustrative order-pipeline example shows why.

Imagine a flag such as new_order_pipeline. Config reads the flag into a boolean field. That field is passed into a function parameter. Inside the function, one branch runs the new pipeline and another keeps the legacy path.

If the flag is permanently true, inlining true is only the first step:

  • The function parameter may be removable, but only after checking every call site.
  • The legacy branch can become unreachable and deletable.
  • The config field may be removable only if nothing else depends on that struct shape.
  • Some tests can be deleted; others must be rewritten for the new default behavior.

Static tools are strong at deterministic rewrites. AI is most useful for propagation judgment: who calls this function, what tests still matter, and whether simplifying a signature is safe.

Inside Uber's AutoClean architecture

AutoClean connects to Uber's feature-flag system of record, detects stale flags, and produces clean, tested diffs for human review. Uber says it runs continuously across monorepos and covers the cleanup lifecycle end to end:

  1. Identify Find flags that appear safe to remove.
  2. Rewrite Update code with agents and deterministic tools.
  3. Fix CI Repair build and test failures caused by the rewrite.
  4. Validate Run static checks and CodeCourt before review.
  5. Route Send the diff to the owning team and keep it fresh until a human decides.

How AI agents work with PolyglotPiranha

The cleanup agent can search and edit the codebase. It also has a boolean-algebra and conditional-simplification tool built on PolyglotPiranha, Uber's lightweight transformation engine for feature-flag related refactors. Uber publishes related work in the open-source Piranha repository.

This split is deliberate. AutoClean is agentic, but the agent should not perform every transformation. A small mistake while simplifying a condition can change which branch runs in production. Boolean algebra is a good fit for deterministic tooling, so the agent calls PolyglotPiranha through MCP (Model Context Protocol) instead of inventing those rewrites alone.

In Uber's example flow, the agent typically:

  1. Finds the flag lookup and replaces it with the rolled-out constant.
  2. Asks PolyglotPiranha to simplify resulting expressions and conditionals.
  3. Traces the constant into callees, removes always-true parameters, and deletes dead branches.
  4. Repeats until no further cleanup remains for that flag.

MCP's role is the connector: it lets the AI agent use PolyglotPiranha as a specialized tool with a clear job, similar to how MCP connects AI apps to external systems and tools in general.

How AutoClean repairs CI failures

After the rewrite, AutoClean opens a diff and lets continuous integration run. Agents can execute nearby tests locally, but one flag cleanup can fan out across a monorepo. Repository-wide CI is the source of truth for whether the change still builds everywhere.

If CI fails, AutoClean reads each failure and routes it to a fixer:

  • Deterministic fixers run first for mechanical issues, such as removing a now-unused default or clearing a lint error.
  • Agentic fixers handle harder cases, such as deciding whether a test should be deleted or rewritten.
  • After each fix, CI runs again. The loop continues until the diff is green or attempts run out.

Editing scope is tightly restricted. A test fixer can edit only test files. Without that limit, an agent might make a failing test pass by changing production code underneath it—the opposite of what cleanup should do. Green CI is necessary, but Uber is clear that CI alone does not prove the cleanup is correct.

CodeCourt: extra AI verification before humans

After CI is green, AutoClean still runs validation. First come deterministic static checks for mechanical leftovers, such as a trivial function that always returns true or a conditional that should already be simplified.

Then comes CodeCourt, Uber's agentic validation layer. CodeCourt turns observed failure modes into explicit properties. Each property has its own reviewer agent. Reviewers run in parallel. Every property must pass, or the diff is abandoned before a human sees it.

The four CodeCourt properties

  • No additions: cleanup should remove or simplify code, not introduce new functionality.
  • Preserves semantics: observable application behavior should stay the same.
  • No intent drift: work must stay focused on the requested stale flag, not quietly remove related flags.
  • No agent artifacts: temporary reasoning comments and other agent leftovers must not remain.

Uber says a single end-to-end reviewer was weaker than focused sub-agents. Separating constraints from the long cleanup loop helps because one editing agent may optimize for the loudest signal, such as passing CI, while missing a quieter cleanup rule.

Why human review still matters

AutoClean prepares review-ready diffs. It does not replace the engineer. After automated gates pass, the owning team decides whether the flag is truly ready to remove. Reviewers can focus on business judgment instead of hunting for every mechanical mistake.

That design is important for anyone studying AI software engineering: AI agents, deterministic tools, CI, and validators work together, and a human still owns the production decision.

What It Means for Developers

Most readers will not install AutoClean tomorrow. The useful lesson is the architecture pattern for large-scale maintenance.

Technical debt and monorepos

Feature flags are a delivery tool, not free forever. When flags pile up, both people and AI assistants pay a reading tax. Continuous cleanup keeps Node.js, Python, Java, and mobile services easier to change.

AI agents plus deterministic tools

Let agents search and decide where to look. Let deterministic engines rewrite high-risk logic such as boolean simplification. MCP-style tool boundaries make that partnership explicit.

CI, tests, and review reliability

Automated testing remains essential, but passing tests are not the whole story. Scoped fixers prevent “cheat” edits. Independent validators catch incomplete cleanups and deleted coverage. Human review still answers whether the change should ship. Concepts like default parameters and classes show how small API surfaces can hide flag plumbing that cleanup must untangle carefully.

Bottom line

Uber's AutoClean story is about deleting code safely at scale. AI agents find and propagate stale flag values. PolyglotPiranha handles sensitive rewrites. CI repair and CodeCourt reduce bad diffs. Humans still approve the final change.

Uber reports more than 16,000 flags and more than 1,000,000 lines cleaned. As new flags keep arriving, AutoClean is meant to keep cleanup moving so stale debt does not quietly grow across the codebase.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author