mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Add per-session code-mode execution limits (#37114)
## What changed - Add `create_session_with_limits` and session-scoped cell execution limits. - Clamp execute and wait yield times to the session's `max_yield_time_ms` without terminating the running cell. - Negotiate support with remote code-mode hosts and include non-default limits in `session/open`, while keeping unlimited sessions compatible with hosts and providers that do not support limits. ## Testing - Cover yield-time clamping, zero-timeout behavior, and isolation between sessions. - Cover wire serialization, capability negotiation, unsupported hosts, and shared process-host execution. GitOrigin-RevId: 9517321cd605bb87f93eeaa6ba331cc2e346e582
This commit is contained in:
@@ -7,6 +7,7 @@ use serde_json::Value as JsonValue;
|
||||
|
||||
use crate::CellId;
|
||||
use crate::CodeModeNestedToolCall;
|
||||
use crate::CodeModeSessionCellExecutionLimits;
|
||||
use crate::CodeModeToolKind;
|
||||
use crate::ExecuteRequest;
|
||||
use crate::FunctionCallOutputContentItem;
|
||||
@@ -16,6 +17,38 @@ use crate::ToolDefinition;
|
||||
use crate::WaitOutcome;
|
||||
use crate::WaitRequest;
|
||||
|
||||
/// The per-cell execution limits carried by a V1 session-open request.
|
||||
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||
pub struct WireSessionCellExecutionLimits {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_yield_time_ms: Option<u64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub max_heap_size_bytes: Option<u64>,
|
||||
}
|
||||
|
||||
impl TryFrom<CodeModeSessionCellExecutionLimits> for WireSessionCellExecutionLimits {
|
||||
type Error = TryFromIntError;
|
||||
|
||||
fn try_from(value: CodeModeSessionCellExecutionLimits) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
max_yield_time_ms: value.max_yield_time_ms,
|
||||
max_heap_size_bytes: value.max_heap_size_bytes.map(u64::try_from).transpose()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<WireSessionCellExecutionLimits> for CodeModeSessionCellExecutionLimits {
|
||||
type Error = TryFromIntError;
|
||||
|
||||
fn try_from(value: WireSessionCellExecutionLimits) -> Result<Self, Self::Error> {
|
||||
Ok(Self {
|
||||
max_yield_time_ms: value.max_yield_time_ms,
|
||||
max_heap_size_bytes: value.max_heap_size_bytes.map(usize::try_from).transpose()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A cell identifier with a wire representation owned by protocol V1.
|
||||
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
#[serde(transparent)]
|
||||
|
||||
Reference in New Issue
Block a user