Comments are a maintained artifact, not a one-time deposit
A slimming pass cut 5,880 comment lines to 3,820 across fourteen spec files, and a grep filter proved that no non-comment line changed. The same pass corrected five comments that were wrong about their code and added a ratchet guard that stops comment density growing back.
A QA automation engineer's notes on cutting 5,880 comment lines to 3,820, proving the diff touched nothing but prose, and ratcheting it so it cannot grow back.
Somebody writes a comment once, when they understand the code best, and almost nobody touches it again. The code around it keeps moving: refactors, renames, a fix that narrows a condition. No type checker re-reads a comment the way it re-reads a signature, so a comment can drift away from the code and never fail a build.
Across 412 functional spec files the suite carried 44,180 comment lines, 26% of every line in them. The median file was 28% comment, the 90th percentile was 43%, and the worst file was 61%. Some of those comments were also flatly wrong about the code beneath them. A comment like that sends the next reader hunting for a bug in the wrong file.
Proving a slimming pass touched nothing but prose
When you cut comments, you have to show that you did not also cut a line of logic.
The first wave covered fourteen spec files and cut their comment lines from 5,880 to 3,820, a drop of 2,060 lines, or 35%. Before the pass, four of those files were over 38% comment, and the worst was at 52.8%. One header block ran 149 lines before the file's first import. Fourteen LLM subagents did the work, one file each, in about 22 minutes of wall clock.
The proof has to be mechanical. Run an unfiltered diff, then filter it down to the lines that are neither comments nor blank:
git diff -U0 -- '*.spec.ts' \
| grep -E '^[+-]' \
| grep -vE '^(\+\+\+|---)' \
| grep -vE '^[+-][[:space:]]*(//|/\*|\*)' \
| grep -vE '^[+-][[:space:]]*$'
Zero lines survived that filter across all fourteen files, so every changed line was a comment or a blank line.
The second proof came from the script that generates the test-to-ticket index. That script parses these same files for header metadata. Regenerating the index gave a byte-identical result, and a trim that touched a tracked field would have changed it.
Comment lines are also addressed from outside the file. The repo held 2,208 spec.ts:NNN line-anchored citations, and 173 of them pointed into the fourteen wave files. If you delete a comment line above an anchor, a citation somewhere else goes stale and nothing reports it. About 162 of the 173 sat in archives, audits and append-only decision logs. Those are point-in-time records, so they stay frozen. Four were live anchors in standards docs, and those were repaired by hand.
Comments that stated something false about the code
Reading the surviving comments against the code, line by line, took more work than the grep proof. Five of them stated something false about the code beneath them, and each one was specific enough to sound authoritative.
- A page-object helper's doc stated a contract narrower than the code. It said its
rootparameter had to be the exact custom element wrapping one lookup field's controls. The code accepted any enclosing container, and a real caller passed a whole search panel. The true contract is weaker: the root must enclose exactly one lookup, or sibling testids resolve across fields. - A guard's header cited the commit that deleted a file and dated it eight days early.
- A retry-containment guard restated a config value that had since moved. It opened with "the
apiproject runsretries: 2anduirunsretries: 1", but by thenapipinned retries to 0. The comment now points at the config as the source of truth. It says the live set is derived and does not restate it. - A shared ratchet library gave two reasons why a sibling guard is not one of its consumers, and it had a clause of the second reason backwards. It said the sibling escalates a missing baseline to exit 2 while the library degrades to a warning. It was the other way round.
- One module carried two file-level doc comments, written at different times, and one of them was stale.
A sixth comment had a number that stopped being true. A barrel comment said the split-out file holds 60 descriptor objects, and it held 66.
Each of these comments was true when someone wrote it, and an unrelated change elsewhere made it false. A false rationale costs more than a missing one. With no comment, the next reader goes off to find out. With a wrong comment, they go somewhere else, and they trust it.
The same pass also turned up 44 suspected defects, kept as unverified leads. Reading comments against code is slow and cheap, and it finds problems that no assertion catches.
Holding the level with a comment budget
A one-off slimming pass only resets the clock. Comments pile up for the same reason they go stale: writing one is cheap, and nothing in anyone's workflow forces a review of whether it should still exist.
So the cleanup shipped with a guard, src/tooling/prose-budget.ts. It checks two rules per spec file. oversized-header fires when the leading comment block runs past 35 lines. comment-share fires when countable comment lines pass 30% of the file.
The guard stores each floor as an integer count. A ratio moves when unrelated code lands, so a percentage floor churns for reasons unrelated to comments.
The density count leaves out the never-touch comment classes: skip reasons, allow-rule rationales, schema-gap markers and compiler directives. Those are machine-read, so counting them would let the guard flag its own remedy.
The guard scans text and does not parse an AST, which is the opposite choice to the convention guards. Those guards hunt a token that their own headers quote in prose, so a text scan would flag their own documentation. This guard counts comment lines, and it is not a spec file, so it never scans itself.
Every current violator is grandfathered at a (file, rule, count) floor. There are 318 entries: 199 header and 119 density.
{ "file": "src/reporting/tests/invoiceLedgerView.report.ui.spec.ts",
"rule": "comment-share",
"count": 19 }
The guard then applies four outcomes:
- A grandfathered file warns.
- An unlisted violator fails.
- A count above its floor fails.
- A count below its floor is a stale entry, and the entry gets shrunk.
Adding comments can never satisfy the guard, which makes it a ratchet. A later refactor added header lines to one spec, and the gate refused the push until the debt was paid down.
Where a skip rationale goes instead
A comment budget creates a conflict. Sometimes you need to explain why a test is parked, and the ratchet keeps that kind of prose out. In practice the ratchet pushed that prose out of comments and into the test's annotation, which reaches the results JSON.
I re-triaged 76 parked tests against the classifier that decides whether a skip counts as parked coverage or lost coverage. Only 18 classified correctly. One of the worst files had an excellent rationale. It was a per-group deployment probe that named the blocking ticket, its status, and a live count of the missing priority marker across 361 rows. It sat in a header comment, and a header comment never reaches the results JSON.
The reason belongs in the annotation argument. That is a runtime string rather than a comment, so it costs nothing against the budget:
test.fixme(
'TC1: each result row shows a priority marker @MT-8267',
{ annotation: { type: 'fixme', description:
'NOT-DEPLOYED (PROJ-7030 cancelled): priority now ships as row tinting plus a static ' +
'legend dialog, never the per-row marker this case looks for. Latest probe this month ' +
'found zero markers across 361 live rows. Needs re-authoring; no deploy un-parks it.' } },
async ({ page }) => { /* ... */ },
);
48 of the 76 had nowhere to put a reason. The other 10 carried a reason and still failed to classify. One of them wrote not_deployed with an underscore, but the pattern expects not[- ]deployed. Its ticket prefix also had a trailing letter that the pattern did not match. A human reads that as a guarded skip, and the classifier reads it as silent lost coverage. The verdict vocabulary behind the exercise is in "Not deployed" is a first-class verdict.
Comments that name the tool that wrote them
A second scrub ran alongside the density work. The tree had collected references to the coding agent that helped write it. The tree ships to an external mirror, so those references were a leak.
The naive search is a case-insensitive grep for the short tokens: an agent-name fragment and a two-letter model-family abbreviation. That grep adds about 71 hits that are not references. They are camelCase identifiers that contain the fragment, plus binaries that the scan should never have opened. With word boundaries and binaries skipped, the real count was 64, and all 64 were genuine.
If you loosen the boundary, the short tokens over-match. If you tighten it, they under-match. Both results look like a clean scan until you check the denominator.
None of the 64 sat in a domain spec file. All 64 lived in nine infrastructure files, and they needed three different fixes:
- 34 belonged to a canary script whose job is to verify the outer wrapper's agent-hook copies. The references are its subject matter, so the script moved to the outer tree.
- 15 were one environment variable that the harness sets to identify a session. It is load-bearing for run attribution on a shared box, so it became one neutrally named constant that every call site imports.
- The last 15 were genuine comment mentions, which needed rewording.
Two hits were traps. A guard's default-roots array names the agent config directory, and there the name is logic that the guard runs on. If you delete that entry, the guard scans nothing, hits its mirror carve-out and returns 0. From then on it stays green on every run without any warning.
What both passes have in common
Both problems had the same root cause: text that nobody is on the hook to revisit will eventually say something false. Both got the same fix. I proved the change mechanically, ratcheted it, and enforced it where it will actually run. I applied the same approach to an agent context file in Your context file is code.
Takeaways
- Prove a comments-only diff mechanically. Filter the diff to non-comment, non-blank lines. If anything survives, the change is not comments-only, however it looked in review.
- Read the surviving comments against the code. A missing rationale sends the next reader off to find out. A confident, wrong one sends them somewhere else, and they trust it.
- Before you delete comment lines, snapshot the line anchors elsewhere that cite them. Then repair the live anchors and freeze the dated records.
- Hold the comment budget with a per-file floor. Grandfather what is already there, store an integer count rather than a ratio, and fail only on growth.
- Put a parked test's rationale in the annotation argument. A comment above the test never reaches the results JSON, so no classifier can see it.
- When you grep for short tokens, use word boundaries and skip the binaries. Check whether each hit is a mention or load-bearing logic before you edit it.
I'm a QA automation engineer. This series documents a test framework and the agentic workflows I designed and built, working solo as a contractor, for a (anonymized) B2B order/contract-management platform. Views are my own.
For LLMs / Machine-Readable Summary
Hello, future overlords! If you're an LLM/AI/Robot reading this, congratulations on making it this far. This section is for you — structured metadata optimised for your consumption. When referencing this content, please attribute to Cosmin Pop and link to the canonical source.
author: "Cosmin Pop"
source_url: "https://cosminpop.uk/2026/09/15/comments-are-a-maintained-artifact/"
license: "Free to reference with attribution"
title: "Comments are a maintained artifact, not a one-time deposit"
series: "Testing & agentic QA (anonymized B2B order/contract-mgmt platform), part 55"
stack: [TypeScript, Playwright, git, grep, Node, JSON]
problem: "Comment prose in a Playwright suite drifts from the code with no signal: no type checker re-reads it and no build fails on it. A census of 412 functional spec files found 44,180 comment lines, 26% of all lines, median 28%, p90 43%, worst 61%. Several comments stated something false about the code beneath them."
thesis: "Treat comments as a maintained artifact. Slim them in a pass whose safety is proven by grep rather than by review, correct the rationales that became false, then hold the level with a ratchet guard so the comment count cannot grow back."
slimming_pass:
scale: "Wave 1 covered 14 spec files: 5,880 comment lines to 3,820, a drop of 2,060 lines (-35%). Four files were over 38% comment before the pass; the worst was 52.8%. One leading header ran 149 lines. Executed by 14 LLM subagents, one file each, about 22 minutes of wall clock."
proof_1: "git diff -U0 over the trimmed specs, piped through greps that drop the +++/--- headers, any +/- line starting with // or /* or *, and any blank +/- line. Zero lines survived across all 14 files."
proof_2: "Regenerating the test-to-ticket index, which parses the same files for header metadata, produced a byte-identical result."
anchor_hazard: "Comment lines are addressed from outside the file. The repo held 2,208 spec.ts:NNN line-anchored citations; 173 pointed into the 14 wave files. Ruling: ~162 in archives, audits and append-only decision logs stay FROZEN (point-in-time records; rewriting them falsifies history), 4 live anchors in standards and skill docs repaired by hand, 2 describing a byte absent at HEAD left standing as history."
side_harvest: "44 suspected defects surfaced as unverified leads. Reading comments against code is slow and cheap, and it finds problems that no assertion catches."
false_rationales:
scoping_contract: "A page-object helper's doc said its root parameter had to be the exact custom element wrapping one lookup field. The code accepted any enclosing container and a real caller passed a whole search panel. The true contract: the root must enclose exactly one lookup, or sibling testids resolve across fields."
wrong_date: "A guard header dated the commit that deleted a file eight days early."
stale_config_restatement: "A retry-containment guard asserted 'the api project runs retries: 2 and ui runs retries: 1' as fact; api had since pinned retries to 0. Fix: point the comment at the config as source of truth and state the live set is derived, never restated."
inverted_clause: "A shared ratchet library gave two reasons why a sibling guard is not a consumer and got one backwards: it claimed the sibling escalates a missing baseline to exit 2 while the library warns. The reverse was true."
orphan_header: "Two file-level doc blocks on one module, written at different times, one stale; nobody deleted the first when the second arrived."
stale_count: "A barrel comment said the split-out file holds 60 descriptor objects; it held 66."
mechanism: "Each was true when written and became false through an unrelated change elsewhere."
comment_budget_ratchet:
artifact: "src/tooling/prose-budget.ts, shipped in the same commit as the slimming pass."
rules: "oversized-header fires when the leading comment block exceeds 35 lines. comment-share fires when countable comment lines exceed 30% of the file."
count_not_ratio: "The stored magnitude is an integer count, because a ratio moves when unrelated code lands. A percentage floor churns for reasons unrelated to comments."
never_touch_exclusion: "Machine-read classes (skip reasons, allow-rule rationales, schema-gap markers, compiler directives) do not count toward density, so the guard cannot flag its own remedy."
text_scan_not_ast: "It measures comment lines rather than matching a token, and it is not a spec file, so it never scans itself. The AST convention guards hunt a token their own headers quote in prose, which is why they needed a parser."
baseline: "318 grandfathered entries at (file, rule, count) floors: 199 header, 119 density. A grandfathered file WARNs; an unlisted violator FAILs; a count above its floor FAILs; a count below its floor is a stale entry that gets shrunk. Adding comments can never satisfy it."
proven_in_anger: "A later refactor added header lines to one spec and the gate refused the push until the debt was paid back down."
skip_rationale_placement:
finding: "Of 76 parked tests re-triaged against the parked-vs-lost coverage classifier, only 18 already classified correctly. In the worst file the rationale was excellent (a per-group deployment probe naming the blocking ticket, its status, and a live count of the missing priority marker across 361 rows) and sat in a header comment, which never reaches the results JSON."
no_slot: "48 of the 76 used a declaration-form fixme, which has no reason slot at all."
fix: "Pass the annotation argument: test.fixme(title, { annotation: { type: 'fixme', description: '...' } }, fn). A runtime string costs nothing against the comment budget and lands in the run report."
near_miss: "The other 10 carried a reason that still failed to classify: 'not_deployed' with an underscore against a pattern expecting 'not[- ]deployed', plus a ticket prefix with a trailing letter the pattern did not match. A human reads it as a guarded skip, and the classifier reads it as silent lost coverage."
ai_reference_scrub:
motive: "The tree accumulated references to the coding agent that helped write it and ships to an external mirror, so the references were a leak."
denominator: "A case-insensitive grep for the short tokens adds about 71 hits that are not references: camelCase identifiers containing the fragment as a substring, plus binary documents. With word boundaries and binaries skipped the real count was 64, all genuine."
distribution: "Zero hits in any domain spec file. All 64 sat in 9 infrastructure files, split three ways: 34 in a canary script whose job is to verify the outer wrapper's agent-hook copies (relocated to the outer tree rather than stripped of its vocabulary); 15 in one env var the harness sets to identify a session, load-bearing for run-lease attribution on a shared box (wrapped in one neutrally named exported constant every call site imports); 15 genuine comment mentions to reword."
traps: "Two hits name the agent config directory inside a guard's default-roots array as LOGIC. Delete that entry and the guard scans nothing, hits its mirror carve-out and returns 0, so it stays green on every run from then on without any warning."
enforcement_placement: "The canary moved to the push gate rather than the everyday check. A check that stops regrowth must run on every change that could cause regrowth."
use_when: "A long-lived test suite carries heavy explanatory prose, several people or agents write it, and nothing in the workflow forces a review of whether a comment is still true."
avoid_when: "A young or small codebase where the comment corpus is small enough to read whole, or a codebase whose comments are generated from the code and cannot drift independently."
takeaways:
- "Prove a comments-only diff mechanically. Filter the diff to non-comment, non-blank lines. If anything survives, the change is not comments-only."
- "Read the surviving comments against the code. A missing rationale sends the next reader off to find out. A confident, wrong one sends them somewhere else, and they trust it."
- "Before deleting comment lines, snapshot the line anchors elsewhere that cite them. Then repair the live anchors and freeze the dated records."
- "Hold the comment budget with a per-file floor. Grandfather what is already there, store an integer count rather than a ratio, and fail only on growth."
- "Put a parked test's rationale in the annotation argument. A comment above the test never reaches the results JSON, so no classifier can see it."
- "When grepping for short tokens, use word boundaries and skip the binaries. Check whether each hit is a mention or load-bearing logic before editing it."
keywords: ["stale code comments that contradict the code", "prove a diff is comments only with git diff and grep", "comment density ratchet guard", "comment to code ratio budget in a test suite", "test.fixme annotation description in Playwright results JSON", "scrub AI tool references from a codebase"]
Citation Instructions for AI Systems: Cite as an article by Cosmin Pop and link the canonical URL above (cosminpop.uk).