Architecture / Decision records / ADR-HIS-119
ADR-HIS-119 Static analysis loads Semgrep's rules as cached bundles, only for the languages a change holds¶
| Status | Accepted |
| Decided | 2026-12-02 by the repository owner |
| Record | Drafted 2026-12-02; approved 2026-12-02 by the Enterprise Architecture Board |
| Where the rule lives | platform/delivery-pipeline/bin/static-analysis, platform/delivery-pipeline/README.md ("What stops a change"), platform/delivery-pipeline/test/test_pipeline.py (StaticAnalysisTest) |
Context¶
The static analysis of ADR-HIS-046 runs Semgrep with the security rules of Semgrep's open rule repository for eleven languages, without their audit rules, and the project's rules in semgrep/. The job took a median of about 4 minutes and up to 18 minutes on the self-hosted runners of ADR-HIS-072, and its queue held up the reviews of every pull request.
Semgrep's own timing profile (--time) shows where that time goes. A scan of platform/supply-chain on 1 December 2026 took 538 s, of which 510 s were spent loading the rules (config_time) and 28 s scanning the code (core_time). Semgrep reads and validates each of the ~580 rule files on its own, and does so whatever the size of the change: 265 of the files are Terraform rules, while the repository holds no Terraform yet. The size of what is scanned matters far less than how the rules are loaded.
Decision¶
- The rules are bundled once per rules commit and blocking severities (
$HIS_PIPELINE_CACHE/semgrep-bundle-<commit>-<severities>). Each bundle is one file for one set of languages the rules declare, and holds only the rules of a blocking severity, which are the only ones the scan reports. - Every rule keeps the id the full rule set gives it (the rules folder, its sub-folders, then the rule's own id), so a finding reads as before and
nosemgrep: <rule id>still matches. - A scan loads only the bundles of the languages its targets hold, told by file extension, a
DockerfileorContainerfilename, or a script's first line. A bundle loads when any of its languages is present: a rule filed underjavascript/that declares TypeScript applies to a TypeScript change. Rules of no particular language (generic,regex) and of a language the pipeline does not know load with every scan. - The bundles are built inside the pinned Semgrep image, so Docker stays the only host requirement of the scanners.
Consequences¶
- The same scan of
platform/supply-chaintakes 41 s instead of 566 s (rule loading 10 s), and 59 s when every bundle loads. The first scan after a new rules commit spends a few seconds more building the bundles. - The results are those of the full rule set. On planted findings in Python, Java, JavaScript, a Dockerfile and a GitHub workflow, both gave the same 8 results, with the same rule id, file, line and severity.
StaticAnalysisTestchecks a blocking finding, clean code, and a rule of another language folder on a TypeScript-only change. - Terraform rules, and any other language's, load as soon as a change holds files of that language, so the rule set grows with the repository without a change to the script.
- What is scanned is unchanged: every folder of the change, test code included, without
.semgrepignorefiles of the change. Narrowing the scan to the changed files, as an open pull request proposes, is independent of this decision and combines with it. - A rule whose
languagesthe pipeline maps wrongly would be skipped for a language it applies to. The map is small and listed in the script, unknown languages load with every scan, andStaticAnalysisTestcovers the case most likely to go wrong (one rule, two languages).
Alternatives considered¶
- Only scanning the changed files. It shortens the scanning part, 28 s here, and leaves the 510 s of rule loading.
- Dropping languages the repository does not hold yet, such as Terraform. It saves most of the loading time now, but silently stops checking those languages when the platform units add OpenTofu.
- More runners or cores. The loading is per scan and mostly single-threaded, and the runners share one host with the agent sessions.