aKode: barra di stato compatta (ctx/t/s a destra), contesto reale, /init breve, tema Automatico, /resume usa provider e modello attuali
Some checks failed
blocking-ci / Bazel (push) Has been cancelled
blocking-ci / Blob size policy (push) Has been cancelled
blocking-ci / cargo-deny (push) Has been cancelled
blocking-ci / Codespell (push) Has been cancelled
blocking-ci / repo-checks (push) Has been cancelled
blocking-ci / rust-ci (push) Has been cancelled
blocking-ci / sdk (push) Has been cancelled
blocking-ci / CI required (push) Has been cancelled
postmerge-ci / rust-ci-full (push) Has been cancelled
postmerge-ci / v8-canary (push) Has been cancelled
postmerge-ci / Postmerge CI results (push) Has been cancelled

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andrea.difonzo
2026-11-11 08:20:46 +01:00
parent 293d2bb842
commit 6b725c7aaa
151 changed files with 1168 additions and 556 deletions

View File

@@ -244,6 +244,8 @@ fn collect_resume_override_mismatches(
mismatch_details
}
/// aKode: only used when a daemon restart reopens live threads; a user resume keeps the current
/// config's provider, model and reasoning effort.
fn merge_persisted_resume_metadata(
request_overrides: &mut Option<HashMap<String, serde_json::Value>>,
typesafe_overrides: &mut ConfigOverrides,
@@ -4242,16 +4244,23 @@ impl ThreadRequestProcessor {
}
InitialHistory::New | InitialHistory::Cleared | InitialHistory::Forked(_) => None,
};
// aKode: a user resume takes provider, model and reasoning effort from the current
// config (or the request's explicit overrides), so switching provider in config (e.g.
// local server -> openrouter) also applies to resumed sessions. Only a daemon restart,
// which reopens live sessions transparently, keeps the values the thread was using.
let restore_saved_model = matches!(target, ThreadResumeTarget::DaemonRecovery(_));
let persisted_metadata = self
.load_and_apply_persisted_resume_metadata(
&thread_history,
persisted_settings.as_ref(),
&mut request_overrides,
&mut typesafe_overrides,
restore_saved_model,
)
.await;
let clear_reasoning_effort = !has_explicit_model_resume_override
let clear_reasoning_effort = restore_saved_model
&& !has_explicit_model_resume_override
&& persisted_metadata
.as_ref()
.is_some_and(|metadata| metadata.reasoning_effort.is_none());
@@ -4290,7 +4299,9 @@ impl ThreadRequestProcessor {
})
}
_ => None,
}),
})
// aKode: the saved provider is enforced only for daemon recovery.
.filter(|_| restore_saved_model),
request_overrides,
typesafe_overrides,
history_cwd,
@@ -4590,6 +4601,7 @@ impl ThreadRequestProcessor {
persisted_settings: Option<&PersistedResumeSettings>,
request_overrides: &mut Option<HashMap<String, serde_json::Value>>,
typesafe_overrides: &mut ConfigOverrides,
restore_saved_model: bool,
) -> Option<ThreadMetadata> {
let InitialHistory::Resumed(resumed_history) = thread_history else {
return None;
@@ -4617,7 +4629,13 @@ impl ThreadRequestProcessor {
.await
.ok()
.flatten()?;
merge_persisted_resume_metadata(request_overrides, typesafe_overrides, &persisted_metadata);
if restore_saved_model {
merge_persisted_resume_metadata(
request_overrides,
typesafe_overrides,
&persisted_metadata,
);
}
Some(persisted_metadata)
}

View File

@@ -388,6 +388,8 @@ async fn thread_resume_and_fork_upgrade_legacy_protected_model_settings() -> Res
.send_thread_resume_request(params!(
ResumeParams,
thread_id = thread_id.clone(),
// aKode: resume no longer restores the saved model, so ask for it explicitly.
model = Some(MODEL.to_string()),
approval_policy = Some(Never),
approvals_reviewer = Some(User),
))
@@ -400,7 +402,11 @@ async fn thread_resume_and_fork_upgrade_legacy_protected_model_settings() -> Res
Never,
);
let id = server
.send_thread_resume_request(params!(ResumeParams, thread_id))
.send_thread_resume_request(params!(
ResumeParams,
thread_id,
model = Some(MODEL.to_string())
))
.await?;
let resumed: ResumeResponse = timeout(TIMEOUT, server.read_response(id)).await??;
assert_protected_with_policy(

View File

@@ -840,7 +840,9 @@ async fn cold_resume_workspace_roots_honor_owned_snapshot_and_caller_overrides()
let response_mock =
responses::mount_sse_sequence(&server, vec![responses::sse_completed("done"); 3]).await;
let codex_home = TempDir::new()?;
// aKode: resume uses the configured model, so configure the one the thread was saved with.
MockResponsesConfig::new(&server.uri())
.with_model("gpt-5.5")
.with_sandbox_mode("workspace-write")
.with_extra_config(
r#"[sandbox_workspace_write]
@@ -1668,8 +1670,10 @@ async fn thread_resume_preserves_acknowledged_model_effort_and_approvals_reviewe
..
} = timeout(DEFAULT_READ_TIMEOUT, mcp.read_response(resume_id)).await??;
assert_eq!(model, "gpt-5.2-codex");
assert_eq!(reasoning_effort, Some(ReasoningEffort::Ultra));
// aKode: model and reasoning effort come from the current config on resume, not from the
// values the thread last used.
assert_eq!(model, "gpt-5.4");
assert_eq!(reasoning_effort, Some(ReasoningEffort::High));
assert_eq!(approvals_reviewer, ApprovalsReviewer::AutoReview);
assert_eq!(thread.cwd.as_path(), live_cwd);
assert_eq!(cwd.as_path(), live_cwd);
@@ -6568,12 +6572,14 @@ fn create_saved_gateway_rollout(home: &Path) -> Result<String> {
)
}
// aKode: the provider a thread was saved with is not enforced on resume; the current config's
// provider serves it. Only an explicit provider override is still validated.
#[test_case::test_case(false, false; "missing_definition_config_override")]
#[test_case::test_case(false, true; "missing_definition_typed_override")]
#[test_case::test_case(true, false; "policy_conflict_config_override")]
#[test_case::test_case(true, true; "policy_conflict_typed_override")]
#[tokio::test]
async fn thread_resume_returns_provider_error_even_with_provider_override(
async fn thread_resume_validates_only_explicit_provider_override(
policy_conflict: bool,
typed_override: bool,
) -> Result<()> {
@@ -6610,67 +6616,13 @@ async fn thread_resume_returns_provider_error_even_with_provider_override(
model_provider: "old_provider".into(),
}
};
// Model and reasoning overrides must not discard the provider being validated.
for mut params in [
ThreadResumeParams::default(),
ThreadResumeParams {
model: Some("gpt-5.1-codex".into()),
..Default::default()
},
ThreadResumeParams {
config: Some(std::collections::HashMap::from([(
"model".into(),
json!("gpt-5.1-codex"),
)])),
..Default::default()
},
ThreadResumeParams {
config: Some(std::collections::HashMap::from([(
"model_reasoning_effort".into(),
json!("high"),
)])),
..Default::default()
},
] {
params.thread_id = thread_id.clone();
let id = client.send_thread_resume_request(params).await?;
let error = client
.read_stream_until_error_message(RequestId::Integer(id))
.await?;
assert_eq!(
error.error,
JSONRPCErrorError {
code: -32600,
message: expected.to_string(),
data: Some(serde_json::to_value(&expected)?),
}
);
}
assert!(
server
.received_requests()
.await
.expect("mock server should record received requests")
.iter()
.all(|request| !request.url.path().ends_with("/responses"))
);
// Failure leaves the history readable and does not create a live session with a new provider.
let id = client
.send_raw_request(
"thread/read",
Some(json!({"threadId": thread_id, "includeTurns": true})),
)
.await?;
let read: codex_app_server_protocol::ThreadReadResponse = client.read_response(id).await?;
assert_eq!(read.thread.model_provider, "old_provider");
// Provider overrides must not bypass admission for the saved provider.
// Asking for the saved provider explicitly is still checked.
let id = client
.send_thread_resume_request(ThreadResumeParams {
thread_id,
model: Some("gpt-5.1-codex".into()),
model_provider: typed_override.then(|| "mock_provider".into()),
thread_id: thread_id.clone(),
model_provider: typed_override.then(|| "old_provider".into()),
config: (!typed_override).then(|| {
std::collections::HashMap::from([("model_provider".into(), json!("mock_provider"))])
std::collections::HashMap::from([("model_provider".into(), json!("old_provider"))])
}),
..Default::default()
})
@@ -6678,37 +6630,25 @@ async fn thread_resume_returns_provider_error_even_with_provider_override(
let error = client
.read_stream_until_error_message(RequestId::Integer(id))
.await?;
assert_eq!(error.error.data, Some(serde_json::to_value(expected)?));
assert_eq!(error.error.data, Some(serde_json::to_value(&expected)?));
let id = client
.send_thread_resume_request(ThreadResumeParams {
thread_id,
..Default::default()
})
.await?;
let resumed: ThreadResumeResponse = client.read_response(id).await?;
assert_eq!(resumed.model_provider, "mock_provider");
Ok(())
}
#[tokio::test]
async fn thread_resume_recovers_after_provider_configuration_is_restored() -> Result<()> {
async fn thread_resume_uses_current_config_provider_not_saved_one() -> Result<()> {
// aKode: a session created with provider A resumes on provider B once config points at B.
let server = create_mock_responses_server_repeating_assistant("Done").await;
let home = TempDir::new()?;
mock_responses_config(&server.uri()).write(home.path())?;
let thread_id = create_saved_gateway_rollout(home.path())?;
let mut client = TestAppServer::builder()
.with_codex_home(home.path())
.build_initialized()
.await?;
let params = ThreadResumeParams {
thread_id,
..Default::default()
};
let id = client.send_thread_resume_request(params.clone()).await?;
let error = client
.read_stream_until_error_message(RequestId::Integer(id))
.await?;
assert_eq!(
error
.error
.data
.as_ref()
.and_then(|data| data["type"].as_str()),
Some("modelProviderNotConfigured")
);
let config_path = home.path().join("config.toml");
let config = std::fs::read_to_string(&config_path)?;
let server_uri = server.uri();
@@ -6718,14 +6658,19 @@ async fn thread_resume_recovers_after_provider_configuration_is_restored() -> Re
"{config}\n[model_providers.old_provider]\nname = 'Original provider'\nbase_url = '{server_uri}/v1'\n"
),
)?;
let thread_id = create_saved_gateway_rollout(home.path())?;
let mut client = TestAppServer::builder()
.with_codex_home(home.path())
.build_initialized()
.await?;
let id = client
.send_thread_resume_request(ThreadResumeParams {
model: Some("gpt-5.2-codex".into()),
..params
thread_id,
..Default::default()
})
.await?;
let resumed: ThreadResumeResponse = client.read_response(id).await?;
assert_eq!(resumed.model_provider, "old_provider");
assert_eq!(resumed.model, "gpt-5.2-codex");
assert_eq!(resumed.model_provider, "mock_provider");
assert_eq!(resumed.model, "gpt-5.4");
Ok(())
}