Skip to content

fix(engine): the markup handshake's open tag belongs to the host (#2549) - #2847

Merged
squid-protocol merged 1 commit into
mainfrom
fix/2549-html-script-func-start
Sep 7, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/2549-html-script-func-start

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Closes #2549.

The bug

The polyglot splitter handed the whole <script …> … </script> element to the JavaScript
lens — opening tag included — and the same for <style>/CSS. Both partitioners did it
(Prism._partition_embedded_languages for the streams, StructuralExtractor._partition_segments
for the counts), and coding_analysis only ever runs a language's rules over the segments left to
that language. So html's func_start, whose only anchor is that tag, matched the raw file and
could never fire once the splitter had run: all 38 corpus html files recorded func_start = 0, and
the rule passed its direct-detector unit tests while being dead in every real scan.

The fix

The handshake's opening delimiter belongs to whichever language wrote it. <script defer> is html;
only what follows the > is JavaScript. The two markup entries in HANDSHAKE_REGISTRY now declare
an open_delimiter (_lens_config.MARKUP_OPEN_TAG_TAIL), and both partitioners end the host
segment at the tag's own > instead of at the trigger:

before   html: "…<body>\n"            js: "<script>var x = 1;</script>"
after    html: "…<body>\n<script>"    js: "var x = 1;</script>"
  • MARKUP_OPEN_TAG_TAIL skips quoted attribute values, so <script data-tpl="a>b"> is not cut
    short. Its three alternatives are disjoint on the first character, so the star cannot
    re-partition a prefix — linear, no backtracking ambiguity.
  • An unterminated tag (or one longer than the lookahead limit) resolves to nothing and falls back
    to the pre-html func_start is unreachable end-to-end: the polyglot splitter consumes <script>/<style> tags before html's rules run #2549 boundary, so no input can land the split mid-attribute.
  • The paired-bracket handshake (asm!() deliberately declares no open delimiter:
    _find_balanced_end counts depth from the opening bracket, so that bracket has to stay inside
    the embedded segment.
  • The closing </script> stays with the embedded segment; nothing in html's rule set matches it,
    and moving it would churn the fixtures for no measured gain.

What moved, and why

crucible_check.py / scope_check.py --expect html,php,… vs origin/main: 291 differences,
html 251, php 5, 35 repo-wide rollups.
Attribution, all of it one cause:

shape count why
func_start (Function/Method Declarations) 38 files the reported bug — the tag is finally in html's segment
io, import, api, events, ssr_boundaries, telemetry, args, dependency_injection 51 the same tag carries src=, id=, name=, on*=, framework attributes — every html rule anchored on the tag was equally dead, which the issue predicted ("any signal whose only html anchor is the script/style tag has the same exposure")
css globals +1 (php/wordpress/wp-login.php) 1 the correction runs both ways: an inline block's own first statement was invisible to any line-anchored embedded rule while the host's tag sat in front of it. ^[ \t]*(?::root|html|body|\*) never saw the html{…} in <style>html{background-color: transparent;}</style>
javascript state_mutation −1 (revealjs_decks/math.html) 1 a false positive removed: JS's rule was matching ; mode= inside <script type="math/tex; mode=display">
spec_match 0% → 100% 29 derived, not a new measurement: _calc_spec_alignment returns 0 when func_start + class_start == 0 (#2655's "nothing to specify" guard), so these files were scoring the empty-file value. They have entities now and no [SPEC-n] tags, which is 100% exposure — the same reading every other language gets
php function LOC ±1 4 a <script> line inside a php function's body now belongs to the php segment
Structural Magnitude / X-Y-Z / health rollups the remainder mass changed, so the layout re-solves corpus-wide

Function extraction is unchanged. No html file's 5. Function Analysis moved: html's
function_data is still the embedded functions the JS lens finds inside the block, which is what
tree_sitter_accuracy_audit.py compares against. functions_found for html therefore stays 0 on
the control corpus — the probe bodies are empty by design, which is keyword-rosetta's own separate
decision (html-probe-bodies-are-empty-by-design), not this fix's business.

Verification

  • tests/core_engine/test_handshake_issue_2549.py — 9 new cases: the boundary in both
    partitioners, <style>, the quoted-> attribute, the unterminated-tag fallback, asm!(
    unchanged, the issue's own micro-repro end to end, the script body still reaching the JS lens,
    and Non-executable <script type=...> blocks: audit walk over-counted (fixed), html func_start over-anchors (open) #2492's non-executable type still raising nothing (its negative lookahead now runs where it
    always meant to).
  • pytest tests/ — 8022 passed, 0 failed.
  • ruff_audit.py --ci, mypy_audit.py --ci, audit_check.py --regenerate — clean.
  • Both golden masters re-blessed via crucible_check.py --update --yes after the uncapped diff
    above was scoped.
  • tri_comparison_chart.py --all --ci and tree_sitter_accuracy_audit.py --ci --all — see below.

Cross-repo

keyword-rosetta owes the paired re-bless (rosetta:rebless-owed): html's manifest bakes
func_start 0 on four files and the ledger carries html-script-func-start-unreachable. The
corpus PR flips that entry to still_reproduces: false, re-blesses func_start to 2/3/1/3 (the
nine <script> tags), and records the live cause of nine-against-the-SPEC's-thirteen as
html-func-start-counts-script-elements. It opens after this merges, per the no-pins flow.

Found on the way out, filed separately, deliberately not fixed here: Prism's copy of the
handshake registry compiles its triggers with re.I only, where the detector adds re.M — so
Prism's partition never fires on a mid-file <script>, and an embedded block is comment-stripped
with the host's rules. A // eval("nope"); line inside a mid-file <script> records
high_risk_execution: 1; the identical block at offset 0 records nothing.

@squid-protocol squid-protocol added core-engine Modifications to the central physics and parsing engine rosetta:rebless-owed Intentionally moves keyword-rosetta counts; audit warns, corpus re-blesses after merge labels Sep 7, 2026
The polyglot splitter handed the whole `<script ...> ... </script>` element to
the JavaScript lens, opening tag included, and the same for `<style>`/CSS. Since
`coding_analysis` only runs a language's rules over the segments left to that
language, html's `func_start` -- whose only anchor IS that tag -- matched the raw
file but could never fire once the splitter had run: all 38 corpus html files
recorded `func_start = 0` while the rule passed its direct-detector unit tests.

The handshake's opening delimiter belongs to whichever language wrote it. The two
markup entries now declare an `open_delimiter` (MARKUP_OPEN_TAG_TAIL) and both
partitioners end the host segment at the tag's own `>`, so only the payload goes
to the embedded lens. Quoted attribute values are skipped (`<script data-tpl="a>b">`
is not cut short) and an unresolvable tag falls back to the pre-#2549 boundary.
`asm!(` declares no open delimiter on purpose: `_find_balanced_end` counts depth
from the opening bracket.

`func_start` was the reported symptom; the tag also carries `src=`, `id=`, `name=`,
`on*=` and framework attributes, so io/import/api/events/ssr_boundaries/telemetry/
args/dependency_injection gained them too. The correction runs both ways: css's
line-anchored `globals` finally sees the `html{...}` opening an inline `<style>`
block, and JavaScript's `state_mutation` stops matching `; mode=` inside
`<script type="math/tex; mode=display">`. Function extraction is unchanged -- no
html file's function list moves.

Both golden masters re-blessed: 291 differences, every one attributed above or a
mass/topology ripple of it (`spec_match` 0% -> 100% on 29 html files is #2655's
"nothing to specify" guard correctly no longer firing).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@squid-protocol
squid-protocol force-pushed the fix/2549-html-script-func-start branch from ac19bf5 to a29e5fd Compare September 7, 2026 14:43
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit fb0a8cc into main Sep 7, 2026
32 checks passed
@squid-protocol
squid-protocol deleted the fix/2549-html-script-func-start branch September 7, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-engine Modifications to the central physics and parsing engine rosetta:rebless-owed Intentionally moves keyword-rosetta counts; audit warns, corpus re-blesses after merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

html func_start is unreachable end-to-end: the polyglot splitter consumes <script>/<style> tags before html's rules run

1 participant