Skip to content

fix: isolate trivy's cache per run to stop the checks-bundle race - #166

Merged
frankmeds merged 1 commit into
mainfrom
fix/trivy-cache-race
Nov 16, 2026
Merged

frankmeds merged 1 commit into
mainfrom
fix/trivy-cache-race

Conversation

@frankmeds

Copy link
Copy Markdown
Contributor

Summary

Linting failed on main right after #165 merged (run 43820249859), although the same check passed on the PR:

trivy config .github/workflows/cicd-stg.yml ... --cache-dir <shared_cachedir>
FATAL ... init Rego scanner: load checks: failed to load rego checks from [.]:
open .../results/trivy/policy/content/policies/kubernetes/policies/privileged.rego: no such file or directory

Cause: trunk runs trivy config once per file, in parallel, and every run shares one --cache-dir. When the checks bundle is missing or more than a day old, each process downloads and unpacks it into the same directory. One process can then read files that another is replacing. That makes the failure random: it depends on how many YAML/Docker files change and on timing.

Fix: a 7-line override in .trunk/trunk.yaml backports the trunk-io/plugins v1.10.0 definition, which gives each run its own --cache-dir ${tmpdir}. We pin plugins v1.6.6, so this changes only the trivy config command and leaves every other linter alone. Drop the override when the plugins ref is bumped.

Testing

  • Reproduced the race locally: 4 parallel trivy config runs sharing a cold cache crashed with the same "load checks ... no such file" error in 2 of 12 rounds.
  • With per-run caches: 0 of 12 rounds failed.
  • Override is applied: I temporarily appended a bogus flag to the override, and trunk failed with unknown flag: --bogus-flag. The trivy command line showed a per-run temp --cache-dir.
  • trunk check passes on the change.

trunk runs 'trivy config' once per file in parallel, all sharing one
--cache-dir. On a cold or day-old cache every process downloads and
unpacks the checks bundle into the same directory, and one can read it
mid-replace ('load checks: ... no such file'), failing Linting at random
(it broke on main right after #165). Backport the trunk-io/plugins
v1.10.0 definition that uses a per-run ${tmpdir} instead.
@frankmeds
frankmeds merged commit fba0025 into main Nov 16, 2026
3 checks passed
@frankmeds
frankmeds deleted the fix/trivy-cache-race branch November 16, 2026 07:23
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.

1 participant