Skip to content

functions_found counts the slicer's synthetic __global_context__ buckets, inflating every per-function descriptor for 5 languages #2691

Closed

Description

@squid-protocol

Found while working #2669 Batch D (the shape-descriptor design pass, #2689).

What happens

detector.py's slicer synthesizes a __global_context__ bucket to hold a file's top-level
statements when they sit outside any function. That bucket is then counted as a function: it
lands in function_data and in functions_found.

On the keyword-rosetta control corpus, where exactly 13 probe functions are planted per language,
five languages report 16:

matlab | 3 synthetic     lua | 3 synthetic     shell | 3 synthetic
ruby   | 3 synthetic     livecode | 3 synthetic
SELECT f.func_name, f.loc FROM function_data f JOIN file_data fd ON f.file_id = fd.id
WHERE fd.file_path LIKE 'matlab/%';
-- __global_context__ | 6
-- __global_context__ | 6
-- __global_context__ | 9
-- entry | 6 ... plus the 13 real probes

python for contrast returns exactly the 13 real probes and no bucket.

Why it matters

Every per-function descriptor divides by functions_found, so all of them are diluted by roughly
3/16 for these five languages — the average is taken over three things that are not functions:

  • avg_func_complexity, avg_func_loc, avg_func_args, max_func_complexity
  • func_complexity_gini, func_internal_density
  • and downstream, cog_raw and structural_mass

This is measurable cross-language bias with a purely internal cause: identical planted intent, but
a denominator that counts synthetic buckets in some languages and not others. It is not a corpus
artifact — any real repository with top-level code gets the same dilution.

Precedent

#2547 is the same family, one consequence over: synthetic slicer bucket names were being counted as
orphans, and the fix taught the orphan/duplicate checks to skip them via
_is_synthetic_satellite_name. That helper already exists and already knows what a synthetic name
looks like — the per-function denominators were simply never given the same treatment.

Fix shape

Exclude synthetic satellite names from functions_found and from every per-function aggregate,
reusing _is_synthetic_satellite_name rather than a second list. The bucket itself should keep
existing (its signals are real code and must still be counted at file level) — it is only its
membership in the function population that is wrong.

Open question for whoever takes it: whether functions_found should drop them silently or report
them separately (functions_found vs slices_found), since a file that is entirely top-level code
would then report 0 functions while still carrying signals.

Blast radius

Golden masters will move for any repo with top-level code in these languages: the per-function
descriptors above, plus cog_raw/structural_mass downstream. No signal counts should change --
the bucket keeps contributing its hits, it just stops being counted as a function.

Corpus-side: keyword-rosetta's functions_found goes 16 -> 13 for matlab/lua/shell/ruby/livecode,
which is the planted value, so this closes rather than opens corpus deviations.

Activity

  1. added
    bug
    metrics
    core-engine
    on Sep 3, 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-enginemetrics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions