Skip to content

Prose-bypass languages (markdown, plus yaml/json/csv/plaintext) never get their structural signatures counted, regardless of regex correctness #691

Closed

Description

@squid-protocol

Summary

Found while closing #597 (markdown strict-parsing tests). Markdown's 4 literate-programming
structural signatures (lit_code_blocks, lit_diagrams, lit_headers, lit_links) have
never been counted in a real scan, independent of whether their regexes are correct. All
25 markdown files in tests/golden_master_audit.json report zero across every signature, not
just the ones touched in #597.

Root cause (confirmed via direct execution, not just code reading)

Two separate mechanisms, and markdown's content flows into the one that's dead-ended:

  1. gitgalaxy/core/detector.py's "Prose Deflection" gate (~line 435):

    if confidence < 0.42 or self.primary_lang_id in (
        "plaintext", "markdown", "json", "yaml", "csv",
    ):
        return {"equations": {}, "functions": [], ...}  # early return, nothing scanned

    This fires before comment_analysis() -- the function that scans comment_stream --
    ever runs.

  2. comment_analysis()'s hardcoded rule whitelist (~line 1066) only checks 6 keys:
    dead_code, doc, ownership, planned_debt, fragile_debt, spec_exposure. Markdown's
    4 lit_* keys aren't on it, so even bypassing (1) wouldn't be enough on its own.

Markdown's entire file content lands in comment_stream via prism.py's "Prose Bypass"
(split_streams, ~line 159) -- code_stream is always empty for markdown, which is why the
normal coding_analysis/code_stream path (the one virtually every other language relies on)
can never see it either.

Why not just make markdown's code_stream non-empty?

Considered and rejected: coding_loc/doc_loc (derived from which stream a file's content
lands in) feed ~10 downstream consumers -- risk-density normalization in
signal_processor.py/security_auditor.py, aggregate stats in record_keeper.py, 3D
visualization mass in gpu_recorder.py, and an anomaly check in statistical_auditor.py
that's specifically if doc_loc > coding_loc * 5. Flipping markdown files from all-doc to
all-code LOC would corrupt all of that for every markdown file in every future scan --
a much bigger blast radius than the signature-counting bug itself.

The fix (verified end-to-end before opening this issue)

Leave prism.py and coding_loc/doc_loc semantics completely untouched. In detector.py:

  1. Add markdown's 4 lit_* keys to comment_analysis's whitelist (no-op for every other
    language, since none of them define those keys).
  2. For markdown specifically, call comment_analysis(comment_stream, ...) before returning
    from the Prose Deflection gate, instead of bailing with an empty dict (function/
    complexity analysis correctly still gets skipped -- markdown has no functions).

Proved this works by running it directly against real Prism output on a sample with
headers/links/fences: coding_loc/doc_loc came back unchanged (0/9, identical to today),
and all 4 signatures came back correctly non-zero.

Scope: markdown only for now

yaml/json/csv are also in the same Prose Deflection tuple and also show all-zero
signatures in the current fixture -- surprising, since yaml's strict-parsing issue (#617/#681)
closed with real, file-traceable golden-master diffs, which doesn't obviously square with this
gate blocking it unconditionally. Worth its own investigation: unlike markdown, yaml's
code_stream is already correctly populated (it doesn't go through the Prose Bypass), so its
fix is likely just "remove yaml from this one gate" -- a different, simpler mechanism than
markdown's, and probably a different root cause than what closed #681 historically. Deferred
rather than folded in here to keep this fix's blast radius scoped and reviewable; will surface
naturally as the strict-parsing epic (#518) works through more languages.

Activity

  1. added
    bug
    core-engine
    on Jul 28, 2026
  2. squid-protocol commented on Jul 28, 2026

    @squid-protocol
    OwnerAuthor

    Update: the fix turned out to need a third piece beyond what's described above. Confirmed via direct execution that fixing detector.py alone does NOT make markdown's signatures show up in the "Structural Signatures" report section -- that section reads a separate hit_vector field, not equations directly.

    There are actually three independent gates in this pipeline, not two:

    1. detector.py's Prose Deflection gate (described above) -- controls whether equations gets populated at all.
    2. gitgalaxy/metrics/signal_processor.py's "STATIC LITERATURE OVERRIDE" (~line 412-454) -- a completely separate gate that unconditionally hardcodes "hit_vector": [0] * len(SIGNAL_SCHEMA) for every doc_languages entry (markdown/plaintext/rst/text), regardless of what raw_signals/equations contains. This is why "Structural Signatures (Net Mitigated Signals)" (which reads hit_vector via audit_recorder.py) stayed at zero even after fixing (1).

    Interestingly, a third, already-existing consumer -- galaxyscope.py's "Instructional Density Multipliers" (~line 1991-2028), which boosts doc_umbrella based on a markdown file's lit_diagrams/lit_code_blocks/lit_headers/lit_links counts -- reads equations directly, bypassing signal_processor.py entirely. That one already showed real diffs from fix (1) alone. It turns out this "instructional density" feature has been silently dead code since it was written, since equations was always empty for markdown before this fix -- worth knowing about for anyone assessing doc_umbrella scores historically.

    Fix now also updates signal_processor.py's override to derive hit_vector from raw_signals the same way the non-doc path already does, instead of hardcoding zero. risk_vector (the actual 0%-logic-risk-for-docs bypass) is untouched -- only hit_vector changes. Verified end-to-end against the real crucible corpus: 51 diffs, every one either a .md file's own Structural Signatures going from 0 to a real count, or a doc_umbrella ripple in the same folder via the now-un-dead multiplier -- no off-target files affected.

  3. added this to the v2.4.6 milestone on Aug 1, 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-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions