Skip to content

(feat,osw): auto clean cache files from temp dir - #9029

Merged
timosachsenberg merged 9 commits into
OpenMS:developfrom
singjc:feat/osw_auto_clean_tmp_cache
Apr 1, 2026
Merged

timosachsenberg merged 9 commits into
OpenMS:developfrom
singjc:feat/osw_auto_clean_tmp_cache

Conversation

@singjc

@singjc singjc commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

When using the cache read options for OpenSwathWorkflow, temporary cache files are written to disk in a temp directory set by the user. These files are usually left to the user to remember to clean up and delete, but sometimes they may be forgotten about and can accumulate and take up storage space. Added the ability to automatically clean and delete the cache files (after each run is processed), and added a flag to let the user explicitly keep the cached files if they want.

Temporary cache management improvements:

  • Added a new flag option keep_cached_files to allow users to retain cached files in the temporary directory, disabling automated cleanup.
  • Implemented logic to create a unique per-run temporary cache directory when the readOptions parameter is set to cache, ensuring isolation and preventing conflicts between runs.
  • Updated calls to loadSwathFiles to use the per-run temporary directory instead of the global temp directory, ensuring that each run uses its own cache space. [1] [2]
  • Added cleanup logic to remove the per-run cache directory after processing, unless the user has set the keep_cached_files flag. This helps manage disk usage and prevents leftover temporary files.

Filesystem compatibility:

  • Changed the construction of the dirpath variable to use std::filesystem::path directly instead of std::filesystem::u8path, improving compatibility and simplifying the code.

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • New Features

    • Added a keep_cached_files CLI flag to control whether per-run temporary cache directories are retained.
    • Caching now isolates artifacts into a unique per-run subdirectory for safer, clearer run-level cache handling.
  • Chores

    • Changelog updated to note automatic per-run cache cleanup behavior.

@coderabbitai

coderabbitai Bot commented Mar 28, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Added a keep_cached_files CLI flag and created per-run temporary cache directories when readOptions == "cache", switching cached reads/writes to the per-run directory; preserved shared temp behavior otherwise. Also added a File::TempDir overload to create temp dirs under a specified base and adjusted parquet path construction.

Changes

