Skip to content

Commit 2c567b7

Browse files
committed
fix: align standalone storage dir fallbacks with plugin + resolve ORT_DYLIB_PATH in warmup
Three functions defaulted to ~/.cache/aft instead of the plugin's ~/.local/share/cortexkit/aft, causing standalone `aft warmup` to write to a different path than the plugin. Fallback now mirrors resolveCortexKitStorageRoot() from the TS plugin (XDG_DATA_HOME, Windows LOCALAPPDATA/APPDATA, ~/.local/share/cortexkit/aft). warmup.rs also never set ORT_DYLIB_PATH, so semantic index warmup failed with dlopen('libonnxruntime.so'). Now resolves the cached library from <storage_dir>/onnxruntime/1.24.4/ (and lib/ subdir) if ORT_DYLIB_PATH is not already set.
1 parent ae446bc commit 2c567b7

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

crates/aft/src/bash_background/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub fn storage_dir(configured: Option<&std::path::Path>) -> PathBuf {
159159
if let Some(dir) = std::env::var_os("AFT_CACHE_DIR") {
160160
return PathBuf::from(dir).join("aft");
161161
}
162-
// Default to the CortexKit shared data root the SAME location the
162+
// Default to the CortexKit shared data root - the SAME location the
163163
// plugins inject as `storage_dir` on every configure. Before this, the
164164
// fallback was the pre-migration `~/.cache/aft`, which only plugin-less
165165
// invocations ever hit; once the daemon-supervised module became such an

crates/aft/src/cli/warmup.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ pub fn run(args: Vec<OsString>) -> Result<(), WarmupError> {
5050
);
5151
}
5252

53+
// Resolve ONNX Runtime from the plugin-managed cache so `aft warmup`
54+
// can build the semantic index without the plugin setting ORT_DYLIB_PATH.
55+
if args.areas.semantic {
56+
try_set_ort_dylib_path(&storage_dir);
57+
}
58+
5359
let ctx = AppContext::new(Box::new(TreeSitterProvider::new()), Config::default());
5460
configure(&ctx, &root, &storage_dir, args.areas, args.force)?;
5561

@@ -249,11 +255,32 @@ fn warmup_storage_dir() -> PathBuf {
249255
if let Some(value) = std::env::var_os("AFT_STORAGE_DIR") {
250256
return PathBuf::from(value);
251257
}
252-
// Same CortexKit shared data root the plugins inject warming here must
258+
// Same CortexKit shared data root the plugins inject - warming here must
253259
// land in the storage universe real sessions will read from.
254260
aft::bash_background::storage_dir(None)
255261
}
256262

263+
/// Set `ORT_DYLIB_PATH` from a cached ONNX Runtime library if not already set.
264+
fn try_set_ort_dylib_path(storage_dir: &std::path::Path) {
265+
if std::env::var_os("ORT_DYLIB_PATH").is_some() {
266+
return;
267+
}
268+
let lib_name = if cfg!(target_os = "macos") {
269+
"libonnxruntime.dylib"
270+
} else if cfg!(target_os = "windows") {
271+
"onnxruntime.dll"
272+
} else {
273+
"libonnxruntime.so"
274+
};
275+
let ort_dir = storage_dir.join("onnxruntime").join("1.24.4");
276+
for candidate in [ort_dir.join(lib_name), ort_dir.join("lib").join(lib_name)] {
277+
if candidate.is_file() {
278+
std::env::set_var("ORT_DYLIB_PATH", &candidate);
279+
break;
280+
}
281+
}
282+
}
283+
257284
/// Build the `configure` params for a warmup run.
258285
///
259286
/// P1 config relocation: core config (search_index/semantic_search) is now
@@ -899,4 +926,33 @@ mod tests {
899926
assert_eq!(err.exit_code(), 2);
900927
assert!(err.to_string().contains("--only requires a value"));
901928
}
929+
930+
#[test]
931+
fn try_set_ort_dylib_path_finds_cached_library() {
932+
use std::sync::Mutex;
933+
static LOCK: Mutex<()> = Mutex::new(());
934+
let _guard = LOCK.lock().unwrap();
935+
std::env::remove_var("ORT_DYLIB_PATH");
936+
937+
let temp = tempfile::tempdir().unwrap();
938+
let lib_name = if cfg!(target_os = "macos") {
939+
"libonnxruntime.dylib"
940+
} else if cfg!(target_os = "windows") {
941+
"onnxruntime.dll"
942+
} else {
943+
"libonnxruntime.so"
944+
};
945+
let ort_dir = temp.path().join("onnxruntime").join("1.24.4");
946+
std::fs::create_dir_all(&ort_dir).unwrap();
947+
let lib_path = ort_dir.join(lib_name);
948+
std::fs::write(&lib_path, b"fake").unwrap();
949+
950+
try_set_ort_dylib_path(temp.path());
951+
952+
assert_eq!(
953+
std::env::var_os("ORT_DYLIB_PATH"),
954+
Some(lib_path.as_os_str().to_owned())
955+
);
956+
std::env::remove_var("ORT_DYLIB_PATH");
957+
}
902958
}

0 commit comments

Comments
 (0)