Skip to content

fix(check-trusted-base): make Lean sorry/axiom matching comment-aware - #532

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/trusted-base-lean-comment-awareness
Jul 27, 2026
Merged

fix(check-trusted-base): make Lean sorry/axiom matching comment-aware#532
hyperpolymath merged 1 commit into
mainfrom
fix/trusted-base-lean-comment-awareness

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

The bug

scripts/check-trusted-base.sh's Lean branch strips only "string literals" from a single line before matching \bsorry\b|^\s*axiom\s. Lean comments nest and span lines, so per-line string stripping cannot see them.

Consequence: a docstring that merely mentions sorry is reported as a soundness-relevant escape hatch, and the repo is told to seed docs/proof-debt.md for a hatch that does not exist.

Found in systemet, whose Audit.lean documents its own policy:

"A theorem that elaborates but smuggles in an axiom or a sorry through an import fails the gate here, not in a status document."

[INFO] Found 1 soundness-relevant escape hatch(es).
[ERROR] No docs/proof-debt.md (or equivalent) found, but 1 escape hatches exist.

That repo's axiom audit reports [propext, Quot.sound] for all 20 headline items — there was no hatch. The repos most likely to trip this are the ones documenting the policy most carefully, and the pressure it creates is to declare debt that doesn't exist — the opposite of what this gate is for.

The fix

strip_lean_noncode() blanks line comments (--), nesting block comments and docstrings (/- -/, /-! -/, /-- -/) and string literals, preserving line numbers so reported positions stay accurate. Markers still quote the original line text. This is the same comment-awareness scan-dangerous.sh already carries for Lean.

Failure direction is deliberate: string state is not carried across lines, so an odd quote over-flags rather than blanking the remainder of a file. For a soundness gate, over-flagging is safe and under-flagging is not.

Verification — it must still catch real holes

Fixture results (3 found, all genuine):

Line Content Flagged?
1 /-! docstring … sorry … -/ no ← was the bug
2 -- line comment mentioning sorry and axiom foo no
3 /- /- nested block with sorry -/ sorry -/ no
4 def okString : String := "the word sorry in a string" no
5 theorem realHole : True := by sorry yes
6 axiom realAxiom : False yes
7 theorem trailing : True := by sorry -- with trailing comment yes
8 theorem fine : True := trivial no

Line 7 is the important one: code before a trailing comment is still matched, so the stripper cannot be used to hide a real hole behind a comment. bash -n clean.

Because this script gates every proof-bearing repo in the estate, I have not merged it — please review the stripper logic before it goes live.

🤖 Generated with Claude Code

The Lean branch stripped only `"string literals"` from a single line before
matching, so it could not see Lean comments -- which nest and span lines. A
docstring that merely MENTIONS `sorry` was therefore reported as a
soundness-relevant escape hatch, and the repo was told to seed
docs/proof-debt.md for a hatch that does not exist.

Found in systemet, whose Audit.lean documents its own policy:

  "A theorem that elaborates but smuggles in an axiom or a `sorry` through
   an import fails the gate here, not in a status document."

  -> [INFO] Found 1 soundness-relevant escape hatch(es).
     [ERROR] No docs/proof-debt.md ... but 1 escape hatches exist.

That repo's axiom audit reports [propext, Quot.sound] for all 20 headline
items; there was no hatch. Any repo that documents its own sorry/axiom policy
in a docstring hits this -- i.e. exactly the repos taking the policy most
seriously. The pressure it creates is to declare debt that does not exist,
which is the opposite of what this gate is for.

Fix: strip_lean_noncode() blanks line comments (--), nesting block comments and
docstrings (/- -/, /-! -/, /-- -/) and string literals, preserving line numbers
so reported positions stay accurate. Markers still quote the ORIGINAL line.
Same comment-awareness fix scan-dangerous.sh already carries for Lean.

Failure direction is deliberate: string state is NOT carried across lines, so an
odd quote over-flags rather than blanking the rest of a file. For a soundness
gate, over-flagging is safe; under-flagging is not.

Verified with fixtures -- must catch real holes, must ignore prose:

  line 1  /-! docstring ... `sorry` ... -/          NOT flagged  (was the bug)
  line 2  -- line comment mentioning sorry/axiom     NOT flagged
  line 3  /- /- nested -/ sorry -/                   NOT flagged
  line 4  def s : String := "the word sorry ..."     NOT flagged
  line 5  theorem realHole : True := by sorry        FLAGGED
  line 6  axiom realAxiom : False                    FLAGGED
  line 7  theorem t : True := by sorry -- trailing   FLAGGED
  line 8  theorem fine : True := trivial             NOT flagged

3 found, all genuine. Before this change the same fixture also reported the
four comment/string lines. `bash -n` clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath merged commit bfe7d9d into main Jul 27, 2026
18 of 21 checks passed
@hyperpolymath
hyperpolymath deleted the fix/trusted-base-lean-comment-awareness branch July 27, 2026 13:03
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.

1 participant