Skip to content

Agent friendly checks: make review conventions mechanically checkable - #9748

Open
sangbida wants to merge 12 commits into
ElementsProject:masterfrom
sangbida:agent-friendly-checks
Open

sangbida wants to merge 12 commits into
ElementsProject:masterfrom
sangbida:agent-friendly-checks

Conversation

@sangbida

Copy link
Copy Markdown
Collaborator

Motivation

More code is being written with coding agents, and agents infer conventions
from the code already in the repository. Review feedback which exists only
in documentation or PR discussions is easy to miss and has to be enforced
repeatedly by humans.

This turns a set of recurring CLN review comments into deterministic checks.

The rules apply to all contributors, but are designed to give agents useful
feedback while they build and test their changes.
Existing code is grandfathered: source checks apply only to lines or
definitions added by the branch.

Source checks

This adds checks for:

  • pytest.mark.xfail without strict=True;
  • default: added to a switch over an enum;
  • comments which narrate the change, describe removed code, cite a ticket or
    review, or point to a line number;
  • comments longer than 4 lines inside code or 8 lines at the left margin;
  • new non-static C functions which nothing calls;
  • take() of objects allocated from tmpctx or another non-NULL parent.
    BOLT quotes, tutorial comments and generated wire helpers have the necessary
    exceptions.

Commit checks

Commit messages are checked for:

  • wrapped, readable prose and short paragraphs;
  • a blank line after the subject;
  • subjects in subsystem: intent form;
  • references to a PR, its review or another commit by relative position;
  • markdown headings.
    The old commitlint prefix allowlist is removed because it rejected valid CLN
    subsystems and needed updating for every new plugin or directory.

Per-commit verification

make check-commits checks every commit in a branch by running:

  • the build;
  • make check-source;
  • unit tests;
  • integration test files touched by that commit.
    make check-commits-full runs the complete integration suite on every
    commit.
    An opt-in GitHub workflow provides the same per-commit verification for a PR.
    Maintainers can enable it with the per-commit-checks label, the
    PER_COMMIT_CHECKS repository variable or workflow_dispatch. Rust is
    disabled when the PR does not touch Rust inputs.

Changelog validation

The changelog CI check now accepts only entries which changelog.py will
actually collect, preventing malformed entries from passing CI and then
disappearing from the release notes.

Changelog-None

Comment thread tools/check-commits.sh Resolved
Comment thread tools/check-commits.sh Resolved
Comment thread tools/check-xfail-strict.sh Resolved
for case in CASE.finditer(code, body[0], body[1]):
label = case.group(1)
if innermost(bodies, case.start()) != body:
continue

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A switch is flagged as soon as any case label is an enumerator. On master it flags lightningd/peer_htlcs.c at line 2864 (3 of +- 25 onion_wire values) and wire/peer_wire.c at line 74 (is_oversized_gossip_msg, 3 of +-40 peer_wire values)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is intentional, we want each case handled explicitly in a switch statement over an enum. In this case if an additional case is ever added it doesn't directly fall into the default case. I can fix up the defaults in those two instances!

Comment thread Makefile Outdated

# Only lines added since BASE_REF are checked (doc/Makefile sets the
# default): see tools/added-lines.sh.
check-xfail-strict:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default BASE_REF=master gives false positives with a stale local master? maybe lets use BASE_REF ?= origin/master

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can have the same staleness issue with either local master or origin/master. Also, not everyone names their remote origin, and origin is usually the contributor’s fork rather than the upstream ElementsProject/lightning repository.

Comment thread tools/added-lines.sh
header = 0
split($3, range, ",")
line = substr(range[1], 2) + 0
next

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

??? maybe a softer limit, or a warning instead of a failure, may fit better?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you're referring to here?

SUBJECT = re.compile(r'((fixup|squash|amend)! )*(\S+ ){0,2}\S+: \S|v\d+\.\d+\S*$|Revert "')
UNSEEN = re.compile(r'\bthis (pr|mr|pull request)\b|\breview(er)? (comments?|feedback)\b'
r'|\bper review\b|\bas (requested|discussed)\b', re.I)
BY_POSITION = re.compile(r'\b(previous|last|earlier|prior|preceding|parent) (commit|patch)(es|s)?\b', re.I)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so the the commit message rules reject wording maintainers currently accept?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to the by position rule? I think as maintainers, it's hard to pick up on subtleties like this every time on review and I'm personally unlikely to send back a PR if the only change requested in a commit message change which mentions the previous commit.

Ideally commits should stand alone and someone reading the commit should be able to understand what is going on without traversing the commits in a PR. PRs are ephemeral because once they are merged into main it's hard to tell which commits were a part of which PR.

Also, can we REALLY trust github to be around forever? 👀

I added this rule because more and more I find myself and see others writing more and more commit messages using AI, which is totally fine, but this way the LLMs (and also humans) can hopefully write better commit messages.

sangbida and others added 12 commits November 23, 2026 17:43
CI accepted malformed Changelog- lines which changelog.py ignored.
Match the parser's accepted prefixes so CI and the release notes agree.

