Skip to content

Feature: multi-language control corpus to validate structural extraction equivalence across languages #1096

Closed

Description

@squid-protocol

Summary

While scoping #1056 (auditing the
tier-aware risk-scoring math in signal_processor.py), a related but distinct validation gap
came up: we have no way to check whether structural extraction itself (detector.py +
gitgalaxy/standards/language_standards.py) treats semantically-equivalent code equivalently
across languages.

These are deliberately separate concerns:

Proposed approach (from discussion, needs design before building)

Build a small public multi-language control corpus — a repo with one directory per language,
each containing "the same program" expressed idiomatically in that language:

  • Files named for control-flow clarity (A.py/B.py style) so the import chain is trivially
    readable, forming a simple linear/known dependency graph (a deliberate cross-check for
    network_risk_sensor.py's dependency DAG / PageRank too, not just detector.py).
  • The program itself doesn't need to be functional or fancy — a minimal dispatcher that exercises
    a deliberately chosen set of language_standards.py signature keys per language (branch, io,
    safety_bypasses, sync_locks, etc.), preferably printing which keyword/function was exercised
    (e.g. "function with keyword X tested") so a human can sanity-check the control file against
    GitGalaxy's own output line-by-line.
  • Each language folder wrapped in that language's idiomatic framework/project shape (not just a
    bare script) so the corpus also stresses guidestar_lens.py's manifest-based Intent Lock, not
    only detector.py in isolation.
  • A centralized diff step: run galaxyscope over the whole corpus and compare each language's
    detected signal counts against the "ground truth" of which keys were deliberately planted,
    flagging any language whose detected counts don't match — an outlier report.

