Skip to content

Scan dense hand-written source instead of excluding it as minified (Fixes #7501) - #7503

Merged
squid-shepherd[bot] merged 1 commit into
mainfrom
fix/7501-dense-source
Nov 2, 2026
Merged

squid-shepherd[bot] merged 1 commit into
mainfrom
fix/7501-dense-source

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

What was broken

Dense hand-written source is a whole program packed onto a few dozen 500-3,000 char lines, with several functions defined inline per line. AI coding agents write this way (#7501: Codex chess engines in C and Rust, a SAT solver). GitGalaxy dropped these files whole. Synthetic repro (C, Rust, Go, about 420 functions on about 36 lines):

step main this PR
aperture Gate 4.1 Blocked (Saturation: Line 4 exceeds 500 chars) admitted
with 4.1 passed: worker MINIFIED/VENDOR DETECTED (avg line > 800), detector skipped, 0 functions extracted
with the worker passed: detector lines > 1,500 chars blanked by the anti-ReDoS shield, so their functions are lost read
auditor Packed Payload Guard (Impossible Density: 160 hits/line) kept, 34 functions per file (one per packed line)

Fix

The issue named two root causes. The class sweep turned up two more of the same kind. All four read width or density and take a long line for minifier output:

  1. aperture._has_definitions (the exemption for Gates 3.4, 4.1 and 5.1) skips lines over 200 chars and only reads heads ending in ) {.
  2. statistical_auditor._has_named_definitions requires _is_ordinary_width.
  3. The worker's is_minified test (galaxyscope.py: average line > 800, or > 50 KB in < 15 lines).
  4. The detector's 1,500-char long-line shield.

Signal: the language, plus functions defined inline on the long lines. Minifiers and packers produce web languages (JS, CSS, HTML) and data. Nobody minifies C, Rust or Go. The new module gitgalaxy/core/dense_source.py holds this:

  • DENSE_EXTENSIONS / DENSE_LANGS list the compiled languages: C/C++, Rust, Go, Java, C#, Zig, Swift, Kotlin, Scala. Template extensions (.jsp, .cshtml, .razor) are left out.
  • defines_inline(line) is a bounded scan for inline definitions. It matches keyword-led heads (fn / func / fun / def) and C-family typed heads ([type] name(args) {). Each quantifier is bounded and each character class is disjoint from the one after it, so the scan is linear in the line. A test runs adversarial 5,000-char lines in well under 1 s. The scan only reads lines of up to DENSE_LINE_MAX = 5,000 chars.
  • is_dense_source requires a compiled-language extension, no line over 5,000 chars, and an inline definition on a long line. It is used by Gate 4.1 and the worker's minification test.
  • Gates 3.4 and 5.1 accept either an ordinary definition (Aperture/auditor payload guards drop real source files (aes_prng.c, tables.c, crc32.cpp, EntityFlags.cs ...: 64 files, ~900 functions) #5460) or a dense one.
  • The detector's shield keeps blanking lines over 1,500 chars, except a line in a dense language that defines a function inline (up to 5,000 chars). Hex rows and data tables are still blanked.
  • Auditor: in a dense language, at least 2 named functions and at least one per 10 physical lines count as source, whatever the width. A packed payload with a function or two over hundreds of wide lines stays relegated.

Not admitted, because a wide line alone never qualifies:

  • web languages, even when they define functions inline;
  • lines over 5,000 chars;
  • wide lines with no inline definition (hex rows, data tables).

Before -> after (tests: tests/core_engine/test_dense_source_7501.py, 33 cases)

Golden masters (vs f09970f72ff3)

full-precision: unchanged. zero-dependency: unchanged. No corpus file is dense compiled-language source, so no file changes classification. Both legs were re-blessed through bugfix_kit.py all / crucible_check.py --update, with zero diff.

Ground-truth ledger

No change (ledger check PASS).

Estate-crucible

61/63 horrors passing before and after; 0 moved.

Audits

mypy / ruff / dead-key PASS. pr_gates.py --fast: lint, audits, secrets, xray, gen-docs, derived, workflows, gauntlet and affected all PASS.

Known limit (separate, not fixed here)

The detector's func_start rules are anchored at the start of a line. On a packed line only the first definition is extracted, so the fixtures yield one function per line, not every function. Java methods written inline in a one-line class body are missed the same way. Fixing either is a detector-wide extraction change with golden drift, so it is left for its own issue.

Lessons for agents

  • Dense or wide source passes through four width gates in a row: aperture 4.1 / 3.4 / 5.1, then the worker's is_minified (average line > 800), then the detector's 1,500-char line blanking, then the auditor's Packed Payload Guard. Fixing only the first one just moves the exclusion to the next. Sweep all of them.
  • A .js fixture named bundle.js is dropped by the ignore rules before any content gate runs. Name fixtures neutrally (app.js).

Fixes #7501

🤖 Generated with Claude Code

…ixes #7501)

Whole programs packed onto a few dozen 500-3,000 char lines, several functions
defined inline per line (typical of AI coding agents), were dropped by the
generated-noise guards: aperture Gate 4.1 (and 3.4/5.1), whose definitions
exemption skipped lines over 200 chars and only read `) {`-terminated heads;
the worker's avg-line minification test; the detector's 1,500-char line
shield; and the auditor's Packed Payload Guard, whose definitions exemption
required ordinary width.

New gitgalaxy/core/dense_source.py: in compiled languages only (C/C++, Rust,
Go, Java, C#, Zig, Swift, Kotlin, Scala; minifiers emit web languages and
data), a function defined inline on a long line, read by a bounded linear
scan up to 5,000 chars, marks the file as source. The auditor accepts named
functions at least every 10 physical lines in those languages.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@squid-protocol
squid-protocol marked this pull request as ready for review November 2, 2026 03:30
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol squid-protocol added the shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md label Nov 2, 2026
@squid-shepherd

squid-shepherd Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dense hand-written code is excluded as minified/packed: the 'has definitions' exemptions miss functions packed on wide lines

1 participant