Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion crates/openhuman-core/src/core/runtime/context_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ impl CoreContext {
if let Some(snapshot) = &self.latest_embedder_config {
if let Ok(mut current) = snapshot.lock() {
*current = config;
crate::config::Config::bind_context_snapshot(snapshot);
// Bound under this guard: relocking the snapshot here would
// deadlock the thread.
current.runtime_state.context_snapshot = Some(Arc::downgrade(snapshot));
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions crates/openhuman-core/src/core/runtime/context_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,38 @@ fn an_embedder_config_is_readable_from_the_context() {
assert_eq!(read.default_model.as_deref(), Some("embedder-model"));
}

/// The desktop's secret preflight replaces the snapshot once it has opened
/// the sealed config; the replacement must return and stay bound.
#[test]
fn replacing_the_embedder_config_returns_and_keeps_it_bound() {
let ctx = ctx_with_config(crate::config::Config::default());
let mut replacement = crate::config::Config::default();
replacement.default_model = Some("after-preflight".into());

let (done, finished) = std::sync::mpsc::channel();
let replacing = Arc::clone(&ctx);
std::thread::spawn(move || {
replacing.replace_latest_embedder_config(replacement);
let _ = done.send(());
});
finished
.recv_timeout(std::time::Duration::from_secs(5))
.expect("replacing the embedder config returns");

let read = ctx.latest_embedder_config().expect("snapshot is bound");
assert_eq!(read.default_model.as_deref(), Some("after-preflight"));
let snapshot = ctx.latest_embedder_config.as_ref().expect("snapshot");
let bound = snapshot
.lock()
.unwrap()
.runtime_state
.context_snapshot
.clone();
assert!(bound
.and_then(|weak| weak.upgrade())
.is_some_and(|bound| Arc::ptr_eq(&bound, snapshot)));
}

#[tokio::test]
async fn the_current_dispatch_sees_the_scoped_embedder_config() {
// This is the read path `load_config_with_timeout` uses. If it resolved
Expand Down
Loading