Repository navigation
Description
Summary
GitGalaxy's Mode-D shell extractor (_slice_by_keywords in gitgalaxy/core/detector.py)
desyncs its scope-depth stack on two residual shell constructs. When it desyncs, the enclosing
block never closes, so _slice_by_keywords emits one file-spanning <name>_[Truncated]
satellite and every function after the trigger is lost — a one-token parse error becomes a
whole-file recall collapse.
Found via the tri-comparison-ledger-sweep for shell (GitGalaxy vs tree-sitter vs ctags). Two
larger triggers in the same area — bogus --/// comment markers and quoted heredoc delimiters
being destroyed before the heredoc state-machine sees them — were fixed in the same PR (they
accounted for 12 of the 16 agree[ctags,tree_sitter]_vs[gitgalaxy] occurrences). This issue
tracks what remains.
Trigger 1 — a bare shell keyword used as a plain word in a command argument
tests/tools corpus: freebsd-src/runulp.sh
[ -n "$L" ] || { echo ERROR: Could not determine ULP limit for $routine in $limits_file && false; }The for in ... limit **for** $routine ... is an ordinary English word inside an echo
argument, but _slice_by_keywords' shell opener set (ScopeParsingRegistry) counts it as a
for loop opener. The { ... } group on that line is balanced, but the phantom +1 from for
is never closed → t() is emitted as t_[Truncated] (swallowing the rest of the file) and
check() at line 61 is never seen.
tree-sitter and ctags both extract t and check correctly.
Shell keywords (if/for/while/until/case and closers fi/done/esac) are only
keywords in command position — first word of a (sub)command, or immediately after ;, |,
&&, ||, {, (, then, do, else, newline. A keyword appearing after other words on a
line is an argument. The opener/closer matching would need command-position awareness to fix this
correctly.
Trigger 2 — SerenityOS Shell brace-block syntax
Corpus: serenity/builtin.sh, serenity/run-tests-and-shutdown.sh
SerenityOS's Shell is not POSIX sh: it uses if cond { ... } / for x in ... { ... } brace
blocks with no then/fi/do/done. GitGalaxy's shell opener/closer set expects the POSIX
keywords, so a { opens scope that the matching } does close, but the intervening if/for
keyword adds an unmatched +1. __complete_job_spec is missed; _complete_unalias and an
anonymous block come out as _[Truncated].
Lower priority — SerenityOS Shell is arguably a separate language. Noted here so it is tracked
rather than rediscovered.
Additionally — contain the blast radius
Independent of either trigger: when a Mode-D block is still open at EOF, _slice_by_keywords
currently emits a single satellite spanning from the desync point to EOF. It could instead
re-scan that swallowed span at scope_depth == 0 for any func_start matches and emit those,
so a single desync costs one function instead of all of them. This would make every future
shell (or ruby/lua) desync far less destructive even when the specific trigger isn't fixed.
Not bugs (documented, do not fix here)
moby/check-config.sh::zgrep— defined nested inside anif ! command -v zgrep; then … fi
guard. GitGalaxy's Mode-D deliberately extracts onlyscope_depth == 0constructs. tree-sitter
and ctags do full nesting. Genuine architectural tradeoff.
Repro
python tests/tools/tri_comparison_chart.py --languages shell
then read shell/function/existence/agree[ctags,tree_sitter]_vs[gitgalaxy] and
shell/function/existence/agree[gitgalaxy]_vs[ctags,tree_sitter] in
docs/self_scan/tri_comparison_ledger.json (both validated with full verdicts in the same PR).
🤖 Generated with Claude Code
Activity
squid-protocol commentedon Aug 29, 2026
Partially addressed by #2406 (the two larger shielding bugs — bogus
--///comment markers and quoted-heredoc-delimiter destruction). This issue tracks the residual: bare shell keyword used as a plain word in a command argument (echo … for $routine), SerenityOS brace syntax, and the suggested EOF-open blast-radius containment.Fix shell Mode-D quote/heredoc shielding; validate all shell tri-comp…
fix(#2405): contain Mode-D scope desync + handle SerenityOS brace blo…