Skip to content

Remove db_complexity metric from the Structural Extractor #1013

Closed

Description

@squid-protocol

Remove db_complexity metric from the Structural Extractor

Description

The db_complexity metric in the GitGalaxy SAST engine (gitgalaxy/core/detector.py) is fundamentally flawed and generates severe false positives. It should be completely removed from the metrics schema and calculation pipeline.

Why it's broken

Currently, the "Database Complexity" score doesn't look for databases at all. It simply sums up basic regex signature hits for completely unrelated concepts, specifically:

  • io (weighted x3)
  • serialization_parsing (weighted x2)
  • state_mutation (weighted x1)

This means a function that simply does local variable reassignments (state_mutation) and prints heavily to standard out (io) will rack up a massive db_complexity score, even if absolutely no database or ORM is involved. The metric was implemented poorly and acts more like an AI hallucination than a valid heuristic.

Why we can't just fix it

To accurately measure computational database complexity (such as N+1 queries, deeply nested joins, or transaction boundaries), we would need an Abstract Syntax Tree (AST). Since GitGalaxy's engine operates natively across 50+ languages without compiling code (using fluid state counters, regex, and whitespace tracking), we are limited to structural heuristics.

Any AST-less regex approach to fixing this (e.g., looking for SELECT or .query() inside an indented loop) would just be another fragile heuristic measuring the volume or presence of database keywords, not true complexity. It would be highly error-prone (e.g., counting SQL strings that are defined inside a loop but executed safely outside of it) and would just replace one false-positive generator with another.

Action Items

  • Remove db_complexity calculation from _calculate_block_metrics in gitgalaxy/core/detector.py.
  • Remove db_complexity from the FunctionNode TypedDict in detector.py.
  • Ensure any downstream aggregators or visualizers in signal_processor.py or the UI drop this field.

Activity

  1. added 2 commits that reference this issue on Aug 4, 2026
    9b0614c
    92f1eaf
  2. added
    scope:frontier
    on Oct 16, 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

    scope:frontier

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions