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
This commit is contained in:
Charlie Marsh
2026-11-19 21:41:45 +00:00
committed by copyberry
parent bc75380d6a
commit 665e0a9a65
10 changed files with 150 additions and 20 deletions
+12 -5
View File
@@ -1360,11 +1360,18 @@ impl MessageProcessor {
ClientRequest::EnvironmentStatus { params, .. } => {
self.environment_processor.environment_status(params).await
}
ClientRequest::FsReadFile { params, .. } => self
.fs_processor
.read_file(params)
.await
.map(|response| Some(response.into())),
ClientRequest::FsReadFile { params, .. } => {
self.fs_processor.read_file(params).await.map(|file| {
// Defer encoding to the stdio writer. Remote control serializes
// for both segment sizing and transmission.
let payload = if session.origin == crate::transport::ConnectionOrigin::Stdio {
ClientResponsePayload::FsReadFileBytes(file)
} else {
ClientResponsePayload::FsReadFile(file.into())
};
Some(payload)
})
}
ClientRequest::FsWriteFile { params, .. } => self
.fs_processor
.write_file(params)
@@ -13,8 +13,8 @@ use codex_app_server_protocol::FsGetMetadataResponse;
use codex_app_server_protocol::FsReadDirectoryEntry;
use codex_app_server_protocol::FsReadDirectoryParams;
use codex_app_server_protocol::FsReadDirectoryResponse;
use codex_app_server_protocol::FsReadFileBytes;
use codex_app_server_protocol::FsReadFileParams;
use codex_app_server_protocol::FsReadFileResponse;
use codex_app_server_protocol::FsRemoveParams;
use codex_app_server_protocol::FsRemoveResponse;
use codex_app_server_protocol::FsUnwatchParams;
@@ -64,16 +64,14 @@ impl FsRequestProcessor {
pub(crate) async fn read_file(
&self,
params: FsReadFileParams,
) -> Result<FsReadFileResponse, JSONRPCErrorError> {
) -> Result<FsReadFileBytes, JSONRPCErrorError> {
let path = PathUri::from_abs_path(&params.path);
let bytes = self
let data = self
.file_system()?
.read_file(&path, Default::default(), /*sandbox*/ None)
.await
.map_err(map_fs_error)?;
Ok(FsReadFileResponse {
data_base64: STANDARD.encode(bytes),
})
Ok(FsReadFileBytes { data })
}
pub(crate) async fn write_file(