Skip to content

feat(python): async send_op + AsyncDaemonConnection (partial #65)#84

Merged
zackees merged 1 commit intomainfrom
feat/65-async-send-op
Apr 18, 2026
Merged

feat(python): async send_op + AsyncDaemonConnection (partial #65)#84
zackees merged 1 commit intomainfrom
feat/65-async-send-op

Conversation

@zackees
Copy link
Copy Markdown
Member

@zackees zackees commented Apr 18, 2026

Summary

Extends the AsyncDaemon scaffold (PR #78) with the method set that issue #65 explicitly targets: "Daemon/DaemonConnection: send_op and any other HTTP call".

Async methods added

  • send_op_async -- tokio/reqwest counterpart to the blocking send_op helper (used by every DaemonConnection HTTP call).
  • AsyncDaemon.ensure_running() -- async daemon bring-up; health poll uses tokio::time::sleep so the event loop isn't pinned.
  • AsyncDaemon.stop() -- async counterpart to Daemon.stop.
  • AsyncDaemonConnection -- new class with:
    • build, deploy, monitor -- async bool-returning wrappers.
    • build_result, deploy_result, monitor_result -- async structured-dict wrappers (same keys as the sync *_result methods: success, message, exit_code, stdout, stderr).
    • __aenter__ / __aexit__ so callers can async with AsyncDaemonConnection(...) as conn:.
  • connect_daemon_async() factory, mirroring connect_daemon.
  • Re-exports: AsyncDaemon, AsyncDaemonConnection, connect_daemon_async from fbuild; AsyncSerialMonitor from fbuild.api.

The sync surface is untouched -- this is purely additive per the issue's Non-goals.

Still remaining for #65

Test plan

  • uv run cargo test -p fbuild-python -- 11 tests pass (8 existing + 3 new).
  • uv run cargo clippy -p fbuild-python --all-targets -- -D warnings -- clean.
  • uv run cargo check --workspace --all-targets -- clean.
  • New tests spin a minimal in-process HTTP mock (raw tokio::net::TcpListener, no extra dev deps) and exercise send_op_async against three paths:
    • send_op_async_parses_success_response
    • send_op_async_parses_failure_response (guards exit_code / stderr parity with the sync API)
    • send_op_async_returns_failure_outcome_on_connection_error (guards against panics when the daemon is down)

The shared parse_outcome / outcome_to_pydict helpers are now exercised from both the sync and async paths, so the structured-result schema stays identical for callers migrating to async.


Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

Extends the AsyncDaemon scaffold (PR #78) with the method set that
#65 explicitly targets: "Daemon/DaemonConnection:
send_op and any other HTTP call".

Added:
- `send_op_async`: tokio/reqwest counterpart to `send_op` that yields
  on I/O instead of blocking a runtime thread.
- `AsyncDaemon.ensure_running` / `AsyncDaemon.stop`: native async
  lifecycle calls so callers no longer need `_run_in_thread` for
  daemon bring-up/shutdown.
- `AsyncDaemonConnection`: new class mirroring `DaemonConnection`
  with async `build`, `deploy`, `monitor`, and their `_result`
  counterparts. Shares `parse_outcome` / `outcome_to_pydict` with
  the sync class so the structured-result schema stays identical.
- `connect_daemon_async` factory.

Re-exports: `AsyncDaemon`, `AsyncDaemonConnection`,
`connect_daemon_async` from `fbuild`; `AsyncSerialMonitor` from
`fbuild.api`.

Still remaining for #65: `AsyncSerialMonitor.read_lines` / `write` /
`write_json_rpc`. These need the shared WebSocket state refactored to
be `Send + Sync` across `.await` points (noted in the scaffold
comment) and are a follow-up PR.

Tests: 3 new Rust tests spin a minimal in-process HTTP mock and
exercise `send_op_async` against success, failure, and connection-
error paths. Failure outcomes must still carry `message` / `exit_code`
/ `stderr` so async callers retain the structured-result parity with
the sync API.

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 57 minutes and 43 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 57 minutes and 43 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: df8313da-fa74-410a-9cbe-98e4b831d3f6

📥 Commits

Reviewing files that changed from the base of the PR and between 41982b2 and 7560b30.

📒 Files selected for processing (3)
  • crates/fbuild-python/src/lib.rs
  • python/fbuild/__init__.py
  • python/fbuild/api/__init__.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/65-async-send-op

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 a50d906 into main Apr 18, 2026
76 checks passed
zackees added a commit that referenced this pull request Apr 18, 2026
#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>
zackees added a commit that referenced this pull request Apr 18, 2026
#65) (#107)

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