Skip to content

fix(core): close #1198's residual python function-extraction gap - #1205

Merged
squid-protocol merged 1 commit into
mainfrom
fix/1198-python-extraction-recall
Aug 10, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/1198-python-extraction-recall

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Two independent bugs in prism.py's Python docstring/comment stripping (upstream of detector.py's function-boundary scanner), plus a third in the asm! embedded-language handshake trigger, together account for all of #1198's reported gap:

  1. _strip_python_docstrings's newline-count bug — it replaced every matched docstring with a fixed single "\n" regardless of how many lines it actually spanned (line-count-neutral only by coincidence for a 2-line docstring). Every other length desynced every following line number by (2 - N) lines, accumulating across a file. This alone reproduced detector.py's reported "dead zone" (_partition_segments through _apply_literal_shield, 7 functions in a row).

  2. _strip_python_docstrings's missing string-shielding — its triple-quote regex ran directly against raw text, so a '"""'/"'''"-shaped sequence inside an ordinary string literal (e.g. nxt.endswith('"""')) could false-open a "docstring" that only closed at the next real """ many lines later, swallowing every real line — including further defs — in between. Same bug class as Contiguous 'dead zones' of real functions silently lost from extraction on production files, independent of mid-file language drift #1184's fix to _apply_literal_shield, just never applied to this sibling implementation.

    Fixed both by mirroring _apply_literal_shield's established pattern: preserve exactly as many newlines as the match spans, and fold plain string/comment recognition into the same atomic alternation so whichever construct starts first at a given position always wins.

  3. Unanchored asm!/__asm__ handshake trigger (language_standards.py) — the same drift Mid-file language-switching (_partition_segments) can be permanently misled by a string literal that merely contains embedded-language delimiter text #1183/fix(core): stop detector.py's embedded-language handshake from firing inside string literals #1190 already fixed for <script>/<style>, just never applied to this third HANDSHAKE_REGISTRY entry. A bare asm!( substring inside an ordinary Python string (e.g. a Rust safety_bypasses test fixture literally containing 'asm!("nop")') falsely triggered the embedded-language handshake and misrouted the rest of the file to assembly's rules — this fully explains the issue's reported near-total extraction loss in test_rust_strict.py/test_objectivec_strict.py. Anchored it to line-start like its two siblings.

Verification

Corpus-wide against ast ground truth across all 228+ .py files in this repo (same methodology as docs/language_status/python.md §9): function recall 2333/2379 (98.1%) → 2379/2379 (100%), 0 hallucinations both before and after.

  • tests/ast_accuracy_baseline.json, tests/golden_master_audit.json, tests/golden_master_zero_dep_audit.json regenerated via their sanctioned tools (ast_accuracy_audit.py --regenerate, update_golden_master.py) to bless this intentional, verified accuracy improvement — diffs are total_loc/function-count increases on affected files plus the expected downstream PageRank/3D-coordinate ripple.
  • Full pytest tests/: 6787 passed, 0 failed.
  • tests/tools/audit_check.py: all clear (ruff/mypy/dead-key/ast-accuracy).
  • tests/tools/crucible_check.py: both full-precision and zero-dependency modes PASS.

Test plan

  • python tests/tools/audit_check.py
  • python tests/tools/crucible_check.py
  • python -m pytest tests/ (full suite)
  • python tests/ast_accuracy_audit.py (100% recall confirmed, no regressions)

Fixes #1198.

🤖 Generated with Claude Code

Two independent bugs in prism.py's Python docstring/comment stripping
(the stage upstream of detector.py's function-boundary scanner) that both
desync code_stream's line numbers from the real file, silently dropping a
contiguous range of real `def`s from extraction:

1. _strip_python_docstrings replaced every matched docstring with a fixed
   single "\n" regardless of how many lines it actually spanned -- only
   line-count-neutral by coincidence for a 2-line docstring; every other
   length shifted every following line number by (2 - N) lines. This
   alone produced detector.py's own reported "dead zone"
   (_partition_segments..._apply_literal_shield, 7 functions).

2. The same function's triple-quote regex ran directly against raw text
   with no string-literal shielding, so a `'"""'`/`"'''"`-shaped sequence
   inside an ordinary (non-triple) string literal could false-open a
   "docstring" that only closed at the next real `"""` many lines later,
   swallowing every real line -- including further `def`s -- in between.
   Same bug class as #1184's fix to _apply_literal_shield, just never
   applied to this sibling implementation in prism.py.

Fixed both by mirroring _apply_literal_shield's established pattern:
preserve exactly as many newlines as the match spans, and fold plain
string/comment recognition into the same atomic alternation so whichever
construct starts first at a given position always wins (single-pass,
no separate contraction-apostrophe or false-triple-quote hazard).

A third, separate bug fully explains the issue's other reported gap
(near-total extraction loss in test_rust_strict.py/test_objectivec_strict.py,
both dense with embedded-language string fixtures): the `asm!`/`__asm__`
entry in HANDSHAKE_REGISTRY (language_standards.py) was still unanchored
-- the exact drift #1183/#1190 already fixed for <script>/<style>, just
never applied to this third registry entry. A bare `asm!(` substring
inside an ordinary Python string (e.g. a Rust safety_bypasses test
fixture literally containing 'asm!("nop")') falsely triggered the
embedded-language handshake and misrouted the rest of the file to
assembly's rules. Anchored it to line-start like its two siblings.

Verified corpus-wide against `ast` ground truth across all 228+ .py files
in this repo (same methodology as docs/language_status/python.md §9):
function recall 2333/2379 (98.1%) -> 2379/2379 (100%), 0 hallucinations,
both before and after. tests/ast_accuracy_baseline.json, golden_master_
audit.json, and golden_master_zero_dep_audit.json regenerated via their
sanctioned tools (ast_accuracy_audit.py --regenerate, update_golden_master.py)
to bless this intentional, verified accuracy improvement -- diffs are
total_loc/function-count increases on affected files plus expected
downstream PageRank/3D-coordinate ripple. Full pytest suite (6787 passed),
tests/tools/audit_check.py, and tests/tools/crucible_check.py (both modes)
all clean.

Fixes #1198.

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 3405285 into main Aug 10, 2026
29 checks passed
@squid-protocol
squid-protocol deleted the fix/1198-python-extraction-recall branch August 10, 2026 12:56
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.

Residual function-extraction gap post-#1193: contiguous dead zone + near-total loss in embedded-foreign-code-heavy files

1 participant