Skip to content

rust/scala lifetime-exemption in _count_top_level_args is dead code (self.language vs self.primary_lang_id) #1872

Description

@squid-protocol

Summary

StructuralExtractor._count_top_level_args (gitgalaxy/core/detector.py, around line 3770) has a guard meant to exempt Rust lifetimes ('_, 'static) and Scala symbols from its string-literal scanner:

elif ch == "'":
    if getattr(self, "language", "") in ("rust", "scala") and re.match(
        r"[a-zA-Z_]\w*\b(?!')", body[i + 1 :]
    ):
        # It's a Rust lifetime or Scala symbol (e.g. `'a>`, `'_ `), not a string literal
        pass
    else:
        in_string = True
        quote_char = ch

self.language is never set anywhere in the class -- the actual attribute is self.primary_lang_id (set at line 497: self.primary_lang_id = lang_id.lower() if lang_id else "unknown"). Confirmed via grep: self.language has zero other references in the file. The getattr(self, "language", "") therefore always falls back to "", so "" in ("rust", "scala") is always False -- this exemption has never fired, for any language, since it was written.

Effect

Every lifetime mark in a Rust (or Scala) function signature gets misread as opening an unterminated string literal, which swallows every subsequent top-level comma until either a real closing quote appears later in the signature or the string never closes -- fusing 2+ real parameters into 1, or (with an odd number of lifetime marks in one signature) undercounting everything after the last one.

Confirmed repro

Found via tests/tools/tri_comparison_ledger.json's rust/function/args/agree[none]_vs[gitgalaxy,tree_sitter] shape (21 occurrences, tree-sitter and ctags both agree with the real signature, GitGalaxy alone is wrong every time) -- dispatched investigation + independent confirmation in the same session. Real signatures, language-crucible/data/rust/:

  • bevy/bevy_ecs_world.rs:1106 spawn_at_with_caller: (&mut self, entity: Entity, bundle: MovingPtr<'_, B>, caller: MaybeLocation) -- real 4 args, GitGalaxy reports 3 (the '_ swallows the comma before caller).
  • bevy/bevy_ecs_world.rs:1270 spawn_with_caller: (&mut self, bundle: MovingPtr<'_, B>, caller: MaybeLocation) -- real 3, GitGalaxy reports 2.
  • serde/serde_core_de_mod.rs:1105 deserialize_unit_struct: (self, name: &'static str, visitor: V) -- real 3, GitGalaxy reports 2.
  • serde/serde_core_de_mod.rs:1152 deserialize_struct: (self, name: &'static str, fields: &'static [&'static str], visitor: V) -- 3 lifetime marks (odd count, string mode never exits) -- real 4, GitGalaxy reports 2.

Suggested fix

getattr(self, "language", "") -> getattr(self, "primary_lang_id", "") (or just self.primary_lang_id, since it's always set in __init__). One-line fix; re-run tests/tools/tri_comparison_chart.py --languages rust,scala and the relevant test_rust_strict.py/test_scala_strict.py args cases afterward to confirm the args counts move.

Scope

This only affects args structural-signature accuracy for rust/scala specifically (epic #813's extraction-pillar naming accuracy), not risk-scoring or any other language. No other language's _count_top_level_args call path is affected -- the guard is scoped to exactly this condition.

🤖 Found via dispatched investigation, tri-comparison-ledger-sweep skill

Activity

  1. added
    bug
    testing
    core-engine
    on Aug 19, 2026
  2. squid-protocol commented on Aug 19, 2026

    @squid-protocol
    OwnerAuthor

    Second, related manifestation found (same root cause, different function)

    Follow-up dispatched investigation on a different ledger shape (rust/function/args/agree[ctags,tree_sitter]_vs[gitgalaxy], extends the worked example already in docs/self_scan/how_to_investigate_a_discrepancy.md) found a second place a Rust lifetime tick gets misread as an unterminated string literal — independently confirmed against source, not just the dispatched agent's claim.

    _matching_paren_end (gitgalaxy/core/detector.py, lines 3675-3703) has no lifetime guard at all (unlike _count_top_level_args's broken-but-present one this issue already covers):

    elif ch in ("'", '"', "`"):
        in_string = True
        quote_char = ch

    This function backs the self-containment check at ~line 4262 (self._matching_paren_end(stripped, 0) == len(stripped) - 1) that decides whether a captured signature is a true self-contained (...) span. A Rust signature with any lifetime tick ('_, 'a, 'static) makes this check falsely fail (the phantom unclosed string swallows the real closing )), so control falls through to the comma/whitespace-split fallback meant for Lisp/Scheme/Shell (~line 4296). For a single-parameter signature with a lifetime and no comma, this produces an OVER-count instead of the other bug's under-count -- e.g. bevy_reflect_path.rs:43's new(path: &'a str): "(path: &'a str)".split() = 3 tokens, GitGalaxy reports 3 args for a real 1-arg function.

    Both bugs share the identical underlying defect (a Rust/Scala lifetime tick never being recognized as non-string during bracket/quote scanning) and should almost certainly be fixed together -- _matching_paren_end needs the same rust/scala lifetime exemption _count_top_level_args was supposed to have (once its self.language→self.primary_lang_id fix lands).

    Confirmed real signatures (language-crucible/data/rust/):

    • Under-count (existing _count_top_level_args bug): bevy/bevy_ecs_table.rs:171 initialize(&mut self, row: TableRow, data: OwningPtr<'_>, tick: Tick, caller: MaybeLocation) — real 5, GitGalaxy reports 3.
    • Over-count (this _matching_paren_end bug): bevy/bevy_reflect_path.rs:43 new(path: &'a str) — real 1, GitGalaxy reports 3. serde/serde_internals_ast.rs:119 all_fields(&'a self) -> Box<dyn Iterator<...>> — real 1, GitGalaxy reports 2.
  3. squid-protocol commented on Aug 20, 2026

    @squid-protocol
    OwnerAuthor

    Note: #1852 (filed 2026-08-18, before this issue) reported the identical bug independently -- closed as a duplicate of this one since this issue's diagnosis is fuller (confirmed root cause + repro cases + the follow-up _matching_paren_end manifestation). Should have searched before filing this -- noting for the record.

  4. added a commit that references this issue on Aug 22, 2026
    0c8c3f0
  5. 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-enginepriority: mediumtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions