Skip to content

fix(perl): give perl its own brace-safe-stream shielding instead of falling through to C-family rules - #1458

Merged
squid-protocol merged 1 commit into
mainfrom
fix/perl-1437-qr-brace-shield
Aug 13, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/perl-1437-qr-brace-shield

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #1437. func_start recall for perl was 70.6% (710/1005). Root cause: perl was falling
through to _build_brace_safe_stream's generic C-family shielding, which shields // as a line
comment and /* */ as a block comment -- neither exists in perl (// is the defined-or
operator). Worse, the generic double/single-quote patterns are unbounded, so a stray escaped quote
inside an unrelated s/.../.../ substitution regex (not a real string delimiter) could pair with
the next unrelated escaped quote anywhere later in the file as a bogus "string", silently
swallowing a { in between and desyncing brace-depth counting for every function after that
point. Confirmed exact repro: language-crucible/data/perl/bugzilla/CGI.pm's s/^\"//g; paired
with s/\"$//g; ~15 lines apart.

Two failed attempts first

Two Gemini/agy dispatches on this issue both failed -- each fixed only the narrower
qr{...}-shielding symptom the issue's own original framing focused on, missing this broader
generic-shield mismatch. Both produced a measurably brace-imbalanced shield output (confirmed via
direct open/close brace counting) and were correctly never committed, caught by the dispatching
subagent's own independent verification each time. Root-caused directly after the second failure
rather than dispatching a third attempt -- the lesson being that a diagnosis wrong at the root
doesn't get fixed by retrying the same narrow framing with tighter guardrails.

Fix

Perl gets its own combined_pattern branch in _build_brace_safe_stream (proper #-comment
handling, no //, no /* */, both quote patterns bounded to {0,200} chars -- same idiom as the
existing rust single-quote / scala backtick bounds already in this function) plus a separate pass
for perl's brace-delimited quote-like operators (qr{}/m{}/s{}{}/tr{}{}/y{}{}/q{}/
qq{}/qw{}/qx{}), reusing the existing _find_balanced_end helper instead of a new
hand-rolled depth counter (which is exactly what went wrong in both failed attempts).

Results

metric before after
found_functions 710 937 (of 1005 real)
extra_functions 1 1 (unchanged)
func recall 70.6% 93.2%

Zero new false positives -- the biggest recall win in this round of fixes.

Test plan

  • tests/extraction/languages/test_perl.py / test_perl_strict.py -- 102 passed (new
    pipeline-level regression test covers both the s/.../.../ cross-pairing repro and the
    qr{} internal-brace case)
  • tree_sitter_accuracy_audit.py --lang perl --regenerate + --summary-table
  • tree_sitter_accuracy_audit.py --all --ci -- all 31 languages clean
  • crucible_check.py --mode both -- both golden masters blessed (large expected diff from
    +227 found functions), re-verified clean after
  • audit_check.py --ci --regenerate -- ruff/mypy/dead-key/ast-accuracy all clean (caught and
    fixed a real mypy union-attr finding on the new code, plus a ruff format pass)

🤖 Generated with Claude Code + Gemini (Antigravity CLI)

@squid-protocol
squid-protocol enabled auto-merge (squash) August 13, 2026 16:16
…alling through to C-family rules (#1437)

perl was falling through to the generic C-family combined_pattern in
_build_brace_safe_stream, which shields `//` as a line comment and
`/* */` as a block comment -- neither exists in perl (`//` is the
defined-or operator). Worse, the generic double/single-quote patterns
were unbounded, so a stray escaped quote inside an unrelated s/.../.../
substitution regex (not a real string delimiter) could pair with the
next unrelated escaped quote anywhere later in the file as a bogus
"string", silently swallowing a `{` in between -- confirmed exact repro:
CGI.pm's `s/^\"//g;` paired with `s/\"$//g;` ~15 lines apart, desyncing
_slice_by_braces for every function after that point.

Two Gemini/agy dispatch attempts on this issue both failed, each fixing
only the narrower qr{}-shielding symptom the issue's own framing focused
on while missing this broader generic-shield mismatch -- both produced a
brace-imbalanced shield output and were correctly never committed.
Root-caused directly after the second failure rather than dispatching a
third attempt.

Fix: perl gets its own combined_pattern branch (proper #-comment
handling, no //, no /* */, both quote patterns bounded to {0,200} chars
-- same idiom as the existing rust single-quote / scala backtick bounds)
plus a separate pass for perl's brace-delimited quote-like operators
(qr{}/m{}/s{}{}/tr{}{}/y{}{}/q{}/qq{}/qw{}/qx{}), reusing the existing
_find_balanced_end helper instead of a new hand-rolled depth counter.

found_functions 710->937 of 1005 real (recall 70.6%->93.2%),
extra_functions unchanged at 1 (zero new false positives).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol force-pushed the fix/perl-1437-qr-brace-shield branch from fd10692 to cfb8d08 Compare August 13, 2026 17:23
@squid-protocol
squid-protocol merged commit a6bdf91 into main Aug 13, 2026
27 checks passed
@squid-protocol
squid-protocol deleted the fix/perl-1437-qr-brace-shield branch August 13, 2026 17:23
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

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.

perl func_start: qr{...}/m{...}-style brace-delimited regex literals desync _slice_by_braces, dropping every function after the first one

1 participant