Repository navigation
Description
Summary
detector.py's Mode A integration path (_slice_by_labels, used for every label-based language:
assembly, cobol, fortran, abap, agc_assembly) has two independent bugs that together
cause real, regex-matched functions/paragraphs/subroutines/methods to be silently dropped from
the final function list. Found while investigating the agc_assembly tri-comparison ledger
(#1945, now merged); confirmed to generalize to all four sibling languages via a follow-up
read-only investigation of their real corpus source.
Bug 1: assembly_returns truncates on ANY keyword occurrence, not just a real terminating statement
# detector.py:572-575
self.assembly_returns = re.compile(
r"\b(?:TC\s+Q|TCF\s+Q|RETURN|RESUME|RELINT|RET|RTS|JMP\s+LR|BLR|END-PERFORM|END-IF|GOBACK|EXIT)\b",
re.IGNORECASE,
)Used at detector.py:1967-1970 to truncate a function's sliced body early once a "return"-like
keyword is seen anywhere in the text between this label and the next one. This has (at least)
three independent failure shapes, all confirmed against real corpus source:
(a) A keyword that's real AGC/COBOL/Fortran/ABAP vocabulary but isn't actually a terminator in
context (legitimate mid-body control flow, not "the function is over"):
agc_assembly:RELINT("release interrupt inhibit") commonly opens a long interrupt-handler
routine rather than closing one —language-crucible/data/agc_assembly/apollo-11/AGC_BLOCK_TWO_SELF-CHECK.agc:303,
ELOOPFIN, a 20+-line real routine truncated to its own label line.fortran: a legitimateEXIT FIND_VEGETATION_PARAMETER_FLAGloop-break statement mid-subroutine
truncates the rest of the body —language-crucible/data/fortran/wrf/module_sf_noahdrv.F:1999
(insideSUBROUTINE SFLX).abap: an earlyRETURN.inside anIFguard clause, and separately anEXIT.breaking aDO
loop, both truncate the rest of the method —language-crucible/data/abap/abapGit/zcl_abapgit_ajson.clas.abap:192,307
(methoddelete).cobol:END-IF(a block closer, not a paragraph terminator) truncates a paragraph, dropping
the real instructions after it —language-crucible/data/cobol/cics-banking-sample-application-cbsa/BNKMENU.cbl:242
(paragraphPMM010.).
(b) The keyword substring appears inside a comment, not code:
assembly:assembly_returnsmatches the word "return" inside a doc-comment
(// @return dl = pc_drive...), truncating the following label —
language-crucible/data/assembly/cosmopolitan/ape.S:251(labelpc:).
(c) The keyword substring appears inside an identifier name, not as a standalone statement:
cobol:\bEXIT\bmatches inside the variable nameWS-EXIT-RETRY-LOOP(hyphens are non-word
characters, so the word-boundary regex is satisfied by the substring even though it's part of a
larger identifier) —language-crucible/data/cobol/cics-banking-sample-application-cbsa/XFRFUN.cbl:105.
None of these three shapes check where the match sits (a real standalone terminating statement
vs. inside a comment, an identifier, or a legitimate non-terminating control-flow keyword) before
truncating end_offset to ret_matches[-1].end().
Bug 2: single-line/blank-collapsed function bodies silently discarded
# detector.py:1972-1974
block = code[start_idx : start_idx + end_offset].strip()
if not block or len(block.splitlines()) < 2:
continueAny function whose sliced body reduces to exactly one non-blank line after .strip() is silently
dropped — no partial-credit, no low-confidence flag, just skipped entirely. This is wrong on its
own even without Bug 1 feeding it truncated input, because single-instruction/single-statement
"trampoline" labels are completely normal in assembly-family code:
agc_assembly:SOPTION1–SOPTION7/SOPTON10, seven consecutive one-instruction labels, all
discarded —language-crucible/data/agc_assembly/apollo-11/AGC_BLOCK_TWO_SELF-CHECK.agc:210-219.assembly:del_command:immediately followed byos22:with zero instructions between —
language-crucible/data/assembly/bootos/os.asm:269-270; also several consecutive one-line
constant labels (stack: equ 0x7700etc.) —os.asm:158-166.cobol:PREMIERE SECTION.immediately followed by paragraphA010.—language-crucible/data/cobol/cics-banking-sample-application-cbsa/BANKDATA.cbl:369-370.fortran/abap: not observed in the sampled corpus (their subroutines/methods are
structurally never one line long in the files checked) — this doesn't rule it out in principle
for those languages, just that no live trigger was found in this pass.
Confirmed real-world scale (agc_assembly only, precisely quantified)
Cross-referencing struct_func_start (raw regex signal) against function_count (named
functions reaching output) via the real pipeline DB across the 10-file agc_assembly corpus:
52 real, regex-matched labels are dropped (11.6% of 812 raw matches), 50 of which are independently
corroborated as real by ctags' own tagging (tri-comparison ledger
agc_assembly/function/existence/agree[ctags]_vs[gitgalaxy], now validated — see #1945). The
other four languages weren't given the same precise corpus-wide count in this pass (the follow-up
investigation confirmed the mechanism is live via targeted examples, not a full census) — worth
doing the same struct_func_start vs. function_count cross-reference for assembly/cobol/
fortran/abap before/after a fix to get real before/after numbers.
Suggested fix direction (not yet implemented)
- Bug 1: don't truncate on a bare keyword match anywhere in the sandbox text. At minimum, require
the match to sit on its own statement (start of line after whitespace, or immediately after a
language-appropriate statement separator), and exclude matches inside a shielded comment/string
region (this repo'sprism.pyalready produces a comment-stripped view for other purposes —
worth checking whether_slice_by_labelscan reuse that instead of scanning rawcode). Fixing
the "legitimate non-terminating keyword" cases (fortran's loop-breakEXIT, abap's guard-clause
RETURN) may need a narrower, more conservative terminator set per language rather than one
shared list, since "is this instruction ever legitimately non-terminating" is language-specific. - Bug 2: for Mode A specifically, a single-line body is a normal, real function — the discard
guard should not apply to this integration mode (or should require an explicit reason beyond
line count, e.g. an actually-empty label with no instruction at all).
Repro
source .venv/bin/activate
galaxyscope language-crucible/data/agc_assembly/apollo-11 --db-only --output /tmp/scan.json
sqlite3 /tmp/scan_master.db "SELECT file_name, function_count, struct_func_start, (struct_func_start - function_count) AS gap FROM file_data ORDER BY gap DESC;"Filed via the tri-comparison-ledger-sweep skill's investigation flow (Claude direct analysis +
a Gemini/agy read-only dispatch for cross-language blast-radius confirmation, 2026-08-20).
Activity
docs(self-scan): link agc_assembly detector.py bug to filed issue #1949…
fix(assembly): real per-function args count via distinct-register cou…
docs(language-status): add assembly §9 tri-comparison writeup
docs(language-status): add assembly coverage doc (#1957)
fix(detector,cobol): close #1949's Bug-2 precision regression, regene…
fix(detector): close remaining assembly data-label false positives, b…