Repository navigation
Description
What
When a JavaScript file has two (or more) top-level named functions with different names but near-identical body shape, the extraction pipeline records the first one and silently drops the second, even though func_start's raw regex correctly matches both. Found via a tree-sitter-based ground-truth accuracy pass for JavaScript (mirroring ast_accuracy_audit.py's Python methodology, #1200) against expressjs/express (v5.2.1).
Repro (real file, minimal isolated scan)
examples/view-locals/index.js in expressjs/express at tag v5.2.1 defines four top-level functions:
function count(req, res, next) { // line 48
User.count(function(err, count){
if (err) return next(err);
res.locals.count = count;
next();
})
}
function users(req, res, next) { // line 56
User.all(function(err, users){
if (err) return next(err);
res.locals.users = users.filter(ferrets);
next();
})
}
function count2(req, res, next) { // line 86 -- same shape as count()
User.count(function(err, count){
if (err) return next(err);
res.locals.count = count;
next();
})
}
function users2(req, res, next) { // line 94 -- same shape as users()
User.all(function(err, users){
if (err) return next(err);
res.locals.users = users.filter(ferrets);
next();
})
}Scanning just that directory (galaxyscope examples/view-locals --db-only), function_data for index.js only contains:
count
users
next <- phantom, see #1221, unrelated to this issue
ferrets
count2 and users2 never appear, despite both being real, differently-named, top-level function declarations.
Confirmed NOT a regex-matching problem
Running func_start directly against the raw file content finds all four correctly, at their real positions:
from gitgalaxy.standards.language_standards import LANGUAGE_DEFINITIONS
fs = LANGUAGE_DEFINITIONS["javascript"]["rules"]["func_start"]
src = open("examples/view-locals/index.js").read()
[(m.group(0), m.span()) for m in fs.finditer(src)]
# 'function count' (48), 'function users' (56), 'function count2' (86), 'function users2' (94)
# -- all four found, at the right offsets.So the raw signature-matching regex is fine; the loss happens somewhere downstream of it -- in whatever stage turns a func_start match into a function_data row (the Mode B brace-slicer / block-boundary dispatcher in detector.py, per this repo's own phase terminology). Root cause not yet diagnosed beyond that -- filing with a confirmed, minimal, isolated (single-file, no cross-file interaction) reproduction rather than guessing further, per this repo's own convention for this class of finding (see docs/language_status/python.md §9's #1184 entry for the same "confirmed mechanism, not yet root-caused to the exact line" shape).
Why this matters
count/count2 and users/users2 are structurally near-identical (same param list shape, same body shape, different only in name and the inner callback's use of that name) -- exactly the shape of copy-pasted example/boilerplate/generated code, which is common in real repos. If the loss is keyed on body/shape similarity rather than name, this could silently undercount function totals on any codebase with repeated boilerplate patterns (e.g. multiple near-identical CRUD handlers, generated route handlers, etc.), not just this specific tutorial file.
Scope note
Distinct from #1221 (bare call statements false-positive as definitions) -- that's a precision bug (phantom extra functions); this is a recall bug (real functions silently missing) with an unrelated mechanism. Also distinct from #1193 (comment-delimiter corruption, line_exclusive languages only -- javascript is standard_block, not affected by that one).
Activity
squid-protocol commentedon Aug 10, 2026
Additional corroborating evidence from a second, unrelated corpus (GitGalaxy's own
site/js/-- the WebGPU visualizer, real hand-written code, not generated/boilerplate like thecount/count2example that opened this issue) -- this looks like the same underlying mechanism (func_startfinds the match,function_datadoesn't have the row), but manifesting inside ES6 class bodies with multiple methods, and at a much higher severity than the original repro suggested:function_datatools/search.js(SearchControllerclass)constructoronly)tools/ally.jsfocusNext, focusPrev, generateDescription, getVisibleNodes, handleNavigation, renderTreetools/poster.js_verifyRenderIntegrity, cleanup, drawLegend, drawTypography, get, handleAccept, handleDecline, initiateCheckout)js/core/materials.jsresolveBasalColor, refresh, constructorpresentget,resolveMaterialPropertiesmissingjs/core/galaxy-engine.jsclearDependencyLines, drawDependencyLines, setAttr, toggleDependencyLines, toggleGlobalWeb)Confirmed via the same method as the original repro:
LANGUAGE_DEFINITIONS["javascript"]["rules"]["func_start"].finditer(src)finds all 10 ofsearch.js's method names (including the 9 missing ones) at their correct positions in the raw text -- so this is not a regex-matching gap, same as thecount2/users2case.Notably this ISN'T a simple "only the first method of a class survives" pattern (
galaxy-engine.jskeeps ~21 of ~26 methods;search.jskeeps only 1 of 10) -- whatever the real mechanism is, it's more selective than a single early-exit. Might be worth checking whether it correlates with specific syntax inside the previous sibling method's body (arrow-function callbacks, template literals, nested braces/parens depth, etc.) tripping up the Mode B brace-slicer's boundary detection for that method, causing it to either over-consume into the next method(s) or lose sync with the class's true structure. Leaving the deeper diagnosis to whoever picks this up -- flagging so the fix isn't scoped too narrowly to just the top-level-duplicate-function shape the issue was originally filed against.squid-protocol commentedon Aug 10, 2026
Relevant prior art found after filing: #789 (csharp) diagnosed the same general failure layer -- `detector.py`'s `_slice_by_braces` (Mode B) does a bounded post-hoc search for the next literal `{` after each regex match to determine a function's body extent, with a `if start_idx < last_end_idx: continue` guard that silently drops any match falling inside territory an earlier match already claimed. That guard is a strong candidate mechanism for what's happening here: if an earlier sibling (`count`'s body, or `search.js`'s `constructor` body) gets a body-boundary search that over-extends past its real closing brace, everything textually between there and the next correctly-detected boundary -- including a same-shaped sibling like `count2`, or eight of `SearchController`'s nine methods -- would fall inside `last_end_idx` and get silently skipped, exactly matching what's observed here (regex finds it, function_data doesn't have it).
#789 was closed without the downstream
_slice_by_bracesfix landing (scoped out as its own follow-up issue, which I can't find filed anywhere) -- this may effectively be that follow-up, now with two independent real-corpus confirmations (expressjs/express for the top-level-duplicate shape, GitGalaxy's own site/js/ for the class-method shape) rather than a synthetic csharp snippet. Worth reading #789's full diagnosis before investigating further here, since it already narrows down the exact function (_slice_by_braces) and the exact guard (last_end_idx) most likely responsible, even though its own repro was csharp-specific.docs: add JavaScript language-status doc, first tree-sitter-based §9 …
fix(core): prevent Prism from swallowing code due to quotes in commen…
fix(core): bounding alone wasn't enough for backtick -- fold comment …
fix(core): bound prism.py's unbounded single-quote shield -- closes #…
fix(core): broaden scala/matlab/haskell func_start recall -- closes #…