Skip to content

feat(python): async WebSocket-backed AsyncSerialMonitor methods#107

Merged
zackees merged 1 commit intomainfrom
feat/65-async-websocket-methods
Apr 18, 2026
Merged

feat(python): async WebSocket-backed AsyncSerialMonitor methods#107
zackees merged 1 commit intomainfrom
feat/65-async-websocket-methods

Conversation

@zackees
Copy link
Copy Markdown
Member

@zackees zackees commented Apr 18, 2026

Closes #65.

Completes the async Python API begun in PRs #73, #78, #84. Adds the WebSocket-backed async methods on AsyncSerialMonitor that were deferred in PR #73's scaffold.

What's in

  • __aenter__ / __aexit__ — async context manager opens /ws/serial-monitor, sends attach handshake, stores split sink/source halves, cleans up (Detach + Close) on exit
  • read_lines(timeout_secs) — async batch read; honors auto_reconnect (Preempted → continue; Reconnected → continue)
  • write(data) — async write, waits for daemon write_ack
  • write_json_rpc(request, timeout_secs) — async JSON-RPC send + poll for REMOTE: response, preserving PR Honor full JSON-RPC wait timeout #57's full-timeout guarantee (empty batch doesn't short-circuit deadline)

Send+Sync refactor

The sync SerialMonitor wraps its WS state in std::sync::Mutex, which can't be held across .await. For the async surface:

  • Split WebSocketStream via .split() into WsSink + WsSource
  • Each half stored in its own Arc<tokio::sync::Mutex<Option<_>>> — concurrent read/write futures don't serialize each other, and each future owns its own Arc clone into future_into_py

Sync SerialMonitor is untouched — purely additive.

Test plan

  • uv run cargo test -p fbuild-python --lib (11 existing tests passing)
  • uv run cargo clippy --workspace --all-targets -- -D warnings
  • uv run cargo fmt --all -- --check

Deferred

Unit tests for the new async methods. Follow-up would need a more elaborate WebSocket mock than the raw tokio::net::TcpListener HTTP mock used for send_op_async in PR #84.

🤖 Generated with Claude Code

#65)

Completes the remaining async surface from #65:
- __aenter__ / __aexit__ — async context-manager that opens the
  /ws/serial-monitor session, sends the attach handshake, stores the
  split sink/source halves, and cleans up on exit.
- read_lines(timeout_secs) — async batch read, honors
  auto_reconnect (Preempted → continue; Reconnected → continue).
- write(data) — async write that waits for daemon write_ack.
- write_json_rpc(request, timeout_secs) — async JSON-RPC send + poll
  for REMOTE: response, preserving the PR #57 full-timeout guarantee
  by keeping polling across empty batches.

Send+Sync refactor:
- Split WebSocketStream via .split() into WsSink + WsSource.
- Each half stored in its own Arc<tokio::sync::Mutex<Option<_>>> so
  concurrent read/write futures do not serialize each other and each
  future owns its own Arc clone.

Sync SerialMonitor is untouched — additive only.

Deferred follow-up: unit tests for the new async methods. The
existing 11 fbuild-python tests still pass; new tests would need
a more elaborate WebSocket mock than the HTTP mock used for
send_op_async (PR #84).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Warning

Rate limit exceeded

@zackees has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 22 minutes and 28 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 22 minutes and 28 seconds.

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5a84c055-7211-49c0-9c6d-090bfc27812a

📥 Commits

Reviewing files that changed from the base of the PR and between d37995b and e905230.

📒 Files selected for processing (1)
  • crates/fbuild-python/src/lib.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/65-async-websocket-methods

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.

@zackees zackees merged commit 71ba843 into main Apr 18, 2026
73 of 77 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.

feat(python): native async API via pyo3-async-runtimes (AsyncSerialMonitor, AsyncDaemon)

1 participant