Skip to content

gitgalaxy reach: count header includes from the scan's stored include strings (no source tree, no new table) (Closes #8529) - #8544

Merged
squid-protocol merged 1 commit into
mainfrom
sensors/include-counts-from-imports
Nov 16, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
sensors/include-counts-from-imports

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

gitgalaxy reach reported a header's reach as the number of files that #include it, but only with --src, because the resolver read the #include lines from the source tree. The scan already stores every file's include strings in file_data.raw_imports, and the resolver needs nothing else. So headers are now counted from the stored strings by default: no source tree, no new table, no schema change, no change to scan output. --src ROOT still reads the source instead; the two readers give the same counts edge for edge. The resolver now follows C's own search order: a quoted include is looked for relative to the includer's folder first (../redismodule.h, sub/x.h), then by the existing path rules (a/x.h matches the header ending in a/x.h; a bare x.h prefers the includer's folder, then the longest shared path). The open item of #8529 asked whether the include resolver could be improved before adding a table to persist include counts: it needs neither. Closes #8529.

Type of change

  • New feature (a post-scan command option; no parsing or engine logic change)

Measured

Scored against libclang's own record of which file includes which header (exact: it comes from the preprocessor; every .c file parsed as a translation unit with every header folder on the include path, direct inclusions at any nesting depth), on six C repositories, per header:

repo libclang include edges edges found (recall) precision per-header counts, Spearman exactly right the engine's popularity column, Spearman
expat 178 100.0% 90.8% +0.885 83.0% +0.958
redis 517 99.8% 83.4% +0.805 59.6% +0.676
libuv 638 99.8% 86.0% +0.922 40.5% +0.705
ndpi 943 100.0% 92.7% +0.786 30.4% +0.684
hiredis 91 97.8% 88.1% +0.944 68.0% +0.942
zlib 62 100.0% 98.4% +0.962 94.7% +0.962

Reading it: nearly every real include is found. Precision is 83 to 98% because every textual #include is counted, including those inside an #if the preprocessor did not take (another platform's headers), so "exactly right" is lower than the ranking agreement. Against the engine's popularity column the new count ranks headers better on redis, libuv and ndpi, level on hiredis and zlib, and worse on expat (+0.885 against +0.958). A correction to what #8529 said: the include-related columns it quoted (+0.38 to +0.71) were pagerank_score and import_count; popularity is a good proxy (+0.68 to +0.96), and import_count is poor (-0.32 to +0.45 here). Exploratory: six repositories, C only; headers of other languages have no include directive and are not measured.

Class / Sibling gaps

Class: header reach for C-family sources, wherever the scan stores include strings. Handled here: the stored-imports reader, the relative-include rule, the shared resolver for both readers. Sibling gaps: (1) #include strings inside an untaken #if are counted (the scan has no preprocessor); (2) a bare x.h that matches several headers picks the one sharing the longest path with the includer, which is wrong when the build's -I order says otherwise; (3) headers of languages with no include directive (Python, Go, Java, Rust) are not measured by include; (4) the stored strings do not say <x.h> from "x.h", so a system header that shares a name with a repository header can be matched to it.

CI checklist

  • python tests/tools/audit_check.py passes
  • tests/tools/test_reach_sensor.py (17 tests; 2 new: the stored-imports reader agrees with the source reader and needs no source tree, and a relative include resolves from the includer's folder) and test_libsurface.py pass
  • Scan output unchanged: no recorder, parser or engine file touched

Files: gitgalaxy/tools/sensors/reach.py, tests/tools/test_reach_sensor.py, docs/wiki/08-24-reach-sensor.md.

Lessons for agents

  • file_data.raw_imports holds a file's include or import strings (JSON list, sorted, deduplicated, relative forms such as ../x.h kept, quotes and angle brackets dropped): enough to compute include graphs after the scan without re-reading source.

🤖 Generated with Claude Code

https://claude.ai/code/session_018srRveGdV73aUiuqkipAic

… strings (no source tree, no new table)

A header's reach is its include count. It needed --src because the resolver read the #include lines from the source tree; the scan already stores
each file's include strings in file_data.raw_imports, which is all the resolver needs. Headers are now counted from them by default (--src still
reads the source instead; the two give identical counts). The resolver follows C's own order: a quoted include relative to the includer's folder
first (../x.h, sub/x.h), then the existing path rules. No schema change, no scan output change.

Part of #8529.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018srRveGdV73aUiuqkipAic
@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 2051730 into main Nov 16, 2026
52 checks passed
@squid-protocol
squid-protocol deleted the sensors/include-counts-from-imports branch November 16, 2026 22:19
squid-protocol added a commit that referenced this pull request Nov 16, 2026
…can database; golden masters re-blessed (#8546)

The LLM brief gets two short sections after 15 (call resolution): 16 "Reach (Who Depends On What)" (the five most-called source files and the
five most-included headers, from gitgalaxy reach) and 17 "Libraries (What The Repository Leans On)" (the eight external libraries with the most
files, from gitgalaxy libsurface; a C or C++ library only if it is in the shipped table, a discovered one only when an import names it). They read
the master database galaxyscope has just written, passed to generate_artifacts as scan_db; absent without one, and a failure to read never stops the
brief. No table, no column; the only scan output that changes is llm.md (a 35-line insertion in both golden brief fixtures).

Reading a WAL-mode database read-only creates -wal and -shm files, which the documented scan output must not contain (test_cli_contract caught it):
the sensors now open the database immutable when no -wal file is beside it (nothing is mid-write) and read-only otherwise.

Closes nothing; follows #8544 (header counts from stored imports) and #8532.


Claude-Session: https://claude.ai/code/session_018srRveGdV73aUiuqkipAic

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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.

Persist external calls and header include counts so a scan can scope a rename (fcall_external, gitgalaxy reach)

1 participant