> ## Content Index
> Fetch the complete content index at: https://www.gauravalbal.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# What a Complexity Check Should Change
- URL: https://www.gauravalbal.com/what-a-complexity-check-should-change/
- Published: 2026-11-25T22:17:31.000Z
- Updated: 2026-11-25T22:17:31.000Z
- Description: When a coding agent clears a warning, I want to know which part of the job became easier.
- Author: Gaurav Albal
- Tags: Agents

Suppose a coding agent hands back a patch on a background worker that sends customer reminders and records that they went out. Everything compiles, the test suite passes, and one function in the diff trips a static complexity warning.

There are two easy responses: require a lower score before review, or dismiss the warning as a proxy for function length. Try each on the reminder worker.

Tell the agent to get the score down before anyone reads the code, and it splits one long routine into `fetch_due_reminders()`, `deliver_notice()`, and `record_sent()`. Every function is now twenty lines long, the names read cleanly, and the check turns green. Meanwhile, if the worker crashes after `deliver_notice()` succeeds on the wire and before `record_sent()` commits to the database, the next poll still has to decide whether to send the same reminder twice.

Wave the warning off altogether, though, and you discard a possible lead for the reviewer deciding where in a twenty-file diff to ask about partial failure.

A static warning earns its keep when it changes what the reviewer asks the agent to show next.

We checked our code-quality rules against nearly 500 confirmed fixes across 14 internal repositories, later changes in five open-source projects, and a month of work spanning about 1,500 agent sessions. Those records pointed to different uses for the warnings: examining failure paths, coordinating changes, and inspecting work the final diff does not show. I don't see a reason to give all of them the same response.

## Where size stops explaining the warning

A complexity measure has to earn its keep against line count. A bigger function has more places for a bug, and a score that rises with size may be taking credit for that.

When we compared functions of broadly similar size, a simple size measure ranked bug-hit code about as well as a general complexity score. Both had modest separation. Size was doing a substantial part of the work.

One family of warnings around interactions with external state still contained roughly four times the bug-hit snapshots expected from that broad size comparison. That gives me a reason to prioritize the code it flags. It does not tell me what is wrong with a particular function.

Put two 120-line functions from the reminder service side by side. One maps user preferences and template variables onto a message payload; the other interleaves retry branches, provider rate-limit responses, clock checks, and database updates. Line count scores them the same. For the second, I would start by asking what state the row is left in when an outbound HTTP call times out after the provider already accepted the request.

## Adding a channel raises a coordination question

Now extend that reminder worker. Suppose product wants a second delivery option—SMS fallback when an email bounces, or webhook delivery for team workspaces.

Nothing inside any single function has to get terribly tangled for that feature to become expensive to maintain. What grows instead is the surface area between modules: delivery status enums get re-exported through shared types, retry schedules start branching on channel capabilities, and five callers now have to agree on which error codes count as retryable.

In the open-source projects, some module-level signals were associated with more frequent changes and work spreading across files. The comparison did not establish them as general defect predictors. Local control-flow measures also tracked change frequency, so these were overlapping signals with different uses.

Evaluating module-boundary warnings only as defect detectors would miss what interests me here. While the new delivery option is still cheap to reshape, I want to know which other files will have to move in lockstep when we add a third channel. Can those channel-specific rules have one clear home before every caller learns its own version?

## Clearing the score versus making the job easier

A per-function complexity cap gives an agent a concrete target. One way to satisfy it is to carve the offending function into smaller helpers until each fragment falls below the line. A score drop tells me that target was met; I still want to know what the extraction improved.

Sometimes extracting helpers improves the code even when total file complexity stays flat. Pulling row-claiming and lease expiration into a well-named helper with one clear postcondition means a caller reading `run_reminder_tick()` can stop holding lock-timeout math in working memory.

An unhelpful extraction cuts horizontally through shared state. Take a messy `process_due_reminder()` routine and chop it into `prepare_context()`, `attempt_delivery()`, `classify_response()`, and `persist_outcome()` in the same file, passing half-mutated retry counters, error flags, and channel config across all four parameter lists. Peak function complexity drops on the dashboard, total complexity across the file barely moves (or creeps upward), and the crash window between sending the message and recording the receipt sits untouched. Worse, a human reviewing the file now has to bounce across four function signatures just to trace one failed send.

File-level complexity totals can stay flat in both a clean extraction and an unhelpful chop-job. I compare the before-and-after diff directly: what responsibility now has one clear home, and what does the caller no longer need to remember?

## What the clean diff leaves out

The session logs contained repeated reads and edits, failed calls, and returns to files already touched. A final diff does not show that sequence.

Suppose an agent spends twenty minutes revisiting a short worker before landing a four-line change. I want to know where those minutes went. It might have been an unstated rule, a misleading test, an editing-tool problem, or ordinary iteration. If we uncovered a rule that only exists in the conversation, I want the next agent to find it in the code or its checks.

Our chosen local complexity flags covered only a minority of the bug-hit function snapshots. Even the broadest covered fewer than one in five. Many of the fixes involved recovery after partial failure, inconsistent assumptions where two parts of the codebase had drifted on the same rule or schema, shared state, or expectations about the environment.

Think back to the reminder worker one more time. Every function in the file can be twelve lines long and crystal clear while the scheduler stores timestamps assuming UTC and the delivery worker interprets them as local time. The reminder still goes out at the wrong time.

Changes to agreed verification rules need their own explanation. If a patch suppresses a check we rely on, it should follow the existing exception policy. Getting CI to pass after changing the rules does not settle whether the original problem was resolved.

## Route the review question

Each class of signal points to a specific piece of evidence to ask for before accepting the work:

__Review questions and evidence to request for each concern.__
| Concern flagged                  | Question it raises                                                         | What to ask the agent to show                                                                                                             |
| -------------------------------- | -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| Failure and recovery             | Question it raisesWhat can succeed before the next step fails?             | What to ask the agent to showWalk through interruption and retry; show what survives and what may safely be repeated.                     |
| Coordination                     | Question it raisesWhich callers, types, or schemas must stay synchronized? | What to ask the agent to showIdentify the coupled responsibilities and explain where the shared rule should live.                         |
| Refactor quality                 | Question it raisesWhat became easier to understand or change?              | What to ask the agent to showCompare the diff: name the responsibility each helper owns and what callers no longer have to track.         |
| Difficulty during the assignment | Question it raisesWhat stalled the work?                                   | What to ask the agent to showShow the relevant attempts, explain the obstacle, and identify any rule or working setup that should change. |
| Changes to agreed verification   | Question it raisesWhy did the patch change a check we rely on?             | What to ask the agent to showResolve the underlying problem or make the case for an exception under the existing policy.                  |

Then read the answer against the code. If the reminder worker is easier to extend because crash recovery has one obvious home and its callers have fewer ordering rules to keep straight, clearing the warning bought something real. If the agent just moved the same fragile assumptions into four tidy helper functions so a score would drop, I still have work to do.