feat: update process ID for event handling (#7261)

This commit is contained in:
jif-oai authored and GitHub committed 2025-11-25 14:21:05 -08:00
1 parent 981e2f742d
commit 28ff364c3a
17 files changed
+473 -163

No files matched your search

+13 -1
View File
@@ -65,12 +65,14 @@ pub(crate) async fn emit_exec_command_begin(
parsed_cmd: &[ParsedCommand],
source: ExecCommandSource,
interaction_input: Option<String>,
process_id: Option<&str>,
) {
ctx.session
.send_event(
ctx.turn,
EventMsg::ExecCommandBegin(ExecCommandBeginEvent {
call_id: ctx.call_id.to_string(),
process_id: process_id.map(str::to_owned),
turn_id: ctx.turn.sub_id.clone(),
command: command.to_vec(),
cwd: cwd.to_path_buf(),
@@ -100,6 +102,7 @@ pub(crate) enum ToolEmitter {
source: ExecCommandSource,
interaction_input: Option<String>,
parsed_cmd: Vec<ParsedCommand>,
process_id: Option<String>,
},
}
@@ -132,6 +135,7 @@ impl ToolEmitter {
cwd: PathBuf,
source: ExecCommandSource,
interaction_input: Option<String>,
process_id: Option<String>,
) -> Self {
let parsed_cmd = parse_command(command);
Self::UnifiedExec {
@@ -140,6 +144,7 @@ impl ToolEmitter {
source,
interaction_input,
parsed_cmd,
process_id,
}
}
@@ -157,7 +162,7 @@ impl ToolEmitter {
) => {
emit_exec_stage(
ctx,
ExecCommandInput::new(command, cwd.as_path(), parsed_cmd, *source, None),
ExecCommandInput::new(command, cwd.as_path(), parsed_cmd, *source, None, None),
stage,
)
.await;
@@ -229,6 +234,7 @@ impl ToolEmitter {
source,
interaction_input,
parsed_cmd,
process_id,
},
stage,
) => {
@@ -240,6 +246,7 @@ impl ToolEmitter {
parsed_cmd,
*source,
interaction_input.as_deref(),
process_id.as_deref(),
),
stage,
)
@@ -319,6 +326,7 @@ struct ExecCommandInput<'a> {
parsed_cmd: &'a [ParsedCommand],
source: ExecCommandSource,
interaction_input: Option<&'a str>,
process_id: Option<&'a str>,
}
impl<'a> ExecCommandInput<'a> {
@@ -328,6 +336,7 @@ impl<'a> ExecCommandInput<'a> {
parsed_cmd: &'a [ParsedCommand],
source: ExecCommandSource,
interaction_input: Option<&'a str>,
process_id: Option<&'a str>,
) -> Self {
Self {
command,
@@ -335,6 +344,7 @@ impl<'a> ExecCommandInput<'a> {
parsed_cmd,
source,
interaction_input,
process_id,
}
}
}
@@ -362,6 +372,7 @@ async fn emit_exec_stage(
exec_input.parsed_cmd,
exec_input.source,
exec_input.interaction_input.map(str::to_owned),
exec_input.process_id,
)
.await;
}
@@ -402,6 +413,7 @@ async fn emit_exec_end(
ctx.turn,
EventMsg::ExecCommandEnd(ExecCommandEndEvent {
call_id: ctx.call_id.to_string(),
process_id: exec_input.process_id.map(str::to_owned),
turn_id: ctx.turn.sub_id.clone(),
command: exec_input.command.to_vec(),
cwd: exec_input.cwd.to_path_buf(),
@@ -46,6 +46,7 @@ struct ExecCommandArgs {
#[derive(Debug, Deserialize)]
struct WriteStdinArgs {
// The model is trained on `session_id`.
session_id: i32,
#[serde(default)]
chars: String,
@@ -128,6 +129,7 @@ impl ToolHandler for UnifiedExecHandler {
"failed to parse exec_command arguments: {err:?}"
))
})?;
let process_id = manager.allocate_process_id().await;
let command = get_command(&args);
let ExecCommandArgs {
@@ -168,6 +170,7 @@ impl ToolHandler for UnifiedExecHandler {
cwd.clone(),
ExecCommandSource::UnifiedExecStartup,
None,
Some(process_id.clone()),
);
emitter.emit(event_ctx, ToolEventStage::Begin).await;
@@ -175,6 +178,7 @@ impl ToolHandler for UnifiedExecHandler {
.exec_command(
ExecCommandRequest {
command,
process_id,
yield_time_ms,
max_output_tokens,
workdir,
@@ -197,7 +201,7 @@ impl ToolHandler for UnifiedExecHandler {
manager
.write_stdin(WriteStdinRequest {
call_id: &call_id,
session_id: args.session_id,
process_id: &args.session_id.to_string(),
input: &args.chars,
yield_time_ms: args.yield_time_ms,
max_output_tokens: args.max_output_tokens,
@@ -255,8 +259,9 @@ fn format_response(response: &UnifiedExecResponse) -> String {
sections.push(format!("Process exited with code {exit_code}"));
}
if let Some(session_id) = response.session_id {
sections.push(format!("Process running with session ID {session_id}"));
if let Some(process_id) = &response.process_id {
// Training still uses "session ID".
sections.push(format!("Process running with session ID {process_id}"));
}
if let Some(original_token_count) = response.original_token_count {