Skip to content

feat(serial): ReaderControl restores ClearBuffer + GetInWaiting (closes #756)#761

Merged
zackees merged 1 commit into
mainfrom
fix/756-reader-control
Jun 22, 2026
Merged

feat(serial): ReaderControl restores ClearBuffer + GetInWaiting (closes #756)#761
zackees merged 1 commit into
mainfrom
fix/756-reader-control

Conversation

@zackees

@zackees zackees commented Jun 22, 2026

Copy link
Copy Markdown
Member

Closes #756. Sub-PR of meta #755.

Summary

PR #750 split handle_serial_ws into reader / writer / inbound tasks for throughput, but the split moved the broadcast receiver rx exclusively into the reader task. As a side effect, ClearBuffer and GetInWaiting (both of which reach into rx) became logged no-ops in the inbound task.

This PR restores both via an internal cross-task control channel.

Design

enum ReaderControl {
    Drain { reply: oneshot::Sender<usize> },
    GetDepth { reply: oneshot::Sender<usize> },
}
  • New unbounded mpsc (control_tx, control_rx) created alongside the existing out-mpsc in handle_serial_ws.
  • Reader's tokio::select! adds a branch on control_rx.recv(). biased; keeps broadcast forwarding the priority so a burst of inbound control requests cannot starve forwarding.
  • Inbound's ClearBuffer handler sends Drain, awaits the oneshot reply with the drop count, logs.
  • Inbound's GetInWaiting handler sends GetDepth, awaits the oneshot reply, ships InWaiting { count } through the writer-mpsc (preserves the writer-is-sole-WS-sink invariant from perf(serial): split daemon WS handler into reader/writer/inbound (closes #749) #750).

Race safety: if reader exits between send and recv (session teardown), the oneshot resolves with Err and inbound logs debug / falls back to count=0.

Protocol impact

None. SerialClientMessage::ClearBuffer and SerialClientMessage::GetInWaiting are unchanged on the wire. Only the internal handler implementation moved.

Test plan

🤖 Generated with Claude Code

#756)

PR #750 split `handle_serial_ws` into reader / writer / inbound tasks
for throughput. As a side effect the `ClearBuffer` and `GetInWaiting`
RPCs became logged no-ops -- both reach into the broadcast receiver
`rx`, which is now owned exclusively by the reader task. Inbound
couldn't touch it.

This commit restores both via a new internal control channel:

```rust
enum ReaderControl {
    Drain { reply: oneshot::Sender<usize> },
    GetDepth { reply: oneshot::Sender<usize> },
}
```

Wiring:
- Unbounded mpsc `(control_tx, control_rx)` created alongside the
  existing out-mpsc.
- Reader's `tokio::select!` adds a branch on `control_rx.recv()`.
  `biased;` keeps broadcast forwarding the priority so a burst of
  inbound control requests cannot starve forwarding.
- Inbound's `ClearBuffer` handler sends `Drain` over the control
  channel and awaits the oneshot reply with the drop count.
- Inbound's `GetInWaiting` handler sends `GetDepth`, awaits the
  oneshot reply, and ships the `InWaiting { count }` response
  through the writer mpsc (preserves the writer-is-sole-WS-sink
  invariant from #750).

Race safety: if the reader has exited between send and recv (session
teardown race), the oneshot resolves with `Err` and the inbound
handler logs debug / falls back to `count=0` rather than crashing.

No API change visible to clients -- the SerialClientMessage protocol
is unchanged, only the internals.

Build: `soldr cargo build -p fbuild-daemon` clean.

Refs #755 (meta).

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

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

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

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

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

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

🚦 How do rate limits work?

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

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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6fc7d5e2-91d8-4913-b159-57ce66a80eeb

📥 Commits

Reviewing files that changed from the base of the PR and between cd25295 and 184af28.

📒 Files selected for processing (1)
  • crates/fbuild-daemon/src/handlers/websockets.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/756-reader-control

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

feat(serial): ReaderControl channel to restore ClearBuffer + GetInWaiting

1 participant