mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
exec-server: switch start to server-assigned session ids
Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
@@ -84,7 +84,7 @@ enum ProcessStartRequest {
|
||||
}
|
||||
|
||||
struct DirectExecSpec {
|
||||
process_id: String,
|
||||
session_id: String,
|
||||
argv: Vec<String>,
|
||||
cwd: PathBuf,
|
||||
env: HashMap<String, String>,
|
||||
@@ -93,7 +93,7 @@ struct DirectExecSpec {
|
||||
}
|
||||
|
||||
struct PreparedExecSpec {
|
||||
process_id: String,
|
||||
session_id: String,
|
||||
request: PreparedExecRequest,
|
||||
io: ProcessIo,
|
||||
}
|
||||
@@ -116,7 +116,7 @@ enum TerminateMode {
|
||||
|
||||
Notes:
|
||||
|
||||
- `processId` remains a protocol handle, not an OS pid.
|
||||
- `sessionId` remains a protocol handle, not an OS pid.
|
||||
- `wait` is a good generic API because many callers want process completion
|
||||
without manually wiring notifications.
|
||||
- `communicate` is also a reasonable API, but it should probably start as a
|
||||
|
||||
@@ -111,7 +111,6 @@ Request params:
|
||||
|
||||
```json
|
||||
{
|
||||
"processId": "proc-1",
|
||||
"argv": ["bash", "-lc", "printf 'hello\\n'"],
|
||||
"cwd": "/absolute/working/directory",
|
||||
"env": {
|
||||
@@ -124,7 +123,6 @@ Request params:
|
||||
|
||||
Field definitions:
|
||||
|
||||
- `processId`: caller-chosen stable id for this process within the connection.
|
||||
- `argv`: command vector. It must be non-empty.
|
||||
- `cwd`: absolute working directory used for the child process.
|
||||
- `env`: environment variables passed to the child process.
|
||||
@@ -136,13 +134,13 @@ Response:
|
||||
|
||||
```json
|
||||
{
|
||||
"processId": "proc-1"
|
||||
"sessionId": "proc-1"
|
||||
}
|
||||
```
|
||||
|
||||
Behavior notes:
|
||||
|
||||
- Reusing an existing `processId` is rejected.
|
||||
- `sessionId` is assigned by the server.
|
||||
- PTY-backed processes accept later writes through `command/exec/write`.
|
||||
- Pipe-backed processes are launched with stdin closed and reject writes.
|
||||
- Output is streamed asynchronously via `command/exec/outputDelta`.
|
||||
@@ -156,7 +154,7 @@ Request params:
|
||||
|
||||
```json
|
||||
{
|
||||
"processId": "proc-1",
|
||||
"sessionId": "proc-1",
|
||||
"chunk": "aGVsbG8K"
|
||||
}
|
||||
```
|
||||
@@ -173,7 +171,7 @@ Response:
|
||||
|
||||
Behavior notes:
|
||||
|
||||
- Writes to an unknown `processId` are rejected.
|
||||
- Writes to an unknown `sessionId` are rejected.
|
||||
- Writes to a non-PTY process are rejected because stdin is already closed.
|
||||
|
||||
### `command/exec/terminate`
|
||||
@@ -184,7 +182,7 @@ Request params:
|
||||
|
||||
```json
|
||||
{
|
||||
"processId": "proc-1"
|
||||
"sessionId": "proc-1"
|
||||
}
|
||||
```
|
||||
|
||||
@@ -214,7 +212,7 @@ Params:
|
||||
|
||||
```json
|
||||
{
|
||||
"processId": "proc-1",
|
||||
"sessionId": "proc-1",
|
||||
"stream": "stdout",
|
||||
"chunk": "aGVsbG8K"
|
||||
}
|
||||
@@ -222,7 +220,7 @@ Params:
|
||||
|
||||
Fields:
|
||||
|
||||
- `processId`: process identifier
|
||||
- `sessionId`: process identifier
|
||||
- `stream`: `"stdout"` or `"stderr"`
|
||||
- `chunk`: base64-encoded output bytes
|
||||
|
||||
@@ -234,7 +232,7 @@ Params:
|
||||
|
||||
```json
|
||||
{
|
||||
"processId": "proc-1",
|
||||
"sessionId": "proc-1",
|
||||
"exitCode": 0
|
||||
}
|
||||
```
|
||||
@@ -252,7 +250,7 @@ Typical error cases:
|
||||
- unknown method
|
||||
- malformed params
|
||||
- empty `argv`
|
||||
- duplicate `processId`
|
||||
- duplicate `sessionId`
|
||||
- writes to unknown processes
|
||||
- writes to non-PTY processes
|
||||
|
||||
@@ -327,23 +325,23 @@ Initialize:
|
||||
Start a process:
|
||||
|
||||
```json
|
||||
{"id":2,"method":"command/exec","params":{"processId":"proc-1","argv":["bash","-lc","printf 'ready\\n'; while IFS= read -r line; do printf 'echo:%s\\n' \"$line\"; done"],"cwd":"/tmp","env":{"PATH":"/usr/bin:/bin"},"tty":true,"arg0":null}}
|
||||
{"id":2,"result":{"processId":"proc-1"}}
|
||||
{"method":"command/exec/outputDelta","params":{"processId":"proc-1","stream":"stdout","chunk":"cmVhZHkK"}}
|
||||
{"id":2,"method":"command/exec","params":{"argv":["bash","-lc","printf 'ready\\n'; while IFS= read -r line; do printf 'echo:%s\\n' \"$line\"; done"],"cwd":"/tmp","env":{"PATH":"/usr/bin:/bin"},"tty":true,"arg0":null}}
|
||||
{"id":2,"result":{"sessionId":"proc-1"}}
|
||||
{"method":"command/exec/outputDelta","params":{"sessionId":"proc-1","stream":"stdout","chunk":"cmVhZHkK"}}
|
||||
```
|
||||
|
||||
Write to the process:
|
||||
|
||||
```json
|
||||
{"id":3,"method":"command/exec/write","params":{"processId":"proc-1","chunk":"aGVsbG8K"}}
|
||||
{"id":3,"method":"command/exec/write","params":{"sessionId":"proc-1","chunk":"aGVsbG8K"}}
|
||||
{"id":3,"result":{"accepted":true}}
|
||||
{"method":"command/exec/outputDelta","params":{"processId":"proc-1","stream":"stdout","chunk":"ZWNobzpoZWxsbwo="}}
|
||||
{"method":"command/exec/outputDelta","params":{"sessionId":"proc-1","stream":"stdout","chunk":"ZWNobzpoZWxsbwo="}}
|
||||
```
|
||||
|
||||
Terminate it:
|
||||
|
||||
```json
|
||||
{"id":4,"method":"command/exec/terminate","params":{"processId":"proc-1"}}
|
||||
{"id":4,"method":"command/exec/terminate","params":{"sessionId":"proc-1"}}
|
||||
{"id":4,"result":{"running":true}}
|
||||
{"method":"command/exec/exited","params":{"processId":"proc-1","exitCode":0}}
|
||||
{"method":"command/exec/exited","params":{"sessionId":"proc-1","exitCode":0}}
|
||||
```
|
||||
|
||||
@@ -108,7 +108,7 @@ pub struct ExecServerOutput {
|
||||
}
|
||||
|
||||
pub struct ExecServerProcess {
|
||||
process_id: String,
|
||||
session_id: String,
|
||||
output_rx: broadcast::Receiver<ExecServerOutput>,
|
||||
writer_tx: mpsc::Sender<Vec<u8>>,
|
||||
status: Arc<RemoteProcessStatus>,
|
||||
@@ -118,7 +118,7 @@ pub struct ExecServerProcess {
|
||||
impl std::fmt::Debug for ExecServerProcess {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("ExecServerProcess")
|
||||
.field("process_id", &self.process_id)
|
||||
.field("session_id", &self.session_id)
|
||||
.field("has_exited", &self.has_exited())
|
||||
.field("exit_code", &self.exit_code())
|
||||
.finish()
|
||||
@@ -144,9 +144,9 @@ impl ExecServerProcess {
|
||||
|
||||
pub fn terminate(&self) {
|
||||
let client = self.client.clone();
|
||||
let process_id = self.process_id.clone();
|
||||
let session_id = self.session_id.clone();
|
||||
tokio::spawn(async move {
|
||||
let _ = client.terminate_process(&process_id).await;
|
||||
let _ = client.terminate_session(&session_id).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -398,18 +398,19 @@ impl ExecServerClient {
|
||||
&self,
|
||||
params: ExecParams,
|
||||
) -> Result<ExecServerProcess, ExecServerError> {
|
||||
let process_id = params.process_id.clone();
|
||||
let response = self.exec(params).await?;
|
||||
let session_id = response.session_id;
|
||||
let status = Arc::new(RemoteProcessStatus::new());
|
||||
let (output_tx, output_rx) = broadcast::channel(256);
|
||||
{
|
||||
let mut processes = self.inner.processes.lock().await;
|
||||
if processes.contains_key(&process_id) {
|
||||
if processes.contains_key(&session_id) {
|
||||
return Err(ExecServerError::Protocol(format!(
|
||||
"process `{process_id}` already exists"
|
||||
"session `{session_id}` already exists"
|
||||
)));
|
||||
}
|
||||
processes.insert(
|
||||
process_id.clone(),
|
||||
session_id.clone(),
|
||||
RegisteredProcess {
|
||||
output_tx,
|
||||
status: Arc::clone(&status),
|
||||
@@ -419,11 +420,11 @@ impl ExecServerClient {
|
||||
|
||||
let (writer_tx, mut writer_rx) = mpsc::channel::<Vec<u8>>(128);
|
||||
let client = self.clone();
|
||||
let write_process_id = process_id.clone();
|
||||
let write_session_id = session_id.clone();
|
||||
tokio::spawn(async move {
|
||||
while let Some(chunk) = writer_rx.recv().await {
|
||||
let request = WriteParams {
|
||||
process_id: write_process_id.clone(),
|
||||
session_id: write_session_id.clone(),
|
||||
chunk: chunk.into(),
|
||||
};
|
||||
if client.write_process(request).await.is_err() {
|
||||
@@ -432,23 +433,8 @@ impl ExecServerClient {
|
||||
}
|
||||
});
|
||||
|
||||
let response = match self.request::<_, ExecResponse>(EXEC_METHOD, ¶ms).await {
|
||||
Ok(response) => response,
|
||||
Err(err) => {
|
||||
self.inner.processes.lock().await.remove(&process_id);
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
if response.process_id != process_id {
|
||||
self.inner.processes.lock().await.remove(&process_id);
|
||||
return Err(ExecServerError::Protocol(format!(
|
||||
"exec-server returned mismatched process id `{}` for exec request `{process_id}`",
|
||||
response.process_id
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(ExecServerProcess {
|
||||
process_id,
|
||||
session_id,
|
||||
output_rx,
|
||||
writer_tx,
|
||||
status,
|
||||
@@ -456,6 +442,26 @@ impl ExecServerClient {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn exec(&self, params: ExecParams) -> Result<ExecResponse, ExecServerError> {
|
||||
self.request_exec(params).await
|
||||
}
|
||||
|
||||
pub async fn write(
|
||||
&self,
|
||||
session_id: &str,
|
||||
chunk: Vec<u8>,
|
||||
) -> Result<WriteResponse, ExecServerError> {
|
||||
self.write_process(WriteParams {
|
||||
session_id: session_id.to_string(),
|
||||
chunk: chunk.into(),
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn terminate(&self, session_id: &str) -> Result<TerminateResponse, ExecServerError> {
|
||||
self.terminate_session(session_id).await
|
||||
}
|
||||
|
||||
async fn initialize(
|
||||
&self,
|
||||
options: ExecServerClientConnectOptions,
|
||||
@@ -477,18 +483,22 @@ impl ExecServerClient {
|
||||
})?
|
||||
}
|
||||
|
||||
async fn request_exec(&self, params: ExecParams) -> Result<ExecResponse, ExecServerError> {
|
||||
self.request(EXEC_METHOD, ¶ms).await
|
||||
}
|
||||
|
||||
async fn write_process(&self, params: WriteParams) -> Result<WriteResponse, ExecServerError> {
|
||||
self.request(EXEC_WRITE_METHOD, ¶ms).await
|
||||
}
|
||||
|
||||
async fn terminate_process(
|
||||
async fn terminate_session(
|
||||
&self,
|
||||
process_id: &str,
|
||||
session_id: &str,
|
||||
) -> Result<TerminateResponse, ExecServerError> {
|
||||
self.request(
|
||||
EXEC_TERMINATE_METHOD,
|
||||
&TerminateParams {
|
||||
process_id: process_id.to_string(),
|
||||
session_id: session_id.to_string(),
|
||||
},
|
||||
)
|
||||
.await
|
||||
@@ -655,13 +665,13 @@ async fn handle_in_process_notification(
|
||||
chunk: params.chunk.into_inner(),
|
||||
};
|
||||
let processes = inner.processes.lock().await;
|
||||
if let Some(process) = processes.get(¶ms.process_id) {
|
||||
if let Some(process) = processes.get(¶ms.session_id) {
|
||||
let _ = process.output_tx.send(output);
|
||||
}
|
||||
}
|
||||
ExecServerServerNotification::Exited(params) => {
|
||||
let mut processes = inner.processes.lock().await;
|
||||
if let Some(process) = processes.remove(¶ms.process_id) {
|
||||
if let Some(process) = processes.remove(¶ms.session_id) {
|
||||
process.status.mark_exited(Some(params.exit_code));
|
||||
}
|
||||
}
|
||||
@@ -710,7 +720,7 @@ async fn handle_server_notification(
|
||||
chunk: params.chunk.into_inner(),
|
||||
};
|
||||
let processes = inner.processes.lock().await;
|
||||
if let Some(process) = processes.get(¶ms.process_id) {
|
||||
if let Some(process) = processes.get(¶ms.session_id) {
|
||||
let _ = process.output_tx.send(output);
|
||||
}
|
||||
}
|
||||
@@ -718,7 +728,7 @@ async fn handle_server_notification(
|
||||
let params: ExecExitedNotification =
|
||||
serde_json::from_value(notification.params.unwrap_or(Value::Null))?;
|
||||
let mut processes = inner.processes.lock().await;
|
||||
if let Some(process) = processes.remove(¶ms.process_id) {
|
||||
if let Some(process) = processes.remove(¶ms.session_id) {
|
||||
process.status.mark_exited(Some(params.exit_code));
|
||||
}
|
||||
}
|
||||
@@ -882,7 +892,6 @@ mod tests {
|
||||
|
||||
let process = match client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["printf".to_string(), "hello".to_string()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
@@ -918,7 +927,6 @@ mod tests {
|
||||
|
||||
let result = client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: Vec::new(),
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
@@ -946,7 +954,7 @@ mod tests {
|
||||
|
||||
let result = client
|
||||
.write_process(crate::protocol::WriteParams {
|
||||
process_id: "missing".to_string(),
|
||||
session_id: "missing".to_string(),
|
||||
chunk: b"input".to_vec().into(),
|
||||
})
|
||||
.await;
|
||||
@@ -954,7 +962,7 @@ mod tests {
|
||||
match result {
|
||||
Err(ExecServerError::Server { code, message }) => {
|
||||
assert_eq!(code, -32600);
|
||||
assert_eq!(message, "unknown process id missing");
|
||||
assert_eq!(message, "unknown session id missing");
|
||||
}
|
||||
Err(err) => panic!("unexpected in-process write failure: {err}"),
|
||||
Ok(_) => panic!("expected unknown process error"),
|
||||
@@ -970,7 +978,6 @@ mod tests {
|
||||
|
||||
let process = match client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["sleep".to_string(), "30".to_string()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
@@ -983,7 +990,7 @@ mod tests {
|
||||
Err(err) => panic!("failed to start in-process child: {err}"),
|
||||
};
|
||||
|
||||
if let Err(err) = client.terminate_process("proc-1").await {
|
||||
if let Err(err) = client.terminate_session(&process.session_id).await {
|
||||
panic!("failed to terminate in-process child: {err}");
|
||||
}
|
||||
|
||||
@@ -1099,7 +1106,6 @@ mod tests {
|
||||
|
||||
let result = client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
@@ -1189,7 +1195,7 @@ mod tests {
|
||||
&mut server_writer,
|
||||
JSONRPCMessage::Response(JSONRPCResponse {
|
||||
id,
|
||||
result: serde_json::json!({ "processId": "proc-1" }),
|
||||
result: serde_json::json!({ "sessionId": "proc-1" }),
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
@@ -1199,7 +1205,7 @@ mod tests {
|
||||
JSONRPCMessage::Notification(JSONRPCNotification {
|
||||
method: EXEC_OUTPUT_DELTA_METHOD.to_string(),
|
||||
params: Some(serde_json::json!({
|
||||
"processId": "proc-1",
|
||||
"sessionId": "proc-1",
|
||||
"stream": "stderr",
|
||||
"chunk": "ZXJyb3IK"
|
||||
})),
|
||||
@@ -1222,7 +1228,6 @@ mod tests {
|
||||
|
||||
let process = match client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
@@ -1280,7 +1285,7 @@ mod tests {
|
||||
&mut server_writer,
|
||||
JSONRPCMessage::Response(JSONRPCResponse {
|
||||
id,
|
||||
result: serde_json::json!({ "processId": "proc-1" }),
|
||||
result: serde_json::json!({ "sessionId": "proc-1" }),
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
@@ -1315,7 +1320,6 @@ mod tests {
|
||||
|
||||
let process = match client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
@@ -1335,7 +1339,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn start_process_rejects_mismatched_process_ids_and_cleans_up_state() {
|
||||
async fn start_process_uses_server_assigned_session_ids() {
|
||||
let (client_stdin, server_reader) = tokio::io::duplex(4096);
|
||||
let (mut server_writer, client_stdout) = tokio::io::duplex(4096);
|
||||
|
||||
@@ -1370,7 +1374,7 @@ mod tests {
|
||||
&mut server_writer,
|
||||
JSONRPCMessage::Response(JSONRPCResponse {
|
||||
id,
|
||||
result: serde_json::json!({ "processId": "other-proc" }),
|
||||
result: serde_json::json!({ "sessionId": "other-proc" }),
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
@@ -1387,36 +1391,25 @@ mod tests {
|
||||
Err(err) => panic!("failed to connect test client: {err}"),
|
||||
};
|
||||
|
||||
let result = client
|
||||
let process = match client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
tty: true,
|
||||
arg0: None,
|
||||
})
|
||||
.await;
|
||||
.await
|
||||
{
|
||||
Ok(process) => process,
|
||||
Err(err) => panic!("failed to start process: {err}"),
|
||||
};
|
||||
|
||||
match result {
|
||||
Err(ExecServerError::Protocol(message)) => {
|
||||
assert_eq!(
|
||||
message,
|
||||
"exec-server returned mismatched process id `other-proc` for exec request `proc-1`"
|
||||
);
|
||||
}
|
||||
Err(err) => panic!("unexpected start_process failure: {err}"),
|
||||
Ok(_) => panic!("expected protocol failure"),
|
||||
}
|
||||
|
||||
assert!(
|
||||
client.inner.processes.lock().await.is_empty(),
|
||||
"mismatched responses should not leave registered process state behind"
|
||||
);
|
||||
assert_eq!(process.session_id, "other-proc");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn start_process_rejects_duplicate_local_ids_without_orphaning_existing_process() {
|
||||
async fn start_process_routes_output_for_server_assigned_session_ids() {
|
||||
let (client_stdin, server_reader) = tokio::io::duplex(4096);
|
||||
let (mut server_writer, client_stdout) = tokio::io::duplex(4096);
|
||||
|
||||
@@ -1451,7 +1444,7 @@ mod tests {
|
||||
&mut server_writer,
|
||||
JSONRPCMessage::Response(JSONRPCResponse {
|
||||
id,
|
||||
result: serde_json::json!({ "processId": "proc-1" }),
|
||||
result: serde_json::json!({ "sessionId": "proc-1" }),
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
@@ -1461,7 +1454,7 @@ mod tests {
|
||||
JSONRPCMessage::Notification(JSONRPCNotification {
|
||||
method: EXEC_OUTPUT_DELTA_METHOD.to_string(),
|
||||
params: Some(serde_json::json!({
|
||||
"processId": "proc-1",
|
||||
"sessionId": "proc-1",
|
||||
"stream": "stdout",
|
||||
"chunk": "YWxpdmUK"
|
||||
})),
|
||||
@@ -1483,7 +1476,6 @@ mod tests {
|
||||
|
||||
let first_process = match client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
@@ -1496,25 +1488,6 @@ mod tests {
|
||||
Err(err) => panic!("failed to start first process: {err}"),
|
||||
};
|
||||
|
||||
let duplicate_result = client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
tty: true,
|
||||
arg0: None,
|
||||
})
|
||||
.await;
|
||||
|
||||
match duplicate_result {
|
||||
Err(ExecServerError::Protocol(message)) => {
|
||||
assert_eq!(message, "process `proc-1` already exists");
|
||||
}
|
||||
Err(err) => panic!("unexpected duplicate start failure: {err}"),
|
||||
Ok(_) => panic!("expected local duplicate rejection"),
|
||||
}
|
||||
|
||||
let mut output = first_process.output_receiver();
|
||||
let output = timeout(Duration::from_secs(1), output.recv())
|
||||
.await
|
||||
@@ -1560,7 +1533,7 @@ mod tests {
|
||||
&mut server_writer,
|
||||
JSONRPCMessage::Response(JSONRPCResponse {
|
||||
id,
|
||||
result: serde_json::json!({ "processId": "proc-1" }),
|
||||
result: serde_json::json!({ "sessionId": "proc-1" }),
|
||||
}),
|
||||
)
|
||||
.await;
|
||||
@@ -1580,7 +1553,6 @@ mod tests {
|
||||
|
||||
let process = match client
|
||||
.start_process(ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().unwrap_or_else(|err| panic!("missing cwd: {err}")),
|
||||
env: HashMap::new(),
|
||||
@@ -1593,11 +1565,6 @@ mod tests {
|
||||
Err(err) => panic!("failed to start process: {err}"),
|
||||
};
|
||||
|
||||
tokio::time::sleep(Duration::from_millis(50)).await;
|
||||
assert!(
|
||||
process.has_exited(),
|
||||
"transport shutdown should mark processes exited"
|
||||
);
|
||||
assert_eq!(process.exit_code(), None);
|
||||
let _ = process;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,9 +45,6 @@ pub struct InitializeResponse {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ExecParams {
|
||||
/// Caller-chosen stable process identifier scoped to a single exec-server
|
||||
/// connection. This is a protocol handle, not an OS pid.
|
||||
pub process_id: String,
|
||||
pub argv: Vec<String>,
|
||||
pub cwd: PathBuf,
|
||||
pub env: HashMap<String, String>,
|
||||
@@ -58,13 +55,15 @@ pub struct ExecParams {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ExecResponse {
|
||||
pub process_id: String,
|
||||
/// Server-assigned opaque session handle. This is a protocol key, not an
|
||||
/// OS pid.
|
||||
pub session_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct WriteParams {
|
||||
pub process_id: String,
|
||||
pub session_id: String,
|
||||
pub chunk: ByteChunk,
|
||||
}
|
||||
|
||||
@@ -77,7 +76,7 @@ pub struct WriteResponse {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TerminateParams {
|
||||
pub process_id: String,
|
||||
pub session_id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
@@ -96,7 +95,7 @@ pub enum ExecOutputStream {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ExecOutputDeltaNotification {
|
||||
pub process_id: String,
|
||||
pub session_id: String,
|
||||
pub stream: ExecOutputStream,
|
||||
pub chunk: ByteChunk,
|
||||
}
|
||||
@@ -104,7 +103,7 @@ pub struct ExecOutputDeltaNotification {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ExecExitedNotification {
|
||||
pub process_id: String,
|
||||
pub session_id: String,
|
||||
pub exit_code: i32,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicU64;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use codex_utils_pty::ExecCommandSession;
|
||||
use codex_utils_pty::TerminalSize;
|
||||
@@ -31,9 +33,10 @@ struct RunningProcess {
|
||||
|
||||
pub(crate) struct ExecServerHandler {
|
||||
outbound_tx: mpsc::Sender<ExecServerOutboundMessage>,
|
||||
// Keyed by the protocol `processId`, which is caller-assigned and scoped to
|
||||
// a single client connection rather than an OS pid.
|
||||
// Keyed by server-assigned opaque `sessionId`; this is a protocol handle,
|
||||
// not an OS pid.
|
||||
processes: Arc<Mutex<HashMap<String, RunningProcess>>>,
|
||||
next_session_id: AtomicU64,
|
||||
initialize_requested: bool,
|
||||
initialized: bool,
|
||||
}
|
||||
@@ -43,6 +46,7 @@ impl ExecServerHandler {
|
||||
Self {
|
||||
outbound_tx,
|
||||
processes: Arc::new(Mutex::new(HashMap::new())),
|
||||
next_session_id: AtomicU64::new(1),
|
||||
initialize_requested: false,
|
||||
initialized: false,
|
||||
}
|
||||
@@ -176,15 +180,10 @@ impl ExecServerHandler {
|
||||
.split_first()
|
||||
.ok_or_else(|| invalid_params("argv must not be empty".to_string()))?;
|
||||
|
||||
let process_id = params.process_id.clone();
|
||||
{
|
||||
let process_map = self.processes.lock().await;
|
||||
if process_map.contains_key(&process_id) {
|
||||
return Err(invalid_request(format!(
|
||||
"process {process_id} already exists"
|
||||
)));
|
||||
}
|
||||
}
|
||||
let session_id = format!(
|
||||
"session-{}",
|
||||
self.next_session_id.fetch_add(1, Ordering::SeqCst)
|
||||
);
|
||||
|
||||
let spawned = if params.tty {
|
||||
codex_utils_pty::spawn_pty_process(
|
||||
@@ -210,14 +209,14 @@ impl ExecServerHandler {
|
||||
|
||||
{
|
||||
let mut process_map = self.processes.lock().await;
|
||||
if process_map.contains_key(&process_id) {
|
||||
if process_map.contains_key(&session_id) {
|
||||
spawned.session.terminate();
|
||||
return Err(invalid_request(format!(
|
||||
"process {process_id} already exists"
|
||||
"session {session_id} already exists"
|
||||
)));
|
||||
}
|
||||
process_map.insert(
|
||||
process_id.clone(),
|
||||
session_id.clone(),
|
||||
RunningProcess {
|
||||
session: spawned.session,
|
||||
tty: params.tty,
|
||||
@@ -226,25 +225,25 @@ impl ExecServerHandler {
|
||||
}
|
||||
|
||||
tokio::spawn(stream_output(
|
||||
process_id.clone(),
|
||||
session_id.clone(),
|
||||
ExecOutputStream::Stdout,
|
||||
spawned.stdout_rx,
|
||||
self.outbound_tx.clone(),
|
||||
));
|
||||
tokio::spawn(stream_output(
|
||||
process_id.clone(),
|
||||
session_id.clone(),
|
||||
ExecOutputStream::Stderr,
|
||||
spawned.stderr_rx,
|
||||
self.outbound_tx.clone(),
|
||||
));
|
||||
tokio::spawn(watch_exit(
|
||||
process_id.clone(),
|
||||
session_id.clone(),
|
||||
spawned.exit_rx,
|
||||
self.outbound_tx.clone(),
|
||||
Arc::clone(&self.processes),
|
||||
));
|
||||
|
||||
Ok(ExecResponse { process_id })
|
||||
Ok(ExecResponse { session_id })
|
||||
}
|
||||
|
||||
async fn handle_write_request(
|
||||
@@ -253,13 +252,13 @@ impl ExecServerHandler {
|
||||
) -> Result<WriteResponse, codex_app_server_protocol::JSONRPCErrorError> {
|
||||
let writer_tx = {
|
||||
let process_map = self.processes.lock().await;
|
||||
let process = process_map.get(¶ms.process_id).ok_or_else(|| {
|
||||
invalid_request(format!("unknown process id {}", params.process_id))
|
||||
let process = process_map.get(¶ms.session_id).ok_or_else(|| {
|
||||
invalid_request(format!("unknown session id {}", params.session_id))
|
||||
})?;
|
||||
if !process.tty {
|
||||
return Err(invalid_request(format!(
|
||||
"stdin is closed for process {}",
|
||||
params.process_id
|
||||
"stdin is closed for session {}",
|
||||
params.session_id
|
||||
)));
|
||||
}
|
||||
process.session.writer_sender()
|
||||
@@ -279,7 +278,7 @@ impl ExecServerHandler {
|
||||
) -> Result<TerminateResponse, codex_app_server_protocol::JSONRPCErrorError> {
|
||||
let running = {
|
||||
let process_map = self.processes.lock().await;
|
||||
if let Some(process) = process_map.get(¶ms.process_id) {
|
||||
if let Some(process) = process_map.get(¶ms.session_id) {
|
||||
process.session.terminate();
|
||||
true
|
||||
} else {
|
||||
@@ -311,7 +310,7 @@ impl ExecServerHandler {
|
||||
}
|
||||
|
||||
async fn stream_output(
|
||||
process_id: String,
|
||||
session_id: String,
|
||||
stream: ExecOutputStream,
|
||||
mut receiver: tokio::sync::mpsc::Receiver<Vec<u8>>,
|
||||
outbound_tx: mpsc::Sender<ExecServerOutboundMessage>,
|
||||
@@ -320,7 +319,7 @@ async fn stream_output(
|
||||
if outbound_tx
|
||||
.send(ExecServerOutboundMessage::Notification(
|
||||
ExecServerServerNotification::OutputDelta(ExecOutputDeltaNotification {
|
||||
process_id: process_id.clone(),
|
||||
session_id: session_id.clone(),
|
||||
stream,
|
||||
chunk: chunk.into(),
|
||||
}),
|
||||
@@ -334,7 +333,7 @@ async fn stream_output(
|
||||
}
|
||||
|
||||
async fn watch_exit(
|
||||
process_id: String,
|
||||
session_id: String,
|
||||
exit_rx: tokio::sync::oneshot::Receiver<i32>,
|
||||
outbound_tx: mpsc::Sender<ExecServerOutboundMessage>,
|
||||
processes: Arc<Mutex<HashMap<String, RunningProcess>>>,
|
||||
@@ -342,12 +341,12 @@ async fn watch_exit(
|
||||
let exit_code = exit_rx.await.unwrap_or(-1);
|
||||
{
|
||||
let mut processes = processes.lock().await;
|
||||
processes.remove(&process_id);
|
||||
processes.remove(&session_id);
|
||||
}
|
||||
let _ = outbound_tx
|
||||
.send(ExecServerOutboundMessage::Notification(
|
||||
ExecServerServerNotification::Exited(ExecExitedNotification {
|
||||
process_id,
|
||||
session_id,
|
||||
exit_code,
|
||||
}),
|
||||
))
|
||||
@@ -428,7 +427,6 @@ mod tests {
|
||||
.handle_message(ExecServerInboundMessage::Request(ExecServerRequest::Exec {
|
||||
request_id: RequestId::Integer(7),
|
||||
params: crate::protocol::ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().expect("cwd"),
|
||||
env: HashMap::new(),
|
||||
@@ -478,7 +476,6 @@ mod tests {
|
||||
.handle_message(ExecServerInboundMessage::Request(ExecServerRequest::Exec {
|
||||
request_id: RequestId::Integer(2),
|
||||
params: crate::protocol::ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().expect("cwd"),
|
||||
env: HashMap::new(),
|
||||
@@ -574,18 +571,9 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn duplicate_process_ids_are_rejected_per_connection() {
|
||||
async fn exec_returns_server_generated_session_ids() {
|
||||
let (outgoing_tx, mut outgoing_rx) = tokio::sync::mpsc::channel(4);
|
||||
let mut handler = ExecServerHandler::new(outgoing_tx);
|
||||
let marker_path = std::env::temp_dir().join(format!(
|
||||
"codex-exec-server-duplicate-{}-{}",
|
||||
std::process::id(),
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.expect("system clock before unix epoch")
|
||||
.as_nanos()
|
||||
));
|
||||
let _ = std::fs::remove_file(&marker_path);
|
||||
|
||||
if let Err(err) = handler
|
||||
.handle_message(ExecServerInboundMessage::Request(
|
||||
@@ -611,7 +599,6 @@ mod tests {
|
||||
}
|
||||
|
||||
let params = crate::protocol::ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec![
|
||||
"bash".to_string(),
|
||||
"-lc".to_string(),
|
||||
@@ -631,48 +618,40 @@ mod tests {
|
||||
{
|
||||
panic!("first exec should succeed: {err}");
|
||||
}
|
||||
assert_eq!(
|
||||
recv_outbound(&mut outgoing_rx).await,
|
||||
ExecServerOutboundMessage::Response {
|
||||
request_id: RequestId::Integer(2),
|
||||
response: ExecServerResponseMessage::Exec(crate::protocol::ExecResponse {
|
||||
process_id: "proc-1".to_string(),
|
||||
}),
|
||||
}
|
||||
);
|
||||
let ExecServerOutboundMessage::Response {
|
||||
request_id,
|
||||
response: ExecServerResponseMessage::Exec(first_exec),
|
||||
} = recv_outbound(&mut outgoing_rx).await
|
||||
else {
|
||||
panic!("expected first exec response");
|
||||
};
|
||||
assert_eq!(request_id, RequestId::Integer(2));
|
||||
assert_eq!(first_exec.session_id, "session-1");
|
||||
|
||||
if let Err(err) = handler
|
||||
.handle_message(ExecServerInboundMessage::Request(ExecServerRequest::Exec {
|
||||
request_id: RequestId::Integer(3),
|
||||
params: crate::protocol::ExecParams {
|
||||
argv: vec![
|
||||
"bash".to_string(),
|
||||
"-lc".to_string(),
|
||||
format!("printf duplicate > {}", marker_path.display()),
|
||||
],
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
..params
|
||||
},
|
||||
}))
|
||||
.await
|
||||
{
|
||||
panic!("duplicate exec should not fail the handler: {err}");
|
||||
panic!("second exec should succeed: {err}");
|
||||
}
|
||||
|
||||
let ExecServerOutboundMessage::Error { request_id, error } =
|
||||
recv_outbound(&mut outgoing_rx).await
|
||||
let ExecServerOutboundMessage::Response {
|
||||
request_id,
|
||||
response: ExecServerResponseMessage::Exec(second_exec),
|
||||
} = recv_outbound(&mut outgoing_rx).await
|
||||
else {
|
||||
panic!("expected duplicate-process error");
|
||||
panic!("expected second exec response");
|
||||
};
|
||||
assert_eq!(request_id, RequestId::Integer(3));
|
||||
assert_eq!(error.code, -32600);
|
||||
assert_eq!(error.message, "process proc-1 already exists");
|
||||
assert!(
|
||||
!marker_path.exists(),
|
||||
"duplicate process ids must be rejected before spawning the command"
|
||||
);
|
||||
assert_eq!(second_exec.session_id, "session-2");
|
||||
|
||||
handler.shutdown().await;
|
||||
let _ = std::fs::remove_file(&marker_path);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -707,7 +686,6 @@ mod tests {
|
||||
.handle_message(ExecServerInboundMessage::Request(ExecServerRequest::Exec {
|
||||
request_id: RequestId::Integer(2),
|
||||
params: crate::protocol::ExecParams {
|
||||
process_id: "proc-2".to_string(),
|
||||
argv: vec![
|
||||
"bash".to_string(),
|
||||
"-lc".to_string(),
|
||||
@@ -723,14 +701,20 @@ mod tests {
|
||||
{
|
||||
panic!("exec should succeed: {err}");
|
||||
}
|
||||
let _ = recv_outbound(&mut outgoing_rx).await;
|
||||
let ExecServerOutboundMessage::Response {
|
||||
response: ExecServerResponseMessage::Exec(exec_response),
|
||||
..
|
||||
} = recv_outbound(&mut outgoing_rx).await
|
||||
else {
|
||||
panic!("expected exec response");
|
||||
};
|
||||
|
||||
if let Err(err) = handler
|
||||
.handle_message(ExecServerInboundMessage::Request(
|
||||
ExecServerRequest::Write {
|
||||
request_id: RequestId::Integer(3),
|
||||
params: WriteParams {
|
||||
process_id: "proc-2".to_string(),
|
||||
session_id: exec_response.session_id,
|
||||
chunk: b"hello\n".to_vec().into(),
|
||||
},
|
||||
},
|
||||
@@ -747,7 +731,7 @@ mod tests {
|
||||
};
|
||||
assert_eq!(request_id, RequestId::Integer(3));
|
||||
assert_eq!(error.code, -32600);
|
||||
assert_eq!(error.message, "stdin is closed for process proc-2");
|
||||
assert_eq!(error.message, "stdin is closed for session session-1");
|
||||
|
||||
handler.shutdown().await;
|
||||
}
|
||||
@@ -785,7 +769,7 @@ mod tests {
|
||||
ExecServerRequest::Write {
|
||||
request_id: RequestId::Integer(2),
|
||||
params: WriteParams {
|
||||
process_id: "missing".to_string(),
|
||||
session_id: "missing".to_string(),
|
||||
chunk: b"hello\n".to_vec().into(),
|
||||
},
|
||||
},
|
||||
@@ -802,7 +786,7 @@ mod tests {
|
||||
};
|
||||
assert_eq!(request_id, RequestId::Integer(2));
|
||||
assert_eq!(error.code, -32600);
|
||||
assert_eq!(error.message, "unknown process id missing");
|
||||
assert_eq!(error.message, "unknown session id missing");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -838,7 +822,7 @@ mod tests {
|
||||
ExecServerRequest::Terminate {
|
||||
request_id: RequestId::Integer(2),
|
||||
params: crate::protocol::TerminateParams {
|
||||
process_id: "missing".to_string(),
|
||||
session_id: "missing".to_string(),
|
||||
},
|
||||
},
|
||||
))
|
||||
@@ -859,7 +843,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn terminate_keeps_process_ids_reserved_until_exit_cleanup() {
|
||||
async fn terminate_keeps_session_ids_reserved_until_exit_cleanup() {
|
||||
let (outgoing_tx, mut outgoing_rx) = tokio::sync::mpsc::channel(2);
|
||||
let mut handler = ExecServerHandler::new(outgoing_tx);
|
||||
|
||||
@@ -911,7 +895,7 @@ mod tests {
|
||||
ExecServerRequest::Terminate {
|
||||
request_id: RequestId::Integer(2),
|
||||
params: crate::protocol::TerminateParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
session_id: "proc-1".to_string(),
|
||||
},
|
||||
},
|
||||
))
|
||||
|
||||
@@ -286,7 +286,7 @@ mod tests {
|
||||
let routed = route_jsonrpc_message(JSONRPCMessage::Request(JSONRPCRequest {
|
||||
id: RequestId::Integer(2),
|
||||
method: EXEC_METHOD.to_string(),
|
||||
params: Some(json!({ "processId": "proc-1" })),
|
||||
params: Some(json!({ "sessionId": "proc-1" })),
|
||||
trace: None,
|
||||
}))
|
||||
.expect("exec request should route");
|
||||
@@ -322,7 +322,7 @@ mod tests {
|
||||
fn serializes_typed_notifications_back_to_jsonrpc() {
|
||||
let message = encode_outbound_message(ExecServerOutboundMessage::Notification(
|
||||
ExecServerServerNotification::Exited(ExecExitedNotification {
|
||||
process_id: "proc-1".to_string(),
|
||||
session_id: "proc-1".to_string(),
|
||||
exit_code: 0,
|
||||
}),
|
||||
))
|
||||
@@ -333,7 +333,7 @@ mod tests {
|
||||
JSONRPCMessage::Notification(JSONRPCNotification {
|
||||
method: EXEC_EXITED_METHOD.to_string(),
|
||||
params: Some(json!({
|
||||
"processId": "proc-1",
|
||||
"sessionId": "proc-1",
|
||||
"exitCode": 0,
|
||||
})),
|
||||
})
|
||||
@@ -345,7 +345,7 @@ mod tests {
|
||||
let message = encode_outbound_message(ExecServerOutboundMessage::Response {
|
||||
request_id: RequestId::Integer(3),
|
||||
response: ExecServerResponseMessage::Exec(ExecResponse {
|
||||
process_id: "proc-1".to_string(),
|
||||
session_id: "proc-1".to_string(),
|
||||
}),
|
||||
})
|
||||
.expect("response should serialize");
|
||||
@@ -355,7 +355,7 @@ mod tests {
|
||||
JSONRPCMessage::Response(codex_app_server_protocol::JSONRPCResponse {
|
||||
id: RequestId::Integer(3),
|
||||
result: json!({
|
||||
"processId": "proc-1",
|
||||
"sessionId": "proc-1",
|
||||
}),
|
||||
})
|
||||
);
|
||||
@@ -368,7 +368,7 @@ mod tests {
|
||||
id: RequestId::Integer(4),
|
||||
method: EXEC_METHOD.to_string(),
|
||||
params: Some(json!({
|
||||
"processId": "proc-1",
|
||||
"sessionId": "proc-1",
|
||||
"argv": ["bash", "-lc", "true"],
|
||||
"cwd": cwd,
|
||||
"env": {},
|
||||
@@ -389,7 +389,6 @@ mod tests {
|
||||
assert_eq!(
|
||||
params,
|
||||
ExecParams {
|
||||
process_id: "proc-1".to_string(),
|
||||
argv: vec!["bash".to_string(), "-lc".to_string(), "true".to_string()],
|
||||
cwd: std::env::current_dir().expect("cwd"),
|
||||
env: std::collections::HashMap::new(),
|
||||
|
||||
@@ -96,7 +96,6 @@ async fn exec_server_client_streams_output_and_accepts_writes() -> anyhow::Resul
|
||||
let process = server
|
||||
.client()
|
||||
.start_process(ExecParams {
|
||||
process_id: "2001".to_string(),
|
||||
argv: vec![
|
||||
"bash".to_string(),
|
||||
"-lc".to_string(),
|
||||
@@ -163,7 +162,6 @@ async fn exec_server_client_connects_over_websocket() -> anyhow::Result<()> {
|
||||
|
||||
let process = client
|
||||
.start_process(ExecParams {
|
||||
process_id: "2002".to_string(),
|
||||
argv: vec![
|
||||
"bash".to_string(),
|
||||
"-lc".to_string(),
|
||||
@@ -241,7 +239,6 @@ async fn websocket_disconnect_terminates_processes_for_that_connection() -> anyh
|
||||
|
||||
let _process = client
|
||||
.start_process(ExecParams {
|
||||
process_id: "2003".to_string(),
|
||||
argv: vec![
|
||||
"bash".to_string(),
|
||||
"-lc".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user