mirror of
https://github.com/openai/codex.git
synced 2026-10-31 19:28:49 +00:00
Scope code mode callback delegates to individual executions (#44865)
## Why A delegate bound at session creation cannot provide different callbacks for cells sharing that session. Each execution needs to retain its own delegate across yields and release it when the cell is cleaned up. ## What changed - Pass `CodeModeSessionDelegate` to `execute` instead of session creation. - Route tool calls, notifications, and cell closure callbacks through the execution's delegate in the in-process runtime and the gRPC and stdio transports. - Retain delegates with pending executions and live cells, releasing them through closure and cancellation cleanup. ## Testing Add coverage for distinct delegates across yielded cells, gRPC callbacks before cell admission, and delegate release after completion or abandoned execution cleanup. Update transport tests to verify callbacks reach the owning cell's delegate. GitOrigin-RevId: 7469f52104b993e790a40c65fb800ad02b7fd606
This commit is contained in:
@@ -148,7 +148,7 @@ impl GrpcCodeModeHost {
|
||||
_ = session.closed.cancelled() => {
|
||||
return Err(Status::cancelled("code-mode session is closed"));
|
||||
}
|
||||
result = session.runtime.execute(request) => {
|
||||
result = session.runtime.execute(request, Arc::new(delegate::GrpcDelegate::new(Arc::downgrade(&session)))) => {
|
||||
result.map_err(Status::failed_precondition)?
|
||||
}
|
||||
};
|
||||
|
||||
@@ -27,7 +27,6 @@ use tonic::Status;
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::GrpcStream;
|
||||
use super::delegate::GrpcDelegate;
|
||||
use super::events::EventSender;
|
||||
use super::validation;
|
||||
use super::waits::ActiveWait;
|
||||
@@ -213,7 +212,6 @@ impl GrpcSession {
|
||||
limits: CodeModeSessionCellExecutionLimits,
|
||||
) -> Arc<Self> {
|
||||
Arc::new_cyclic(|weak: &Weak<Self>| {
|
||||
let delegate = Arc::new(GrpcDelegate::new(weak.clone()));
|
||||
let failure_session = weak.clone();
|
||||
let failure_handler = Arc::new(move |reason: String| {
|
||||
if let Some(session) = failure_session.upgrade() {
|
||||
@@ -223,13 +221,10 @@ impl GrpcSession {
|
||||
});
|
||||
Self {
|
||||
id,
|
||||
runtime: Arc::new(
|
||||
InProcessCodeModeSession::with_delegate_and_task_failure_handler(
|
||||
delegate,
|
||||
failure_handler,
|
||||
limits,
|
||||
),
|
||||
),
|
||||
runtime: Arc::new(InProcessCodeModeSession::with_task_failure_handler(
|
||||
failure_handler,
|
||||
limits,
|
||||
)),
|
||||
closed,
|
||||
state: Mutex::new(SessionState::default()),
|
||||
events,
|
||||
|
||||
@@ -412,7 +412,11 @@ impl HostState {
|
||||
);
|
||||
return;
|
||||
};
|
||||
let result = session.execute(request).await;
|
||||
let delegate = Arc::new(RemoteDelegate::new(
|
||||
session_id.clone(),
|
||||
Arc::clone(&self.peer),
|
||||
));
|
||||
let result = session.execute(request, delegate).await;
|
||||
match result {
|
||||
Ok(started) => {
|
||||
let cell_id = started.cell_id.clone();
|
||||
@@ -517,10 +521,6 @@ impl HostState {
|
||||
{
|
||||
return Err(format!("code-mode session ID `{session_id}` was reused"));
|
||||
}
|
||||
let delegate = Arc::new(RemoteDelegate::new(
|
||||
session_id.clone(),
|
||||
Arc::clone(&self.peer),
|
||||
));
|
||||
let peer = Arc::downgrade(&self.peer);
|
||||
let task_failure_handler = Arc::new(move |reason| {
|
||||
if let Some(peer) = peer.upgrade() {
|
||||
@@ -529,13 +529,10 @@ impl HostState {
|
||||
});
|
||||
sessions.insert(
|
||||
session_id,
|
||||
Arc::new(
|
||||
InProcessCodeModeSession::with_delegate_and_task_failure_handler(
|
||||
delegate,
|
||||
task_failure_handler,
|
||||
cell_execution_limits,
|
||||
),
|
||||
),
|
||||
Arc::new(InProcessCodeModeSession::with_task_failure_handler(
|
||||
task_failure_handler,
|
||||
cell_execution_limits,
|
||||
)),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user