Skip to content

fix(python): vectorized_math ignores '@' in strings and comments (#4136) - #4148

Merged
squid-protocol merged 1 commit into
mainfrom
fix/4136-matmul-strings
Oct 2, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/4136-matmul-strings

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Fixes #4136

What changed

  • New scope filter outside_literals (detector.py _apply_scope_filter). It uses the existing _scope_filters mechanism (CRITICAL ENGINE RULE 17), so it only ever removes matches and counts, spatial maps and threat locations stay consistent. A match is kept only if its span is identical in the index-aligned string/comment shield that _build_indentation_safe_stream already builds for the indentation slicer. If any character of the match sits in a string literal or comment, the match is dropped. Nothing new was written for the masking itself.
  • python vectorized_math now declares "_scope_filters": {"vectorized_math": "outside_literals"}. The @ arm also accepts the augmented form a @= b. Before, the = failed the operand lookahead, so @= was never counted.
  • Decorators were already excluded by declared domain sensors: rules whose densest match is a different construct than the sentence names (from #2897) #2898's one-line operand gap. That is now covered by regression tests (@app.get(...), an indented @property, and a decorator right after a ) line).
  • Docs: the stream contract corollary 1 (signal_contracts.py, re-rendered docs/signal_contracts.md), rule 18 in how_to_add_a_language.md, and the vectorized_math schema line now name the opt-in filter.

Known limitation: a matmul inside an f-string interpolation (f"{a @ b}") is masked along with the rest of the string.

Differential scan / golden masters

crucible_check.py (both modes) showed 9 differences per fixture. All of them are in vectorized_math, and nothing else moved. Re-blessed with --update --yes:

file before -> after cause
fastapi/tests/test_response_model_data_filter.py 7 -> 0 "[email protected]" string fixtures
fastapi/tests/test_response_model_data_filter_no_inheritance.py 7 -> 0 same
fastapi/tests/test_union_forms.py 2 -> 0 "[email protected]"
fastapi/tests/test_application.py 1 -> 0 email in a string
twisted/transport.py 3 -> 0 b"[email protected]"
cython/Nodes.py 1 -> 0 "... every @cname method ..." string
numpy/genapi.py 1 -> 0 'einsum.cpp' path string
numpy/ufunc_docstrings.py 2 -> 0 matmul text inside add_newdoc strings
numpy/_linalg.py 12 -> 10 two hits inside strings; the 10 real matmul(/tensordot/.dot( calls stay

I checked every dropped match against the source line. All of them are string or comment text, and none is a real operator.

Verification

  • tests/extraction/languages/test_python_strict.py: 109 passed, including the new vectorized_math fires on '@' inside Python string literals #4136 tests (strings, comments, docstrings, decorators, a @ b, f(a)@g(b), a @= b, a mixed line, and ReDoS on the new arm).
  • Full suite (-n 8): 13353 passed. 3 ReDoS timing tests failed under load while the crucible scan was running in parallel (css, javascript import, zig). None touch Python, and all 3 pass when re-run serially.
  • tests/tools/audit_check.py: ruff, mypy, dead-key and ast-accuracy all clear. signal_contract_audit.py --ci: no new findings.

🤖 Generated with Claude Code

The code stream keeps string literals, so python's matmul '@' arm counted
"text-embedding-gecko@003", "[email protected]" fixtures and
b"[email protected]". Add a language-agnostic `outside_literals`
scope filter that drops any match touching a string literal or comment in
the existing index-aligned shield (_build_indentation_safe_stream), and opt
python vectorized_math into it. Also count the augmented `a @= b` form,
which the operand lookahead rejected.

Golden masters: 9 python files lose string-literal hits (fastapi
test_response_model_data_filter*.py 7 -> 0 each, plus twisted, numpy,
cython, other fastapi tests); nothing else moves.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit a5ff38e into main Oct 2, 2026
38 checks passed
@squid-protocol
squid-protocol deleted the fix/4136-matmul-strings branch October 2, 2026 17:32
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.

vectorized_math fires on '@' inside Python string literals

1 participant