Skip to content

agents: no comments unless needed, plus comment budget guard - #14764

Merged
TrapsterDK merged 4 commits into
mainfrom
comments-rule-guard
Nov 24, 2026
Merged

TrapsterDK merged 4 commits into
mainfrom
comments-rule-guard

Conversation

@TrapsterDK

@TrapsterDK TrapsterDK commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #14766

Linked Issue

No issue: owner request to drop comments repo-wide; the sweep PRs delete the comments, this one sets the rule and the guard.

Changes

  • AGENTS.md: the Comments bullet is now "none by default, in every language", including Rust //////! and Go doc comments. It keeps only what tools read: one-line Starlark docstrings, clap /// help, // SAFETY:, lint/format/gazelle directives, LCOV_EXCL_*, # floor:, Actions pin comments, license headers and shebangs. Where code truly cannot say it, at most one short line is allowed. The rules on issue numbers, links and See: chains, on prose_rules_test, and on assigned strings stay. No other doc stated the old rule (I checked docs/AGENTS.md, CONTRIBUTING.md, .claude/ and the prose rules).
  • New //tools/ci:comment_budget_test (tools/ci/comment_budget_test.rs):
    • Counts comment lines that are not exempt in rs, go, bzl, BUILD, py, sh, js/mjs/ts, cc/h and yml/yaml. The scanner knows each language's strings, raw strings, heredocs and YAML block scalars, so // inside a string is not counted.
    • Skips testdata/, fixtures/, golden(s)/, third_party/, lock files and generated files.
    • Sums per top-level directory and fails when a directory goes over its budget, naming the directory and the files that grew. Going under budget never fails, so the sweep PRs only need to lower the numbers if they want to.
    • On failure it writes the regenerated budget to the test outputs.
    • Unit tests cover a plain comment, a doc comment, Keep markers, clap help lines, strings holding //, and skipped/generated files.
  • tools/ci/comment_budget.txt: per-file budgets at main 73bbcc2 (19531 lines). Top directories: cli 7146, tools 4404, core 3076, deploy 1585, gazelle 1561.
  • tools/ci/repos.bzl: the @dx_test_tags_sources snapshot also writes other_code.json (go, py, sh, js, mjs, ts, cc, h, yml, yaml).

Verification

  • tools/dx test //tools/ci:comment_budget_test //tools/ci:host_env_test: comment_budget_test passed (8/8). host_env_test failed 14/15; all 4 of its problems are in files this PR doesn't touch (.bazelrc, cli/prebuilt/bundle.bzl, haskell/private/toolchain/repos.bzl, julia/private/runtime/julia_src.BUILD.bazel).
  • Other //tools/ci guards: repos_bzl, repos_walk, gazelle_rust_coverage, rust_test_crate_deps, test_tags, test_duplicates, bzl_visibility, review_paths and dx_guard passed. These failed on files this PR doesn't touch, with origin/main unchanged at 73bbcc2: hub_literals, lint_attributes, prose_rules, repo_rule_refetch, sandbox_escape, starlark_docs, test_budget, unreferenced_files and zero_compat. tools/ci/repos.bzl not-reproducible 1 matches its allowlist line. unreferenced_files reports tools/ci/BUILD.bazel orphan-target 1 from filegroups that already exist on main; this diff adds no filegroup or exports_files.
  • tools/dx check --affected: widened to //... because repos.bzl feeds a module extension. Its generate phase reported drift in 37 BUILD files and 4 stale locks, all outside this diff. The Bazel server then crashed with java.lang.OutOfMemoryError: Java heap space on the //... build. Scoped instead: tools/dx check --apply //tools/ci:comment_budget_test passed generate, format, lint and typecheck (the rustfmt fix is the second commit), and comment_budget_test passed 8/8 again after it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xut2hxcqqAoDeuSr83mscS

AGENTS.md now says no comments by default in every language, keeping
only what tools read and at most one short line where code cannot say it.

//tools/ci:comment_budget_test counts comment lines that are not exempt
in Rust, Go, Starlark, Python, shell, JS/TS, C++ and YAML sources, per
top-level directory, and fails when a directory goes over the budget in
tools/ci/comment_budget.txt, naming the files that grew. The snapshot
repo rule gains other_code.json for the non-Rust, non-Starlark sources.

