Repository navigation
Description
Summary
Prism's copy of the handshake registry compiles its triggers without re.M
(prism.py —
re.compile(trigger_config["trigger"], re.I)), while StructuralExtractor's copy compiles the
same patterns with re.I | re.M (detector.py, and #1183's comment says why: "re.M is required
for the ^ anchor to match at the start of any line rather than only the start of the whole file
— without it, a genuine mid-file <script> (the normal case) would never match either").
Every registry trigger is ^-anchored (^[ \t]*<script\b, ^[ \t]*<style\b,
^[ \t]*(?:asm!\s*\(|__asm__)), so Prism's _partition_embedded_languages only ever fires on a
file whose very first byte opens the block. In every real file the embedded segment is never
formed, and the whole file is comment-stripped with the host language's rules.
#1183 fixed exactly this drift in the other direction (detector's copy had lost the ^ anchor);
the re.M half of the pair was never applied to Prism.
Evidence (micro-repro)
Identical <script> block, once at offset 0 and once where it normally lives:
mid = '<html>\n<body>\n<script>\n// eval("nope");\nvar x = 1;\n</script>\n</body>\n'
top = '<script>\n// eval("nope");\nvar x = 1;\n</script>\n'code_stream keeps the JS comment? |
comment_stream |
coding/doc LOC | recorded signals | |
|---|---|---|---|---|
| mid-file | yes — // eval("nope"); |
'' |
7 / 0 | high_risk_execution: 1 ← false positive |
| offset 0 | no | // eval("nope"); |
3 / 1 | — |
The commented-out eval( is counted as executable risk in the normal case and correctly ignored
in the degenerate one. html's own block_exclusive <!-- --> rules are what ran over the
JavaScript body.
Impact
- Comment/code stream misattribution. On the pinned
language-cruciblecorpus, 12 of the 38
html files carry 55 JavaScript//lines that survive intocode_stream.doc_locis
derived astotal_active_lines - coding_loc, so each one is counted as code and subtracted
from documentation. Worst:vscode_webviews/webWorkerExtensionHostIframe.html(14),
revealjs_decks/math.html(10),revealjs_decks/demo.html(8). - False signals from commented-out code, as above — the detector's own partition is correct,
but it runs over acode_streamthat Prism never cleaned. - Affects any host language with a line-anchored handshake: html/php
<script>/<style>, and
Rust/Casm!(/__asm__.
Not blocking anything today: it is orthogonal to #2549 (which is about which segment the tag
belongs to, in a partitioner that does run), and the fix is a corpus-wide re-bless of its own —
which is why it is filed rather than folded into that PR.
Fix shape
Add re.M to Prism's trigger compilation so the two copies agree, or better, derive both from one
place the way #1183 made the detector derive its registry from LENS_CONFIG — the two partitioners
have now drifted twice on the same three patterns. Then re-bless both golden masters; expect the
diff to be concentrated in Coding LOC/Documentation LOC and in signals that were reading
commented-out embedded code.
References
- Mid-file language-switching (_partition_segments) can be permanently misled by a string literal that merely contains embedded-language delimiter text #1183 (the same drift, fixed in
detector.py), Lua: polyglot segmentation splits a function when a [[ ]] long string contains embedded HTML/CSS/JS #2440 (the Lua-masking pair, correctly applied to both) - Found while fixing html func_start is unreachable end-to-end: the polyglot splitter consumes <script>/<style> tags before html's rules run #2549;
tests/core_engine/test_handshake_issue_2549.py::test_both_partitioners_move_the_same_boundarydocuments the asymmetry in a comment and works around it.
Activity
squid-protocol commentedon Sep 10, 2026
PR #2943 open (CI running). Two notes beyond the issue as filed:
A third copy.
language_lens.pycompiles the same registry too, also withre.Ialone — so_detect_hybridsonly ever reported a polyglotlang_mixfor the degenerate offset-0 file. The fix takes the issue's "better" option (one source):_lens_config.COMPILED_HANDSHAKE_REGISTRY, shared by all three, with a test pinning the identity so a fourth copy cannot appear.No corpus re-bless is owed. The issue expected one;
rosetta_auditreads 46/46 with 0 regressions. The manifests gate planted signal counts, and none move — the redistribution is entirely in derived LOC columns, which live in the bias report and regenerate on their own schedule. Reachability scan over both corpora: rosetta has mid-file triggers in html only; the crucible adds groovy, php, lua, c and zig.Golden diff is 194 substantive cells across html (101) and groovy (36): 11 html files move 64 JavaScript
//lines out ofCoding LOCintoDocumentation LOC, conserved per file. The groovy case is worth one reviewer's look and is described in the PR — gradle'sEnrichedReportRendereremits injected JavaScript from a triple-quoted string, and its ~61 lines of real JS logic had been recorded as documentation.