Skip to content

Commit 6f15a8e

Browse files
committed
Use local provider for remote overnight runs
1 parent 115c61b commit 6f15a8e

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

src/tui/app/commands_overnight.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::{App, DisplayMessage};
22
use crate::overnight::{OvernightCommand, OvernightStartOptions};
3+
use crate::provider::Provider;
4+
use std::sync::Arc;
35

46
pub(super) fn handle_overnight_command(app: &mut App, trimmed: &str) -> bool {
57
let Some(command) = crate::overnight::parse_overnight_command(trimmed) else {
@@ -20,11 +22,12 @@ pub(super) fn handle_overnight_command(app: &mut App, trimmed: &str) -> bool {
2022
.map(std::path::PathBuf::from)
2123
.filter(|path| path.is_dir())
2224
.or_else(|| std::env::current_dir().ok());
25+
let provider = overnight_provider_for_app(app);
2326
let options = OvernightStartOptions {
2427
duration,
2528
mission,
2629
parent_session: app.session.clone(),
27-
provider: app.provider.fork(),
30+
provider,
2831
registry: app.registry.clone(),
2932
working_dir,
3033
use_current_session: true,
@@ -53,6 +56,35 @@ fn show_overnight_help(app: &mut App) {
5356
));
5457
}
5558

59+
fn overnight_provider_for_app(app: &mut App) -> Arc<dyn Provider> {
60+
if !app.is_remote {
61+
return app.provider.fork();
62+
}
63+
64+
// Remote-attached TUIs intentionally use NullProvider because normal turns
65+
// execute in the remote backend process. `/overnight` is supervised by the
66+
// launching TUI process, so it needs a real local provider instead of the
67+
// remote placeholder. Restore the displayed session model when possible and
68+
// otherwise fall back to the local default provider.
69+
let provider: Arc<dyn Provider> = Arc::new(crate::provider::MultiProvider::new_fast());
70+
if let Some(model) = app
71+
.session
72+
.model
73+
.as_deref()
74+
.map(str::trim)
75+
.filter(|model| !model.is_empty() && *model != "unknown")
76+
&& let Err(error) = provider.set_model(model)
77+
{
78+
app.push_display_message(DisplayMessage::system(format!(
79+
"Overnight could not restore remote model `{}` locally: {}. Using local default provider `{}` instead.",
80+
model,
81+
error,
82+
provider.name()
83+
)));
84+
}
85+
provider
86+
}
87+
5688
fn show_overnight_status(app: &mut App) {
5789
match crate::overnight::latest_manifest() {
5890
Ok(Some(manifest)) => {

0 commit comments

Comments
 (0)