No issue: owner request to drop comments repo-wide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hxcqqAoDeuSr83mscS
@TrapsterDK TrapsterDK added the needs-review Touches review paths; needs a second-session Review: comment label Nov 23, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hxcqqAoDeuSr83mscS
@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

Review: changes requested

The test fails only when a directory's total grows. It never asks for an exact match, so the sweep PRs #14758–#14763 will not trip it. It has no unwrap, panic, unsafe, network use or tags, and its output is deterministic (BTreeMap). These need fixing:

  1. tools/ci/comment_budget_test.rs:649-675: the budget can only go stale, never tighter. Counts are summed per top-level directory, nothing prompts anyone to lower them, and lines for deleted files keep adding to their directory's total. Once the sweeps merge, cli stays at 7146, so thousands of new comment lines would pass. Print a non-failing "budget can be lowered to N" message for each directory under budget, and re-baseline after the sweeps.
  2. tools/ci/comment_budget_test.rs:15: SKIPPED_DIRS lists fixtures but not the singular fixture. That puts 24 files / 153 lines of tools/docs/*/fixture/ test data into the budget (for example tools/docs/go/fixture/money.go 21, tools/docs/cc/fixture/include/shapes.h 19). The doc comments in those files are the input the docs tests check, and comments: drop comments in tools/docs and tools/ci #14760 leaves them alone for that reason.
  3. AGENTS.md:17-18 contradict the new line 14. Line 17 says "Three exceptions only" while line 14 now keeps about ten. Line 18 says "One line on what a thing does … is welcome", which reads as permission to comment every function. Fold line 17 into line 14 and limit line 18 to docs. Line 14 is also about 115 words; it is plain but not short.

Minor: tools/ci/repos.bzl:136 reads and watches every pnpm-lock.yaml (about 1 MB) and every fixture file, even though the test throws them away. Comments inside YAML run: | blocks are never counted.

🤖 Generated with Claude Code

comment_budget_test now checks each file against its own budget. An
unlisted file has a budget of 0. A file under its budget passes and
prints a note naming //tools/ci:comment_budget_update, which rewrites
comment_budget.txt to the lower of budget and current count and drops
zero lines. fixture/ and *_fixture(s)/ directories are skipped like
fixtures/ and testdata/. AGENTS.md keeps the comment rule short with
the exceptions as a list, drops the old "Three exceptions only" line
and limits the "one line on what a thing does" sentence to docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hxcqqAoDeuSr83mscS
@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

Addressed the review in a64f019:

  • comment_budget_test now checks per file. Unlisted files have budget 0, files over budget fail with path: N comment lines, budget M, files under budget print a note.
  • New //tools/ci:comment_budget_update (tools/dx run //tools/ci:comment_budget_update) rewrites comment_budget.txt, only lowering or dropping lines. Running it dropped the 24 fixture/ files (153 lines).
  • fixture/ and *_fixture(s)/ dirs are skipped like fixtures/ and testdata/.
  • AGENTS.md: short comment rule plus an exceptions list, old "Three exceptions only" line removed, "one line on what a thing does" limited to docs.

//tools/ci:comment_budget_test passes (11 tests). //tools/ci:prose_rules_test fails on the design-page word limit (docs/design/*.md over 1300 words). Those files are the same as on main, so this PR didn't cause it.

Not done: the minor repos.bzl point (reading lock and fixture files into other_code.json).

🤖 Generated with Claude Code

@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

Review: changes requested

The three earlier code findings are fixed at a64f019:

  • Per-file budgets: over_budget uses budget 0 for an unlisted file, and under_budget only prints a note (tools/ci/comment_budget/lib.rs:654-676, comment_budget_test.rs:28-43).
  • fixture/, *_fixture/ and *_fixtures/ are skipped (lib.rs:15-22,90-101). comment_budget.txt has no fixture, testdata, golden or third_party entries, and it is sorted under LC_ALL=C.
  • //tools/ci:comment_budget_update can only lower or remove lines. lowered loops over the existing budget keys only and writes min(found, limit). add skips 0, so files that are gone or now skipped drop out. New files are never added, and a parse problem aborts before the write (lib.rs:678-689, update.rs:30-36).

The non-test Rust has no unwrap, expect, panic! or unchecked indexing; it uses only get/unwrap_or*. The test reads only runfiles through read_input/rlocation and is size = "small", so it stays hermetic.

Still open in AGENTS.md:

  1. AGENTS.md:21 conflicts with AGENTS.md:22. Line 21 allows "at most one short line for a real platform quirk", but comment_lines counts that line and nothing exempts it. The update target can't raise a budget either. Example: add # macOS ships bash 3.2, no mapfile. to any .sh file. The test fails with "Delete the new comments", even though line 21 allowed the comment. Either drop the quirk exception, or say that a quirk line needs a reviewed hand edit to tools/ci/comment_budget.txt.
  2. AGENTS.md:14-23: the rule is still 10 lines and about 100 words, not about 3 short lines. Put the exceptions on one line, for example: "No comments in any language (Rust //////! and Go doc comments included). Kept: one Starlark docstring line per item, one clap --help line per flag, // SAFETY:, tool directives, license headers, shebangs, LCOV_EXCL_* with reason:/issue:, # floor:." Then merge line 23 into line 22.

Nothing else in AGENTS.md or docs/AGENTS.md conflicts with the rule. The repos.bzl point from last time is still minor and doesn't block.

🤖 Generated with Claude Code

…sed lines

AGENTS.md drops the platform-quirk allowance, since budgets only shrink,
and puts the rule on two lines plus one exceptions line. The budget test
now skips `# Why:` and `# Upstream:` lines, which tools parse, and its
failure message says to delete the comment and never raise a budget.
comment_budget.txt is lowered to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Xut2hxcqqAoDeuSr83mscS
@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

Addressed the re-review in 53df380:

  • AGENTS.md: the platform-quirk allowance is gone. The rule is now two lines plus one exceptions line, and the assigned-strings line is merged in.
  • comment_budget_test now skips # Why: and # Upstream: lines too (dx: was already skipped). The failure message says "Delete the new comments. Never raise a budget; tools/dx run //tools/ci:comment_budget_update only lowers it."
  • The update target lowered comment_budget.txt to 19366 lines in 1690 files.

tools/dx test //tools/ci:comment_budget_test passes (11 tests).

🤖 Generated with Claude Code

@TrapsterDK

Copy link
Copy Markdown
Collaborator Author

Review: approve

Both requested changes are in at 53df380:

  • The quirk allowance is gone. AGENTS.md:14-16 has the rule, one Kept: exceptions line and the budget line. The old "Three exceptions only" line is removed, and "one line on what a thing does" now only applies to docs.
  • The failure message (comment_budget_test.rs) says "Delete the new comments. Never raise a budget; tools/dx run //tools/ci:comment_budget_update only lowers it."

Exemptions (tools/ci/comment_budget/lib.rs directive, pinned, license_header, clap_lines): tool directives, LCOV_EXCL_ (substring match), floor:, SAFETY:, Why:, Upstream:, dx: (this covers dx:begin/dx:end), shebangs, license headers and uses: …@<40 hex> # vX pins are all skipped, and skips_keep_markers tests each one. I checked every # Why: / # Upstream: / # dx: line and every workflow pin comment in the tree, and none would count in a new file. AGENTS.md and docs/AGENTS.md have nothing that contradicts the rule. CLAUDE.md only includes those two files.

Non-blocking:

  1. Why: is exempt in every language and on any line, so // Why: anything in a .rs file gets past the budget. The only reader is gazelle_ignore_test, which wants it right after # gazelle:ignore in BUILD files. Consider limiting the exemption to that spot.
  2. AGENTS.md:15 doesn't list Actions sha-pin comments, but the test exempts them. Someone following "no comments" literally could delete # v4.1.0.
  3. Only the first line of a // SAFETY: or # Upstream: comment is exempt. Continuation lines count, for example cli/os_sys/src/spawn.rs:47 and python/private/py_cc_toolchain.bzl:4. Existing files already have budget for them, but a new file with a two-line SAFETY comment will fail. That's fine if one line is the intent.

🤖 Generated with Claude Code

@TrapsterDK
TrapsterDK merged commit 3a60116 into main Nov 24, 2026
22 of 33 checks passed
@TrapsterDK
TrapsterDK deleted the comments-rule-guard branch November 24, 2026 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review Touches review paths; needs a second-session Review: comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant