Skip to content

fix(bundle-analysis): clean up temp files on load failure#917

Merged
drazisil-codecov merged 2 commits into
mainfrom
fix/bundle-analysis-tempfile-leak
May 6, 2026
Merged

fix(bundle-analysis): clean up temp files on load failure#917
drazisil-codecov merged 2 commits into
mainfrom
fix/bundle-analysis-tempfile-leak

Conversation

@drazisil-codecov
Copy link
Copy Markdown
Contributor

@drazisil-codecov drazisil-codecov commented May 6, 2026

Summary

  • BundleAnalysisReportLoader.load() called tempfile.mkstemp() but never deleted the temp file on the FileNotInStorageError path (returned None without cleanup) or on any unexpected exception path
  • Workers running many BA tasks accumulated SQLite temp files on disk until hitting No space left on device (WORKER-WNZ)
  • Fix restructures the try/except so both error paths call os.unlink(db_path) before returning/re-raising; the happy path still transfers ownership to the returned BundleAnalysisReport, which has its own cleanup() method

Test plan

  • test_load_cleans_up_tempfile_on_file_not_found — patches mkstemp to capture the path, asserts file no longer exists after load() returns None
  • test_load_cleans_up_tempfile_on_unexpected_error — same, but for an unexpected RuntimeError that should re-raise
  • test_save_load_bundle_report — existing happy-path test still passes

🤖 Generated with Claude Code


Note

Low Risk
Low risk: narrow change to temporary-file lifecycle in BundleAnalysisReportLoader.load, plus targeted unit tests; only impacts failure paths and should reduce disk-leak incidents.

Overview
Fixes BundleAnalysisReportLoader.load() to always clean up the mkstemp-created SQLite temp file when the report is missing (FileNotInStorageError) or when any unexpected exception occurs, instead of leaking files on disk.

Adds unit tests that assert the temp file is deleted on both not found and unexpected error paths, while keeping the existing save/load happy-path behavior intact.

Reviewed by Cursor Bugbot for commit f2003b3. Bugbot is set up for automated code reviews on this repo. Configure here.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@drazisil-codecov drazisil-codecov force-pushed the fix/bundle-analysis-tempfile-leak branch from 4b2c3c5 to 4adb001 Compare May 6, 2026 12:21
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4adb001. Configure here.

Comment thread libs/shared/shared/bundle_analysis/storage.py
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented May 6, 2026

Merging this PR will not alter performance

✅ 9 untouched benchmarks


Comparing fix/bundle-analysis-tempfile-leak (f2003b3) with main (3d2b291)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (9203b6d) during the generation of this report, so 3d2b291 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@codecov-notifications
Copy link
Copy Markdown

codecov-notifications Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@sentry
Copy link
Copy Markdown
Contributor

sentry Bot commented May 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.89%. Comparing base (9203b6d) to head (f2003b3).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #917   +/-   ##
=======================================
  Coverage   91.89%   91.89%           
=======================================
  Files        1316     1316           
  Lines       50633    50639    +6     
  Branches     1625     1625           
=======================================
+ Hits        46531    46537    +6     
  Misses       3796     3796           
  Partials      306      306           
Flag Coverage Δ
apiunit 94.95% <ø> (ø)
sharedintegration 36.96% <9.09%> (-0.01%) ⬇️
sharedunit 84.90% <100.00%> (+<0.01%) ⬆️
workerintegration 58.53% <ø> (ø)
workerunit 90.37% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@thomasrockhu-codecov
Copy link
Copy Markdown
Contributor

Make sure os.close(fd) doesn't affect our ability to use db_path downstream

@drazisil-codecov drazisil-codecov added this pull request to the merge queue May 6, 2026
@drazisil-codecov
Copy link
Copy Markdown
Contributor Author

Confirmed locally that unlinking fd does not affect db_path.

Merged via the queue into main with commit 2e45f4f May 6, 2026
52 of 53 checks passed
@drazisil-codecov drazisil-codecov deleted the fix/bundle-analysis-tempfile-leak branch May 6, 2026 14:45
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.

2 participants