Why this needs its own design pass before scoping into sub-issues

  • Key selection: not every language_standards.py signature key has a sensible
    same-shape equivalent in every language (the epic's own framing — "where all languages have
    something other than none" — is the hard part: e.g. COBOL doesn't have closures, Rust's
    unsafe isn't the same risk shape as Python's eval). Needs a real mapping pass across
    LANGUAGE_DEFINITIONS, not just picking keys that sound universal.
  • Maintenance cost of a public repo: unlike the golden-master corpus (real-world repos we
    don't own), this would be a repo we author and maintain — every new language added via
    how_to_add_a_language.md would ideally get a corresponding control-corpus folder, which is an
    ongoing tax, not a one-time build.
  • Overlap with existing tooling: tests/extraction/languages/test_<lang>.py (epic Epic: Harden the four extraction gauntlets (function/args/class/dependency) per language #813) and
    test_<lang>_strict.py (epic Epic: Harden the strict structural-signature test suite (non-extraction-pillar rules) per language #1069) already assert per-language regex correctness against
    hand-picked valid/invalid/pathological snippets. This corpus would be a different validation
    shape (real end-to-end galaxyscope runs, cross-language relative comparison, dependency-DAG
    shape) rather than a replacement for those — worth being explicit about what it catches that
    they don't (e.g. prism.py stream-splitting interactions, tier/archetype classification,
    cross-language ecosystem-context bleed like [BUG/METRICS] SignalProcessor's ecosystem-context risk multiplier subsystem is dead code #1053) before committing to building it.

Non-goals (for now)

References

Activity

  1. added
    enhancement
    testing
    core-engine
    on Aug 6, 2026
  2. added this to the v2.4.8 milestone on Aug 16, 2026
  3. squid-protocol commented on Aug 31, 2026

    @squid-protocol
    OwnerAuthor

    Design plan (2026-08-31)

    Grounded in a fresh measurement against the live LANGUAGE_DEFINITIONS registry (the wiki taxonomy matrix is stale — 51 columns vs. the current 46 active languages; everything below derives from language_standards.py at build time so the corpus can't drift the same way).

    Measured foundation

    39 of 46 active languages share a full core set of 20 signal keys: func_start, branch, import, args, api, doc, planned_debt, fragile_debt, safety, safety_bypasses, io, globals, encapsulation, test, high_risk_execution, dead_code, ownership, telemetry, state_mutation, cleanup. The 7 stragglers (markdown, jcl, css, html, yaml, yacc, solidity) each miss only 1–6 keys → Tier 1 (full shell, 39 langs) and Tier 2 (reduced shell + per-language expected-signal manifest, 7 langs). Nobody excluded.

    Program shell (identical design, per-language expression)

    • Functions only, no classes — class_start expected = 0 everywhere is itself a free false-positive tripwire (same bug class as the css @media-as-function history, CSS at-rules (@layer / @media / @supports) counted as functions; css tree-sitter-accuracy baseline stale (real_functions 24→25) #2507).
    • One probe function per signal, fixed count (~12–15 functions, e.g. probe_branch, probe_io, …), each planting an exact number of that signal's keywords (exact diffs catch both misses and FPs; "works on broken code" removes the usual reason to be loose).
    • Files main→A→B→C forming a known linear import chain — cross-checks network_risk_sensor.py's DAG/PageRank, not just detector.py.
    • Idiomatic minimal manifest per language folder (package.json / Cargo.toml / Makefile…) to stress guidestar_lens.py's Intent Lock.

    Symmetric decoy design

    Signals split across two surfaces; decoys cross them in both directions, every decoy recorded with expected count 0:

    • Code-stream signals (branch, io, eval-equivalents…): decoys planted in comments and string literals — tests prism.py stripping + literal shielding.
    • Comment-surface signals (planned_debt, fragile_debt): a # HACK tag on one designated function is a true positive; the reverse decoy is a code identifier literally named HACK_LEVEL, which must not count.

    Framework first — the harness is the reviewer

    Per-language versions get fanned out to other models, but only after the harness exists, because the harness is what makes generated versions safe to accept:

    1. tools/keyword_menu.py — mines each language's rule regexes from LANGUAGE_DEFINITIONS, emits a per-language menu of safe literal keywords per signal (the taxonomical equivalence map, applied mechanically).
    2. SPEC.md — the canonical shell: probe list, occurrence counts, decoy rules, file/import layout. This is the generation prompt.
    3. tools/verify_language.py — runs galaxyscope on one language folder, diffs detected counts against expected_signals.json, fails on any mismatch. Gates every per-language PR: a version that passes is correct by construction; one that fails is a bad generation or a real engine bug — both are the point.
    4. tools/bias_report.py — the payoff: identical planted intent everywhere, so divergence in downstream risk scores across languages = measured language bias. Outlier report.

    Sequencing

    • Phase 1 — new repo keyword-rosetta (sibling checkout, same convention as language-crucible): SPEC + keyword-menu generator + manifest schema.
    • Phase 2 — verify/bias harness.
    • Phase 3 — 3 hand-checked reference languages spanning morphology extremes: python (indent), cobol (positional/sequence-area), javascript (brace). Validate the loop end-to-end.
    • Phase 4 — fan out remaining ~36 Tier-1 + 7 Tier-2 languages, one PR per language, harness-gated.
    • Phase 5 — first bias report; file per-outlier follow-up issues here; add a "create the control-corpus folder" step to how_to_add_a_language.md (makes the maintenance tax this issue flagged explicit and cheap).

    Work starting on a side branch in the new repo.

  4. squid-protocol commented on Aug 31, 2026

    @squid-protocol
    OwnerAuthor

    Status update (2026-08-31): 3 languages locked, first bias numbers, gating system in place

    Corpus repo (local, pre-publish) now has python, cobol, javascript reference folders, each passing an exact-count end-to-end gate (75/77/80 assertions respectively) with every deviation from planted intent validated in a tri-comparison-style ledger (deviation_ledger.json + docs/GATING.md, modeled on docs/self_scan/tri_comparison_README.md's entry lifecycle — unvalidated → investigated → validated verdict, still_reproduces only flipped by a fresh scan).

    First bias report (identical planted intent in all 3 languages): 12/18 signals diverge, and the mean per-file risk scores diverge hard —

    risk cobol javascript python
    risk_safety_score 53.1 28.1 28.6
    risk_tech_debt 40.0 32.6 32.8
    risk_cognitive_load 8.1 8.4 4.8

    Same program, ~1.9× the measured safety risk in COBOL. Part of that traces to shapes now filed as issues:

    Per the corpus's gating rule, current engine behavior is baked into manifests with ledger references; when a fix lands, the affected manifests re-baseline in the same change that flips the ledger entry's still_reproduces.

    Next: remaining Tier-1 fan-out (framework + SPEC are the generation prompt), Tier-2 reduced shells, and the Phase-5 pinned-tag CI integration.

  5. squid-protocol commented on Aug 31, 2026

    @squid-protocol
    OwnerAuthor

    Status update (2026-08-31, part 2): 11 languages locked, variance gate added — no risk metric currently passes cross-language validation

    Corpus now covers abap, ada, assembly, cobol, fortran, haskell, javascript, python, rust, shell, sqlite — the legacy set plus one language per morphology family. All 11 pass the exact-count end-to-end gate (72–80 assertions each); every deviation has a validated deviation_ledger.json entry (21 shapes total).

    New: auto-regenerated variance chart (docs/bias_variance_chart.svg, rebuilt on every bias_report.py run, tri-comparison-chart style): one strip per risk metric, one unlabeled dot per language, positioned by deviation from the cross-language median. Green band ±25%, red beyond ±50% — any dot in red fails that metric's cross-language validation. Current verdicts on identical planted intent:

    • risk_cognitive_load FAIL (python 4.8 … assembly 33.0 — 6.8×)
    • risk_safety_score FAIL (javascript 28.1 … fortran 70.2 — 2.5×)
    • risk_tech_debt FAIL (ada/haskell 20.0 … sqlite 60.0 — 3×)
    • risk_api_exposure FAIL (ada/haskell 0.0 … fortran 9.7)

    14/18 signals diverge from uniform planted intent. Largest single-signal spread: branch 3 (abap) → 25 (assembly, where call/ret count as control transfers).

    New upstream findings this batch:

    Remaining: ~28 Tier-1 + 7 Tier-2 languages (fan-out ready), then pinned-tag CI integration.

  6. squid-protocol commented on Aug 31, 2026

    @squid-protocol
    OwnerAuthor

    Status update (2026-08-31, part 3): 23 languages locked

    Batch 3 added the 12 mainstream languages (c, cpp, csharp, java, go, kotlin, typescript, php, ruby, lua, perl, swift) — all pass the exact-count gate (72–76 assertions each). Ledger now 29 validated shapes.

    23-language variance gate: 11 PASS / 4 WARN / 19 FAIL across 34 metrics. Confirmed-consistent core: func_start, import, pagerank, telemetry, cleanup, ownership + 5 risk scores. Notably, dependency_links dropped to FAIL at 23 languages — the gate caught two real resolution gaps: swift's _dependency_capture requires 2+ char module names (import a never resolves), and haskell chains don't convert either (same case-family as #2540).

    New ledgered shapes worth upstream eyes (not yet filed as issues — say the word and I'll file):

    • php: every file's <?php open tag counts branch +1 (the ternary ? alternation matches the tag — systematic per-file FP on all real PHP)
    • go: every quoted import counts safety_bypasses (the dot-import alternation's (?:\.[ \t]+)? is optional, so it fires on all imports)
    • kotlin branch counts return (main = 8 for 3 planted); swift api counts the word open inside string literals (API-exposure from prose)
    • flux ×3 weighting refined: it's per-function, not per-file (go micro-evidence: 11 = 3×3 + 2×1)
    • prism/detector: string-literal shielding is selective by signal family (if/try/open count inside a literal, eval does not) #2535's shielding matrix extended to all 23: selective profile holds for 10 of the new 12; ruby counts eval from literals (eval-as-bypass, like shell); perl's eval survives only by syntax shape, not surface shielding

    Remaining: ~16 Tier-1 (agc_assembly, apex, dart, dockerfile, embedded_python, groovy, livecode, m4, makefile, matlab, objective-c, powershell, scala, scheme, tcl, zig) + 7 Tier-2.

  7. squid-protocol commented on Aug 31, 2026

    @squid-protocol
    OwnerAuthor

    The corpus repo is now public: https://github.com/squid-protocol/keyword-rosetta (23 languages, the variance gate, the deviation ledger, and the per-language findings report — see docs/findings_by_language.md for the defect → issue → evidence-file reference, organized by language).

  8. squid-protocol commented on Aug 31, 2026

    @squid-protocol
    OwnerAuthor

    Status (2026-08-31, final for this phase): FULL REGISTRY COVERAGE — 46/46 languages

    Batch 5 added the 7 Tier-2 reduced shells (markdown, jcl, css, html, yaml, yacc, solidity). Every language in LANGUAGE_DEFINITIONS now has a locked, gate-passing control folder. PR: squid-protocol/keyword-rosetta#1 (retitled: 23 new languages across batches 4+5). Ledger: 35 validated shapes.

    New issue from Tier-2: #2549 — html func_start is unreachable end-to-end: the polyglot splitter consumes <script>/<style> tags before html's rules run (micro-repro: a script's JS body signals land on the html row, but func stays 0). The rule passes direct-detector tests and is dead in production — exactly the class of bug only an end-to-end corpus can catch.

    Other Tier-2 notes: solidity is the 6th return-counts-as-branch language (#2545); yacc + markdown join m4/scheme as DAG-invisible (no _dependency_capture); jcl's INCLUDE MEMBER= chain resolves and manifests api purely via orphan conversion despite jcl having no api rule; css's at-rules triple-count (func+branch, @supports also safety); solidity's SPDX line counts ownership on every real .sol file.

    46-language verdict: 3 PASS / 0 WARN / 30 FAIL (pagerank, risk_churn, risk_secrets_risk are the only survivors at full morphology range — func_start fell to FAIL on html's dead rule and the RUN/at-rule/EXEC function morphologies).

    Phase 4 (fan-out) is complete. Remaining from the original plan: Phase 5 — pinned-tag CI integration in gitgalaxy + a keyword-rosetta GH Action running the verifier on changed folders.

  9. squid-protocol commented on Aug 31, 2026

    @squid-protocol
    OwnerAuthor

    Closing: delivered by keyword-rosetta — 46/46 languages, gated, and already paying for itself

    The proposed corpus was built as the public repo keyword-rosetta (PolyForm NC). Every language in LANGUAGE_DEFINITIONS — all 46 — has a locked control folder passing its end-to-end gate. Mapping the original proposal to what shipped:

    Key selection (the "where all languages have something" design concern): solved empirically, not by picking keys that sound universal — tools/keyword_menu.py mines each language's self-validated keyword menu from the live LANGUAGE_DEFINITIONS, and a 20-key CORE_SIGNALS registry drives the shell. 39 Tier-1 languages carry all 20 signals; the 7 zero-signal morphologies (markdown, jcl, css, html, yaml, yacc, solidity) get reduced Tier-2 shells rather than pretending parity.

    The trivially-readable dependency chain: every folder is the same main → a → b → c linear DAG, which cross-checks network_risk_sensor.py exactly as proposed — pagerank is one of only three metrics that passes strict cross-language validation.

    Self-describing probes: SPEC.md's 12-probe canonical shell, each probe announcing what it exercises, with decoy rules to catch over-matching.

    The centralized diff/outlier step: tools/verify_language.py runs real galaxyscope --db-only scans and asserts 72–80 planted-vs-detected checks per language; tools/bias_report.py produces the cross-language bias report and the variance chart now embedded in this repo's README (#2554). Bottom-line verdict on identical planted intent: 3 of 33 metrics pass the strict cross-language gate; on average 75% of languages land within ±25% of the cross-language median per metric. A companion incidence report sizes each confirmed bias shape against real licensed code.

    "What it catches that the gauntlets don't" — the issue asked for this to be explicit before building, and it's now demonstrated rather than argued: 14 engine defect classes filed (#2535–#2547, #2549), several only catchable end-to-end: #2549 (html func_start alive in unit tests but dead in production — the polyglot splitter consumes the tags first), #2535 (string-literal shielding is selective by signal family), #2536 (raw hit_vector unrecoverable past the Contextual Baseline Fix), #2546 (undocumented ×3 flux weighting). First fix already landed and the corpus re-baselined behind it (#2538 closed; PR #2548 + rosetta commit 0e8ebfa). Every known deviation lives in a validated deviation ledger (35 shapes) with a tri-comparison-style lifecycle per GATING.md.

    The maintenance-tax concern: rosetta's own CI runs the verifier on any changed data/ folder, and PR #2559 makes the control folder an explicit part of how_to_add_a_language.md's process, so a new language can't silently skip it.

    Deliberately not delivered from the original sketch: idiomatic framework/manifest wrapping to stress guidestar_lens.py's Intent Lock — only python/javascript/rust carry manifests today; the bare probe shells keep planted counts exact. Carried as an explicit option (with that tradeoff named) into the successor.

    Remaining work → #2557: the gitgalaxy-side pinned-tag CI gate (crucible-pin pattern) and the cross-repo re-baseline protocol as the filed defects get fixed.

    Closing as complete for the corpus itself and its measurement program.

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

    core-engineenhancementtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions