feat(checkpatch): feed checkpatch.pl findings into review as opt-in ground truth#22
feat(checkpatch): feed checkpatch.pl findings into review as opt-in ground truth#22nethum529 wants to merge 2 commits into
Conversation
The reviewer inferred style and obvious-correctness issues from the diff text alone, guessing at findings that scripts/checkpatch.pl already produces deterministically. That ground truth never reached the model. Add an opt-in, kernel-only stage that runs scripts/checkpatch.pl on each reviewed commit and injects its error- and warning-level findings into the reviewer's reference context as a "# --- checkpatch ---" block, the same way lore follow-up data is appended. checkpatch is run with --no-tree on the commit patch, so its output does not depend on the worktree's checked-out state, and its non-zero exit on findings is captured rather than treated as failure. The stage mirrors the lei/lore handling: it is configured from BORO_CHECKPATCH_ENABLED (default off) and BORO_CHECKPATCH_MAX_BYTES, and degrades gracefully to a no-op when the script or perl is absent, so every other stage still runs. It is additive; no pipeline restructuring. Closes NVIDIA#6 Signed-off-by: nethum529 <nethumweerasinghe.nw@gmail.com>
…it show Signed-off-by: nethum529 <nethumweerasinghe.nw@gmail.com>
2a235dc to
b4d520a
Compare
|
Can you provide a better description for commit |
|
I also see a potential issue with this approach: if we execute ./scripts/checkpatch.pl from the worktree, a malicious commit could modify checkpatch.pl to run arbitrary code. I'm not sure exactly how to address this... should we always run checkpatch.pl from a known branch (latest Linus git)? |
So with checkpatch on, review checks the commit out and runs that tree's own
Pinning checkpatch is needed but not enough: it still runs with cwd in the Let me know how you'd like me to proceed |
Intent
Implement NVIDIA/boro issue #6: feed scripts/checkpatch.pl output into the agentic review as opt-in, kernel-only ground truth. New src/checkpatch.rs stage runs checkpatch with --no-tree on each reviewed commit's patch and injects its ERROR/WARNING-level findings into the model's reference context as a new '# --- checkpatch ---' block in prompts::build_reference_context, deliberately mirroring the existing lei/lore upstream-followup handling. Config via CheckpatchConfig::from_env: BORO_CHECKPATCH_ENABLED (default OFF, opt-in, parsed case-insensitively) and BORO_CHECKPATCH_MAX_BYTES (default 16384). Deliberate design decisions a diff-only reviewer would not know: (1) checkpatch exits non-zero precisely when it has findings, so exit status is intentionally ignored for the findings path and stdout is captured regardless; run_checkpatch returns a CheckpatchOutcome enum (Findings/Clean/Failed) so a non-zero exit with no findings is surfaced as Failed and logged, letting an opted-in user tell a broken integration from a clean commit rather than silently no-op; (2) availability is a per-tree scripts/checkpatch.pl file check, not a PATH OnceLock, because it is a tree file; perl presence is the process-global OnceLock; (3) additive only, no pipeline restructuring, kernel-only for now (QEMU/sparse are future follow-ups per the issue); (4) findings injected as reference context, not as deterministic findings, exactly as the issue asked. Also fixed a latent missing 'used += block.len()' on the upstream-followup block so the new checkpatch budget check is accurate. The document pipeline step is intentionally skipped because README docs are already included in the commit and prior runs generated stray scratch commits. Already validated locally: 348 tests pass, cargo fmt --check clean, default clippy clean on new code, and it passed a rust review plus a 4-lens scrutinize plus a confirmation pass.
What Changed
src/checkpatch.rsstage that runs the kernel tree'sscripts/checkpatch.plwith--no-treeover each reviewed commit's format-patch mbox, gated behindBORO_CHECKPATCH_ENABLED(default off) andBORO_CHECKPATCH_MAX_BYTES(default 16384);run_checkpatchignores exit status for the findings path and returns aCheckpatchOutcomeenum (Findings/Clean/Failed) so a broken integration is surfaced rather than silently no-op'd.src/prompts.rsto inject filtered ERROR/WARNING-level checkpatch output intobuild_reference_contextas a new# --- checkpatch ---reference block, mirroring the existing upstream-followup handling, and fixed a missingused += block.len()budget accounting for that block.src/git.rsformat-patch/mbox helpers and wired the stage intosrc/main.rs, with README documentation for the new opt-in configuration.Risk Assessment
✅ Low: The change is a well-bounded, opt-in, additive fix that correctly routes a format-patch mbox into checkpatch with full graceful-degradation and strong test coverage; it properly addresses the prior round's finding with no new defects.
Testing
Ran the checkpatch unit tests and the full 349-test suite (all green), then demonstrated the feature end-to-end by running the actual boro pipeline (format_patch -> run_checkpatch -> build_reference_context) with the real upstream checkpatch.pl on a real kernel commit carrying planted style violations; the resulting reference context contained the# --- checkpatch ---block with the ERROR/WARNING findings and the authoritative-ground-truth instruction wrapper, CHECK-level and summary lines correctly filtered out. This is the model-facing surface the issue asked for. No product-level UI is involved (this is a CLI/agentic-review data-injection change), so the evidence is a captured reference-context transcript rather than a screenshot. No failures or flakiness found; worktree left clean.Evidence: Injected reference-context block from real checkpatch.pl (E2E)
# --- checkpatch ---scripts/checkpatch.plreported the following error- and warning-level findings on this commit. Treat them as authoritative style/correctness ground truth rather than re-deriving them from the diff: /tmp/.tmpWDwIVN:21: WARNING: Missing or malformed SPDX-License-Identifier tag in line 1 /tmp/.tmpWDwIVN:25: ERROR: spaces required around that '=' (ctx:VxV) /tmp/.tmpWDwIVN:26: WARNING: Missing a blank line after declarations /tmp/.tmpWDwIVN:26: ERROR: space required before the open parenthesis '(' /tmp/.tmpWDwIVN:28: WARNING: line length of 107 exceeds 100 columnsEvidence: E2E reproduction script (kernel-style tree + violating commit)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
src/main.rs:3183- run_checkpatch is fed git::show_patch output (git show --pretty=medium), which begins withcommit <sha>/Author:/Date:headers and indents the commit message by 4 spaces. checkpatch.pl expects git format-patch / mbox input. Diff-level findings stay correct (line numbers come from the @@ hunk headers), but commit-log-level checks run over the git-show header lines and the +4-space-indented body, which can produce spurious ERROR/WARNING findings (e.g. 'Possible unwrapped commit description') or silently skip Subject:-dependent checks. Because render_summary labels the output as 'authoritative ground truth', inaccurate commit-log findings can mislead the reviewer model. Consider feeding format-patch/mbox output instead.🔧 Fix: feed checkpatch a format-patch mbox instead of git show
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
cargo test checkpatch(20 checkpatch/prompts unit tests: parse_enabled case-insensitivity, max_bytes parsing, is_active gating, Findings/Clean/Failed outcomes, truncation-with-marker, filter keeps only ERROR/WARNING)cargo testfull suite: 349 passed, 0 failedE2E: built a kernel-style tree with the real upstream scripts/checkpatch.pl, committed drivers/foo/foo.c with deliberate style violations, then drove git::format_patch -> checkpatch::run_checkpatch -> prompts::build_reference_context via a temporary in-crate test and captured the rendered# --- checkpatch ---reference block (temp test reverted afterward; git diff HEAD clean)⏭️ **Document** - skipped
Step was skipped.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.