Skip to content

Update libs, external review and refactor sync command execution - #3

Merged
marcomq merged 2 commits into
mainfrom
dev
Jun 7, 2026
Merged

Update libs, external review and refactor sync command execution#3
marcomq merged 2 commits into
mainfrom
dev

Conversation

@marcomq

@marcomq marcomq commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Enhanced async function call documentation clarifying call_function vs call_async_function usage.
    • Expanded venv setup guidance with uv-based workflow.
  • Bug Fixes

    • Improved error handling for Python code with embedded NUL characters.
    • Better async call error reporting on RustPython backend.
  • Chores

    • Bumped version to 0.3.1.
    • Updated dependencies (serde_json, thiserror, tokio, pyo3, rustpython).
    • Removed GitHub Actions CI workflow.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@marcomq, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 40 minutes and 10 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

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.

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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb757bf6-e784-4875-9660-d21604b3935f

📥 Commits

Reviewing files that changed from the base of the PR and between 6288b8d and 0a09d8c.

📒 Files selected for processing (2)
  • README.md
  • src/rustpython_runner.rs
📝 Walkthrough

Walkthrough

This PR modernizes the async_py library with a version bump to 0.3.1, dependency updates, and significant backend refactoring. The synchronous command execution mechanism is rewritten to avoid blocking Tokio runtimes. Both PyO3 and RustPython backends receive improvements: PyO3 gains centralized error handling for string-to-CString conversion, and RustPython is modernized with a builder-pattern interpreter initialization and improved error reporting. Documentation is expanded with clarifications on async function handling and venv setup.

Changes

Library modernization and backend refactoring

Layer / File(s) Summary
Dependency version updates and metadata
Cargo.toml, .gitignore
Crate version bumped to 0.3.1; dependencies updated to newer versions (serde_json, thiserror, tokio, pyo3 0.28, rustpython-vm/stdlib 0.5); once_cell removed; .gitignore updated for .serena artifact.
Backend compilation conditional gating
src/lib.rs
Conditional compilation refactored to cfg(all(feature = "pyo3", not(feature = "rustpython"))); test guards updated; Tokio Handle import replaces Runtime for better modularity.
Synchronous command execution refactor
src/lib.rs
Dedicated sync worker thread removed; send_command_sync now detects Tokio runtime with Handle::try_current() and offloads blocking operations to OS thread when inside async context; path canonicalization fallback prevents panic on failure.
PyO3 string-to-CString error handling
src/pyo3_runner.rs
New python_code_to_cstring helper centralizes string-to-CString conversion, mapping embedded-NUL errors to Python ValueError instead of panicking; RunCode, EvalCode, and RunFile use the helper for graceful error propagation.
RustPython backend modernization
src/rustpython_runner.rs
Interpreter initialization switched to builder pattern with native stdlib registration; RunFile injects parent directory into sys.path and reads file source with explicit error handling; async calls return VM-created NotImplementedError; error printing uses vm.write_exception for proper exception rendering; JSON conversions use lossy string handling.
Documentation updates and test additions
README.md, src/lib.rs
README expanded with async_py version reference, call_function vs call_async_function distinction, RustPython async limitation note, set_venv clarification with uv examples, and updated inline-python comparison; new tests verify post-stop error behavior and backend-specific error reporting.
CI workflow removal
src/rust.yml
GitHub Actions workflow deleted; removes the test job running cargo test on main branch across multiple platforms.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

🐰 A library grows up with grace,
Backends dancing in their place,
Sync no longer blocks the flow,
Errors caught where they should go,
Version bumped, let futures sing!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Title check ✅ Passed The title mentions 'Update libs' and 'refactor sync command execution' which are significant changes in Cargo.toml and src/lib.rs, but omits major work like async handling improvements, test updates, and RustPython refactoring.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

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

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/rustpython_runner.rs (1)

218-223: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Remove stale traceback line offset for main.py.

Line 219–223 still subtracts 2 from traceback lines for main.py, but RunFile now runs the user file source directly, so this remapping is no longer valid and can misreport line numbers.

Suggested fix
-            let line = if file == "main.py" {
-                original_line - 2 // sys.path import has 2 additional lines
-            } else {
-                original_line
-            };
+            let line = original_line;
🤖 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/rustpython_runner.rs` around lines 218 - 223, The code subtracts 2 from
trace.lineno for file == "main.py" (original_line - 2) which is now incorrect
since RunFile runs the user source directly; remove that special-case remapping
and always use trace.lineno.get() (i.e., set line = original_line) so reported
traceback line numbers are accurate; update the logic around original_line/line
in rustpython_runner.rs (the branch that checks file == "main.py") to stop
applying the -2 offset.
🤖 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 `@README.md`:
- Around line 104-106: The README statement about call_async_function is
misleading: instead of saying it is "only available with the default PyO3
backend", update the wording to clarify that the call_async_function API exists
for both backends but only functions at runtime with the PyO3 backend — with the
RustPython backend invoking call_async_function will return an "unsupported"
error at runtime; change the sentence around the symbol call_async_function to
explicitly mention PyO3 provides runtime support while RustPython reports
unsupported, so readers understand the API is present but behavior differs by
backend.

---

Outside diff comments:
In `@src/rustpython_runner.rs`:
- Around line 218-223: The code subtracts 2 from trace.lineno for file ==
"main.py" (original_line - 2) which is now incorrect since RunFile runs the user
source directly; remove that special-case remapping and always use
trace.lineno.get() (i.e., set line = original_line) so reported traceback line
numbers are accurate; update the logic around original_line/line in
rustpython_runner.rs (the branch that checks file == "main.py") to stop applying
the -2 offset.
🪄 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: e888536d-7ca1-4e8f-93f3-6f0c3739abd2

📥 Commits

Reviewing files that changed from the base of the PR and between 469bc43 and 6288b8d.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • .gitignore
  • Cargo.toml
  • README.md
  • src/lib.rs
  • src/pyo3_runner.rs
  • src/rust.yml
  • src/rustpython_runner.rs
💤 Files with no reviewable changes (1)
  • src/rust.yml

Comment thread README.md Outdated
@marcomq marcomq changed the title Update libs, external review, small improvements Update libs, external review and refactor sync command execution Jun 7, 2026
@marcomq
marcomq merged commit d006e15 into main Jun 7, 2026
4 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.

1 participant