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
27 changes: 22 additions & 5 deletions rust/crates/pumas-core/src/discovery/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,29 @@ async fn ordinary_drop_retains_owner_until_real_finite_index_mutation_and_ipc_se
.is_err());
// This diagnostic handle still owns the mutable library after settlement.
drop(primary);
let successor = attach_or_start(
registry.clone(),
&root,
&CompatibilityRequirements::default(),
)
// Dropping the owner does not release the native store lock immediately:
// a child spawned by a parallel test can briefly inherit its descriptor.
// Only that busy refusal is retried, within a bound.
let successor = tokio::time::timeout(std::time::Duration::from_secs(5), async {
loop {
match attach_or_start(
registry.clone(),
&root,
&CompatibilityRequirements::default(),
)
.await
{
Err(crate::PumasError::InvalidParams { message })
if message.contains("already running for physical store") =>
{
tokio::time::sleep(std::time::Duration::from_millis(20)).await;
}
other => break other,
}
}
})
.await
.expect("physical store lease was not released after the owner dropped")
.unwrap();
assert!(matches!(&successor, LocalAccess::Owned { .. }));
successor.shutdown_owned().await.unwrap();
Expand Down
33 changes: 31 additions & 2 deletions rust/crates/pumas-core/src/model_library/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,20 @@ fn identify_gguf<R: Read + Seek>(file: &mut R, path: &Path) -> Result<ModelTypeI
// Then: metadata key-value pairs

let mut header = [0u8; 24];
file.read_exact(&mut header)
.map_err(|e| PumasError::io_with_path(e, path))?;
match file.read_exact(&mut header) {
Ok(()) => {}
// Too short for a GGUF header: malformed content, not a failed read.
// Validation reports the unusable file; import must not fail on it.
Err(error) if error.kind() == std::io::ErrorKind::UnexpectedEof => {
return Ok(ModelTypeInfo {
format: FileFormat::Gguf,
model_type: ModelType::Unknown,
family: None,
extra: HashMap::new(),
});
}
Err(error) => return Err(PumasError::io_with_path(error, path)),
}

let version = u32::from_le_bytes(header[4..8].try_into().unwrap());
let metadata_count = u64::from_le_bytes(header[16..24].try_into().unwrap());
Expand Down Expand Up @@ -1033,6 +1045,23 @@ pub fn extract_gguf_metadata(path: impl AsRef<Path>) -> Result<HashMap<String, S
mod tests {
use super::*;

#[test]
fn truncated_gguf_is_identified_as_unknown_not_an_io_failure() {
// A .gguf too short for its header (here, no GGUF magic at all) is
// malformed content; identification must not fail the import.
let temp = tempfile::tempdir().unwrap();
let path = temp.path().join("weights.gguf");
std::fs::write(&path, b"retained artifact").unwrap();
let info = identify_model_type(&path).unwrap();
assert_eq!(info.format, FileFormat::Gguf);
assert_eq!(info.model_type, ModelType::Unknown);
std::fs::write(&path, b"GGUF\x03\x00\x00\x00").unwrap();
assert_eq!(
identify_model_type(&path).unwrap().model_type,
ModelType::Unknown
);
}

#[test]
fn acquired_descriptor_identification_ignores_unselected_context() {
let temp = tempfile::tempdir().unwrap();
Expand Down
14 changes: 13 additions & 1 deletion rust/crates/pumas-core/src/runtime_profiles/process_owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,19 @@ mod tests {
assert!(custody.drain(Duration::from_secs(5)).unwrap());
assert!(!custody.is_active());
assert!(!custody.has_parked_child());
let after_confirmed_drain = PhysicalStoreLease::try_acquire(&store);
// A child forked by a parallel test briefly holds an inherited copy of
// the lock until its exec closes it, so release is awaited (bounded).
let release_deadline = std::time::Instant::now() + Duration::from_secs(5);
let after_confirmed_drain = loop {
let attempt = PhysicalStoreLease::try_acquire(&store);
if !matches!(&attempt, Err(StoreLeaseError::Busy(_)))
|| std::time::Instant::now() >= release_deadline
{
break attempt;
}
drop(attempt);
std::thread::sleep(Duration::from_millis(10));
};
assert!(
after_confirmed_drain.is_ok(),
"confirmed fixture drain did not release physical store: {after_confirmed_drain:?}"
Expand Down
Loading