Skip to content

python func_start regex misses Cython cdef/cpdef module-level function definitions #1999

Closed

Description

@squid-protocol

Summary

GitGalaxy's python language block deliberately routes .pyx/.pxd/.pxi (Cython) files under
the python extension set (LANGUAGE_DEFINITIONS["python"]["extensions"] -- "comprehensive
surface area... Cython"), but func_start's regex only ever matched the literal def keyword.
Cython's cdef/cpdef module-level function definitions (cdef int _allocate_buffer(array self) except -1:) have no def keyword at all, so they were a complete recall gap.

Evidence

Found via the tri-comparison-ledger-sweep on python/function/existence/agree[ctags]_vs[gitgalaxy,tree_sitter]
(68 occurrences, docs/self_scan/tri_comparison_ledger.json). Direct gather_language("python")
name-diff confirmed the full scope: language-crucible/data/python/cython/MemoryView.pyx (52
missing) and .../MemoryView.pxd (16 missing) -- 100% of GitGalaxy's misses on this shape, ctags-
corroborated, 0 found by GitGalaxy or tree-sitter (tree-sitter-python has no concept of Cython's
cdef class/cdef function syntax either -- a separate, already-documented limitation, see Claim
2 in docs/why_gitgalaxy_beats_ast_here.md).

Fix (shipped in the same PR)

gitgalaxy/standards/language_standards.py's python func_start regex gained a second
alternative matching cdef/cpdef function signatures, excluding cdef class/struct/enum/
union/extern/packed/fused (declarations, not functions -- class_start already owns cdef class). Tolerates up to 2 return-type words plus an optional pointer star before the name (cdef char *pybuffer_index(...)), bounded-repetition throughout (no ReDoS risk).

Verified: new extraction-gauntlet cases in tests/extraction/languages/test_python.py (valid/
invalid/pathological + a dedicated ReDoS sweep), crucible_check.py against the full ~80-repo
corpus (31 diffs, all scoped to python/cython, both golden masters re-blessed), ruff/mypy audits
clean.

Known residual gap (not fixed, out of scope)

One function, get_slice_from_memview in MemoryView.pyx, still isn't found: its return type is
a Cython/Tempita code-generation template placeholder (cdef {{memviewslice_name}} *get_slice_from_memview(...)), not standard Cython syntax. Left undone given its narrow scope (1
occurrence, a codegen-template artifact rather than real end-user Cython source).

Activity

  1. squid-protocol commented on Aug 21, 2026

    @squid-protocol
    OwnerAuthor

    Follow-up (2026-08-21): the documented residual gap (get_slice_from_memview) is now closed too.

    That function's return type is a Cython Tempita codegen placeholder (cdef {{memviewslice_name}} *get_slice_from_memview(...)). Closing it took two fixes, not one:

    1. Widened func_start's return-type token to also accept a bounded {{identifier}} placeholder
      form (in addition to a plain identifier).
    2. That alone wasn't enough -- it surfaced a second, separate bug in the shared
      _extract_name name-normalizer (detector.py), used by every language, not just python. Its
      generic split("{") truncation step (meant to cut a C-style body-opening brace off the raw
      match) mistook the placeholder's own {{/}} for that brace, truncating the match down to
      the bogus name "cdef" instead of the real get_slice_from_memview. Confirmed via the real
      scan pipeline (not just the isolated regex) -- the DB was recording a phantom function literally
      named cdef at that line before this second fix.

    GitGalaxy now finds all 84 real functions in cython/MemoryView.pyx (100% recall vs. ctags, up
    from 83/84). Verified against the full ~80-repo crucible corpus a second time (diffs scoped only
    to python/cython, both golden masters re-blessed again) and new test coverage added to both
    tests/extraction/languages/test_python.py (func_start regex) and
    tests/core_engine/test_detector.py (_extract_name, since that fix is shared infrastructure).

    python/function/existence/agree[ctags]_vs[gitgalaxy,tree_sitter] no longer reproduces at all.

  2. added
    bug
    core-engine
    threat: false-negative
    on Aug 26, 2026
  3. added this to the v2.4.9 milestone on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginethreat: false-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions