Support environment updates in app-server settings APIs (#60655)

## What changed

Add experimental `environments` fields to `turn/settings/update` and `thread/settings/update`. Turn updates apply to later steps of the running turn; thread updates apply to future turns. Omission or `null` preserves the selection, while `[]` clears it. Providing `cwd` in a thread update without an environment list selects the defaults for that directory.

Include the ordered environment selection in `thread/settings/updated`. Wait for Core to accept thread settings updates before returning success, and return rejections as request errors.

## Testing

Add integration coverage for attaching, replacing, preserving, and clearing environments; rejected updates; and the distinction between later steps and future turns.

GitOrigin-RevId: bfebeda57c676be94427aeb0c567c0b94fd9c387
This commit is contained in:
sayan-oai
2026-11-10 20:35:28 +00:00
committed by copyberry
parent 82e6bacb9c
commit c9bbed2dae
15 changed files with 327 additions and 7 deletions
@@ -1113,6 +1113,7 @@ client_request_definitions! {
#[experimental("turn/settings/update")]
TurnSettingsUpdate => "turn/settings/update" {
params: v2::TurnSettingsUpdateParams,
inspect_params: true,
serialization: thread_id(params.thread_id),
response: v2::TurnSettingsUpdateResponse,
},
@@ -4623,6 +4624,7 @@ mod tests {
thread_id: "thr_123".to_string(),
thread_settings: v2::ThreadSettings {
disabled_plugin_ids: Vec::new(),
environments: Some(Vec::new()),
cwd: absolute_path("/tmp/repo"),
approval_policy: v2::AskForApproval::Never,
approvals_reviewer: v2::ApprovalsReviewer::User,
@@ -4,6 +4,7 @@ use super::AskForApproval;
use super::SandboxMode;
use super::SandboxPolicy;
use super::Thread;
use super::ThreadEnvironment;
use super::ThreadHistoryMode;
use super::ThreadItem;
use super::ThreadRealtimeItem;
@@ -242,6 +243,12 @@ pub struct ThreadSettingsUpdateParams {
/// Override the working directory for subsequent turns.
#[ts(optional = nullable)]
pub cwd: Option<PathBuf>,
/// Replace the environments for future turns without changing the running turn.
/// Omitted/null preserves the selection unless `cwd` is also provided, which selects
/// the default environments for that directory. [] clears the selection.
#[experimental("thread/settings/update.environments")]
#[ts(optional = nullable)]
pub environments: Option<Vec<TurnEnvironmentParams>>,
/// Override the approval policy for subsequent turns.
#[experimental(nested)]
#[ts(optional = nullable)]
@@ -306,6 +313,11 @@ pub struct ThreadSettings {
#[serde(default)]
pub disabled_plugin_ids: Vec<String>,
pub cwd: AbsolutePathBuf,
/// Environments configured for future turns, in priority order, primary first.
/// `null` means the server does not expose the selection; [] means none are selected.
#[experimental("thread/settings.environments")]
#[serde(default)]
pub environments: Option<Vec<ThreadEnvironment>>,
pub approval_policy: AskForApproval,
pub approvals_reviewer: ApprovalsReviewer,
pub sandbox_policy: SandboxPolicy,
@@ -43,7 +43,9 @@ pub enum TurnStatus {
/// Unsupported fields are rejected rather than silently ignored.
/// Any live task kind may accept publication. Child sessions and consumers of
/// frozen initial settings are unchanged.
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, JsonSchema, TS)]
#[derive(
Serialize, Deserialize, Debug, Default, Clone, PartialEq, JsonSchema, TS, ExperimentalApi,
)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[ts(export_to = "v2/")]
pub struct TurnSettingsUpdateParams {
@@ -53,6 +55,11 @@ pub struct TurnSettingsUpdateParams {
/// Already captured steps and pending approvals retain their original reviewer.
#[ts(optional = nullable)]
pub approvals_reviewer: Option<ApprovalsReviewer>,
/// Replace the environments for subsequent steps of this turn, not future turns.
/// Omitted/null preserves the selection; [] clears it. An already-started step is unchanged.
#[experimental("turn/settings/update.environments")]
#[ts(optional = nullable)]
pub environments: Option<Vec<TurnEnvironmentParams>>,
/// Omission or `null` leaves the model unchanged.
#[ts(optional = nullable)]
pub model: Option<String>,