Files
codex/codex-rs/app-server-transport/src/outgoing_message.rs
Charlie Marsh 665e0a9a65 Stream app-server fs/readFile responses over stdio (#62599)
## Why

Large file reads over stdio previously allocated both a base64 string
and a complete JSON response before writing to stdout.

## What changed

Keep file contents as bytes until the stdio writer encodes them
directly into the newline-delimited JSON response through a bounded
buffer. Clients still receive the same `dataBase64` field.

## Testing

Compare streamed output byte for byte with the eagerly encoded
response for empty files, inputs that require base64 padding, and
files larger than the write buffer. Check that JSON-RPC conversion
preserves the request ID and base64 payload.

GitOrigin-RevId: 730f201f0905fd15e32b6e9c5b2ef02ca21c7532
2026-11-19 21:41:45 +00:00

50 lines
1.4 KiB
Rust

use codex_app_server_protocol::ClientResponsePayload;
use codex_app_server_protocol::JSONRPCErrorError;
use codex_app_server_protocol::RequestId;
use codex_app_server_protocol::ServerNotificationEnvelope;
use codex_app_server_protocol::ServerRequest;
use serde::Serialize;
use tokio::sync::oneshot;
pub use codex_app_server_remote_client::ConnectionId;
/// Outgoing message from the server to the client.
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
#[allow(clippy::large_enum_variant)]
pub enum OutgoingMessage {
Request(ServerRequest),
/// AppServerNotification is specific to the case where this is run as an
/// "app server" as opposed to an MCP server.
AppServerNotification(ServerNotificationEnvelope),
Response(OutgoingResponse),
Error(OutgoingError),
}
#[derive(Debug, Clone, Serialize)]
pub struct OutgoingResponse<T = Box<ClientResponsePayload>> {
pub id: RequestId,
pub result: T,
}
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct OutgoingError {
pub error: JSONRPCErrorError,
pub id: RequestId,
}
#[derive(Debug)]
pub struct QueuedOutgoingMessage {
pub message: OutgoingMessage,
pub write_complete_tx: Option<oneshot::Sender<()>>,
}
impl QueuedOutgoingMessage {
pub fn new(message: OutgoingMessage) -> Self {
Self {
message,
write_complete_tx: None,
}
}
}