Skip to content

[Refactor] receive_dict() returns the status and the error as dict#1029

Merged
jan-janssen merged 6 commits into
mainfrom
receive_dict
Jul 3, 2026
Merged

[Refactor] receive_dict() returns the status and the error as dict#1029
jan-janssen merged 6 commits into
mainfrom
receive_dict

Conversation

@jan-janssen

@jan-janssen jan-janssen commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of interactive task execution by handling socket responses more consistently.
    • Fixed shutdown and task-result handling so returned values and errors are processed in a predictable way.
    • Updated error reporting for failed interactive sessions, reducing unexpected exceptions during communication.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@jan-janssen, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 4 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9455c17a-0cdb-4549-a466-182ca63e0f3f

📥 Commits

Reviewing files that changed from the base of the PR and between b1a8e85 and d1d9705.

📒 Files selected for processing (2)
  • src/executorlib/standalone/interactive/communication.py
  • src/executorlib/task_scheduler/interactive/shared.py
📝 Walkthrough

Walkthrough

SocketInterface.receive_dict now returns the raw deserialized payload rather than unwrapping "result"/"error"; shutdown extracts ["result"] explicitly. Task scheduler paths (blockallocation.py, shared.py) replace try/except exception handling around send_and_receive_dict with direct dict-key branching on "result"/"error". Tests updated accordingly.

Changes

Dict-based result/error handling refactor

Layer / File(s) Summary
SocketInterface receive_dict and shutdown changes
src/executorlib/standalone/interactive/communication.py
receive_dict returns the full deserialized dict instead of unwrapping result/error; shutdown now indexes ["result"] from the response explicitly.
Task scheduler initialization and execution paths
src/executorlib/task_scheduler/interactive/blockallocation.py, src/executorlib/task_scheduler/interactive/shared.py
_set_init_function, _execute_task_without_cache, and _execute_task_with_cache replace try/except exception capture with direct branching on "result" vs "error" keys returned by send_and_receive_dict, including special-casing ExecutorlibSocketError.
Test updates for dict-based result/error
tests/unit/standalone/interactive/test_communication.py
Tests updated to assert on output["result"] and output["error"] instead of comparing raw return values or expecting raised exceptions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Shared
  participant BlockAllocation
  participant SocketInterface
  participant Socket

  Shared->>SocketInterface: send_and_receive_dict(task_dict)
  SocketInterface->>Socket: send serialized data
  Socket-->>SocketInterface: raw bytes
  SocketInterface->>SocketInterface: receive_dict() returns cloudpickle.loads(data)
  SocketInterface-->>Shared: dict output {"result"} or {"error"}
  alt output has "result"
    Shared->>Shared: set future_obj result
  else output["error"] is ExecutorlibSocketError
    Shared-->>Shared: return False
  else other error
    Shared->>Shared: set future_obj exception
  end

  BlockAllocation->>SocketInterface: send_and_receive_dict(init message)
  SocketInterface-->>BlockAllocation: dict output
  BlockAllocation->>BlockAllocation: set interface_initialization_exception if "error" present
Loading

Possibly related PRs

  • pyiron/executorlib#795: Modifies the same _execute_task_without_cache / _execute_task_with_cache functions in shared.py for error/exception handling around task dispatch.
  • pyiron/executorlib#800: Also changes how send_and_receive_dict() outputs are interpreted and propagated into the task Future in the same functions.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: receive_dict now returns the raw payload as a dict instead of unwrapping result or error.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch receive_dict

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.

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/executorlib/standalone/interactive/communication.py (1)

78-89: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

receive_dict() should return an error dict on crash
src/executorlib/standalone/interactive/communication.py:78-89 still raises ExecutorlibSocketError when the spawner dies, but tests/unit/standalone/interactive/test_communication.py::test_interface_serial_with_stopped_process and the downstream task code now expect {"error": ExecutorlibSocketError(...)}. That exception will bypass the new output["error"] handling. Replace the raise with an error dict here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/executorlib/standalone/interactive/communication.py` around lines 78 -
89, `receive_dict()` in `Communication` still raises `ExecutorlibSocketError`
when `_spawner.poll()` indicates the process has crashed, but callers now expect
an error payload instead. Update the crash branch in `receive_dict()` to return
a dictionary with an `error` key containing the `ExecutorlibSocketError`
instance, and keep the existing receive/logging flow unchanged for the non-crash
path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/executorlib/task_scheduler/interactive/shared.py`:
- Around line 146-150: In the success path inside the shared task scheduler
flow, `result` is undefined when handling the `if "result" in output` branch,
causing a `NameError` after cache writes. Update the
`future_obj.set_result(...)` call in the relevant function in `shared.py` to use
the value already extracted from `output` (the same one stored in
`data_dict["output"]`), and keep the cache-hit and cache-miss branches
consistent.

---

Outside diff comments:
In `@src/executorlib/standalone/interactive/communication.py`:
- Around line 78-89: `receive_dict()` in `Communication` still raises
`ExecutorlibSocketError` when `_spawner.poll()` indicates the process has
crashed, but callers now expect an error payload instead. Update the crash
branch in `receive_dict()` to return a dictionary with an `error` key containing
the `ExecutorlibSocketError` instance, and keep the existing receive/logging
flow unchanged for the non-crash path.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6d9ef240-a317-4665-863d-03059fea6136

📥 Commits

Reviewing files that changed from the base of the PR and between 7346897 and b1a8e85.

📒 Files selected for processing (4)
  • src/executorlib/standalone/interactive/communication.py
  • src/executorlib/task_scheduler/interactive/blockallocation.py
  • src/executorlib/task_scheduler/interactive/shared.py
  • tests/unit/standalone/interactive/test_communication.py

Comment thread src/executorlib/task_scheduler/interactive/shared.py Outdated
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.22%. Comparing base (6dfe717) to head (d1d9705).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1029      +/-   ##
==========================================
- Coverage   94.23%   94.22%   -0.02%     
==========================================
  Files          39       39              
  Lines        2118     2113       -5     
==========================================
- Hits         1996     1991       -5     
  Misses        122      122              

☔ 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
jan-janssen merged commit faf71ea into main Jul 3, 2026
38 checks passed
@jan-janssen
jan-janssen deleted the receive_dict branch July 3, 2026 18:22
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