Repository navigation
Description
Batch B.1 of #2669 (child of epic #2560). Filed by a T1 session; implementation is B.3 (T2), bless is B.5 (T1).
The defect
A doc rule that lists both a doc-comment marker (/**, ///, =pod) and the doc tags
that live inside that marker's block (@param, @return, - parameter, …) as independent
alternatives counts one doc comment once per marker plus once per tag.
This is exactly the shape fixed for python/embedded_python in #2658 (paired """ delimiters
into one bounded span). It was never swept across the other languages that carry it.
Post-Batch A (keyword-rosetta 357345f, the pin KEYWORD_ROSETTA_REF currently points at), the
rosetta corpus plants exactly one doc construct per language, so doc should be 1 everywhere.
Eight languages read 2:
| language | planted construct | matches today |
|---|---|---|
| java | /** @param argv probe input */ |
/** + @param |
| groovy | /** @param argv probe input */ |
/** + @param |
| kotlin | /** @param argv probe input */ |
/** + @param |
| php | /** @param $argv probe input */ |
/** + @param |
| scala | /** @param argv probe input */ |
/** + @param |
| solidity | /// @param flag the probe input |
/// + @param |
| perl | =pod … =cut |
=pod + =cut (#2670) |
| cobol | AUTHOR. + *> @return |
AUTHOR. is claimed by doc and ownership (#2661 step 2, the #2659 shape) |
Verified by running each language's live doc rule over the real prism.split_streams() output
for its corpus files — the raw match lists above reproduce docs/bias_data.json doc exactly
(8 languages at 2, the other 38 at 1). doc is counted in both coding_analysis (per segment, over
code_stream) and comment_analysis (over comment_stream), both len(finditer(...)), so
non-overlapping alternation is what decides the count.
It is much worse off-corpus
The corpus only plants one of {marker, tag} in the other family members, which is the sole
reason they read 1 — not because their rule is right. One ordinary Doxygen/JSDoc/ApexDoc block:
/** @brief do it
* @param x in
* @return out
*/| language | doc for that one comment |
|---|---|
| c, cpp, objective-c, apex | 4 |
| java, javascript, typescript | 3 |
| dart, yacc | 2 |
swift (/// - parameter + /// - returns:) |
4 for a 2-line comment |
solidity (/// @notice + /// @param) |
4 for a 2-line comment |
So this is a real-repo scoring defect, not a corpus artifact: every well-documented C/C++/Java/TS
file has been scoring doc proportional to tag density rather than doc-comment count. Since
doc is a defense term in _calc_documentation
(gitgalaxy/metrics/signal_processor.py ~L1499, doc_weight 1.0, alongside doc_loc at 0.33),
the effect is a silently deflated risk_documentation for tag-heavy code. Documentation mass is
already carried by doc_loc; doc counting comments once is the coherent semantic, and it is the
one #2658 already established for python (a docstring with three :param: tags counts 1 today).
Correct precedent already in the registry — ada, assembly, haskell and livecode fuse marker and
tag into a single alternative (--[ \t]*(?:@param|@return|…)), so they cannot double-count. css and
sqlite are safe for the same reason. rust and zig list markers only, no tags.
Fix shape
Per language, in this alternation order:
- Block form first —
/\*\*[\s\S]{0,15000}?\*/(and objective-c's/\*![\s\S]{0,15000}?\*/),
so the whole block including its tags is one hit. Identical bound and non-greedy body to python/embedded_python: doc rule counts each docstring twice (open and close delimiters both match, no pairing) #2658. - Line-marker form next —
///→///[^\n]*, so/// @param xis one hit, not two. - Bare tags last, unchanged, so a tag outside any doc comment still counts (java's
@Operation
/@Schemaare real annotations incode_stream, not javadoc). - Remove the tag that
ownershipalready owns (the livecode (+~14 siblings): doc rule claims 'Author:' which ownership already owns — every header author line double-counts (ada has the correct pattern) #2659 rule): dropAUTHORfrom cobol's
docheader alternation, and@authorfrom apex's.
perl (#2670) takes the same treatment in POD vocabulary — pair the opener to ^=cut:
^=(?:pod|head[1-6]|item|over|back|begin|end|encoding|for)\b[\s\S]{0,15000}?^=cut\b
|^=(?:pod|head[1-6]|item|over|back|begin|end|encoding|for)\b
apex needs one extra half-step. Its doc and ownership both list @author, but ownership
requires a colon (@author:\s+), so idiomatic ApexDoc @author Joe is doc-only (doc 3, ownership 0)
while @author: Joe double-counts. Dropping @author from doc alone would lose the bare form
entirely, so relax that one alternative to colon-optional, leaving the prose-risky
Author|Copyright|… alternatives colon-required:
(?:@author:?\s+|(?:Author|Created by|Maintainer|Copyright|Tim Berners-Lee):\s+)([^\n]+)
Checked: @author Joe → doc 1 / own 1; @author: Joe → doc 0 / own 1; the corpus's
// Author: … → doc 1 / own 1 (unchanged); prose the Author of this module → 0 / 0.
Explicit non-goal. A run of consecutive /// lines still counts once per line (csharp and rust
score 2 for a 2-line /// comment before and after). Folding runs into one comment would move every
/// language with no corpus signal to validate against, and it is a separate semantic decision —
leave it, and ledger it if it ever surfaces as a cell.
Prototype result
Candidate patterns for all 18 family members (the 8 above plus c, cpp, objective-c, dart, javascript,
typescript, swift, yacc, csharp) run over the full 46-language corpus through prism.split_streams,
both streams:
- Exactly 8 languages move, all 2 → 1: cobol, groovy, java, kotlin, perl, php, scala, solidity.
- 36 languages unchanged. No
doccell moves anywhere else in the corpus. - Every language then reads the planted
doc= 1 — the wholedoccolumn goes green. - Idiomatic-snippet recheck: c/cpp/objective-c/apex 4 → 1, java/javascript/typescript 3 → 1,
dart/yacc 2 → 1, swift 4 → 2 and solidity 4 → 2 (two///lines, per the non-goal above).
ReDoS detonation on the new quantified alternatives, 200k+ chars of never-terminated input:
java candidate 0.0062s, solidity candidate 0.0062s, perl candidate 0.0020s. Safe — bounded and
non-greedy, same profile as #2658's probe. Unterminated blocks now fail closed (no match) instead of
counting the opener, which is #2658's accepted trade-off.
Caveat worth carrying into B.3: comment_stream is a concatenation of a file's comments, so a
malformed unterminated /** can pair with a later block's */ within the 15000-char bound. Same
property python has had since #2658; bounded, and only reachable on malformed input. For perl the
POD hits land in code_stream, which is segmented — pairing assumes a POD block does not straddle a
segment boundary.
Scope for B.3 / B.5
- Registry-regex layer only. No slicer, DAG or scoring change — keeps Rosetta to green: cause-first batch plan + multi-session coordination (child of #2560) #2669's one-layer-per-PR rule.
- Strict tests in
tests/extraction/languages/test_<lang>_strict.py(all 18 targets already have a
_strictfile except c, cpp, csharp, dart, objective-c, swift, typescript, yacc — those get one):
positive (one doc comment = 1), negative (a tag outside any doc comment still counts), and a ReDoS
timing probe per new quantified pattern. - B.5 bless: expect
risk_documentationto rise on real repos with tag-heavy doc comments — the
defense term was inflated. That is the intended direction, and the golden-master diff should show
it only wheredocmoved. - Closes-with: perl doc: a correctly-closed POD block counts twice (=pod + =cut) — the #2658 delimiter shape #2670 (perl) and cobol: doc rule's AUTHOR-vs-ownership collision needs a corpus-side doc line planted before the engine fix (#2659 follow-up) #2661 step 2 (cobol) are members of this family and should be
closed by the same PR. apex import rule: re.IGNORECASE neutralises the [A-Z] guard, so every qualified reference (foo.bar) counts as an import #2671 (apeximport/re.IGNORECASE) is a different rule but the same
one-regex/one-test shape and the same apex file, so B.3 should carry it in the same PR. - Corpus side: cobol re-blesses
doc2 → 1, retiring ledgercobol-2661-author-doc-collision; perl
retiresperl-pod-delimiter-double-count. Both arestill_reproduces: truetoday.
Activity
chore(crucible): re-bless golden masters for the B.3 wave-2 regex batch
fix(core-engine): Rosetta batch 3 wave 2 — doc-comment pairing, rule …