Skip to content

fix(core-engine): Rosetta batch 3 wave 2 — doc-comment pairing, rule over-claims, three None rules (#2669) - #2681

Merged
squid-protocol merged 6 commits into
mainfrom
fix/2669-b3-wave2
Sep 3, 2026
Merged

squid-protocol merged 6 commits into
mainfrom
fix/2669-b3-wave2

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Description

Batch B.3 wave 2 of #2669 — the registry-regex fixes that DO move the control corpus. Wave 1 (#2677, merged) was the zero-movement half.

Closes #2672, #2670, #2661, #2671, #2675, #2645, #2646, #2647.

commit issues effect
c4a8e601 #2672 (+#2670, #2661 step 2) doc comment counts once, not once per marker + once per tag — 17 languages
660101d7 #2672 + #2671 apex doc block, @author → ownership, import type-guard restored
28de6f50 #2675 three rules stop counting tokens another rule owns
d79b6350 #2645, #2646, #2647 three None rules wired

One layer only (registry regex), per #2669's stacking rules.

Corpus movement — 12 languages, each with only its intended delta

doc 2 -> 1   java  groovy  kotlin  php  scala  solidity  perl  cobol
import 6->3  apex                    safety_bypasses 4->2  livecode, lua
io 5 -> 3    dockerfile              (fortran withdrawn, see below)

Every mover lands exactly on its planted value. The other 12 languages this PR touches stay green: c, cpp, objective-c, dart, javascript, typescript, swift, csharp, yacc, html, yaml, fortran. na_check --ci: no new unreviewed absences.

The nine corpus-inert doc languages read 1 today only because the corpus plants one of {marker, tag} and never both — the defect was latent, not absent. One ordinary Doxygen block scored doc 4 in c/cpp/objective-c and 3 in java/javascript/typescript.

Two things withdrawn after implementation

fortran is withdrawn from #2675. I filed COMMON in safety_bypasses as an over-claim. test_fortran_strict.py:418 has documented the opposite since #1059 — "an intentional double-classification, not a false collision" — and it is right: a COMMON block lets distinct program units alias the same storage with no type checking, which is genuinely unchecked memory sharing, unlike livecode's scope declaration or lua's table reference. The #2650/#2659 sweep touched that same file for the author-header class and deliberately left COMMON alone. Implementation had renamed the test and inverted its assertion; that was reverted. fortran safety_bypasses 3 vs planted 2 is intended morphology for the ledger.

#2644 (yacc class_start) is pulled — details on its own thread. yacc is absent from detector.py's _CLASS_START_NAMED_EXTRACTION_LANGS, so wiring its class_start would not use the new %union rule at all: it falls through to the legacy generic class|struct|interface|trait|enum fallback, which then claims the 57 bare struct Foo declarations in the embedded C action code of real grammars — measured 17 and 9 phantom classes on the two real .y files, against an honest 0 today. Fixing it means editing the detector allowlist, i.e. the slicer layer, which this PR's one-layer rule excludes. The %union rule itself is validated (1/1 on both real files) and recorded on #2644 for its own PR.

On the three newly-wired rules

docs/GATING.md makes a cell n/a because its rule is None, so wiring one ends the exemption. The corpus contains no srcdoc, no author: and no teardown verb, so all three still measure 0 — and because the manifests already record 0, verify_language.py and rosetta-audit stay green. What changes is the bias report: those cells leave n/a (excluded from medians) and become comparable 0s against medians of 3, 1 and 2. The companion corpus PR plants the idioms so they never surface red.

Cross-repo

Core Engine Modification Checklist

  • Golden Master Verification — pending; scoped diff and bless to follow in this PR.
  • Tri-Comparison Audit — to re-run post-bless.
  • Tree-Sitter Accuracy — to re-run post-bless.

Full extraction suite 6415 passed, 3 skipped, 8 xfailed. ruff format clean on all 46 touched files; ruff check clean on every language file (test-file S101 and one RUF005 are pre-existing on main).

🤖 Generated with Claude Code

squid-protocol and others added 4 commits September 2, 2026 19:02
…once per tag (#2672)

A `doc` rule listing BOTH a doc-comment marker (`/**`, `///`, `=pod`) AND
the tags that live inside it (`@param`, `@return`, `- parameter`, ...) as
independent alternatives counted one comment once per marker plus once per
tag. This is the #2658 shape (python/embedded_python, commit 30a0701),
never swept across the 18 languages that share it.

Fix shape, per language, in alternation order: the bounded non-greedy block
form first (`/\*\*[\s\S]{0,15000}?\*/`, plus objective-c's `/\*!...\*/`),
the line-marker form next (`///` -> `///[^\n]*`), bare tags last so a tag
outside any doc comment still counts -- java's `@Operation`/`@Schema` are
real annotations, not javadoc. perl pairs its POD opener to `^=cut`. cobol
drops `AUTHOR` from the doc header alternation, since `ownership` owns it
exclusively.

Eight languages move to their planted value on the control corpus, each
with a single `doc 2 -> 1` delta and nothing else: java, groovy, kotlin,
php, scala, solidity, perl, cobol. The other nine (c, cpp, objective-c,
dart, javascript, typescript, swift, csharp, yacc) are corpus-inert -- they
read 1 only because the corpus plants one of {marker, tag} and never both,
so the defect was latent, not absent. One ordinary Doxygen block scored
`doc` 4 in c/cpp/objective-c and 3 in java/javascript/typescript.

Since `doc` is a defense term in `_calc_documentation`, this RAISES
`risk_documentation` on tag-heavy real code. That is the intended
direction: documentation mass is already carried by `doc_loc`, so `doc`
counting comments once is the coherent semantic, and it is the one #2658
established for python.

cobol's change corrects two pre-existing tests that encoded the AUTHOR
double-count as intentional. That is the same call #2650/#2659 already made
for ~14 languages -- see `test_abap_doc_vs_ownership_overlap_is_intentional`
being renamed to `..._author_collision_fix` in 6feb8cb -- and cobol is the
last language in that set, which is what #2661 exists to finish.

Corpus rebless is a separate PR. Closes #2670 and #2661 step 2.

Batch B.3 of #2669. Implemented by Claude Sonnet 5, reviewed here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… the import type-guard (#2672, #2671)

#2672 -- apex's share of the doc family: the block form now counts once
instead of once per marker plus once per tag, and `@author` is dropped from
`doc` because `ownership` owns it (the #2659 rule). That removal needs a
companion change: apex's `ownership` required a colon (`@author:`), so
idiomatic ApexDoc `@author Joe` was doc-only and would have been lost
entirely. Only that one alternative is relaxed to colon-optional; the
prose-risky `Author|Copyright|...` alternatives stay colon-required, so
`the Author of this module` still scores nothing.

#2671 -- the `import` rule is compiled `re.IGNORECASE`, which neutralised
the `[A-Z]` guard in its type-reference alternative: it degraded from
"lowercase receiver, capitalised member" to "any word.word", so every
qualified method call counted as an import. Restored with a scoped
`(?-i:[A-Z]\w*)` flag override, which re-enables case sensitivity for just
the member-name class while `Type.forName` and the namespace-exclusion
lookahead stay case-insensitive -- a one-token diff that keeps the single
compiled pattern detector.py expects.

Corpus: `import` 6 -> 3 (its planted value), `doc` stays 1, `ownership`
stays 1. `foo.bar`, `conn.clear` and `Logger.info` no longer count as
imports; `System.debug`/`Database.query` remain excluded by the existing
lookahead, and `Type.forName` still counts.

The two issues are separate rules but the same file and test shape, so they
ship together per #2672's own recommendation. Corpus rebless is a separate
PR.

Batch B.3 of #2669. Implemented by Claude Sonnet 5, reviewed here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…2675)

The #2659 family: a rule claiming a token another rule already owns, or
matching a token in a form too broad to mean what the rule means. Each
lands exactly on its planted corpus value, with the owning rule undisturbed
at its own planted value.

- livecode `safety_bypasses` dropped `global\s+`. `disable messages`,
  `unlock screen` and dynamic `do` are genuine bypasses; `global ` is a
  scope declaration that `globals` owns exclusively. 4 -> 2.
- lua `safety_bypasses` dropped `_G`/`_ENV` (a bare reference to the global
  table, owned by `globals`) and `collectgarbage` (GC control, owned by
  `cleanup`). rawget/rawset/rawlen/debug.*/getfenv/setfenv stay -- those
  really do defeat metatables or the environment. 4 -> 2.
- dockerfile `io`: the bare package-manager names exist to catch a network
  fetch (`apt-get install`), but also matched `RUN apt-get clean` and
  `RUN yum clean all`, which touch no network and no external file --
  `cleanup` owns those exact phrases. Now requires a non-clean subcommand.
  5 -> 3, with all six install forms kept.

fortran was in the filed issue and has been WITHDRAWN, not implemented.
`test_fortran_strict.py:418` has documented since #1059 that `COMMON`
firing both `globals` and `safety_bypasses` is "an intentional
double-classification, not a false collision" -- one of a family from the
same ambiguity sweep, and correct on the language, since a COMMON block
lets distinct program units alias the same storage with no type checking.
That is genuinely unchecked memory sharing, unlike livecode's scope
declaration or lua's table reference. Notably the #2650/#2659 sweep touched
that same test file for the author-header class and deliberately left
COMMON alone. fortran `safety_bypasses` 3 vs planted 2 is therefore
intended morphology for the ledger, not a defect.

Corpus rebless is a separate PR.

Batch B.3 of #2669. Implemented by Claude Sonnet 5; the fortran withdrawal
was caught in review here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
- html `high_risk_execution` (was None): `srcdoc=` embeds a full inline
  document, including <script> content, as a string. It never tripped the
  HANDSHAKE_REGISTRY (whose trigger needs `^[ \t]*<script\b` at a line
  start, not a token inside a quoted attribute) and `io`'s attribute list
  omitted it, so a file that is entirely `<iframe srcdoc="<script>eval(1)
  </script>">` scored 0. Matches the attribute's presence rather than
  sniffing its contents -- the primitive is the risk, as with bare
  eval/exec elsewhere. Per #2645, `on[a-z]+=` and `href="javascript:"` are
  deliberately NOT routed here; they are already correctly claimed by
  listeners/reflection_metaprogramming/safety_bypasses.
- yaml `ownership` (was None): the `author:` / `contact:`-block idiom of
  action.yml and OpenAPI `info.contact`.
- yaml `cleanup` (was None): shell-embedded teardown verbs inside run:/
  script: blocks. Its root-path exclusion is widened from the issue's
  sketch so that `rm -rf /2` no longer matches BOTH cleanup and
  high_risk_execution -- the latter explicitly claims any `/` not followed
  by a letter, pinned by its own existing regression test. The two rules
  are now exact complements. Also covers the space-separated
  `docker compose down`, which the issue named in prose but not in its
  illustrative regex.

These are corpus-visible even though they plant no keyword: GATING.md makes
a cell n/a BECAUSE its rule is None, so wiring one ends the exemption. The
control corpus contains no `srcdoc`, no `author:` and no teardown verb, so
all three still measure 0 -- the manifests already record 0, so
`verify_language.py` and `rosetta-audit` stay green. What changes is the
bias report: the cells leave n/a (excluded from medians) and become
comparable 0s against medians of 3, 1 and 2. The paired corpus PR plants
the idioms so they never surface red; the screened plant text is in its
description.

#2644 (yacc class_start) was the fourth issue of this shape and has been
PULLED -- see its own thread. yacc is absent from detector.py's
_CLASS_START_NAMED_EXTRACTION_LANGS, so wiring its class_start would not
use the new %union rule at all; it would fall through to the legacy generic
`class|struct|interface|trait|enum` fallback and claim the 57 bare
`struct Foo` declarations in the embedded C action code of real grammars
(17 and 9 phantom classes on the two real .y files). Fixing that means
editing the detector allowlist -- the slicer layer -- which #2669's
stacking rule keeps out of a registry-regex PR.

Batch B.3 of #2669. Implemented by Claude Sonnet 5, reviewed here.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

squid-protocol and others added 2 commits September 2, 2026 19:16
Blessed after a scoped-diff review, with user sign-off. All 710
differences attribute to the 17 languages this branch changes, plus
aggregate rows -- zero unexplained:

  cobol 207   php 93   lua 52   perl 42   typescript 31   java 28
  apex 20   scala 20   solidity 19   javascript 13   groovy 13
  swift 6   c 5   cpp 4   kotlin 4   html 3   dart 2
  aggregates 148

cobol dominates because dropping AUTHOR from `doc` (#2672, #2661 step 2)
fires on every real COBOL file carrying an AUTHOR paragraph, and a lower
`doc` raises risk_documentation, which ripples into the exposure rows.
That is the intended direction: `doc` is a defense term in
_calc_documentation and was inflated by tag/marker double-counting.

Unlike wave 1 there are ZERO topological coordinate diffs. Consistent:
wave 1 changed func_start, which changes function counts and therefore
structural mass, re-solving the 3D layout corpus-wide. Wave 2 changes
doc/import/safety_bypasses counts, which feed the risk formulas but not
mass, so nothing moves in space.

Scoping note for the next bless: attributing by DIRECTORY name
under-attributes. A first pass left 15 stragglers that were really
`.CBL` (uppercase), an extensionless `exiftool` perl script, and a
`Jenkinsfile` -- the same directory-vs-language trap as `.gradle` and
objective-c. Attribute by the file's actual language, not its folder.
The diff itself came from regenerating the audit and running
golden_diff.deep_compare directly, since crucible_check.py surfaces
only ~28 of 710 (documented in CLAUDE.md as of #2680).

Batch B.3 of #2669.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…aim it (#2645)

Follow-on to this branch's own #2645 change, found while planting the
corpus idiom that `high_risk_execution` now measures.

`srcdoc` is an iframe-only attribute, and `io`'s bare-tag alternative
claimed `<iframe` unconditionally -- so planting the srcdoc that
high_risk_execution needs would have pushed html's io from its planted 3
to 5, trading one out-of-band cell for another and leaving the corpus no
better off.

Excluding srcdoc-bearing iframes is not a workaround, it is the correct
reading: such a frame performs no I/O at all, its document is inline, and
per the HTML spec `srcdoc` overrides `src` when both are present. A real
fetch (`<iframe src=...>`) is untouched, and an explicit `src=` attribute
keeps counting through the attribute alternative either way.

Both corpora are unmoved by the rule change itself (crucible html io
362 -> 362, rosetta 3 -> 3) -- neither contained an iframe. With the
companion corpus plant, html's high_risk_execution reaches its planted 2
while io holds at its planted 3.

This supersedes a test added earlier in this same branch that framed the
overlap as an intentional double-classification by analogy with yaml's
`curl ... | bash`. The analogy does not hold: there the curl genuinely
fetches, so both signals are true at once; here the frame fetches nothing.
The test now pins the corrected behaviour and says why.

Batch B.3 of #2669.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@squid-protocol
squid-protocol marked this pull request as ready for review September 3, 2026 00:08
@squid-protocol

Copy link
Copy Markdown
Owner Author

Cross-repo step 3 done: keyword-rosetta#35 merged (216d57abf731477014edde452e03089d3e148f64) and KEYWORD_ROSETTA_REF bumped to that full 40-character SHA. Re-running rosetta-audit, which should now go green — the corpus at that commit carries the reblessed manifests these fixes produce.

One item still owed on the corpus side: #35 merged with ENGINE_REF still set to pull/2681/head, so keyword-rosetta main is currently pinned to this branch rather than to engine main. Resetting it right now would turn that repo red, because engine main does not yet contain these fixes and the reblessed manifests would fail against it. So the reset follows immediately after this PR merges, as its own one-line PR. Tracked here so it is not forgotten — a stale ENGINE_REF on main silently builds every future corpus PR against a frozen engine ref.

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.

doc rules count one doc comment once per marker AND once per tag — 18 languages, 8 red rosetta cells (the #2658 shape, unswept)

1 participant