Skip to content

Lua Mode-D: a mid-file keyword desync emits one oversized _[Truncated] satellite that swallows real functions #2437

Closed

Description

@squid-protocol

Summary

_slice_by_keywords (Mode D) desynchronises its opener/closer keyword count somewhere mid-file in
several language-crucible/data/lua files, leaving one scope open. Unlike an EOF desync (#2405's
blast-radius containment re-scans that remnant), a desync whose scope DOES eventually close
mid-file produces one oversized <name>_[Truncated] satellite that swallows every real function
declared inside the runaway span.

Surfaced by the tri-comparison-ledger-sweep for lua:
lua/function/existence/agree[gitgalaxy]_vs[ctags,tree_sitter] -- 8 of ~9 occurrences are
_[Truncated] satellites (BinaryTreesDemo_[Truncated], WriteForm_[Truncated],
bit.bnot_[Truncated], Anonymous_Block_[Truncated], new_[Truncated], ...). It also accounts
for part of the residual lua/function/existence/agree[ctags,tree_sitter]_vs[gitgalaxy] recall
gap (api.lua:B, binarytrees.lua:WriteForm sit inside the same span).

Likely triggers (to confirm)

  • a lua keyword (end, do, for, if, function) used as a table key or string that
    prism.py's lua shielding leaves live
  • repeat ... until vs the \bend\b / \buntil\b closer set
  • function-as-a-value on a line the opener regex counts but no matching end is attributed to

Contain the blast radius (independent of the trigger)

Same idea as #2405's EOF containment but for a mid-file runaway: when a Mode-D satellite's span
exceeds a sanity threshold (e.g. > N lines or > X% of the file) AND _slice_by_labels finds >= 2
func_start matches inside it, re-slice it by labels instead of emitting one _[Truncated]
block.

Found by

tri-comparison-ledger-sweep (lua), 2026-08-29.

Activity

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

    @squid-protocol
    OwnerAuthor

    Update from PR #2441 (the same sweep that filed this):

    The two keyword-desync sources this issue lists as "likely triggers" turned out to be
    _apply_literal_shield bugs, both fixed in #2441:

    • # (Lua length operator) and // (floor division) were in the shared default
      comment_markers set, so for i = 1, #arg do ... end was truncated at the # and lost its
      end from the Mode-D count (bit.bnot_[Truncated]).
    • Lua long-bracket literals [[ ]] / --[[ ]] were never shielded (code.lua's
      Anonymous_Block_[Truncated], coroutine.lua's new_[Truncated]).

    After #2441, every lua corpus file's Mode-D keyword count is perfectly balanced — this issue
    has no remaining lua repro.
    The 4 residual _[Truncated] satellites
    (binarytrees.lua, events.lua, fetch.lua, maxmind.lua) are a different mechanism —
    polyglot segmentation splitting a function when a [[ ]] string carries embedded HTML — now
    tracked separately as #2440.

    The "contain the blast radius for a mid-file runaway" suggestion is still a reasonable defensive
    measure to keep if a non-lua Mode-D language hits this shape, but it's no longer load-bearing for
    lua. Closing vs. keeping open as a general hardening task is a maintainer call.

  3. squid-protocol commented on Aug 30, 2026

    @squid-protocol
    OwnerAuthor

    Resolved by the accumulated lua fixes — #2438 (one-line function heads), #2439 (proto-table class gate), #2440 (polyglot <style> split), #2447 (\z string-continuation shield), #2461 (;-anchored func_start/function_opener).

    Verified as of main @ 5ea3eaa: zero _[Truncated] satellites in the entire lua corpus (and none in shell/tcl/ruby either — the Mode-D mid-file desync class is gone corpus-wide). The ledger shape this issue was surfaced by, lua/function/existence/agree[gitgalaxy]_vs[ctags,tree_sitter], is now still_reproduces: false.

    The generic blast-radius-containment mechanism proposed here (re-slice an oversized Mode-D satellite by labels when it contains ≥2 func_start matches) is a reasonable defensive hardening, but there is no remaining repro to drive or validate it. Closing; if a future corpus addition re-triggers a mid-file desync, reopen with that file as the repro.

  4. 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-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions