feat(python): async WebSocket-backed AsyncSerialMonitor methods#107
feat(python): async WebSocket-backed AsyncSerialMonitor methods#107
Conversation
#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>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Closes #65.
Completes the async Python API begun in PRs #73, #78, #84. Adds the WebSocket-backed async methods on
AsyncSerialMonitorthat 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 exitread_lines(timeout_secs)— async batch read; honorsauto_reconnect(Preempted → continue; Reconnected → continue)write(data)— async write, waits for daemonwrite_ackwrite_json_rpc(request, timeout_secs)— async JSON-RPC send + poll forREMOTE: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
SerialMonitorwraps its WS state instd::sync::Mutex, which can't be held across.await. For the async surface:WebSocketStreamvia.split()intoWsSink+WsSourceArc<tokio::sync::Mutex<Option<_>>>— concurrent read/write futures don't serialize each other, and each future owns its ownArcclone intofuture_into_pySync
SerialMonitoris 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 warningsuv run cargo fmt --all -- --checkDeferred
Unit tests for the new async methods. Follow-up would need a more elaborate WebSocket mock than the raw
tokio::net::TcpListenerHTTP mock used forsend_op_asyncin PR #84.🤖 Generated with Claude Code