Skip to content

Fix #621: standard_block comment stripping corrupted 5 languages (and my first attempt broke 24 others) - #625

Merged
squid-protocol merged 1 commit into
mainfrom
fix-standard-block-delimiters
Jul 26, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix-standard-block-delimiters

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

The bug (#621)

sqlite, lua, haskell, powershell, and perl were all classified lexical_family: "standard_block", but that family's shared regex only used C-style ////* */ delimiters. None of these 5 languages use those -- they got zero comment/code separation at all, confirmed empirically against the real config before this fix. Notably, each of these 5 languages' own source comment already named the family it was supposed to be in ("Maps to Family 5 (Hybrid Dash)", "Family 4 (Hybrid Hash)", "Family 6 (Polyglot)") -- the lexical_family value just never matched, the same class of drift as the python/json copy-paste bug found while scaffolding the per-language test issues.

First attempt was wrong -- caught by the golden crucible

My first fix added all 9 of standard_block's configured delimiter tokens to its one shared regex. That's what #621 itself proposed, and it's wrong: standard_block covers 29 languages sharing one compiled regex, and -- is a decrement operator / # is a preprocessor directive in C-family languages, not a comment marker. The shared regex started swallowing real C++ code:

while (i-- > 0) { ... }   ->  everything from `i` onward treated as a comment
#include <vector>          ->  treated as a comment entirely

The golden-crucible regression test caught this immediately -- a real C++ file's import/cast/macro counts collapsed to 0. Reverted before it ever got committed.

The actual fix: split into sub-families, don't share one regex across incompatible conventions

  • multi_style_dash (sqlite, lua): -- line comments, plus /* */ and --[[ ]] block forms.
  • embedded_syntax (powershell): # line comments, plus <# #> blocks.
  • recursive_block_haskell (haskell): -- line, {- -} block -- reuses the existing iterative inside-out peel algorithm (recursive_block, used by Rust/Swift/Dart/Scala) with Haskell's own tokens, since Haskell's blocks genuinely nest (its own comment said so explicitly). Confirmed nested {- {- inner -} outer -} now peels correctly, inside-out.
  • perl moved to the existing line_exclusive family -- needed no new family at all, since that family already leads with #. Its fuller "Polyglot" vision from the original comment (POD blocks, =head/=cut) is a known, separate, unfixed gap -- noted in the source, not solved here.

Also fixed a stale comment at the top of gitgalaxy_config.py that claimed LEXICAL_FAMILY_HEURISTICS isn't what drives comment/code separation -- confirmed via galaxyscope.py that it's exactly what gets passed into Prism.

Golden master fixtures

Updated both tests/golden_master_audit.json (full-precision) and tests/golden_master_zero_dep_audit.json (zero-dependency) via the sanctioned tests/tools/update_golden_master.py, after manually reviewing the diffs in both modes:

  • Direct, large corrections for the 5 fixed languages' directories in the crucible corpus (e.g. one SQL-heavy directory's Cognitive Load Exposure dropped from 84.99% to 5.0% -- comments were previously being scored as risky code).
  • Expected ripple in global aggregates that reshuffle whenever any file's score changes anywhere (leaderboard "top 10" reordering, corpus-wide z-score-normalized averages) -- confirmed these are small/negligible for unrelated languages, not signal corruption.
  • Zero "Expected N, Got 0" collapse patterns anywhere outside the 5 target languages (the exact shape of corruption the first, rejected attempt produced).

Test plan

  • pytest tests/ -- 916 passed
  • python tests/ruff_audit.py --ci -- clean (148-finding baseline, no new)
  • python tests/mypy_audit.py --ci -- clean
  • ruff format --check on all modified source files
  • pytest -m golden_crucible passes in both full-precision and zero-dependency venvs
  • New tests in test_prism.py: line + block comments for all 5 languages against the real config, Haskell nesting correctness, C-family (cpp/c/javascript) unaffected including the specific decrement-operator/preprocessor case that broke in the first attempt, string-literal shielding for the new dash/hash patterns

