Skip to content

refactor: use cloneable async channels for shared receivers#18398

Merged
bolinfest merged 1 commit into
mainfrom
pr18398
Apr 17, 2026
Merged

refactor: use cloneable async channels for shared receivers#18398
bolinfest merged 1 commit into
mainfrom
pr18398

Conversation

@bolinfest

@bolinfest bolinfest commented Apr 17, 2026

Copy link
Copy Markdown
Collaborator

This is the first mechanical cleanup in a stack whose higher-level goal is to enable Clippy coverage for async guards held across .await points.

The follow-up commits enable Clippy's await_holding_lock lint and the configurable await_holding_invalid_type lint for Tokio guard types. This PR handles the cases where the underlying issue is not protected shared mutable state, but a tokio::sync::mpsc::UnboundedReceiver wrapped in Arc<Mutex<_>> so cloned owners can call recv().await.

Using a mutex for that shape forces the receiver lock guard to live across .await. Switching these paths to async-channel gives us cloneable Receivers, so each owner can hold a receiver handle directly and await messages without an async mutex guard.

What changed

  • In codex-rs/code-mode, replace the turn-message mpsc::UnboundedSender/UnboundedReceiver plus Arc<Mutex<Receiver>> with async_channel::Sender/Receiver.
  • In codex-rs/codex-api, replace the realtime websocket event receiver with an async_channel::Receiver, allowing RealtimeWebsocketEvents clones to receive without locking.
  • Add async-channel as a dependency for codex-code-mode and codex-api, and update Cargo.lock.

Verification

  • The split stack was verified at the final lint-enabling head with just clippy.

@starr-openai starr-openai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clean. await should never block because unbounded and yields there seem fine

@bolinfest bolinfest merged commit c9c4caa into main Apr 17, 2026
33 of 36 checks passed
@bolinfest bolinfest deleted the pr18398 branch April 17, 2026 22:20
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants