Skip to content

Fix flaky ignore overlay tests from shared artifact dir - #6854

Merged
rdimitrov merged 2 commits into
mainfrom
rdimitrov/ignore-artifact-dir-race
Oct 19, 2026
Merged

rdimitrov merged 2 commits into
mainfrom
rdimitrov/ignore-artifact-dir-race

Conversation

@rdimitrov

Copy link
Copy Markdown
Member

Summary

TestGetOverlayPaths failed intermittently in CI (run) with the .ssh directory overlay missing while the .env file overlay was present.

Why: every ignore.Processor in a process used the same artifact directory, $TMPDIR/toolhive/overlays/thvignore-<pid>, but Cleanup() removes that directory as if the processor owned it. When a parallel test's Cleanup() ran between another processor's MkdirAll(artifactDir) and MkdirTemp(artifactDir, "dir-*"), the MkdirTemp failed with ENOENT. createOverlayMount logs that at debug level and returns nil, so the directory overlay was silently dropped. File overlays use os.CreateTemp("") instead, which is why only directory overlays were affected.

What:

  • The workload ID now includes a per-process sequence number (thvignore-<pid>-<n>), so each processor owns its own artifact directory and Cleanup() only removes storage it created.
  • Added TestGetOverlayMountsConcurrentCleanup, which runs 16 goroutines that each create, use, and clean up processors against the same source tree. Before the fix it dropped the overlay hundreds of times per run; with the fix it passes.

Type of change

  • Bug fix

Test plan

  • Unit tests: go test -race -count=50 ./pkg/ignore/... passes; the new test fails on the old code (416 dropped overlays across -count=5)
  • Linting: golangci-lint v2.15.0 (CI-pinned) on ./pkg/ignore/..., 0 issues
  • Manual testing: confirmed no artifact directories are left under $TMPDIR/toolhive/overlays after the test runs

Does this introduce a user-facing change?

No. Overlay artifact directories for ignored paths are now nested under thvignore-<pid>-<n> instead of thvignore-<pid>; nothing outside pkg/ignore references that path.

Special notes for reviewers

  • Production (pkg/container/docker/client.go) creates one processor per mount and never calls Cleanup(), so the race is not reachable there today. The fix is in the code rather than the test because a dropped overlay fails open, leaving an ignored directory such as .ssh visible in the container.
  • In production, each mount now gets its own parent directory instead of sharing one per process. Each one already holds its own dir-* subdirectories, so the added cost is one directory per processor.

🤖 Generated with Claude Code

Every Processor in a process shared $TMPDIR/toolhive/overlays/thvignore-<pid>
as its artifact directory, yet Cleanup removes that directory as if it owned
it. When one processor cleaned up between another's MkdirAll and MkdirTemp,
the MkdirTemp failed, the error was logged at debug level, and the directory
overlay was silently dropped. This made TestGetOverlayPaths flaky in CI and
would leave an ignored directory unmasked if it happened outside tests.

Add a per-process sequence number to the workload ID so each processor owns
a distinct directory, and add a concurrent stress test that reproduces the
dropped overlay on the old code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rdimitrov
rdimitrov requested a review from JAORMX as a code owner October 19, 2026 10:58
@github-actions github-actions Bot added the size/XS Extra small PR: < 100 lines changed label Oct 19, 2026
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.72%. Comparing base (5c06e05) to head (b8d8864).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6854      +/-   ##
==========================================
- Coverage   79.73%   79.72%   -0.01%     
==========================================
  Files         819      819              
  Lines       83667    83667              
==========================================
- Hits        66711    66707       -4     
- Misses      16951    16955       +4     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Oct 19, 2026
@rdimitrov
rdimitrov merged commit 7e35c5b into main Oct 19, 2026
46 checks passed
@rdimitrov
rdimitrov deleted the rdimitrov/ignore-artifact-dir-race branch October 19, 2026 12:21
@github-actions github-actions Bot mentioned this pull request Oct 19, 2026
2 tasks
@jhrozek jhrozek mentioned this pull request Nov 23, 2026
3 of 10 tasks
devin-ai-integration Bot pushed a commit to jstar0/toolhive that referenced this pull request Nov 23, 2026
Address review feedback: rebase on main so the per-processor artifact
directory from stacklok#6854 is used, extend TestGetOverlayMountsConfinedToMount
with wildcard directory cases (file skip, symlink inside and outside the
mount, pattern beyond the mount), and drop the standalone test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant