Skip to content

Warn when init_function is combined with cache_directory - #1085

Merged
jan-janssen merged 1 commit into
mainfrom
warn-init-function-cache
Oct 21, 2026
Merged

jan-janssen merged 1 commit into
mainfrom
warn-init-function-cache

Conversation

@jan-janssen

@jan-janssen jan-janssen commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

Addresses #1084 by warning the user. This does not fix the underlying caching issue.

The cache key is computed from fn, args and kwargs only. It does not include the state the init_function sets up in the worker. Functions that read this state can therefore get stale results from the cache, without any error. Until the cache key accounts for that state, executorlib now emits a UserWarning when init_function and cache_directory are both set.

Changes

  • New check_init_function_with_cache() in standalone/inputcheck.py. It warns when both init_function and cache_directory are not None.
  • The check is called wherever both options can meet with block_allocation=True:
    • create_single_node_executor (SingleNodeExecutor)
    • create_slurm_executor (SlurmJobExecutor)
    • create_flux_executor (FluxJobExecutor)
    • create_pysqa_block_allocation_scheduler (SlurmClusterExecutor / FluxClusterExecutor with block allocation)
  • Tests:

Testing

  • tests/unit/standalone/test_inputcheck.py, tests/unit/executor/test_single_cache.py, test_single_noblock.py, test_single_dependencies.py, test_api.py: pass locally.
  • ruff check / ruff format --check on the changed source files: clean.
  • tests/unit/standalone/interactive/test_spawner.py and the MPI executor tests fail locally on main as well. My local MPI setup runs only one rank, so these failures are unrelated to this PR.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Added a warning when initialization logic is used together with cached execution results, helping prevent stale or unexpected results.
    • Applied this validation consistently across supported executor and scheduler configurations.
    • Cached submissions using initialization logic now clearly indicate the potential compatibility issue while preserving independent task results.
  • Tests

    • Added coverage for warning behavior and confirmed no warning appears when either caching or initialization is not configured.

The cache key is computed from the submitted function and its arguments
only, so it does not reflect the state set by the init_function. Functions
which depend on this state can therefore return stale results from the
cache. Until this is fixed, warn the user when both options are set.

See #1084

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 09551ff2-380c-48a5-be3b-e9e6d02d5c45
📥 Commits

Reviewing files that changed from the base of the PR and between fef1804 and 2e242f0.

📒 Files selected for processing: 7
  • src/executorlib/executor/flux.py
  • src/executorlib/executor/single.py
  • src/executorlib/executor/slurm.py
  • src/executorlib/standalone/inputcheck.py
  • src/executorlib/task_scheduler/interactive/spawner_pysqa.py
  • tests/unit/executor/test_single_cache.py
  • tests/unit/standalone/test_inputcheck.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The PR adds a warning when an initialization function and cache directory are configured together. It calls the check from Flux, single-node, Slurm, and PySQA block-allocation executor creation paths, with tests for warning behavior and cached submissions.

Changes: Initializer and cache validation

Layer / File(s) Summary
Add the initializer and cache warning
src/executorlib/standalone/inputcheck.py, tests/unit/standalone/test_inputcheck.py
Adds a check that warns when both init_function and cache_directory are set. Tests cover both the warning case and cases where either value is None.
Call the check during executor creation
src/executorlib/executor/flux.py, src/executorlib/executor/single.py, src/executorlib/executor/slurm.py, src/executorlib/task_scheduler/interactive/spawner_pysqa.py, tests/unit/executor/test_single_cache.py
Adds the check to four executor creation paths. A cache test verifies the warning and that three submissions return independent results of 1.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related issues

  • Issue 1084 — This PR warns about the stale-cache risk when initialization and caching are combined. It does not change cache-key behavior.
Merge Risk: ⚪ Minimal · up to 2e242

The warning is in place for the supported executor creation paths, and no new merge-blocking risk is established. The underlying cache-key issue remains unresolved.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: warning when init_function is used with cache_directory.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.28%. Comparing base (3974465) to head (2e242f0).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1085      +/-   ##
==========================================
+ Coverage   94.26%   94.28%   +0.01%     
==========================================
  Files          39       39              
  Lines        2180     2187       +7     
==========================================
+ Hits         2055     2062       +7     
  Misses        125      125              

☔ 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.

@jan-janssen

Copy link
Copy Markdown
Member Author

@prabhath-c This should at least give a warning when using the init_function and the cache_directory at the same time. This is the case for pylammpsmpi.

@jan-janssen
jan-janssen merged commit c2291d8 into main Oct 21, 2026
238 of 255 checks passed
@jan-janssen
jan-janssen deleted the warn-init-function-cache branch October 21, 2026 16:17
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