Cohort / File(s) Summary
OpenSwath workflow
src/topp/OpenSwathWorkflow.cpp
Added keep_cached_files CLI flag; create per-run temp dir when readOptions == "cache" and pass it to loadSwathFiles(...); use shared tmp when not caching; minor formatting tweaks.
TempDir API
src/openms/include/OpenMS/SYSTEM/File.h, src/openms/source/SYSTEM/File.cpp
Added File::TempDir(const String& base_dir, bool keep_dir=false) overload that creates a unique subdirectory under a provided base directory.
Parquet path construction
src/topp/OpenSwathWorkflow.cpp
Switched from std::filesystem::u8path(std::string(parquet_dir)) to std::filesystem::path(std::string(parquet_dir)) for parquet zip streaming.
Changelog
CHANGELOG.md
Added OpenSwathWorkflow entry: “Added cache file auto cleanup (#9029)”.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as CLI
    participant Workflow as OpenSwathWorkflow
    participant Loader as loadSwathFiles
    participant FS as FileSystem

    CLI->>Workflow: parse flags (incl. keep_cached_files, readOptions)
    alt readOptions == "cache"
        Workflow->>FS: create per_run_tmp under tempDirectory
        Workflow->>Loader: load/write cached artifacts using per_run_tmp
        Loader->>FS: read/write cached files in per_run_tmp
    else
        Workflow->>Loader: load/write using shared tmp_dir
    end
    Workflow->>Workflow: processing completes
    alt created per_run_tmp && !keep_cached_files
        Workflow->>FS: remove per_run_tmp recursively
    else
        Note right of Workflow: retain per_run_tmp
    end
Loading

Suggested reviewers

  • cbielow

Poem

🐰 I dug a tiny temp with care,
Per-run caches nestled safe in there,
A flag to keep or let them go,
I tidy hops and tidy snow,
Files tucked or gone — I prune with flair!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly matches the main change: adding automated cache file cleanup with a per-run temporary directory and optional keep flag for OpenSwathWorkflow.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/topp/OpenSwathWorkflow.cpp`:
- Around line 1027-1048: The per-run cache directory cleanup currently runs too
early and not reliably on failure paths; modify the code around per_run_tmp and
created_run_tmp so that any run-local cache-backed objects/readers are destroyed
or explicitly closed before calling File::removeDirRecursively(per_run_tmp), and
wrap the created_run_tmp cleanup in an RAII scope guard (or an inner scope) that
calls File::removeDirRecursively in its destructor so the directory is removed
on all exits (normal, return, exception); ensure the cleanup guard is
constructed only when created_run_tmp is true and reference the same per_run_tmp
variable used when creating the directory.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ff94cb47-ae14-4ed2-aa2b-160341bee4ac

📥 Commits

Reviewing files that changed from the base of the PR and between 22e9c8f and ad73091.

📒 Files selected for processing (1)
  • src/topp/OpenSwathWorkflow.cpp

Comment thread src/topp/OpenSwathWorkflow.cpp Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/topp/OpenSwathWorkflow.cpp`:
- Around line 1078-1098: The per_run_tmp allocation is unsafe: when readoptions
== "cache" treat both an existing directory and a failed makeDir() as allocation
failures; do not mark created_run_tmp true just because File::isDirectory()
returned true. Modify the block that creates per_run_tmp (variables per_run_tmp,
created_run_tmp and calls to File::getUniqueName(), File::isDirectory(),
File::makeDir()) so that you loop/retry generating a fresh unique name if the
candidate already exists or if makeDir() fails (or else abort/propagate an
error), and only set created_run_tmp = true after a confirmed successful
File::makeDir() call.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2762f141-ef4e-4ee7-b039-6a53ddd29a2b

📥 Commits

Reviewing files that changed from the base of the PR and between ad73091 and 7ac2a84.

📒 Files selected for processing (2)
  • CHANGELOG
  • src/topp/OpenSwathWorkflow.cpp
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG

Comment thread src/topp/OpenSwathWorkflow.cpp Resolved
Comment thread src/topp/OpenSwathWorkflow.cpp Outdated
bool created_run_tmp = false;
if (readoptions == "cache")
{
const int max_attempts = 10;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this needed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We have some mechanisms to delete temp files in our tests or search engine adapters. Maybe worth a look

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out, I've updated to using some of the existing stuff in File.cpp/h

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/openms/include/OpenMS/SYSTEM/File.h (1)

42-47: Use explicit Doxygen tags for the new public constructor docs.

Please switch this new constructor comment block to @brief style (and keep @param tags) to match header documentation rules consistently.

As per coding guidelines: “Use Doxygen @brief (required) followed by blank line and details.”

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/SYSTEM/File.h` around lines 42 - 47, Update the
Doxygen for the public constructor TempDir(const String& base_dir, bool keep_dir
= false) to use an explicit `@brief` tag followed by a blank line and then the
longer description, and retain the `@param` tags for base_dir and keep_dir; in
other words replace the current freeform comment lines with an `@brief` one-line
summary, a blank line, detailed explanation, and the existing `@param` entries so
the comment follows the project's header documentation rules.
src/topp/OpenSwathWorkflow.cpp (1)

1052-1054: Consider logging the effective run-local temp path on load failures.

Now that loading uses per_run_tmp, the failure message should print that value (instead of shared tmp_dir) for accurate diagnostics.

Suggested patch
-                           << "  (split_file=" << (split_file ? "true" : "false") << ", tmp_dir='" << tmp_dir << "', readoptions='" << readoptions << "')"
+                           << "  (split_file=" << (split_file ? "true" : "false") << ", tmp_dir='" << per_run_tmp << "', readoptions='" << readoptions << "')"
...
-                           << "  (split_file=" << (split_file ? "true" : "false") << ", tmp_dir='" << tmp_dir << "', readoptions='" << readoptions << "')"
+                           << "  (split_file=" << (split_file ? "true" : "false") << ", tmp_dir='" << per_run_tmp << "', readoptions='" << readoptions << "')"

Also applies to: 1067-1069

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/topp/OpenSwathWorkflow.cpp` around lines 1052 - 1054, The failure
branches that check the return of loadSwathFiles currently log the shared
tmp_dir value, but since loading uses per_run_tmp the error message should
include per_run_tmp for accurate diagnostics; update the error logging in the
if-block(s) that follow loadSwathFiles (the call passing per_run_tmp and
&qc_consumer) to print the effective per_run_tmp path instead of tmp_dir, and
make the analogous change for the second loadSwathFiles call (the other failing
branch around the subsequent call) so both failure messages report per_run_tmp.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/openms/include/OpenMS/SYSTEM/File.h`:
- Around line 42-47: Update the Doxygen for the public constructor TempDir(const
String& base_dir, bool keep_dir = false) to use an explicit `@brief` tag followed
by a blank line and then the longer description, and retain the `@param` tags for
base_dir and keep_dir; in other words replace the current freeform comment lines
with an `@brief` one-line summary, a blank line, detailed explanation, and the
existing `@param` entries so the comment follows the project's header
documentation rules.

In `@src/topp/OpenSwathWorkflow.cpp`:
- Around line 1052-1054: The failure branches that check the return of
loadSwathFiles currently log the shared tmp_dir value, but since loading uses
per_run_tmp the error message should include per_run_tmp for accurate
diagnostics; update the error logging in the if-block(s) that follow
loadSwathFiles (the call passing per_run_tmp and &qc_consumer) to print the
effective per_run_tmp path instead of tmp_dir, and make the analogous change for
the second loadSwathFiles call (the other failing branch around the subsequent
call) so both failure messages report per_run_tmp.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9f5fbb50-c863-4cc6-b2de-179c2bf9c7b1

📥 Commits

Reviewing files that changed from the base of the PR and between 307203d and bb73451.

📒 Files selected for processing (4)
  • CHANGELOG
  • src/openms/include/OpenMS/SYSTEM/File.h
  • src/openms/source/SYSTEM/File.cpp
  • src/topp/OpenSwathWorkflow.cpp
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG

@timosachsenberg
timosachsenberg merged commit bbb059e into OpenMS:develop Apr 1, 2026
38 checks passed
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