Repository navigation
Wait for ONNX Runtime work before aft warmup and aft index exit #1495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
benchmarks/aft-search/slice-descriptors/fix-ort-cli-exit-quiesce.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "slice_class": "non_ranking", | ||
| "targeted_mechanism": "none", | ||
| "kind": "harness", | ||
| "fixtures": [ | ||
| "crates/aft/tests/integration/cli_ort_exit_test.rs", | ||
| "crates/aft/src/data_layer/meaning.rs", | ||
| "crates/aft/src/main.rs" | ||
| ], | ||
| "slices": [ | ||
| "fix-ort-cli-exit-quiesce" | ||
| ], | ||
| "note": "The one-shot `aft warmup` and `aft index` commands now wait for in-flight ONNX Runtime work before the process ends, as the standalone and daemon shutdowns already do. The only change in data_layer/meaning.rs is a test-hooks-only hold before embedding model creation, which release builds do not compile. No change to search ranking, routing, indexing or the meaning-search fill itself." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| //! A one-shot CLI command must not end while a background thread is inside | ||
| //! ONNX Runtime. Ending runs ONNX Runtime's C++ static destructors, and a | ||
| //! meaning-search fill still creating its embedding session then reads freed | ||
| //! memory and the process dies with SIGSEGV after its output is complete. | ||
|
|
||
| use std::io::{BufRead, BufReader}; | ||
| use std::path::Path; | ||
| use std::process::{Child, Command, Stdio}; | ||
| use std::sync::mpsc; | ||
| use std::time::{Duration, Instant}; | ||
|
|
||
| use crate::test_helpers::aft_binary; | ||
|
|
||
| fn wait_for_file(path: &Path, child: &mut Child, what: &str) { | ||
| let deadline = Instant::now() + Duration::from_secs(60); | ||
| while !path.exists() { | ||
| if let Some(status) = child.try_wait().unwrap() { | ||
| panic!("aft exited with {status} before {what}"); | ||
| } | ||
| assert!(Instant::now() < deadline, "timed out waiting for {what}"); | ||
| std::thread::sleep(Duration::from_millis(10)); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn warmup_exit_waits_for_a_fill_inside_model_creation() { | ||
| let temp = tempfile::tempdir().unwrap(); | ||
| let home = temp.path().join("home"); | ||
| let storage = temp.path().join("storage"); | ||
| let root = temp.path().join("root"); | ||
| let hold = temp.path().join("hold"); | ||
| for dir in [&home, &storage, &root.join("src"), &hold] { | ||
| std::fs::create_dir_all(dir).unwrap(); | ||
| } | ||
| std::fs::write( | ||
| root.join("src/lib.rs"), | ||
| "pub fn greet() -> &'static str {\n \"hello\"\n}\n", | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| // The fill holds inside the section until `release` exists, so warmup | ||
| // never sees the meaning-search fill complete and ends through its timeout. | ||
| let mut child = Command::new(aft_binary::aft_binary()) | ||
| .arg("warmup") | ||
| .arg("--root") | ||
| .arg(&root) | ||
| .args(["--only", "semantic", "--timeout", "2000"]) | ||
| .env_clear() | ||
| .env("HOME", &home) | ||
| .env("USERPROFILE", &home) | ||
| .env("APPDATA", &home) | ||
| .env("LOCALAPPDATA", &home) | ||
| .env("XDG_CONFIG_HOME", &home) | ||
| .env("XDG_CACHE_HOME", &home) | ||
| .env("XDG_DATA_HOME", &home) | ||
| .env("XDG_STATE_HOME", &home) | ||
| .env("AFT_STORAGE_DIR", &storage) | ||
| .env("AFT_TEST_DISABLE_FILE_WATCHER", "1") | ||
| .env("AFT_TEST_HOLD_FILL_MODEL_CREATION", &hold) | ||
| .stdin(Stdio::null()) | ||
| .stdout(Stdio::null()) | ||
| .stderr(Stdio::piped()) | ||
| .spawn() | ||
| .unwrap(); | ||
| let stderr = child.stderr.take().unwrap(); | ||
| let (lines_tx, lines_rx) = mpsc::channel(); | ||
| let reader = std::thread::spawn(move || { | ||
| for line in BufReader::new(stderr).lines().map_while(Result::ok) { | ||
| let _ = lines_tx.send(line); | ||
| } | ||
| }); | ||
|
|
||
| wait_for_file( | ||
| &hold.join("entered"), | ||
| &mut child, | ||
| "the fill entered model creation", | ||
| ); | ||
|
|
||
| // The timeout message is printed on the way out, before the exit path. | ||
| let deadline = Instant::now() + Duration::from_secs(60); | ||
| let mut seen = Vec::new(); | ||
| loop { | ||
| let remaining = deadline.saturating_duration_since(Instant::now()); | ||
| match lines_rx.recv_timeout(remaining) { | ||
| Ok(line) => { | ||
| let done = line.starts_with("aft warmup timed out"); | ||
| seen.push(line); | ||
| if done { | ||
| break; | ||
| } | ||
| } | ||
| Err(error) => { | ||
| let _ = child.kill(); | ||
| panic!("no warmup timeout message ({error}); stderr so far: {seen:#?}"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Without the quiesce the process ends within milliseconds of that | ||
| // message, while the fill is still inside the section. | ||
| std::thread::sleep(Duration::from_secs(1)); | ||
| let early = child.try_wait().unwrap(); | ||
| if early.is_some() { | ||
| reader.join().unwrap(); | ||
| seen.extend(lines_rx.try_iter()); | ||
| panic!( | ||
| "warmup exited ({early:?}) while a fill was inside ONNX Runtime model creation; \ | ||
| stderr: {seen:#?}" | ||
| ); | ||
| } | ||
| assert!( | ||
| !hold.join("left").exists(), | ||
| "the fill left the section before it was released" | ||
| ); | ||
|
|
||
| std::fs::write(hold.join("release"), b"").unwrap(); | ||
| let deadline = Instant::now() + Duration::from_secs(30); | ||
| let status = loop { | ||
| if let Some(status) = child.try_wait().unwrap() { | ||
| break status; | ||
| } | ||
| if Instant::now() >= deadline { | ||
| let _ = child.kill(); | ||
| panic!("warmup did not exit after the fill was released"); | ||
| } | ||
| std::thread::sleep(Duration::from_millis(10)); | ||
| }; | ||
| reader.join().unwrap(); | ||
| // The exit code of a timed-out warmup is unchanged. | ||
| assert_eq!(status.code(), Some(1), "{status}"); | ||
| assert!( | ||
| hold.join("left").exists(), | ||
| "the process ended before the fill finished its ONNX Runtime section" | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.