mirror of
https://github.com/openai/codex.git
synced 2026-10-18 17:18:52 +00:00
Rename exec-server file handle management identifiers (#49702)
## What changed Rename `file_read` to `file_handle` and `FileReadHandleManager` to `FileHandleManager`. Update the filesystem handler field, handle ID validation helper, and related constants to use file handle terminology. File operations, limits, and error messages remain unchanged. GitOrigin-RevId: 25ad81a917386da23fd42ecff79bd47a482ce430
This commit is contained in:
committed by
copyberry
parent
3620b2caf8
commit
3b16b5a5b0
@@ -6,7 +6,7 @@ use std::sync::Arc;
|
||||
use codex_file_system::FILE_READ_CHUNK_SIZE;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
const MAX_OPEN_FILE_READS: usize = 128;
|
||||
const MAX_OPEN_FILES: usize = 128;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub(crate) struct FileReadBlock {
|
||||
@@ -15,11 +15,11 @@ pub(crate) struct FileReadBlock {
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub(crate) struct FileReadHandleManager {
|
||||
pub(crate) struct FileHandleManager {
|
||||
handles: Arc<Mutex<HashMap<String, Arc<File>>>>,
|
||||
}
|
||||
|
||||
impl FileReadHandleManager {
|
||||
impl FileHandleManager {
|
||||
pub(crate) async fn open(
|
||||
&self,
|
||||
handle_id: String,
|
||||
@@ -33,10 +33,10 @@ impl FileReadHandleManager {
|
||||
format!("file read handle `{handle_id}` already exists"),
|
||||
));
|
||||
}
|
||||
if handles.len() >= MAX_OPEN_FILE_READS {
|
||||
if handles.len() >= MAX_OPEN_FILES {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidInput,
|
||||
format!("at most {MAX_OPEN_FILE_READS} file reads may be open per connection"),
|
||||
format!("at most {MAX_OPEN_FILES} file reads may be open per connection"),
|
||||
));
|
||||
}
|
||||
handles.insert(handle_id.clone(), file);
|
||||
@@ -15,7 +15,7 @@ mod environment_config;
|
||||
mod environment_provider;
|
||||
mod environment_registry;
|
||||
mod environment_toml;
|
||||
mod file_read;
|
||||
mod file_handle;
|
||||
mod forward;
|
||||
mod fs_helper;
|
||||
mod fs_helper_main;
|
||||
|
||||
@@ -14,7 +14,7 @@ use crate::GetMetadataOptions;
|
||||
use crate::ReadFileOptions;
|
||||
use crate::RemoveOptions;
|
||||
use crate::WriteFileOptions;
|
||||
use crate::file_read::FileReadHandleManager;
|
||||
use crate::file_handle::FileHandleManager;
|
||||
use crate::local_file_system::LocalFileSystem;
|
||||
use crate::protocol::FS_READ_DIRECTORY_METHOD;
|
||||
use crate::protocol::FS_WRITE_FILE_METHOD;
|
||||
@@ -47,7 +47,7 @@ use crate::rpc::internal_error;
|
||||
use crate::rpc::invalid_request;
|
||||
use crate::rpc::not_found;
|
||||
|
||||
const MAX_FILE_READ_HANDLE_ID_BYTES: usize = 32;
|
||||
const MAX_FILE_HANDLE_ID_BYTES: usize = 32;
|
||||
// Each read-directory entry needs four JSON values. Keep same-version
|
||||
// producers comfortably below the shared 256K-value decoder budget.
|
||||
const MAX_READ_DIRECTORY_ENTRIES: usize = 50_000;
|
||||
@@ -55,19 +55,19 @@ const MAX_READ_DIRECTORY_ENTRIES: usize = 50_000;
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct FileSystemHandler {
|
||||
file_system: LocalFileSystem,
|
||||
file_reads: FileReadHandleManager,
|
||||
file_handles: FileHandleManager,
|
||||
}
|
||||
|
||||
impl FileSystemHandler {
|
||||
pub(crate) fn new(runtime_paths: ExecServerRuntimeOptions) -> Self {
|
||||
Self {
|
||||
file_system: LocalFileSystem::with_runtime_paths(runtime_paths),
|
||||
file_reads: FileReadHandleManager::default(),
|
||||
file_handles: FileHandleManager::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn shutdown(&self) {
|
||||
self.file_reads.close_all().await;
|
||||
self.file_handles.close_all().await;
|
||||
}
|
||||
|
||||
pub(crate) async fn discover_capability_roots(
|
||||
@@ -121,14 +121,14 @@ impl FileSystemHandler {
|
||||
&self,
|
||||
params: FsOpenParams,
|
||||
) -> Result<FsOpenResponse, JSONRPCErrorError> {
|
||||
validate_file_read_handle_id(¶ms.handle_id)?;
|
||||
validate_file_handle_id(¶ms.handle_id)?;
|
||||
let file = self
|
||||
.file_system
|
||||
.open_file_for_read(¶ms.path, params.sandbox.as_ref())
|
||||
.await
|
||||
.map_err(map_fs_error)?;
|
||||
let handle_id = self
|
||||
.file_reads
|
||||
.file_handles
|
||||
.open(params.handle_id, file)
|
||||
.await
|
||||
.map_err(map_fs_error)?;
|
||||
@@ -139,9 +139,9 @@ impl FileSystemHandler {
|
||||
&self,
|
||||
params: FsReadBlockParams,
|
||||
) -> Result<FsReadBlockResponse, JSONRPCErrorError> {
|
||||
validate_file_read_handle_id(¶ms.handle_id)?;
|
||||
validate_file_handle_id(¶ms.handle_id)?;
|
||||
let block = self
|
||||
.file_reads
|
||||
.file_handles
|
||||
.read_block(¶ms.handle_id, params.offset, params.len)
|
||||
.await
|
||||
.map_err(map_fs_error)?;
|
||||
@@ -155,8 +155,8 @@ impl FileSystemHandler {
|
||||
&self,
|
||||
params: FsCloseParams,
|
||||
) -> Result<FsCloseResponse, JSONRPCErrorError> {
|
||||
validate_file_read_handle_id(¶ms.handle_id)?;
|
||||
self.file_reads.close(¶ms.handle_id).await;
|
||||
validate_file_handle_id(¶ms.handle_id)?;
|
||||
self.file_handles.close(¶ms.handle_id).await;
|
||||
Ok(FsCloseResponse {})
|
||||
}
|
||||
|
||||
@@ -335,10 +335,10 @@ impl FileSystemHandler {
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_file_read_handle_id(handle_id: &str) -> Result<(), JSONRPCErrorError> {
|
||||
if handle_id.len() > MAX_FILE_READ_HANDLE_ID_BYTES {
|
||||
fn validate_file_handle_id(handle_id: &str) -> Result<(), JSONRPCErrorError> {
|
||||
if handle_id.len() > MAX_FILE_HANDLE_ID_BYTES {
|
||||
return Err(invalid_request(format!(
|
||||
"file read handle ID must not exceed {MAX_FILE_READ_HANDLE_ID_BYTES} bytes"
|
||||
"file read handle ID must not exceed {MAX_FILE_HANDLE_ID_BYTES} bytes"
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user