Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

fix(rust)!: adopt maintained Candle ZIP 9 backport (#765)

Krisztian Gajdar175d226be527
diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md
index 648fb8e7c..7f4c854e2 100644
--- a/COMPATIBILITY.md
+++ b/COMPATIBILITY.md
@@ -2,6 +2,29 @@
> Last Updated: 2026-03-17
+## Candle checkpoint filenames: ZIP 9 migration
+
+The Rust/Candle worker's maintained Candle 0.10.2 backport replaces yanked ZIP 7
+with ZIP 9. This adoption is a **breaking minor change**, because ZIP 9 changes
+how two classes of non-ASCII NPZ/PTH archive filenames are decoded:
+
+| Filename bytes and ZIP flag | ZIP 7 name | ZIP 9 name |
+| --- | --- | --- |
+| Valid UTF-8 bytes `C3 A9`, UTF-8 flag (bit 11) clear | `├⌐` (CP437) | `é` (UTF-8) |
+| Invalid UTF-8 byte `82`, UTF-8 flag set | `�` (replacement character) | `é` (CP437 fallback) |
+
+ZIP 9 tries UTF-8 first regardless of the flag, then falls back to CP437.
+Ordinary ASCII, correctly flagged UTF-8, and CP437 filenames whose bytes are
+not valid UTF-8 retain their names. Checkpoint loading does not extract archive
+entries to filesystem paths.
+
+To retain a previous tensor/member name in an affected archive, regenerate it
+with that intended name encoded as valid UTF-8 and the ZIP UTF-8 flag set. For
+example, encode `é` itself as UTF-8 to retain that ZIP 7 name, rather than
+reusing unflagged `C3 A9` bytes. Regenerate invalid flagged filenames using the
+intended Unicode name. This migration applies to ZIP-backed NPZ/PTH checkpoints;
+the Safetensors format is unaffected.
+
This document defines SIE's compatibility commitments: what constitutes a breaking change, how deprecations are communicated, and what must be true before declaring 1.0.
---
diff --git a/packages/sie_server_rust/Cargo.lock b/packages/sie_server_rust/Cargo.lock
index f2a3da187..7f45c0119 100644
--- a/packages/sie_server_rust/Cargo.lock
+++ b/packages/sie_server_rust/Cargo.lock
@@ -309,8 +309,7 @@ checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04"
[[package]]
name = "candle-core"
version = "0.10.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6bd9895436c1ba5dc1037a19935d084b838db066ff4e15ef7dded020b7c12a4a"
+source = "git+https://github.com/superlinked/candle?rev=9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0#9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0"
dependencies = [
"accelerate-src",
"byteorder",
@@ -386,8 +385,7 @@ dependencies = [
[[package]]
name = "candle-kernels"
version = "0.10.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "742e2ac226b777134436e9e692f44e77c278b8a7abb1554dc10e44dc911b349f"
+source = "git+https://github.com/superlinked/candle?rev=9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0#9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0"
dependencies = [
"cudaforge",
]
@@ -406,8 +404,7 @@ dependencies = [
[[package]]
name = "candle-metal-kernels"
version = "0.10.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4b6b5a4cae6b4e1ab0efcee4dc05272d11b374a3d1ba121b3a961e36be54ab60"
+source = "git+https://github.com/superlinked/candle?rev=9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0#9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0"
dependencies = [
"half",
"objc2",
@@ -479,8 +476,7 @@ dependencies = [
[[package]]
name = "candle-ug"
version = "0.10.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ca0fc3167cbc99c8ec1be618cb620aa21dca95038f118c3579a79370e3dc5f77"
+source = "git+https://github.com/superlinked/candle?rev=9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0#9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0"
dependencies = [
"ug",
"ug-cuda",
@@ -1038,7 +1034,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -2232,6 +2228,18 @@ dependencies = [
"tempfile",
]
+[[package]]
+name = "nix"
+version = "0.31.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d"
+dependencies = [
+ "bitflags 2.13.0",
+ "cfg-if",
+ "cfg_aliases",
+ "libc",
+]
+
[[package]]
name = "nohash-hasher"
version = "0.2.0"
@@ -2807,7 +2815,7 @@ dependencies = [
"once_cell",
"socket2",
"tracing",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -3129,7 +3137,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -3188,7 +3196,7 @@ dependencies = [
"security-framework",
"security-framework-sys",
"webpki-root-certs",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -3457,6 +3465,7 @@ dependencies = [
"tracing-opentelemetry",
"tracing-subscriber",
"uuid",
+ "zip",
]
[[package]]
@@ -3647,7 +3656,7 @@ dependencies = [
"getrandom 0.4.3",
"once_cell",
"rustix",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -4427,7 +4436,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -4700,13 +4709,14 @@ dependencies = [
[[package]]
name = "zip"
-version = "7.2.0"
+version = "9.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c42e33efc22a0650c311c2ef19115ce232583abbe80850bc8b66509ebef02de0"
+checksum = "a954114b47a54df49f83d2722814e86b23d4bb1b54a1b90fb7d92b41619ddc22"
dependencies = [
"crc32fast",
"indexmap",
"memchr",
+ "nix",
"typed-path",
]
diff --git a/packages/sie_server_rust/Cargo.toml b/packages/sie_server_rust/Cargo.toml
index 6c28b4f5d..71d90ef3b 100644
--- a/packages/sie_server_rust/Cargo.toml
+++ b/packages/sie_server_rust/Cargo.toml
@@ -14,6 +14,11 @@ exclude = [
"vendor/candle-splade-pool",
]
+[patch.crates-io]
+# Keep core and Metal kernel types in one immutable maintained source cohort.
+candle-core = { git = "https://github.com/superlinked/candle", rev = "9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0" }
+candle-metal-kernels = { git = "https://github.com/superlinked/candle", rev = "9d2d6c6c1831c3d6444faca8e687dce06bd6bbe0" }
+
[lib]
name = "sie_server_rust"
path = "src/lib.rs"
@@ -72,6 +77,7 @@ rmp-serde = "1"
uuid = { version = "1", features = ["v4"] }
[dev-dependencies]
+zip = { version = "9.0.4", default-features = false }
opentelemetry_sdk = { version = "0.32", features = ["testing"] }
tempfile = "3"
diff --git a/packages/sie_server_rust/tests/candle_zip.rs b/packages/sie_server_rust/tests/candle_zip.rs
new file mode 100644
index 000000000..13c295ec6
--- /dev/null
+++ b/packages/sie_server_rust/tests/candle_zip.rs
@@ -0,0 +1,232 @@
+//! Exercise the maintained Candle ZIP compatibility patch through the worker's
+//! locked dependency graph. Based on huggingface/candle#4041.
+
+use candle::npy::NpzTensors;
+use candle::{Device, Error, Result, Tensor};
+use std::borrow::Cow;
+use std::io::{Read, Write};
+use std::path::Path;
+
+fn write_named_tensor(path: &Path, name: &str) -> Result<()> {
+ let tensor = Tensor::new(&[2u32, 4, 6], &Device::Cpu)?;
+ Tensor::write_npz(&[(name, &tensor)], path)?;
+ Ok(())
+}
+
+fn assert_named_tensor(path: &Path, name: &str) -> Result<()> {
+ let loaded = Tensor::read_npz(path)?;
+ assert_eq!(loaded.len(), 1);
+ assert_eq!(loaded[0].0, name);
+ assert_eq!(loaded[0].1.to_vec1::<u32>()?, vec![2, 4, 6]);
+ let selected = Tensor::read_npz_by_name(path, &[name])?;
+ assert_eq!(selected[0].to_vec1::<u32>()?, vec![2, 4, 6]);
+ let lazy = NpzTensors::new(path)?;
+ assert_eq!(
+ lazy.names().iter().map(|n| n.as_str()).collect::<Vec<_>>(),
+ vec![name]
+ );
+ let tensor = lazy.get(name)?.expect("the named tensor must be indexed");
+ assert_eq!(tensor.to_vec1::<u32>()?, vec![2, 4, 6]);
+ Ok(())
+}
+
+fn use_cp437_name(path: &Path, ascii_name: &[u8]) -> Result<()> {
+ let mut bytes = std::fs::read(path)?;
+ let positions: Vec<_> = bytes
+ .windows(ascii_name.len())
+ .enumerate()
+ .filter_map(|(i, x)| (x == ascii_name).then_some(i))
+ .collect();
+ assert_eq!(positions.len(), 2);
+ for index in positions {
+ bytes[index] = 0x82;
+ }
+ std::fs::write(path, bytes)?;
+ Ok(())
+}
+
+fn set_utf8_flag(path: &Path, enabled: bool) -> Result<()> {
+ let mut bytes = std::fs::read(path)?;
+ let mut headers = 0;
+ for index in 0..bytes.len().saturating_sub(10) {
+ let offset = match &bytes[index..index + 4] {
+ b"PK\x03\x04" => 6,
+ b"PK\x01\x02" => 8,
+ _ => continue,
+ };
+ let mut flags = u16::from_le_bytes([bytes[index + offset], bytes[index + offset + 1]]);
+ if enabled {
+ flags |= 1 << 11;
+ } else {
+ flags &= !(1 << 11);
+ }
+ bytes[index + offset..index + offset + 2].copy_from_slice(&flags.to_le_bytes());
+ headers += 1;
+ }
+ assert_eq!(headers, 2);
+ std::fs::write(path, bytes)?;
+ Ok(())
+}
+
+#[test]
+fn npz_borrowed_utf8_names() -> Result<()> {
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ write_named_tensor(&path, "données")?;
+ let mut archive = zip::ZipArchive::new(std::fs::File::open(&path)?)?;
+ let entry = archive.by_index(0)?;
+ assert!(matches!(entry.name()?, Cow::Borrowed("données.npy")));
+ assert_named_tensor(&path, "données")
+}
+
+#[test]
+fn npz_owned_cp437_names() -> Result<()> {
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ write_named_tensor(&path, "a")?;
+ use_cp437_name(&path, b"a.npy")?;
+ let mut archive = zip::ZipArchive::new(std::fs::File::open(&path)?)?;
+ let entry = archive.by_index(0)?;
+ assert!(matches!(entry.name()?, Cow::Owned(name) if name == "é.npy"));
+ assert_named_tensor(&path, "é")
+}
+
+#[test]
+fn npz_clear_utf8_flag_uses_zip9_utf8_first_decoding() -> Result<()> {
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ write_named_tensor(&path, "é")?;
+ set_utf8_flag(&path, false)?;
+ // ZIP 7 returned "é" for bytes C3 A9 with bit 11 clear; ZIP 9 uses UTF-8.
+ assert_named_tensor(&path, "é")
+}
+
+#[test]
+fn npz_set_utf8_flag_uses_zip9_cp437_fallback() -> Result<()> {
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ write_named_tensor(&path, "a")?;
+ use_cp437_name(&path, b"a.npy")?;
+ set_utf8_flag(&path, true)?;
+ // ZIP 7 returned U+FFFD for invalid UTF-8 byte 82; ZIP 9 falls back to CP437.
+ assert_named_tensor(&path, "é")
+}
+
+#[test]
+fn npz_unicode_path_overrides_raw_name() -> Result<()> {
+ let source = tempfile::NamedTempFile::new()?.into_temp_path();
+ write_named_tensor(&source, "a")?;
+ let mut archive = zip::ZipArchive::new(std::fs::File::open(&source)?)?;
+ let mut data = Vec::new();
+ archive.by_index(0)?.read_to_end(&mut data)?;
+
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ let mut archive = zip::ZipWriter::new(std::fs::File::create(&path)?);
+ let mut options = zip::write::FullFileOptions::default();
+ // Info-ZIP Unicode Path: version 1, CRC32 of b"a.npy", UTF-8 name.
+ let mut unicode_path = vec![1];
+ unicode_path.extend_from_slice(&0x663227a9u32.to_le_bytes());
+ unicode_path.extend_from_slice("é.npy".as_bytes());
+ options.add_extra_field(0x7075, unicode_path, false)?;
+ archive.start_file("a.npy", options)?;
+ archive.write_all(&data)?;
+ archive.finish()?;
+
+ assert_named_tensor(&path, "é")?;
+ assert!(Tensor::read_npz_by_name(&path, &["a"]).is_err());
+ Ok(())
+}
+
+#[test]
+fn pth_utf8_and_cp437_names() -> Result<()> {
+ for cp437 in [false, true] {
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ let mut archive = zip::ZipWriter::new(std::fs::File::create(&path)?);
+ archive.start_file("a/data.pkl", zip::write::SimpleFileOptions::default())?;
+ // torch.save({"weight": torch.tensor([2., 4., 6.])}), protocol 2.
+ archive.write_all(
+ &[
+ b"\x80\x02}q\x00X\x06\x00\x00\x00weightq\x01ctorch._utils\n".as_slice(),
+ b"_rebuild_tensor_v2\nq\x02((X\x07\x00\x00\x00storageq\x03",
+ b"ctorch\nFloatStorage\nq\x04X\x01\x00\x00\x000q\x05",
+ b"X\x03\x00\x00\x00cpuq\x06K\x03tq\x07QK\x00K\x03\x85q\x08",
+ b"K\x01\x85q\x09\x89ccollections\nOrderedDict\nq\x0a)Rq\x0b",
+ b"tq\x0cRq\x0ds.",
+ ]
+ .concat(),
+ )?;
+ archive.start_file("a/data/0", zip::write::SimpleFileOptions::default())?;
+ for value in [2f32, 4., 6.] {
+ archive.write_all(&value.to_le_bytes())?;
+ }
+ archive.finish()?;
+ if cp437 {
+ use_cp437_name(&path, b"a/data.pkl")?;
+ use_cp437_name(&path, b"a/data/0")?;
+ }
+ let tensors = candle::pickle::read_all(&path)?;
+ assert_eq!(tensors.len(), 1);
+ assert_eq!(tensors[0].0, "weight");
+ assert_eq!(tensors[0].1.to_vec1::<f32>()?, vec![2., 4., 6.]);
+ }
+ Ok(())
+}
+
+#[test]
+fn invalid_npz_returns_zip_errors() -> Result<()> {
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ std::fs::write(&path, b"not a zip archive")?;
+ assert!(matches!(Tensor::read_npz(&path), Err(Error::Zip(_))));
+ assert!(matches!(NpzTensors::new(&path), Err(Error::Zip(_))));
+ Ok(())
+}
+
+#[test]
+fn invalid_pth_returns_zip_error() -> Result<()> {
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ std::fs::write(&path, b"not a zip archive")?;
+ assert!(matches!(
+ candle::pickle::read_pth_tensor_info(&path, false, None),
+ Err(Error::Zip(_))
+ ));
+ Ok(())
+}
+
+#[test]
+fn selective_npz_preserves_unsupported_compression_error() -> Result<()> {
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ write_named_tensor(&path, "a")?;
+ let mut bytes = std::fs::read(&path)?;
+ let mut headers = 0;
+ for index in 0..bytes.len().saturating_sub(12) {
+ let offset = match &bytes[index..index + 4] {
+ b"PK\x03\x04" => 8,
+ b"PK\x01\x02" => 10,
+ _ => continue,
+ };
+ bytes[index + offset..index + offset + 2].copy_from_slice(&255u16.to_le_bytes());
+ headers += 1;
+ }
+ assert_eq!(headers, 2);
+ std::fs::write(&path, bytes)?;
+ // The directory is readable; the error arises when opening its entry.
+ let mut archive = zip::ZipArchive::new(std::fs::File::open(&path)?)?;
+ assert!(matches!(
+ archive.by_index(0),
+ Err(zip::result::ZipError::CompressionMethodNotSupported(255))
+ ));
+ assert!(matches!(
+ Tensor::read_npz_by_name(&path, &["a"]),
+ Err(Error::Zip(
+ zip::result::ZipError::CompressionMethodNotSupported(255)
+ ))
+ ));
+ Ok(())
+}
+
+#[test]
+fn selective_npz_reports_missing_array() -> Result<()> {
+ let path = tempfile::NamedTempFile::new()?.into_temp_path();
+ write_named_tensor(&path, "a")?;
+ assert!(matches!(
+ Tensor::read_npz_by_name(&path, &["missing"]),
+ Err(Error::Npy(_))
+ ));
+ Ok(())
+}
diff --git a/tools/ci/check_release_contract.py b/tools/ci/check_release_contract.py
index ceab4bd1c..433a2a229 100755
--- a/tools/ci/check_release_contract.py
+++ b/tools/ci/check_release_contract.py
@@ -206,6 +206,7 @@ CANDLE_PATHS = (
"packages/sie_server_rust/src/observability/tracing.rs",
"packages/sie_server_rust/src/observability/transport.rs",
"packages/sie_server_rust/src/text_prep.rs",
+ "packages/sie_server_rust/tests/candle_zip.rs",
"packages/sie_server_rust/vendor/candle-cublaslt/Cargo.toml",
"packages/sie_server_rust/vendor/candle-cublaslt/LICENSE-APACHE",
"packages/sie_server_rust/vendor/candle-cublaslt/LICENSE-MIT",
@@ -833,7 +834,7 @@ def candle_source_errors() -> list[str]:
expected = set(CANDLE_PATHS)
if actual != expected:
errors.append(
- "Candle source closure differs from the reviewed 66-path allowlist: "
+ f"Candle source closure differs from the reviewed {len(expected)}-path allowlist: "
f"missing={sorted(expected - actual)}, unexpected={sorted(actual - expected)}"
)
return errors