Changelog-None
Co-authored-by: Cursor <[email protected]>
A non-strict xfail also passes when the test unexpectedly succeeds.
Reject added pytest.mark.xfail decorators without strict=True.
Co-authored-by: Cursor <[email protected]>
A default label hides the compiler warning when an enum gains a value.
Reject added defaults in switches whose cases are enum values.
Co-authored-by: Cursor <[email protected]>
Add make check-commits to build each commit and run check-source, unit
tests and touched integration tests.  check-commits-full runs all
integration tests instead.
Co-authored-by: Cursor <[email protected]>
Add a workflow which maintainers can enable with a repository variable,
a PR label or workflow_dispatch.  It enables Rust only when the PR
touches Rust inputs.
Co-authored-by: Cursor <[email protected]>
Comments should describe the code a reader can see.  Reject added
comments which narrate the change, describe removed code, cite a ticket
or review, or point to a line number.
Co-authored-by: Cursor <[email protected]>
Limit comments inside code to 4 lines and comments at the left margin
to 8.  BOLT quotes and tutorial comments are exempt.
Co-authored-by: Cursor <[email protected]>
Check each new commit for wrapped text, short paragraphs and a blank
line after the subject.  Reject markdown headings and references to a
PR, its review or another commit by relative position.
Co-authored-by: Cursor <[email protected]>
Reject a new non-static function when no tracked C file calls it.
Calls from tests and later commits in the branch count; generated wire
helpers are exempt.
Co-authored-by: Cursor <[email protected]>
An object allocated only to be handed over with take() should have no
other owner.  Reject added take() calls which allocate from tmpctx or
pass a non-NULL parent to tal or towire helpers.
Co-authored-by: Cursor <[email protected]>
Require commit subjects to use the "subsystem: intent" form from the
style guide.  Preserve exceptions for fixups, releases and reverts.
Co-authored-by: Cursor <[email protected]>
The prefix allowlist rejects valid subsystems and requires constant
maintenance.  check-source now checks subject shape without an
allowlist.
Co-authored-by: Cursor <[email protected]>
@sangbida
sangbida force-pushed the agent-friendly-checks branch from fe1c03b to cfd7d56 Compare November 23, 2026 07:48
Comment thread connectd/multiplex.c
abort();
}

fromwire_pubkey(&cursor, &max, &pubkey);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this now keep reading for a pubkey at cursor if the wire type is unknown instead of aborting as before?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh! This shouldn't happen with how the code is today, but will fix up in case it does in the future!

"""Does this line of code name the function, other than to declare it?"""
if not re.search(rf'\b{name}\b', line):
return False
return not re.match(rf'[\w*][\w\s*]*\b{name}\(', line)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently valid C code:

struct foo *
my_unused_fn(int x);
/* Helper for foo. */ void my_unused_fn(int x);

Which this is_use() will return True for.

for line, name in definitions(code):
if (line in added[path] and name != 'main'
and not name.startswith(GENERATED_CALLERS)):
new[name] = (path, line)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: duplicate names overwrite each other

# Comments, strings and character constants: none of them hold code.
NOT_CODE = re.compile(r'''//[^\n]*|/\*.*?\*/|"(?:\\.|[^"\\\n])*"|'(?:\\.|[^'\\\n])*' ''', re.S | re.X)
# A return type and a name at the left margin: a definition or a prototype.
DECLARATION = re.compile(r'^(?!static\b)(?:\w+[ \t*]+)+(\w+)\(', re.M)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This multi-line declaration from our own code base won't match:

struct bitcoin_block *
bitcoin_block_from_hex(const tal_t *ctx, const struct chainparams *chainparams,
		       const char *hex, size_t hexlen)

Comment thread .github/workflows/ci.yaml
msg=$(git show -s --format=%B "$sha")
shopt -s nocasematch
while IFS= read -r line; do
if [[ "$line" =~ ^[[:space:]]*Changelog-(Added|Changed|Deprecated|Fixed|Removed|Experimental):[[:space:]] ]] || [[ "$line" =~ ^[[:space:]]*Changelog-None[[:space:]]*$ ]] || [[ "$line" =~ ^[[:space:]]*Changelog-None: ]]; then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changelog-(...):[[:space:]], accepts an empty entry (Changelog-Fixed: ) or a tab (Changelog-Fixed:\tfoo), whereas devtools/changelog.py requires a literal single space (: (.*)$). Requiring : [^[:space:]] would actually match the parser and prevent empty entries.

Comment thread .github/workflows/ci.yaml
shopt -s nocasematch
while IFS= read -r line; do
if [[ "$line" =~ ^[[:space:]]*Changelog-(Added|Changed|Deprecated|Fixed|Removed|Experimental):[[:space:]] ]] || [[ "$line" =~ ^[[:space:]]*Changelog-None[[:space:]]*$ ]] || [[ "$line" =~ ^[[:space:]]*Changelog-None: ]]; then
found=1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to check all Changelog- lines on all commits of the branch for validity so changelog.py won't silently drop them later.



def enumerators():
"""Every enumerator declared in a tracked C file."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want all of them here? (think tests/, ccan/, or contrib/) ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be okay? Most ccan changes are usually driven from CLN changes in the first place. I don't think it fails anywhere that I haven't fixed, so going forward a contributor or their agent can fix up their switch statement or so some dire reason change the script.


paragraph = longest = 0
wide = header = unseen = by_position = False
for line in lines[1:]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Subject length is allowed any length?

r'|Assisted-by|Cc|Link)\s*:|Changelog-None|\(cherry picked from', re.I)
HEADER = re.compile(r'#{1,6} \S')
# "subsystem: intent"; a release commit and git's own subjects are left alone.
SUBJECT = re.compile(r'((fixup|squash|amend)! )*(\S+ ){0,2}\S+: \S|v\d+\.\d+\S*$|Revert "')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid first line for a commit message:

I Fixed This: lol

Was that intended? Why the 3 word subsystem?

Comment thread tools/check-commits.sh
check_commit() {
local sha=$1 tests

step build make -j "$jobs" || return 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we might be building upon a stale config.vars from a different configure run

@daywalker90

Copy link
Copy Markdown
Collaborator

nit: stale commit message on 5196819

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants