mirror of
https://github.com/openai/codex.git
synced 2026-05-04 11:26:33 +00:00
## Summary - Add a pushed `ExecProcessEvent` stream alongside retained `process/read` output. - Publish local and remote output, exit, close, and failure events. - Cover the event stream with shared local/remote exec process tests. ## Testing - `cargo check -p codex-exec-server` - `cargo check -p codex-rmcp-client` - Not run: `cargo test` per repo instruction; CI will cover. ## Stack ```text o #18027 [6/6] Fail exec client operations after disconnect │ o #18212 [5/6] Wire executor-backed MCP stdio │ o #18087 [4/6] Abstract MCP stdio server launching │ @ #18020 [3/6] Add pushed exec process events │ o #18086 [2/6] Support piped stdin in exec process API │ o #18085 [1/6] Add MCP server environment config │ o main ``` --------- Co-authored-by: Codex <noreply@openai.com>
92 lines
2.3 KiB
Rust
92 lines
2.3 KiB
Rust
use std::sync::Arc;
|
|
|
|
use async_trait::async_trait;
|
|
use tokio::sync::watch;
|
|
use tracing::trace;
|
|
|
|
use crate::ExecBackend;
|
|
use crate::ExecProcess;
|
|
use crate::ExecProcessEventReceiver;
|
|
use crate::ExecServerError;
|
|
use crate::StartedExecProcess;
|
|
use crate::client::ExecServerClient;
|
|
use crate::client::Session;
|
|
use crate::protocol::ExecParams;
|
|
use crate::protocol::ReadResponse;
|
|
use crate::protocol::WriteResponse;
|
|
|
|
#[derive(Clone)]
|
|
pub(crate) struct RemoteProcess {
|
|
client: ExecServerClient,
|
|
}
|
|
|
|
struct RemoteExecProcess {
|
|
session: Session,
|
|
}
|
|
|
|
impl RemoteProcess {
|
|
pub(crate) fn new(client: ExecServerClient) -> Self {
|
|
trace!("remote process new");
|
|
Self { client }
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl ExecBackend for RemoteProcess {
|
|
async fn start(&self, params: ExecParams) -> Result<StartedExecProcess, ExecServerError> {
|
|
let process_id = params.process_id.clone();
|
|
let session = self.client.register_session(&process_id).await?;
|
|
if let Err(err) = self.client.exec(params).await {
|
|
session.unregister().await;
|
|
return Err(err);
|
|
}
|
|
|
|
Ok(StartedExecProcess {
|
|
process: Arc::new(RemoteExecProcess { session }),
|
|
})
|
|
}
|
|
}
|
|
|
|
#[async_trait]
|
|
impl ExecProcess for RemoteExecProcess {
|
|
fn process_id(&self) -> &crate::ProcessId {
|
|
self.session.process_id()
|
|
}
|
|
|
|
fn subscribe_wake(&self) -> watch::Receiver<u64> {
|
|
self.session.subscribe_wake()
|
|
}
|
|
|
|
fn subscribe_events(&self) -> ExecProcessEventReceiver {
|
|
self.session.subscribe_events()
|
|
}
|
|
|
|
async fn read(
|
|
&self,
|
|
after_seq: Option<u64>,
|
|
max_bytes: Option<usize>,
|
|
wait_ms: Option<u64>,
|
|
) -> Result<ReadResponse, ExecServerError> {
|
|
self.session.read(after_seq, max_bytes, wait_ms).await
|
|
}
|
|
|
|
async fn write(&self, chunk: Vec<u8>) -> Result<WriteResponse, ExecServerError> {
|
|
trace!("exec process write");
|
|
self.session.write(chunk).await
|
|
}
|
|
|
|
async fn terminate(&self) -> Result<(), ExecServerError> {
|
|
trace!("exec process terminate");
|
|
self.session.terminate().await
|
|
}
|
|
}
|
|
|
|
impl Drop for RemoteExecProcess {
|
|
fn drop(&mut self) {
|
|
let session = self.session.clone();
|
|
tokio::spawn(async move {
|
|
session.unregister().await;
|
|
});
|
|
}
|
|
}
|