Closes #621.

🤖 Generated with Claude Code

…ne regex

sqlite/lua/haskell/powershell/perl were classified "standard_block" but
don't use its C-style // and /* */ delimiters -- they got zero comment
stripping (empirically confirmed against the real config). Each language's
own comment even already said which family it was SUPPOSED to be in
("UPGRADED: Maps to Family 5 (Hybrid Dash)", "Family 4 (Hybrid Hash)",
"Family 6 (Polyglot)") -- the lexical_family VALUE just never matched,
same class of drift as the python/json copy-paste bug found earlier.

The first attempted fix (add all 9 of standard_block's configured
delimiter tokens to its one shared regex) was rejected after the golden
crucible caught it: `--` is a decrement operator and `#` is a preprocessor
directive in C-family languages, not a comment marker, so a shared regex
corrupted real code (`i-- > 0` and `#include <vector>` both got swallowed
into the comment stream, collapsing real signal counts to 0 for an
affected C++ file in the crucible corpus).

Fixed properly instead, by giving incompatible conventions their own
families so no regex is ever shared across them:
- multi_style_dash (sqlite, lua): -- line, plus /* */ and --[[ ]] blocks.
- embedded_syntax (powershell): # line, plus <# #> block.
- recursive_block_haskell (haskell): -- line, {- -} block -- reuses
  recursive_block's iterative inside-out peel algorithm (Rust/Swift/Dart/
  Scala) with Haskell's own tokens, since Haskell's blocks genuinely nest
  (confirmed: nested {- {- inner -} outer -} now peels correctly).
- perl moved to the existing line_exclusive family (needed no new family
  at all; its full "Polyglot" POD-block vision from the original comment
  -- =head/=cut -- remains a known, separate, unfixed gap).

Also fixed a stale top-of-file comment in gitgalaxy_config.py claiming
LEXICAL_FAMILY_HEURISTICS isn't what drives comment/code separation --
confirmed via galaxyscope.py that it's exactly what's passed into Prism.

Golden master fixtures (both full-precision and zero-dependency) updated
via the sanctioned tests/tools/update_golden_master.py, reviewed before
blessing: all drift traces to the 5 corrected languages plus expected
global-ranking/z-score ripple (leaderboard reordering, one flagged-artifact
count dropping by exactly 1 from a resolved false-positive). No direct
signal-count corruption for any unrelated language in either fixture.

Full suite (916 tests), ruff audit, mypy audit, and both golden-crucible
modes all pass.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit b71ff49 into main Jul 26, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the fix-standard-block-delimiters branch July 26, 2026 16:03
squid-protocol added a commit that referenced this pull request Jul 26, 2026
#627)

Fills the remaining gaps #622 called out, on top of what #625 already
covered for the standard_block split:

- block_exclusive (xml) and non_lexical (plaintext) now have a dedicated
  real-config test, not just the existing mock-based bypass test. Also
  added a test documenting a latent (not live) gap: neither family has an
  entry in _compile_regex_matrix()'s branch list, so a FUTURE language
  assigned either family without also being added to split_streams()'s
  hardcoded "prose bypass" list would silently get zero comment stripping
  -- same failure shape as #386/#621, just not triggered by anything in
  the real config today.
- ReDoS immunity tests against the REAL compiled patterns for
  standard_block/multi_style_dash/embedded_syntax/line_exclusive/
  recursive_block_haskell (previously only the mock-config branch-selection
  logic and the unrelated suppression-tag regex had pathological-payload
  coverage).
- String-literal shielding tests for haskell and powershell, extending the
  one #621 added for lua to the other two new families.

Full suite (920 tests), ruff audit, mypy audit, and both golden-crucible
modes pass. No source changes -- test-only, so the golden master fixtures
are untouched.

Closes #622.

Co-authored-by: Joe Esquibel <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant