Files
codex/codex-rs/app-server-protocol/src/protocol/v2/thread_sample.rs
T
Keyan Zhang 0bc1e7db9a Allow per-sample model overrides in thread/sample (#62419)
## Why

Clients sampling a thread could only use the source thread's model.

## What changed

Add an optional `model` field to the experimental `thread/sample`
request. Omitting it or passing `null` inherits the source thread's
model. When an override is supplied, the server uses the selected
model's capabilities to decide whether to apply the requested
reasoning effort.

## Testing

Add an app-server integration test that checks model selection and
reasoning effort for the overridden sample, then verifies that a
subsequent sample and a follow-up turn use the source model.

GitOrigin-RevId: f5c54ca3d693d31e1f3e0628a520583330a5d56d
2026-11-19 03:37:31 +00:00

69 lines
2.7 KiB
Rust

//! One model response on an ephemeral fork that inherits the source's configuration and context.
use super::ThreadSource;
use crate::JsonSchema;
use crate::RequestId;
use crate::TS;
use codex_protocol::openai_models::ReasoningEffort;
use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadSampleParams {
pub thread_id: String,
/// The loaded source's latest turn, which must be finished (completed, failed, or interrupted) unless `allowInProgressTurn` is true.
pub expected_turn_id: String,
/// Allow sampling the latest turn before it finishes.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub allow_in_progress_turn: bool,
pub prompt: String,
/// Override the model for this sample.
/// Omit or pass `null` to inherit the source thread's model.
#[ts(optional = nullable)]
pub model: Option<String>,
/// Applied only when the provider and model support cache-preserving reasoning-effort updates.
#[ts(optional = nullable)]
pub effort: Option<ReasoningEffort>,
#[ts(optional = nullable)]
pub thread_source: Option<ThreadSource>,
#[ts(optional = nullable)]
pub turn_trigger: Option<String>,
/// Optional metadata to enrich Codex's ResponsesAPI turn metadata.
#[ts(optional = nullable)]
pub responsesapi_client_metadata: Option<HashMap<String, String>>,
/// Disable MCP servers when the inherited window uses incremental tools on Responses Lite.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub disable_mcp: bool,
/// Override upstream interruption on cancellation for this sample; otherwise inherit the parent.
#[ts(optional = nullable)]
pub interrupt_on_cancel: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadSampleResponse {
pub source_turn_id: String,
pub response_id: String,
/// Assistant text from the response, or null if it attempted a tool call or completed without text.
pub text: Option<String>,
pub input_tokens: Option<i64>,
pub cached_input_tokens: Option<i64>,
pub output_tokens: Option<i64>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[ts(export_to = "v2/")]
pub struct ThreadSampleCancelParams {
pub request_id: RequestId,
}
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq, JsonSchema, TS)]
#[serde(rename_all = "camelCase")]
#[ts(export_to = "v2/")]
pub struct ThreadSampleCancelResponse {}