Skip to content

Conversation

@jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented Dec 11, 2025

Example:

from executorlib import SingleNodeExecutor

class Test:
    def __call__(self, a, b):
        return a+b

with SingleNodeExecutor(cache_directory="./test") as exe:
    f = exe.submit(Test(), a=1, b=2)
    print(f.result())

Summary by CodeRabbit

  • Refactor

    • Improved function-name handling during task serialization to more robustly derive names for edge-case callables.
  • Tests

    • Added coverage ensuring executor caching works with callable class instances and that cached inputs and outputs match runtime results.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 11, 2025

Warning

Rate limit exceeded

@jan-janssen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 1 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 7ddfd86 and 9e1a26f.

📒 Files selected for processing (2)
  • src/executorlib/standalone/serialize.py (2 hunks)
  • tests/test_standalone_serialize.py (1 hunks)

Walkthrough

Replaced direct use of fn.name with a new _get_function_name(fn) helper in serialize_funct to robustly obtain function names; added a test that submits a callable class instance to validate caching behavior.

Changes

Cohort / File(s) Summary
Serialization helper
src/executorlib/standalone/serialize.py
Added _get_function_name(fn: Callable) -> str that returns fn.__name__ if present, falls back to a name derived from __str__ or "fn". Updated serialize_funct() to use this helper when constructing the task key instead of fn.__name__.
Cache test
tests/test_singlenodeexecutor_cache.py
Added callable class AddClass with __call__(self, a, b) and new test test_cache_data_class() that registers cloudpickle, submits AddClass instances to SingleNodeExecutor, collects results, reads cache entries, and asserts cached input/output sums match expected totals.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review areas:
    • _get_function_name behavior for bound methods, lambdas, functools.partial, and decorated callables.
    • Consistency of task key format with existing consumers (backward compatibility).
    • Test assertions and how cache entries are read/parsed to ensure they reflect real cache schema.

Possibly related PRs

Poem

🐇 I hop through code with nimble paws,
I name each task without a pause,
When name hides behind a veil,
I sniff a label, leave a trail,
Caching cheer with tiny claws ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 and accurately describes the main change: adding support for caching callable class instances that lack a name attribute, which is the core problem addressed by the new _get_function_name helper.

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.

@jan-janssen jan-janssen linked an issue Dec 11, 2025 that may be closed by this pull request
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/test_singlenodeexecutor_cache.py (1)

20-23: LGTM - callable class for testing.

The AddClass implementation correctly provides a callable instance without a __name__ attribute, which is exactly what this PR aims to support.

Optional: For PEP 8 compliance, add spaces around the + operator on line 22: return a + b

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e417d4 and c36e842.

📒 Files selected for processing (2)
  • src/executorlib/standalone/serialize.py (2 hunks)
  • tests/test_singlenodeexecutor_cache.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/test_singlenodeexecutor_cache.py (1)
src/executorlib/executor/single.py (1)
  • SingleNodeExecutor (20-190)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: unittest_win
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.11)
  • GitHub Check: unittest_old
  • GitHub Check: notebooks
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.13)
  • GitHub Check: unittest_openmpi (macos-latest, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-latest, 3.12)
  • GitHub Check: unittest_openmpi (ubuntu-22.04-arm, 3.13)
  • GitHub Check: unittest_openmpi (ubuntu-24.04-arm, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.12)
  • GitHub Check: unittest_mpich (macos-latest, 3.13)
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-mpich.yml)
  • GitHub Check: unittest_mpich (ubuntu-latest, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-22.04-arm, 3.13)
  • GitHub Check: unittest_mpich (ubuntu-24.04-arm, 3.13)
  • GitHub Check: unittest_slurm_mpich
  • GitHub Check: unittest_flux_openmpi
  • GitHub Check: notebooks_integration
  • GitHub Check: unittest_flux_mpich
  • GitHub Check: benchmark (ubuntu-latest, 3.13, .ci_support/environment-openmpi.yml)
🔇 Additional comments (1)
src/executorlib/standalone/serialize.py (1)

78-78: Verify the helper implementation handles all cases correctly.

The change from fn.__name__ to _get_function_name(fn=fn) correctly supports callables without the __name__ attribute. However, ensure the helper function's fallback logic (parsing __str__()) produces consistent, valid names across different callable types.

Comment on lines 104 to 110
def _get_function_name(fn: Callable) -> str:
if hasattr(fn, "__name__"):
return fn.__name__
elif hasattr(fn, "__str__"):
return fn.__str__().split()[0].split(".")[-1]
else:
return "fn"
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Strengthen the fallback logic for callable instances.

The __str__() parsing on line 108 is fragile and may produce inconsistent results:

  1. For instances without module qualification (e.g., <AddClass object at 0x...>), split(".")[-1] would return <AddClass (including the < character)
  2. Custom __str__() implementations could break this parsing entirely
  3. The logic assumes a specific __str__ format that may not hold for all callables

Consider using type(fn).__name__ or fn.__class__.__name__ for callable instances, which directly returns the class name without fragile string parsing.

Apply this diff to improve robustness:

 def _get_function_name(fn: Callable) -> str:
     if hasattr(fn, "__name__"):
         return fn.__name__
-    elif hasattr(fn, "__str__"):
-        return fn.__str__().split()[0].split(".")[-1]
+    elif hasattr(fn, "__class__"):
+        return fn.__class__.__name__
     else:
         return "fn"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def _get_function_name(fn: Callable) -> str:
if hasattr(fn, "__name__"):
return fn.__name__
elif hasattr(fn, "__str__"):
return fn.__str__().split()[0].split(".")[-1]
else:
return "fn"
def _get_function_name(fn: Callable) -> str:
if hasattr(fn, "__name__"):
return fn.__name__
elif hasattr(fn, "__class__"):
return fn.__class__.__name__
else:
return "fn"
🤖 Prompt for AI Agents
In src/executorlib/standalone/serialize.py around lines 104 to 110, the fallback
that parses fn.__str__() is fragile and can produce incorrect names (e.g.,
includes “<” or depends on custom __str__ formats); change the logic to return
fn.__name__ if present, otherwise return type(fn).__name__ (or
fn.__class__.__name__) for callable instances, and only fall back to the literal
"fn" if neither is available, keeping the returned value as a simple string.

@codecov
Copy link

codecov bot commented Dec 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.27%. Comparing base (c9ad866) to head (9e1a26f).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #865      +/-   ##
==========================================
+ Coverage   93.26%   93.27%   +0.01%     
==========================================
  Files          38       38              
  Lines        1796     1800       +4     
==========================================
+ Hits         1675     1679       +4     
  Misses        121      121              

☔ View full report in Codecov by Sentry.
📢 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 jan-janssen merged commit c749923 into main Dec 11, 2025
62 of 63 checks passed
@jan-janssen jan-janssen deleted the noname branch December 11, 2025 17:19
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.

[Bug] Caching fails for abstract objects

2 participants