Files
codex/prs/bolinfest/study/PR-1686-study.md
2025-09-02 15:17:45 -07:00

78 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
**PR 1686 Review Takeaways — bolinfest**
**DOs**
- Log channel send failures and continue: treat as “receiver closed.”
```rust
if let Err(e) = sender.send(outgoing).await {
tracing::warn!("Dropping response; client disconnected or closed: {e}");
}
```
- Keep response-sending helpers side-effecting; dont return Result from them.
```rust
pub(crate) async fn send_response_with_optional_error(
&self,
id: RequestId,
message: Option<ToolCallResponseResult>,
error: Option<bool>,
) {
let response = ToolCallResponse {
request_id: id.clone(),
is_error: error,
result: message,
};
let result: CallToolResult = response.into();
self.send_response::<mcp_types::CallToolRequest>(id, result).await;
}
```
- Prefer specific error types only when propagation is meaningful.
```rust
#[derive(Debug)]
enum SendErr { Closed }
async fn try_send(sender: &tokio::sync::mpsc::Sender<OutgoingMessage>, m: OutgoingMessage)
-> Result<(), SendErr>
{
sender.send(m).await.map_err(|_| SendErr::Closed)
}
```
- Keep conversions conventional: convert response → result, pass `id` explicitly.
```rust
let response = ToolCallResponse { request_id: id.clone(), is_error, result: payload };
let result: CallToolResult = response.into();
self.send_response::<mcp_types::CallToolRequest>(id, result).await;
```
- Use inline formatting consistently for logs/messages.
```rust
let session = session_id;
tracing::info!("Submitting user input for session {session}");
```
**DONTs**
- Dont bubble `mpsc::Sender::send` errors as `anyhow::Result` from helpers.
```rust
// Avoid
pub async fn send_response(...) -> anyhow::Result<()> { /* ... */ }
```
- Dont attempt recovery loops on a closed receiver; theres nothing meaningful to do.
```rust
// Avoid retry loops; just log and return.
```
- Dont force “Result all the way up” when callers cant act on it.
```rust
// Avoid turning a fire-and-forget send into a chained anyhow::Result.
```
- Dont create clever `From/Into` that return tuples or compound outputs.
```rust
// Avoid
let (result, id): (CallToolResult, RequestId) = response.into();
// Prefer
let result: CallToolResult = response.into();
```