mirror of
https://github.com/openai/codex.git
synced 2026-12-02 00:31:03 +00:00
Merge branch 'main' into jif/rename-3
This commit is contained in:
@@ -1108,7 +1108,7 @@ async fn thread_goal_set_edits_objective_without_resetting_usage() -> Result<()>
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 12,
|
||||
/*token_delta*/ 50,
|
||||
codex_state::ThreadGoalAccountingMode::ActiveOnly,
|
||||
codex_state::GoalAccountingMode::ActiveOnly,
|
||||
Some(persisted_goal.goal_id.as_str()),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -123,7 +123,7 @@ pub fn map_api_error(err: ApiError) -> CodexErr {
|
||||
status: http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||
request_id: None,
|
||||
}),
|
||||
TransportError::Timeout => CodexErr::Timeout,
|
||||
TransportError::Timeout => CodexErr::RequestTimeout,
|
||||
TransportError::Network(msg) | TransportError::Build(msg) => {
|
||||
CodexErr::Stream(msg, None)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ use http::Method;
|
||||
use serde::Deserialize;
|
||||
use serde_json::to_value;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct CompactClient<T: HttpTransport> {
|
||||
session: EndpointSession<T>,
|
||||
@@ -37,10 +38,19 @@ impl<T: HttpTransport> CompactClient<T> {
|
||||
&self,
|
||||
body: serde_json::Value,
|
||||
extra_headers: HeaderMap,
|
||||
request_timeout: Duration,
|
||||
) -> Result<Vec<ResponseItem>, ApiError> {
|
||||
let resp = self
|
||||
.session
|
||||
.execute(Method::POST, Self::path(), extra_headers, Some(body))
|
||||
.execute_with(
|
||||
Method::POST,
|
||||
Self::path(),
|
||||
extra_headers,
|
||||
Some(body),
|
||||
|req| {
|
||||
req.timeout = Some(request_timeout);
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
let parsed: CompactHistoryResponse =
|
||||
serde_json::from_slice(&resp.body).map_err(|e| ApiError::Stream(e.to_string()))?;
|
||||
@@ -51,10 +61,11 @@ impl<T: HttpTransport> CompactClient<T> {
|
||||
&self,
|
||||
input: &CompactionInput<'_>,
|
||||
extra_headers: HeaderMap,
|
||||
request_timeout: Duration,
|
||||
) -> Result<Vec<ResponseItem>, ApiError> {
|
||||
let body = to_value(input)
|
||||
.map_err(|e| ApiError::Stream(format!("failed to encode compaction input: {e}")))?;
|
||||
self.compact(body, extra_headers).await
|
||||
self.compact(body, extra_headers, request_timeout).await
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -146,6 +146,9 @@ const X_CODEX_WS_STREAM_REQUEST_START_MS_CLIENT_METADATA_KEY: &str =
|
||||
const RESPONSES_WEBSOCKETS_V2_BETA_HEADER_VALUE: &str = "responses_websockets=2026-02-06";
|
||||
const RESPONSES_ENDPOINT: &str = "/responses";
|
||||
const RESPONSES_COMPACT_ENDPOINT: &str = "/responses/compact";
|
||||
// `/responses/compact` is unary, so the timeout covers the full response rather than one idle
|
||||
// period between stream events.
|
||||
const COMPACT_REQUEST_TIMEOUT_IDLE_MULTIPLIER: u32 = 4;
|
||||
const MEMORIES_SUMMARIZE_ENDPOINT: &str = "/memories/trace_summarize";
|
||||
#[cfg(test)]
|
||||
pub(crate) const WEBSOCKET_CONNECT_TIMEOUT: Duration =
|
||||
@@ -502,12 +505,16 @@ impl ModelClient {
|
||||
if let Some(header_value) = self.generate_attestation_header_for().await {
|
||||
extra_headers.insert(X_OAI_ATTESTATION_HEADER, header_value);
|
||||
}
|
||||
let compact_request_timeout = client_setup
|
||||
.api_provider
|
||||
.stream_idle_timeout
|
||||
.saturating_mul(COMPACT_REQUEST_TIMEOUT_IDLE_MULTIPLIER);
|
||||
let client =
|
||||
ApiCompactClient::new(transport, client_setup.api_provider, client_setup.api_auth)
|
||||
.with_telemetry(Some(request_telemetry));
|
||||
let trace_attempt = compaction_trace.start_attempt(&payload);
|
||||
let result = client
|
||||
.compact_input(&payload, extra_headers)
|
||||
.compact_input(&payload, extra_headers, compact_request_timeout)
|
||||
.await
|
||||
.map_err(map_api_error);
|
||||
trace_attempt.record_result(result.as_deref());
|
||||
|
||||
@@ -459,7 +459,7 @@ impl Session {
|
||||
|
||||
self.account_thread_goal_wall_clock_usage(
|
||||
&state_db,
|
||||
codex_state::ThreadGoalAccountingMode::ActiveOnly,
|
||||
codex_state::GoalAccountingMode::ActiveOnly,
|
||||
TerminalMetricEmission::Emit,
|
||||
)
|
||||
.await?;
|
||||
@@ -601,7 +601,7 @@ impl Session {
|
||||
let state_db = self.require_state_db_for_thread_goals().await?;
|
||||
self.account_thread_goal_wall_clock_usage(
|
||||
&state_db,
|
||||
codex_state::ThreadGoalAccountingMode::ActiveOnly,
|
||||
codex_state::GoalAccountingMode::ActiveOnly,
|
||||
TerminalMetricEmission::Emit,
|
||||
)
|
||||
.await?;
|
||||
@@ -1028,7 +1028,7 @@ impl Session {
|
||||
self.conversation_id,
|
||||
time_delta_seconds,
|
||||
token_delta,
|
||||
codex_state::ThreadGoalAccountingMode::ActiveOnly,
|
||||
codex_state::GoalAccountingMode::ActiveOnly,
|
||||
expected_goal_id.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
@@ -1119,7 +1119,7 @@ impl Session {
|
||||
};
|
||||
self.account_thread_goal_wall_clock_usage(
|
||||
&state_db,
|
||||
codex_state::ThreadGoalAccountingMode::ActiveOnly,
|
||||
codex_state::GoalAccountingMode::ActiveOnly,
|
||||
TerminalMetricEmission::Suppress,
|
||||
)
|
||||
.await?;
|
||||
@@ -1129,7 +1129,7 @@ impl Session {
|
||||
async fn account_thread_goal_wall_clock_usage(
|
||||
&self,
|
||||
state_db: &StateDbHandle,
|
||||
mode: codex_state::ThreadGoalAccountingMode,
|
||||
mode: codex_state::GoalAccountingMode,
|
||||
terminal_metric_emission: TerminalMetricEmission,
|
||||
) -> anyhow::Result<Option<ThreadGoal>> {
|
||||
let _accounting_permit = self.goal_runtime.accounting_permit().await?;
|
||||
|
||||
@@ -89,6 +89,8 @@ pub enum CodexErr {
|
||||
/// Returned by run_command_stream when the spawned child process timed out (10s).
|
||||
#[error("timeout waiting for child process to exit")]
|
||||
Timeout,
|
||||
#[error("request timed out")]
|
||||
RequestTimeout,
|
||||
/// Returned by run_command_stream when the child could not be spawned (its stdout/stderr pipes
|
||||
/// could not be captured). Analogous to the previous `CodexError::Spawn` variant.
|
||||
#[error("spawn failed: child stdout/stderr not captured")]
|
||||
@@ -192,6 +194,7 @@ impl CodexErr {
|
||||
| CodexErr::CyberPolicy { .. } => false,
|
||||
CodexErr::Stream(..)
|
||||
| CodexErr::Timeout
|
||||
| CodexErr::RequestTimeout
|
||||
| CodexErr::UnexpectedStatus(_)
|
||||
| CodexErr::ResponseStreamFailed(_)
|
||||
| CodexErr::ConnectionFailed(_)
|
||||
|
||||
@@ -48,12 +48,12 @@ pub use model::ThreadGoalStatus;
|
||||
pub use model::ThreadMetadata;
|
||||
pub use model::ThreadMetadataBuilder;
|
||||
pub use model::ThreadsPage;
|
||||
pub use runtime::GoalAccountingMode;
|
||||
pub use runtime::GoalStore;
|
||||
pub use runtime::GoalUpdate;
|
||||
pub use runtime::RemoteControlEnrollmentRecord;
|
||||
pub use runtime::RuntimeDbPath;
|
||||
pub use runtime::ThreadFilterOptions;
|
||||
pub use runtime::ThreadGoalAccountingMode;
|
||||
pub use runtime::ThreadGoalAccountingOutcome;
|
||||
pub use runtime::goals_db_filename;
|
||||
pub use runtime::goals_db_path;
|
||||
|
||||
@@ -66,6 +66,7 @@ mod remote_control;
|
||||
mod test_support;
|
||||
mod threads;
|
||||
|
||||
pub use goals::GoalAccountingMode;
|
||||
pub use goals::GoalStore;
|
||||
pub use goals::GoalUpdate;
|
||||
pub use goals::ThreadGoalAccountingMode;
|
||||
|
||||
@@ -26,7 +26,7 @@ pub enum ThreadGoalAccountingOutcome {
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum ThreadGoalAccountingMode {
|
||||
pub enum GoalAccountingMode {
|
||||
ActiveStatusOnly,
|
||||
ActiveOnly,
|
||||
ActiveOrComplete,
|
||||
@@ -387,7 +387,7 @@ WHERE thread_id = ?
|
||||
thread_id: ThreadId,
|
||||
time_delta_seconds: i64,
|
||||
token_delta: i64,
|
||||
mode: ThreadGoalAccountingMode,
|
||||
mode: GoalAccountingMode,
|
||||
expected_goal_id: Option<&str>,
|
||||
) -> anyhow::Result<ThreadGoalAccountingOutcome> {
|
||||
let time_delta_seconds = time_delta_seconds.max(0);
|
||||
@@ -400,20 +400,20 @@ WHERE thread_id = ?
|
||||
|
||||
let now_ms = datetime_to_epoch_millis(Utc::now());
|
||||
let status_filter = match mode {
|
||||
ThreadGoalAccountingMode::ActiveStatusOnly => "status = 'active'",
|
||||
ThreadGoalAccountingMode::ActiveOnly => "status IN ('active', 'budget_limited')",
|
||||
ThreadGoalAccountingMode::ActiveOrComplete => {
|
||||
GoalAccountingMode::ActiveStatusOnly => "status = 'active'",
|
||||
GoalAccountingMode::ActiveOnly => "status IN ('active', 'budget_limited')",
|
||||
GoalAccountingMode::ActiveOrComplete => {
|
||||
"status IN ('active', 'budget_limited', 'complete')"
|
||||
}
|
||||
ThreadGoalAccountingMode::ActiveOrStopped => {
|
||||
GoalAccountingMode::ActiveOrStopped => {
|
||||
"status IN ('active', 'paused', 'blocked', 'usage_limited', 'budget_limited')"
|
||||
}
|
||||
};
|
||||
let budget_limit_status_filter = match mode {
|
||||
ThreadGoalAccountingMode::ActiveStatusOnly
|
||||
| ThreadGoalAccountingMode::ActiveOnly
|
||||
| ThreadGoalAccountingMode::ActiveOrComplete => "status = 'active'",
|
||||
ThreadGoalAccountingMode::ActiveOrStopped => {
|
||||
GoalAccountingMode::ActiveStatusOnly
|
||||
| GoalAccountingMode::ActiveOnly
|
||||
| GoalAccountingMode::ActiveOrComplete => "status = 'active'",
|
||||
GoalAccountingMode::ActiveOrStopped => {
|
||||
"status IN ('active', 'paused', 'blocked', 'usage_limited', 'budget_limited')"
|
||||
}
|
||||
};
|
||||
@@ -802,7 +802,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 5,
|
||||
/*token_delta*/ 5,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
Some(original.goal_id.as_str()),
|
||||
)
|
||||
.await
|
||||
@@ -840,7 +840,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 12,
|
||||
/*token_delta*/ 30,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1062,7 +1062,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 7,
|
||||
/*token_delta*/ 5,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1080,7 +1080,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 3,
|
||||
/*token_delta*/ 15,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1098,7 +1098,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 5,
|
||||
/*token_delta*/ 5,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1133,7 +1133,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 5,
|
||||
/*token_delta*/ 5,
|
||||
ThreadGoalAccountingMode::ActiveStatusOnly,
|
||||
GoalAccountingMode::ActiveStatusOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1181,7 +1181,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 3,
|
||||
/*token_delta*/ 25,
|
||||
ThreadGoalAccountingMode::ActiveOrStopped,
|
||||
GoalAccountingMode::ActiveOrStopped,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1215,7 +1215,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 1,
|
||||
/*token_delta*/ 50,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1262,7 +1262,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 1,
|
||||
/*token_delta*/ 50,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1313,7 +1313,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 1,
|
||||
/*token_delta*/ 50,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1360,7 +1360,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 1,
|
||||
/*token_delta*/ 50,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1413,7 +1413,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 30,
|
||||
/*token_delta*/ 200,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1431,7 +1431,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 30,
|
||||
/*token_delta*/ 200,
|
||||
ThreadGoalAccountingMode::ActiveOrComplete,
|
||||
GoalAccountingMode::ActiveOrComplete,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1480,7 +1480,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 30,
|
||||
/*token_delta*/ 200,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1498,7 +1498,7 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 30,
|
||||
/*token_delta*/ 200,
|
||||
ThreadGoalAccountingMode::ActiveOrStopped,
|
||||
GoalAccountingMode::ActiveOrStopped,
|
||||
/*expected_goal_id*/ None,
|
||||
)
|
||||
.await
|
||||
@@ -1531,14 +1531,14 @@ mod tests {
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 4,
|
||||
/*token_delta*/ 40,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
);
|
||||
let second = runtime.thread_goals().account_thread_goal_usage(
|
||||
thread_id,
|
||||
/*time_delta_seconds*/ 6,
|
||||
/*token_delta*/ 60,
|
||||
ThreadGoalAccountingMode::ActiveOnly,
|
||||
GoalAccountingMode::ActiveOnly,
|
||||
/*expected_goal_id*/ None,
|
||||
);
|
||||
let (first, second) = tokio::join!(first, second);
|
||||
|
||||
Reference in New Issue
Block a user