Skip to content

fix(#2405): contain Mode-D scope desync + handle SerenityOS brace blocks - #2431

Merged
squid-protocol merged 1 commit into
mainfrom
fix/2405-mode-d-blast-radius
Aug 29, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/2405-mode-d-blast-radius

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Fixes #2405 (Trigger 1 — bare keyword used as a plain word in an argument — left for a follow-up;
it needs full command-position awareness).

Two changes to _slice_by_keywords

1. Shell brace-block guard (SerenityOS /bin/Shell)

3 corpus files carry #!/bin/Shell and write if cond { ... } / for x in ... { ... } /
match $x { ... } with no then/do/fi/done. Both the keyword (+1) and the trailing
{ (+1) fired while only } (−1) closed → a permanent +1 desync per block that swallowed the
rest of the file. Fix: when a loop/conditional keyword sits on a line ending in a bare {
block opener, the brace pair owns the scope — drop the keyword's contribution. Safe for POSIX (an
if/for header never ends in a bare {), no dialect detection needed.

2. Blast-radius containment

In the keyword-scoped shell / ruby / lua / elixir dialects, a single desync leaves one scope open
to EOF, so the remnant satellite can be almost the whole file — hiding every function after the
desync. Fix: re-scan the swallowed span for func_start matches (Mode-A greedy label slice)
and emit them individually; only the first keeps the _[Truncated] marker. Scoped to those four
dialects — matlab's trailing-function-without-end is a legitimate idiom (#1266), not a desync.

Result

before after
shell func recall 99.1% 99.6%
shell funcs found (corpus) 463 (3 truncated) 466 (1 truncated)
lua func recall 78.7% 81.5%
lua funcs found (corpus) 500 517

builtin.sh (SerenityOS) now yields 4 clean functions (_complete_unalias, __complete_job_spec,
_complete_kill, _complete_cd); runulp.sh's check is recovered even though t still
desyncs (Trigger 1). lua's +17 come from re-scanning its 8 pre-existing truncation spans.

tree-sitter-accuracy

  • lua --regenerate — improvement locked in.
  • shell extra_functions: 14 → 15, written from measure() (gate-overridden). The +1 is
    tree-sitter-bash failing on SerenityOS /bin/Shell syntax — builtin.sh has 4 real
    name() {} functions, tree-sitter recovers 1, has_error=True. Documented as a 5th instance
    under Claim 3
    in why_gitgalaxy_beats_ast_here.md (GitGalaxy correct, grammar structurally
    can't).

Differential Scan

crucible_check.py full corpus: every file-level diff is a lua or shell file. The ~315
changes on other files are all Topological Coordinates X/Z recomputing from the shifted
function graph — zero other structural signals moved. Both golden masters re-blessed, re-verified
PASS both modes. ast-accuracy / ruff / mypy: no change. 6808 tests pass; 2 new detector tests.

tri_comparison_chart.svg regenerated by the post-merge tri-comparison-history.yml job, not here.

🤖 Generated with Claude Code

https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S

Two changes to `_slice_by_keywords`, per the approved scope (Trigger 1 --
bare keyword used as a plain word in a command argument -- left for a
follow-up, needs full command-position awareness):

1. Shell brace-block guard. SerenityOS `/bin/Shell` (`#!/bin/Shell`, 3
   corpus files) writes `if cond { ... }` / `for x in ... { ... }` with
   no `then`/`do`/`fi`/`done`. Both the keyword (+1) and the trailing `{`
   (+1) fired while only `}` (-1) closed -- a permanent +1 desync per
   block that swallowed the rest of the file. When a loop/conditional
   keyword sits on a line that ends in a bare `{` block opener, the brace
   pair owns the scope, so drop the keyword's contribution. Safe for
   POSIX (an `if`/`for` header never ends in a bare `{`).

2. Blast-radius containment. In the keyword-scoped shell / ruby / lua /
   elixir dialects, a single opener/closer desync leaves one scope open
   to EOF, so the remnant satellite can be almost the whole file --
   hiding every function after the desync point. Re-scan the swallowed
   span for `func_start` matches (Mode-A greedy label slice) and emit
   those individually; only the first keeps the `_[Truncated]` marker.
   Scoped to those four dialects: matlab's trailing-`function`-without-
   `end` is a legitimate idiom (#1266), not a desync.

Result: shell 463 -> 466 funcs (3 truncations -> 1), lua 500 -> 517
(recovered from 8 pre-existing truncation spans; the spans' own markers
remain -- a separate lua Mode-D issue). Summary table: shell func recall
99.1% -> 99.6%, lua 78.7% -> 81.5%.

- tree-sitter-accuracy: lua --regenerate (improvement locked in); shell
  extra_functions 14 -> 15 written from measure() (gate-overridden). The
  +1 is `tree-sitter-bash` failing on SerenityOS `/bin/Shell` syntax
  (`builtin.sh`: 4 real `name() {}` functions, tree-sitter parses 1,
  has_error=True) -- documented as a 5th instance under Claim 3 in
  docs/why_gitgalaxy_beats_ast_here.md.
- Differential Scan (crucible_check, full corpus): every file-level diff
  is a lua or shell file; the ~315 other changes are all `Topological
  Coordinates X/Z` recomputing from the shifted function graph, zero
  other structural signals moved. Both golden masters re-blessed,
  re-verified PASS.
- ast-accuracy / ruff / mypy: no change.

New: test_detector_mode_d_shell_serenity_brace_blocks,
test_detector_mode_d_blast_radius_containment.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019Zm1uVBpVEZJ9SB7bWFR8S
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit e5e9a92 into main Aug 29, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the fix/2405-mode-d-blast-radius branch August 29, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell Mode-D scope desync: bare keyword in an argument (and SerenityOS brace syntax) swallows the rest of the file

1 participant