From 140b63b8c65f6f9e801eca7f5334374b8ad22ec3 Mon Sep 17 00:00:00 2001 From: MrScripty Date: Fri, 6 Nov 2026 04:00:42 -0700 Subject: [PATCH 1/2] fix(deps): move zip to 9.x and pyo3 to 0.29 for security advisories zip below 9.0.5 is affected by parser-differential ("zip cloaking"), symlink-target exhaustion and AES HMAC bypass advisories, and the managed-runtime installer extracts downloaded zip archives with it. pyo3 below 0.29 has an out-of-bounds read in PyList/PyTuple nth and a missing Sync bound on closure-backed functions. zip 9 makes ZipFile generic over its reader and entry names fallible, so error messages now use the raw name lossily. pyo3 0.29 renames with_gil to attach, allow_threads to detach and Bound::downcast to cast. New tests extract a real zip and reject a parent-escaping entry. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 587 +++++++++++------- Cargo.toml | 4 +- crates/inference/src/backend/pytorch.rs | 32 +- .../src/backend/pytorch_cuda_inventory.rs | 8 +- .../src/backend/pytorch_image_generation.rs | 4 +- crates/inference/src/backend/pytorch_tests.rs | 152 ++--- .../src/backend/pytorch_text_dependencies.rs | 6 +- .../inference/src/backend/pytorch_worker.rs | 2 +- .../pytorch_worker_image_contract_tests.rs | 8 +- .../pytorch_worker_image_python_tests.rs | 22 +- .../inference/src/managed_runtime/archive.rs | 61 +- .../tests/diffusers_guidance_native.rs | 6 +- .../tests/pytorch_cuda_inventory_native.rs | 2 +- 13 files changed, 547 insertions(+), 347 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6137db1a6..0125e062d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,8 +15,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", - "cipher", - "cpufeatures", + "cipher 0.4.4", + "cpufeatures 0.2.17", +] + +[[package]] +name = "aes" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fc36d7440d015b45468ba08a21e80e056ebbd014c611c6298bb7503e04bd1" +dependencies = [ + "cipher 0.5.2", + "cpubits", + "cpufeatures 0.3.1", + "zeroize", ] [[package]] @@ -124,7 +136,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -135,7 +147,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -144,15 +156,6 @@ version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" -[[package]] -name = "arbitrary" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" -dependencies = [ - "derive_arbitrary", -] - [[package]] name = "arc-swap" version = "1.8.0" @@ -298,7 +301,7 @@ dependencies = [ "arrow-select", "flatbuffers", "lz4_flex", - "zstd", + "zstd 0.13.3", ] [[package]] @@ -777,11 +780,11 @@ dependencies = [ "bytes", "form_urlencoded", "hex", - "hmac", + "hmac 0.12.1", "http 0.2.12", "http 1.4.0", "percent-encoding", - "sha2", + "sha2 0.10.9", "time", "tracing", ] @@ -1154,7 +1157,7 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "digest", + "digest 0.10.7", ] [[package]] @@ -1168,7 +1171,7 @@ dependencies = [ "cc", "cfg-if", "constant_time_eq 0.4.2", - "cpufeatures", + "cpufeatures 0.2.17", ] [[package]] @@ -1180,6 +1183,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", + "zeroize", +] + [[package]] name = "block-padding" version = "0.3.3" @@ -1444,21 +1457,11 @@ dependencies = [ [[package]] name = "bzip2" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47" -dependencies = [ - "bzip2-sys", -] - -[[package]] -name = "bzip2-sys" -version = "0.1.13+1.0.8" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14" +checksum = "f3a53fac24f34a81bc9954b5d6cfce0c21e18ec6959f44f56e8e90e4bb7c346c" dependencies = [ - "cc", - "pkg-config", + "libbz2-rs-sys", ] [[package]] @@ -1564,7 +1567,7 @@ dependencies = [ "maybe-owned", "rustix 1.1.3", "rustix-linux-procfs", - "windows-sys 0.61.2", + "windows-sys 0.60.2", "winx", ] @@ -1655,7 +1658,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" dependencies = [ - "cipher", + "cipher 0.4.4", ] [[package]] @@ -1700,7 +1703,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" dependencies = [ "smallvec", - "target-lexicon", + "target-lexicon 0.12.16", ] [[package]] @@ -1745,8 +1748,18 @@ version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ - "crypto-common", - "inout", + "crypto-common 0.1.7", + "inout 0.1.4", +] + +[[package]] +name = "cipher" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" +dependencies = [ + "crypto-common 0.2.2", + "inout 0.2.5", ] [[package]] @@ -1798,6 +1811,12 @@ dependencies = [ "cc", ] +[[package]] +name = "cmov" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c9ea0ac24bc397ab3c98583a3c9ba74fa56b09a4449bbe172b9b1ddb016027a" + [[package]] name = "colorchoice" version = "1.0.4" @@ -1885,6 +1904,12 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const-oid" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c" + [[package]] name = "const-random" version = "0.1.18" @@ -1907,15 +1932,18 @@ dependencies = [ [[package]] name = "constant_time_eq" -version = "0.3.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" +checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" [[package]] name = "constant_time_eq" -version = "0.4.2" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b" +checksum = "9eb6feb175df65d0a3ccd3e73484e940d0ac664e8034f0519fd49a93db3071d9" +dependencies = [ + "rustversion", +] [[package]] name = "convert_case" @@ -1998,6 +2026,12 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "417bef24afe1460300965a25ff4a24b8b45ad011948302ec221e8a0a81eb2c79" +[[package]] +name = "cpubits" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15b85f9c39137c3a891689859392b1bd49812121d0d61c9caf00d46ed5ce06ae" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -2007,6 +2041,15 @@ dependencies = [ "libc", ] +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + [[package]] name = "crc" version = "3.4.0" @@ -2099,6 +2142,15 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + [[package]] name = "cssparser" version = "0.29.6" @@ -2168,6 +2220,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "ctutils" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261af4dc7a06ea8a527a8717d8cbba3417530d6ea14e1edb3de6b67806be474f" +dependencies = [ + "cmov", +] + [[package]] name = "daachorse" version = "1.0.1" @@ -2609,7 +2670,7 @@ dependencies = [ "md-5", "rand 0.9.2", "regex", - "sha2", + "sha2 0.10.9", "unicode-segmentation", "uuid", ] @@ -2977,32 +3038,20 @@ version = "0.7.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" dependencies = [ - "const-oid", + "const-oid 0.9.6", "pem-rfc7468", "zeroize", ] [[package]] name = "deranged" -version = "0.5.5" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" +checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e" dependencies = [ - "powerfmt", "serde_core", ] -[[package]] -name = "derive_arbitrary" -version = "1.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e567bd82dcff979e4b03460c307b3cdc9e96fde3d73bed1496d2bc75d9dd62a" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.114", -] - [[package]] name = "derive_builder" version = "0.20.2" @@ -3053,12 +3102,25 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer", - "const-oid", - "crypto-common", + "block-buffer 0.10.4", + "const-oid 0.9.6", + "crypto-common 0.1.7", "subtle", ] +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.1", + "const-oid 0.10.2", + "crypto-common 0.2.2", + "ctutils", + "zeroize", +] + [[package]] name = "dirs" version = "5.0.1" @@ -3098,7 +3160,7 @@ dependencies = [ "libc", "option-ext", "redox_users 0.5.2", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -3375,7 +3437,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]] @@ -3546,6 +3608,7 @@ checksum = "b375d6465b98090a5f25b1c7703f3859783755aa9a80433b36e0379a3ec2f369" dependencies = [ "crc32fast", "miniz_oxide", + "zlib-rs", ] [[package]] @@ -4110,7 +4173,7 @@ dependencies = [ "libc", "log", "rustversion", - "windows-link 0.2.1", + "windows-link 0.1.3", "windows-result 0.4.1", ] @@ -4157,11 +4220,24 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "r-efi", + "r-efi 5.3.0", "wasip2", "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi 6.0.0", + "wasm-bindgen", +] + [[package]] name = "gio" version = "0.18.4" @@ -4514,7 +4590,7 @@ version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" dependencies = [ - "hmac", + "hmac 0.12.1", ] [[package]] @@ -4523,7 +4599,16 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "digest", + "digest 0.10.7", +] + +[[package]] +name = "hmac" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f" +dependencies = [ + "digest 0.11.3", ] [[package]] @@ -4626,6 +4711,15 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "135b12329e5e3ce057a9f972339ea52bc954fe1e9358ef27f95e89716fbc5424" +[[package]] +name = "hybrid-array" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3944cf8cf766b40e2a1a333ee5e9b563f854d5fa49d6a8ca2764e97c6eddb214" +dependencies = [ + "typenum", +] + [[package]] name = "hyper" version = "0.14.32" @@ -4740,7 +4834,7 @@ dependencies = [ "libc", "percent-encoding", "pin-project-lite", - "socket2 0.5.10", + "socket2 0.6.2", "system-configuration", "tokio", "tower-service", @@ -5006,8 +5100,8 @@ dependencies = [ "tower-http 0.5.2", "uuid", "which", - "zip 2.4.2", - "zstd", + "zip 9.4.1", + "zstd 0.13.3", ] [[package]] @@ -5040,6 +5134,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "inout" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b5cf4372d022092674a83b8febf5865f7a573cc0c5baec5e49c879b6a20978f" +dependencies = [ + "hybrid-array", +] + [[package]] name = "instant" version = "0.1.13" @@ -5188,7 +5291,7 @@ dependencies = [ "portable-atomic", "portable-atomic-util", "serde_core", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -5580,7 +5683,7 @@ dependencies = [ "tokio", "tracing", "xxhash-rust", - "zstd", + "zstd 0.13.3", ] [[package]] @@ -5998,11 +6101,17 @@ dependencies = [ "once_cell", ] +[[package]] +name = "libbz2-rs-sys" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32f454fd6831a29c0e827ed075bca2a15be201bd57f4168f0fd1041124eab17e" + [[package]] name = "libc" -version = "0.2.180" +version = "0.2.191" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" [[package]] name = "libloading" @@ -6142,24 +6251,12 @@ dependencies = [ ] [[package]] -name = "lzma-rs" -version = "0.3.0" +name = "lzma-rust2" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "297e814c836ae64db86b36cf2a557ba54368d03f6afcd7d947c266692f71115e" +checksum = "ef1d73c59a56771343712b22ea5615092c612c16ba291c0979e3105dfeec4890" dependencies = [ - "byteorder", - "crc", -] - -[[package]] -name = "lzma-sys" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27" -dependencies = [ - "cc", - "libc", - "pkg-config", + "sha2 0.11.1", ] [[package]] @@ -6256,7 +6353,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf" dependencies = [ "cfg-if", - "digest", + "digest 0.10.7", ] [[package]] @@ -6540,6 +6637,18 @@ dependencies = [ "libc", ] +[[package]] +name = "nix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags 2.10.0", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "no-std-compat" version = "0.4.1" @@ -6568,7 +6677,7 @@ dependencies = [ "tokio", "tokio-test", "uuid", - "zstd", + "zstd 0.13.3", ] [[package]] @@ -6645,7 +6754,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -6701,9 +6810,9 @@ dependencies = [ [[package]] name = "num-conv" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" [[package]] name = "num-integer" @@ -7122,7 +7231,7 @@ dependencies = [ "reqwest", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "tokio", "uuid", ] @@ -7312,8 +7421,8 @@ dependencies = [ "uuid", "which", "workflow-nodes", - "zip 2.4.2", - "zstd", + "zip 9.4.1", + "zstd 0.13.3", ] [[package]] @@ -7659,8 +7768,18 @@ version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2" dependencies = [ - "digest", - "hmac", + "digest 0.10.7", + "hmac 0.12.1", +] + +[[package]] +name = "pbkdf2" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112d82ceb8c5bf524d9af484d4e4970c9fd5a0cc15ba14ad93dccd28873b0629" +dependencies = [ + "digest 0.11.3", + "hmac 0.13.0", ] [[package]] @@ -7959,12 +8078,12 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e847e2c91a18bfa887dd028ec33f2fe6f25db77db3619024764914affe8b69a6" dependencies = [ - "aes", + "aes 0.8.4", "cbc", "der", - "pbkdf2", + "pbkdf2 0.12.2", "scrypt", - "sha2", + "sha2 0.10.9", "spki", ] @@ -8048,6 +8167,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "ppmd-rust" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd4acc8d264ea385db64ccfdcdfd5909ee9eda0975666723d59f3bfec80b3611" + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -8158,7 +8283,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be769465445e8c1474e9c5dac2018218498557af32d9ed057325ec9a41ae81bf" dependencies = [ "heck 0.5.0", - "itertools 0.11.0", + "itertools 0.14.0", "log", "multimap", "once_cell", @@ -8178,7 +8303,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" dependencies = [ "anyhow", - "itertools 0.11.0", + "itertools 0.14.0", "proc-macro2", "quote", "syn 2.0.114", @@ -8261,7 +8386,7 @@ dependencies = [ "semver 1.0.27", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "sysinfo", "tar", "tempfile", @@ -8275,42 +8400,37 @@ dependencies = [ "uuid", "walkdir", "windows-sys 0.59.0", - "zstd", + "zstd 0.13.3", ] [[package]] name = "pyo3" -version = "0.23.5" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872" +checksum = "700d18fa267b73b9b521fd7e13580e2f446916f176cacee1ab63fcc8191f1655" dependencies = [ - "cfg-if", - "indoc", "libc", - "memoffset", "once_cell", "portable-atomic", "pyo3-build-config", "pyo3-ffi", "pyo3-macros", - "unindent", ] [[package]] name = "pyo3-build-config" -version = "0.23.5" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb" +checksum = "7b3fc0c4d08f6bb10e71fe39dfb9e2f59c6eb6854e22ec8092f50c69a4499adb" dependencies = [ - "once_cell", - "target-lexicon", + "target-lexicon 0.13.5", ] [[package]] name = "pyo3-ffi" -version = "0.23.5" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d" +checksum = "dfc0b8e19df29aad7086cf977bb0c2a2f143e30567eb113e9cf72b62ca698330" dependencies = [ "libc", "pyo3-build-config", @@ -8318,9 +8438,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.23.5" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da" +checksum = "6100e8a4b5eba53afaa5ed078364851a0b2499c553a44c31026b929049b49dc6" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -8330,13 +8450,12 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.23.5" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028" +checksum = "6143877a16e82b5a727b7127ff4cd86858a24a28d745d72f43e6f227c7b1bdb3" dependencies = [ "heck 0.5.0", "proc-macro2", - "pyo3-build-config", "quote", "syn 2.0.114", ] @@ -8389,7 +8508,7 @@ dependencies = [ "quinn-udp", "rustc-hash", "rustls 0.23.36", - "socket2 0.5.10", + "socket2 0.6.2", "thiserror 2.0.18", "tokio", "tracing", @@ -8426,7 +8545,7 @@ dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2 0.5.10", + "socket2 0.6.2", "tracing", "windows-sys 0.60.2", ] @@ -8446,6 +8565,12 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + [[package]] name = "radium" version = "0.7.0" @@ -8797,7 +8922,7 @@ dependencies = [ "form_urlencoded", "getrandom 0.2.17", "hex", - "hmac", + "hmac 0.12.1", "home", "http 1.4.0", "jsonwebtoken", @@ -8811,8 +8936,8 @@ dependencies = [ "rust-ini", "serde", "serde_json", - "sha1", - "sha2", + "sha1 0.10.6", + "sha2 0.10.9", "tokio", ] @@ -8966,15 +9091,15 @@ version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8573f03f5883dcaebdfcf4725caa1ecb9c15b2ef50c43a07b816e06799bb12d" dependencies = [ - "const-oid", - "digest", + "const-oid 0.9.6", + "digest 0.10.7", "num-bigint-dig", "num-integer", "num-traits", "pkcs1", "pkcs8", "rand_core 0.6.4", - "sha2", + "sha2 0.10.9", "signature", "spki", "subtle", @@ -9062,7 +9187,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.11.0", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -9224,7 +9349,7 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97a22f5af31f73a954c10289c93e8a50cc23d971e80ee446f1f6f7137a088213" dependencies = [ - "cipher", + "cipher 0.4.4", ] [[package]] @@ -9347,9 +9472,9 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0516a385866c09368f0b5bcd1caff3366aace790fcd46e2bb032697bb172fd1f" dependencies = [ - "pbkdf2", + "pbkdf2 0.12.2", "salsa20", - "sha2", + "sha2 0.10.9", ] [[package]] @@ -9644,8 +9769,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha1" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "digest 0.11.3", ] [[package]] @@ -9655,8 +9791,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", - "digest", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "digest 0.11.3", ] [[package]] @@ -9699,7 +9846,7 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ - "digest", + "digest 0.10.7", "rand_core 0.6.4", ] @@ -9982,7 +10129,7 @@ dependencies = [ "rustls 0.23.36", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "smallvec", "thiserror 2.0.18", "tokio", @@ -10021,7 +10168,7 @@ dependencies = [ "quote", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "sqlx-core", "sqlx-mysql", "sqlx-postgres", @@ -10043,7 +10190,7 @@ dependencies = [ "byteorder", "bytes", "crc", - "digest", + "digest 0.10.7", "dotenvy", "either", "futures-channel", @@ -10053,7 +10200,7 @@ dependencies = [ "generic-array", "hex", "hkdf", - "hmac", + "hmac 0.12.1", "itoa", "log", "md-5", @@ -10063,8 +10210,8 @@ dependencies = [ "rand 0.8.5", "rsa", "serde", - "sha1", - "sha2", + "sha1 0.10.6", + "sha2 0.10.9", "smallvec", "sqlx-core", "stringprep", @@ -10092,7 +10239,7 @@ dependencies = [ "futures-util", "hex", "hkdf", - "hmac", + "hmac 0.12.1", "home", "itoa", "log", @@ -10102,7 +10249,7 @@ dependencies = [ "rand 0.8.5", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "smallvec", "sqlx-core", "stringprep", @@ -10487,7 +10634,7 @@ dependencies = [ "tantivy-bitpacker", "tantivy-common", "tantivy-fst", - "zstd", + "zstd 0.13.3", ] [[package]] @@ -10584,6 +10731,12 @@ version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" +[[package]] +name = "target-lexicon" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" + [[package]] name = "tauri" version = "2.9.5" @@ -10674,7 +10827,7 @@ dependencies = [ "semver 1.0.27", "serde", "serde_json", - "sha2", + "sha2 0.10.9", "syn 2.0.114", "tauri-utils", "thiserror 2.0.18", @@ -10866,7 +11019,7 @@ dependencies = [ "getrandom 0.3.4", "once_cell", "rustix 1.1.3", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -10955,12 +11108,11 @@ dependencies = [ [[package]] name = "time" -version = "0.3.46" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9da98b7d9b7dad93488a84b8248efc35352b0b2657397d4167e7ad67e5d535e5" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" dependencies = [ "deranged", - "itoa", "js-sys", "libc", "num-conv", @@ -10973,15 +11125,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" [[package]] name = "time-macros" -version = "0.2.26" +version = "0.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc610bac2dcee56805c99642447d4c5dbde4d01f752ffea0199aee1f601dc4" +checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85" dependencies = [ "num-conv", "time-core", @@ -11475,6 +11627,12 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e43ffa54726cdc9ea78392023ffe9fe9cf9ac779e1c6fcb0d23f9862e3879d20" +[[package]] +name = "typed-path" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e" + [[package]] name = "typeid" version = "1.0.3" @@ -11720,12 +11878,6 @@ dependencies = [ "weedle2", ] -[[package]] -name = "unindent" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3" - [[package]] name = "unreachable" version = "1.0.0" @@ -12159,7 +12311,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.48.0", ] [[package]] @@ -12803,7 +12955,7 @@ dependencies = [ "once_cell", "percent-encoding", "raw-window-handle", - "sha2", + "sha2 0.10.9", "soup3", "tao-macros", "thiserror 2.0.18", @@ -12875,15 +13027,6 @@ version = "0.8.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3" -[[package]] -name = "xz2" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2" -dependencies = [ - "lzma-sys", -] - [[package]] name = "yoke" version = "0.8.1" @@ -12950,23 +13093,9 @@ dependencies = [ [[package]] name = "zeroize" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.3" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.114", -] +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" [[package]] name = "zerotrie" @@ -13004,45 +13133,51 @@ dependencies = [ [[package]] name = "zip" -version = "2.4.2" +version = "7.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42e33efc22a0650c311c2ef19115ce232583abbe80850bc8b66509ebef02de0" +dependencies = [ + "crc32fast", + "indexmap 2.13.0", + "memchr", + "typed-path 0.12.1", +] + +[[package]] +name = "zip" +version = "9.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabe6324e908f85a1c52063ce7aa26b68dcb7eb6dbc83a2d148403c9bc3eba50" +checksum = "23f17fbc870bfac28c6228aed7d6e6df352e26bf7015c4313727e16a7a01ce5e" dependencies = [ - "aes", - "arbitrary", + "aes 0.9.4", "bzip2", - "constant_time_eq 0.3.1", + "constant_time_eq 0.6.1", "crc32fast", - "crossbeam-utils", "deflate64", - "displaydoc", "flate2", - "getrandom 0.3.4", - "hmac", + "getrandom 0.4.3", + "hmac 0.13.0", "indexmap 2.13.0", - "lzma-rs", + "libc", + "lzma-rust2", "memchr", - "pbkdf2", - "sha1", - "thiserror 2.0.18", + "nix 0.31.3", + "pbkdf2 0.13.0", + "ppmd-rust", + "sha1 0.11.0", "time", - "xz2", + "typed-path 0.13.0", + "windows-sys 0.61.2", "zeroize", "zopfli", - "zstd", + "zstd 0.14.3", ] [[package]] -name = "zip" -version = "7.2.0" +name = "zlib-rs" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42e33efc22a0650c311c2ef19115ce232583abbe80850bc8b66509ebef02de0" -dependencies = [ - "crc32fast", - "indexmap 2.13.0", - "memchr", - "typed-path", -] +checksum = "40990edd51aae2c2b6907af74ffb635029d5788228222c4bb811e9351c0caad3" [[package]] name = "zmij" @@ -13068,7 +13203,16 @@ version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" dependencies = [ - "zstd-safe", + "zstd-safe 7.2.4", +] + +[[package]] +name = "zstd" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3ae9bf90af6e40197bef767eeefc46ad6397420fe873830bd85e5fbbfb3c70" +dependencies = [ + "zstd-safe 8.2.0", ] [[package]] @@ -13080,11 +13224,20 @@ dependencies = [ "zstd-sys", ] +[[package]] +name = "zstd-safe" +version = "8.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded520f16b29e1a9b771c722221b2b0a0398c2316d9bb3c42b458a5414d7434b" +dependencies = [ + "zstd-sys", +] + [[package]] name = "zstd-sys" -version = "2.0.16+zstd.1.5.7" +version = "2.1.2+zstd.1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748" +checksum = "481ada9c543b2323cbb7bbdbb5249177fbf0188ed959ed2c15e4b22421c84ed3" dependencies = [ "cc", "pkg-config", diff --git a/Cargo.toml b/Cargo.toml index 3fd0a061c..42a5178d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,14 +93,14 @@ tower-http = { version = "0.5", features = ["cors"] } tokio-stream = "0.1" # Python interop -pyo3 = { version = "0.23", features = ["auto-initialize"] } +pyo3 = { version = "0.29", features = ["auto-initialize"] } # Utilities uuid = { version = "1", features = ["v4"] } zstd = "0.13" flate2 = "1" tar = "0.4" -zip = "2" +zip = "9.0.5" chrono = { version = "0.4", features = ["serde"] } dirs = "6" tempfile = "3" diff --git a/crates/inference/src/backend/pytorch.rs b/crates/inference/src/backend/pytorch.rs index ea144476a..09751de9d 100644 --- a/crates/inference/src/backend/pytorch.rs +++ b/crates/inference/src/backend/pytorch.rs @@ -354,7 +354,7 @@ fn init_worker_from_envelope_blocking( request_id: &str, envelope_json: String, ) -> Result<(), BackendError> { - Python::with_gil(|py| { + Python::attach(|py| { pytorch_worker::ensure_worker_initialised(py).map_err(|e| { PyTorchBackend::init_worker_failure_from_message( request_id, @@ -473,7 +473,7 @@ fn shutdown_worker_from_envelope_blocking( request_id: &str, envelope_json: String, ) -> Result<(), BackendError> { - Python::with_gil(|py| { + Python::attach(|py| { pytorch_worker::ensure_worker_initialised(py).map_err(|e| { PyTorchBackend::shutdown_worker_failure_from_message( request_id, @@ -910,7 +910,7 @@ pub async fn active_loaded_model_info() -> Result )) })?; tokio::task::spawn_blocking(move || { - Python::with_gil(|py| -> Result { + Python::attach(|py| -> Result { let worker = pytorch_worker::worker_module(py).map_err(|e| { kv_worker_failure_from_message( &request_id, @@ -953,7 +953,7 @@ pub async fn save_live_kv_snapshot(path: &Path) -> Result Result { + Python::attach(|py| -> Result { let worker = pytorch_worker::worker_module(py).map_err(|e| { kv_worker_failure_from_message( &request_id, @@ -997,7 +997,7 @@ pub async fn restore_live_kv_snapshot(path: &Path) -> Result Result { + Python::attach(|py| -> Result { let worker = pytorch_worker::worker_module(py).map_err(|e| { kv_worker_failure_from_message( &request_id, @@ -1039,7 +1039,7 @@ pub async fn clear_live_kv_snapshot() -> Result<(), BackendError> { )) })?; tokio::task::spawn_blocking(move || { - Python::with_gil(|py| -> Result<(), BackendError> { + Python::attach(|py| -> Result<(), BackendError> { let worker = pytorch_worker::worker_module(py).map_err(|e| { kv_worker_failure_from_message( &request_id, @@ -1394,7 +1394,7 @@ impl PyTorchBackend { })?; tokio::task::spawn_blocking(move || { - Python::with_gil(|py| -> Result { + Python::attach(|py| -> Result { let worker = match &isolated { Some(worker) => worker.module(py), None => pytorch_worker::worker_module(py), @@ -1451,7 +1451,7 @@ impl PyTorchBackend { let envelope = shutdown_worker_envelope_json(&request_id)?; self.selected_audio_residency_possible = true; tokio::task::spawn_blocking(move || { - Python::with_gil(|py| { + Python::attach(|py| { let module = worker.module(py).map_err(|error| { Self::shutdown_worker_failure_from_message(&request_id, error.to_string()) })?; @@ -1615,7 +1615,7 @@ impl PyTorchBackend { } let info = tokio::task::spawn_blocking(move || { - Python::with_gil(|py| -> Result { + Python::attach(|py| -> Result { let worker = match &isolated { Some(worker) => worker.module(py), None => pytorch_worker::worker_module(py), @@ -1815,7 +1815,7 @@ impl PyTorchBackend { }); } - if let Ok(dict) = token_obj.downcast::() { + if let Ok(dict) = token_obj.cast::() { let text_value = dict.get_item("text").map_err(|error| { Self::stream_worker_failure_from_message( request_id, @@ -1870,7 +1870,7 @@ impl PyTorchBackend { usage_obj: &Bound<'_, PyAny>, ) -> Result, BackendError> { let usage_dict = usage_obj - .downcast::() + .cast::() .map_err(|error| { Self::stream_worker_failure_from_message( request_id, @@ -2303,7 +2303,7 @@ impl PyTorchBackend { request_id: &str, envelope_json: String, ) -> Result<(), BackendError> { - Python::with_gil(|py| -> Result<(), BackendError> { + Python::attach(|py| -> Result<(), BackendError> { let worker = pytorch_worker::worker_module(py).map_err(|e| { Self::unload_worker_failure_from_message( request_id, @@ -2835,7 +2835,7 @@ impl PyTorchBackend { let mut stream = self.text_jobs.spawn(move |mut producer| { producer.check()?; - let text = Python::with_gil(|py| -> Result { + let text = Python::attach(|py| -> Result { let worker = pytorch_worker::worker_module(py).map_err(|e| { Self::generate_text_worker_failure_from_message( &request_id, @@ -2945,7 +2945,7 @@ impl PyTorchBackend { let stream = self.text_jobs.spawn(move |mut producer| { producer.check()?; - Python::with_gil(|py| -> Result<(), BackendError> { + Python::attach(|py| -> Result<(), BackendError> { let failure = |error: PyErr| { Self::stream_worker_failure_from_message(&request_id, error.to_string()) }; @@ -3043,7 +3043,7 @@ impl InferenceBackend for PyTorchBackend { // Log the transformers version for diagnostics let tf_version = tokio::task::spawn_blocking(|| { - Python::with_gil(|py| -> String { + Python::attach(|py| -> String { py.import("transformers") .and_then(|m| m.getattr("__version__")) .and_then(|v| v.extract::()) @@ -3481,7 +3481,7 @@ impl InferenceBackend for PyTorchBackend { let truncate_result = tokio::task::spawn_blocking({ let request_id = request_id.clone(); move || { - Python::with_gil(|py| -> Result { + Python::attach(|py| -> Result { let worker = pytorch_worker::worker_module(py).map_err(|e| { kv_truncate_worker_failure_from_message( &request_id, diff --git a/crates/inference/src/backend/pytorch_cuda_inventory.rs b/crates/inference/src/backend/pytorch_cuda_inventory.rs index 9aa749dc9..bd7a15359 100644 --- a/crates/inference/src/backend/pytorch_cuda_inventory.rs +++ b/crates/inference/src/backend/pytorch_cuda_inventory.rs @@ -65,7 +65,7 @@ impl PyTorchBackend { /// that API's lazy-initialization path. This flag is not proof of custody. pub async fn observe_cuda_inventory() -> PyTorchCudaInventory { tokio::task::spawn_blocking(|| { - Python::with_gil(|py| { + Python::attach(|py| { let Ok(torch) = py.import("torch") else { return unavailable(PyTorchCudaInventoryUnavailable::PythonProbeFailed); }; @@ -208,7 +208,7 @@ cuda = Cuda() } #[test] fn cuda_inventory_observes_owner_ordinals_uuid_and_known_zero_without_promoting_capacity() { - Python::with_gil(|py| { + Python::attach(|py| { let devices = facts(controlled(py, "")); assert_eq!(devices[0].device_id.as_str(), "cuda:0"); assert_eq!(devices[1].device_id.as_str(), "cuda:1"); @@ -227,7 +227,7 @@ cuda = Cuda() } #[test] fn cuda_inventory_missing_malformed_or_duplicate_identity_stays_unavailable() { - Python::with_gil(|py| { + Python::attach(|py| { for settings in [ "cuda.uuids[0] = []", "cuda.uuids[0] = [0]*16", @@ -251,7 +251,7 @@ cuda = Cuda() } #[test] fn cuda_inventory_rejects_probe_errors_partial_enumeration_hip_and_unbounded_counts() { - Python::with_gil(|py| { + Python::attach(|py| { for (settings, reason) in [ ( "cuda.available = False", diff --git a/crates/inference/src/backend/pytorch_image_generation.rs b/crates/inference/src/backend/pytorch_image_generation.rs index a549e2ec0..a77d291f4 100644 --- a/crates/inference/src/backend/pytorch_image_generation.rs +++ b/crates/inference/src/backend/pytorch_image_generation.rs @@ -44,7 +44,7 @@ impl PyTorchBackend { reject_cancelled_image_generation(&context)?; tokio::task::spawn_blocking(move || { - Python::with_gil(|py| -> Result { + Python::attach(|py| -> Result { let worker = pytorch_worker::worker_module(py).map_err(|error| { image_worker_failure_from_message( &request_id, @@ -107,7 +107,7 @@ impl PyTorchBackend { let batch_execution_id = request.batch_execution_id.clone(); tokio::task::spawn_blocking(move || { - Python::with_gil( + Python::attach( |py| -> Result { let worker = pytorch_worker::worker_module(py).map_err(|error| { image_worker_failure_from_message( diff --git a/crates/inference/src/backend/pytorch_tests.rs b/crates/inference/src/backend/pytorch_tests.rs index a2dd43a08..2d5b770ba 100644 --- a/crates/inference/src/backend/pytorch_tests.rs +++ b/crates/inference/src/backend/pytorch_tests.rs @@ -655,7 +655,7 @@ fn test_pytorch_worker_load_envelope_tolerates_additive_fields() { #[test] fn test_python_worker_contract_projects_task_profile_loader() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let envelope = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -700,7 +700,7 @@ fn test_python_worker_contract_projects_task_profile_loader() { #[test] fn test_python_worker_contract_tolerates_additive_load_fields() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let envelope = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -760,7 +760,7 @@ fn test_python_worker_contract_tolerates_additive_load_fields() { #[test] fn test_python_worker_contract_rejects_unsupported_task_profile_loader() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let envelope = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -802,7 +802,7 @@ fn test_python_worker_contract_rejects_unsupported_task_profile_loader() { #[test] fn test_python_worker_contract_rejects_missing_load_entry_path() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let envelope = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -840,7 +840,7 @@ fn test_python_worker_contract_rejects_missing_load_entry_path() { #[test] fn test_python_worker_load_value_error_after_projection_maps_to_model_load_failed() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_stubbed_dependencies(py); let patch = CString::new( r#" @@ -897,7 +897,7 @@ module.load_model = fail_load_model #[test] fn test_python_worker_load_unexpected_loader_exception_maps_to_model_load_failed() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_stubbed_dependencies(py); let patch = CString::new( r#" @@ -954,7 +954,7 @@ module.load_model = fail_load_model #[test] fn test_python_worker_load_invalid_loader_stays_invalid_request() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_stubbed_dependencies(py); let envelope = serde_json::json!({ "request_id": "req-worker-load-invalid-loader", @@ -1086,7 +1086,7 @@ fn test_pytorch_worker_generate_text_dllm_envelope_decodes_backend_local_control #[test] fn test_python_worker_contract_projects_dllm_generation_controls() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!( "../../tests/fixtures/pytorch_worker_contract/generate_text_dllm_request.json" @@ -1121,7 +1121,7 @@ fn test_python_worker_contract_projects_dllm_generation_controls() { #[test] fn test_python_worker_contract_tolerates_additive_generate_fields() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let envelope = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -1591,7 +1591,7 @@ fn test_pytorch_worker_truncate_kv_cache_envelope_rejects_empty_path() { #[test] fn test_python_worker_contract_projects_unload_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!("../../tests/fixtures/pytorch_worker_contract/unload_model_request.json"); @@ -1608,7 +1608,7 @@ fn test_python_worker_contract_projects_unload_envelope() { #[test] fn test_python_worker_contract_projects_init_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!("../../tests/fixtures/pytorch_worker_contract/init_worker_request.json"); @@ -1625,7 +1625,7 @@ fn test_python_worker_contract_projects_init_envelope() { #[test] fn test_python_worker_contract_projects_shutdown_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!( "../../tests/fixtures/pytorch_worker_contract/shutdown_worker_request.json" @@ -1643,7 +1643,7 @@ fn test_python_worker_contract_projects_shutdown_envelope() { #[test] fn test_python_worker_shutdown_from_envelope_returns_structured_success() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_stubbed_dependencies(py); let fixture = include_str!( "../../tests/fixtures/pytorch_worker_contract/shutdown_worker_request.json" @@ -1668,7 +1668,7 @@ fn test_python_worker_shutdown_from_envelope_returns_structured_success() { #[test] fn test_python_worker_response_helpers_emit_success_contract() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let locals = PyDict::new(py); locals @@ -1714,7 +1714,7 @@ response_json = worker_contract.worker_success_response_json( #[test] fn test_python_worker_response_helpers_emit_error_contract() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let response_json = module @@ -1752,7 +1752,7 @@ fn test_python_worker_response_helpers_emit_error_contract() { #[test] fn test_python_worker_contract_rejects_invalid_init_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let wrong_operation = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -1795,7 +1795,7 @@ fn test_python_worker_contract_rejects_invalid_init_envelope() { #[test] fn test_python_worker_contract_rejects_invalid_shutdown_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let wrong_operation = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -1838,7 +1838,7 @@ fn test_python_worker_contract_rejects_invalid_shutdown_envelope() { #[test] fn test_python_worker_contract_projects_get_loaded_info_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!( "../../tests/fixtures/pytorch_worker_contract/get_loaded_info_request.json" @@ -1856,7 +1856,7 @@ fn test_python_worker_contract_projects_get_loaded_info_envelope() { #[test] fn test_python_worker_contract_rejects_invalid_get_loaded_info_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let wrong_operation = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -1899,7 +1899,7 @@ fn test_python_worker_contract_rejects_invalid_get_loaded_info_envelope() { #[test] fn test_python_worker_contract_projects_clear_kv_cache_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!( "../../tests/fixtures/pytorch_worker_contract/clear_kv_cache_request.json" @@ -1917,7 +1917,7 @@ fn test_python_worker_contract_projects_clear_kv_cache_envelope() { #[test] fn test_python_worker_contract_rejects_invalid_clear_kv_cache_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let wrong_operation = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -1960,7 +1960,7 @@ fn test_python_worker_contract_rejects_invalid_clear_kv_cache_envelope() { #[test] fn test_python_worker_contract_projects_save_kv_cache_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!("../../tests/fixtures/pytorch_worker_contract/save_kv_cache_request.json"); @@ -1983,7 +1983,7 @@ fn test_python_worker_contract_projects_save_kv_cache_envelope() { #[test] fn test_python_worker_contract_rejects_invalid_save_kv_cache_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let wrong_operation = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -2026,7 +2026,7 @@ fn test_python_worker_contract_rejects_invalid_save_kv_cache_envelope() { #[test] fn test_python_worker_contract_projects_restore_kv_cache_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!( "../../tests/fixtures/pytorch_worker_contract/restore_kv_cache_request.json" @@ -2050,7 +2050,7 @@ fn test_python_worker_contract_projects_restore_kv_cache_envelope() { #[test] fn test_python_worker_contract_rejects_invalid_restore_kv_cache_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let wrong_operation = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -2093,7 +2093,7 @@ fn test_python_worker_contract_rejects_invalid_restore_kv_cache_envelope() { #[test] fn test_python_worker_contract_projects_truncate_kv_cache_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!( "../../tests/fixtures/pytorch_worker_contract/truncate_kv_cache_request.json" @@ -2125,7 +2125,7 @@ fn test_python_worker_contract_projects_truncate_kv_cache_envelope() { #[test] fn test_python_worker_contract_rejects_invalid_truncate_kv_cache_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let wrong_operation = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -2168,7 +2168,7 @@ fn test_python_worker_contract_rejects_invalid_truncate_kv_cache_envelope() { #[test] fn test_python_worker_contract_rejects_invalid_unload_envelope() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let wrong_operation = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -2292,7 +2292,7 @@ fn test_pytorch_worker_audio_transcription_envelope_tolerates_additive_fields() #[test] fn test_python_worker_contract_projects_audio_transcription_fields() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let fixture = include_str!( "../../tests/fixtures/pytorch_worker_contract/audio_transcription_request.json" @@ -2348,7 +2348,7 @@ fn test_python_worker_contract_projects_audio_transcription_fields() { #[test] fn test_python_worker_contract_tolerates_additive_audio_transcription_fields() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let envelope = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -2384,7 +2384,7 @@ fn test_python_worker_contract_tolerates_additive_audio_transcription_fields() { #[test] fn test_python_worker_contract_rejects_audio_transcription_legacy_device() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let mut value: serde_json::Value = serde_json::from_str(include_str!( "../../tests/fixtures/pytorch_worker_contract/audio_transcription_request.json" @@ -2407,7 +2407,7 @@ fn test_python_worker_contract_rejects_audio_transcription_legacy_device() { #[test] fn test_python_worker_contract_rejects_audio_transcription_auto_device_field() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let mut value: serde_json::Value = serde_json::from_str(include_str!( "../../tests/fixtures/pytorch_worker_contract/audio_transcription_request.json" @@ -3030,7 +3030,7 @@ fn test_pytorch_generate_text_stream_envelope_rejects_policy_transformers_kwargs #[test] fn test_python_worker_contract_rejects_additive_backend_kwargs() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_contract_module(py); let envelope = serde_json::json!({ "contract_version": PYTORCH_WORKER_CONTRACT_VERSION, @@ -3913,7 +3913,7 @@ fn test_pytorch_worker_stream_token_extraction_error_normalizes_to_backend_error #[test] fn test_pytorch_worker_stream_token_accepts_string_chunk() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let token = pyo3::types::PyString::new(py, "hello"); let chunk = PyTorchBackend::stream_chunk_from_python_token("req-stream-token", token.as_any()) @@ -3927,7 +3927,7 @@ fn test_pytorch_worker_stream_token_accepts_string_chunk() { #[test] fn test_pytorch_worker_stream_token_accepts_replace_dict_chunk() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let token = pyo3::types::PyDict::new(py); token.set_item("mode", "replace").expect("set mode"); token.set_item("text", "final text").expect("set text"); @@ -3955,7 +3955,7 @@ fn test_pytorch_worker_stream_token_accepts_replace_dict_chunk() { #[test] fn test_pytorch_worker_stream_token_accepts_usage_only_dict_chunk() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let token = pyo3::types::PyDict::new(py); let usage = pyo3::types::PyDict::new(py); usage.set_item("prompt_tokens", 7).expect("set prompt"); @@ -3981,7 +3981,7 @@ fn test_pytorch_worker_stream_token_accepts_usage_only_dict_chunk() { #[test] fn test_pytorch_worker_stream_token_bounds_usage_counts() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let token = pyo3::types::PyDict::new(py); let usage = pyo3::types::PyDict::new(py); usage.set_item("prompt_tokens", 2).expect("set prompt"); @@ -4007,7 +4007,7 @@ fn test_pytorch_worker_stream_token_bounds_usage_counts() { #[test] fn test_pytorch_worker_stream_token_rejects_dict_without_text_or_usage() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let token = pyo3::types::PyDict::new(py); token.set_item("mode", "replace").expect("set mode"); @@ -6231,7 +6231,7 @@ impl TextIteratorBarrier { .unwrap() .send(()) .unwrap(); - py.allow_threads(|| self.release.lock().unwrap().recv().unwrap()); + py.detach(|| self.release.lock().unwrap().recv().unwrap()); } } @@ -6250,7 +6250,7 @@ async fn production_text_iterator_drains_before_successful_load_and_unload() { ] { let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); let (release_tx, release_rx) = std::sync::mpsc::channel(); - let saved = Python::with_gil(|py| { + let saved = Python::attach(|py| { load_worker_module_with_stubbed_dependencies(py); py.run(c"import sys, types sys.modules['torch'].no_grad = lambda: (lambda f: f)\nsys.modules['torch.nn'] = types.SimpleNamespace(functional=types.SimpleNamespace()) @@ -6334,7 +6334,7 @@ def shutdown_worker_from_envelope(envelope): .await; } } - Python::with_gil(|py| { + Python::attach(|py| { let worker = super::pytorch_worker::worker_module(py).unwrap(); for (name, value) in saved { worker.setattr(name, value).unwrap(); @@ -6361,7 +6361,7 @@ def shutdown_worker_from_envelope(envelope): }; tokio::pin!(operation); assert!(operation.as_mut().now_or_never().is_none()); - Python::with_gil(|py| { + Python::attach(|py| { let worker = super::pytorch_worker::worker_module(py).unwrap(); assert!(worker .getattr("_rt03_effects") @@ -6384,7 +6384,7 @@ def shutdown_worker_from_envelope(envelope): ); assert!(stream.next().await.unwrap().unwrap().done); } - Python::with_gil(|py| { + Python::attach(|py| { let worker = super::pytorch_worker::worker_module(py).unwrap(); assert_eq!( worker @@ -6415,7 +6415,7 @@ async fn assert_failed_text_cleanup_retries( device: inference_device_id("cpu"), }); backend.resident_allocation_uncertain = true; - Python::with_gil(|py| { + Python::attach(|py| { super::pytorch_worker::worker_module(py) .unwrap() .setattr("_rt03_fail_text", true) @@ -6440,7 +6440,7 @@ async fn assert_failed_text_cleanup_retries( assert!(backend.ready); assert!(backend.loaded_model.is_some()); assert!(backend.resident_allocation_uncertain); - Python::with_gil(|py| { + Python::attach(|py| { let effects = super::pytorch_worker::worker_module(py) .unwrap() .getattr("_rt03_effects") @@ -6460,7 +6460,7 @@ async fn assert_failed_text_cleanup_retries( } assert!(backend.loaded_model.is_none()); assert!(!backend.resident_allocation_uncertain); - Python::with_gil(|py| { + Python::attach(|py| { let effects = super::pytorch_worker::worker_module(py) .unwrap() .getattr("_rt03_effects") @@ -6486,7 +6486,7 @@ async fn assert_failed_text_restart_preserves_residency( }; gateway.start(&original).await.unwrap(); let previous = gateway.runtime_lifecycle_snapshot().await; - Python::with_gil(|py| { + Python::attach(|py| { super::pytorch_worker::worker_module(py) .unwrap() .setattr("_rt03_fail_text", true) @@ -6534,7 +6534,7 @@ async fn assert_failed_text_restart_preserves_residency( .last_error .unwrap() .contains("controlled text producer failure")); - Python::with_gil(|py| { + Python::attach(|py| { let effects = super::pytorch_worker::worker_module(py) .unwrap() .getattr("_rt03_effects") @@ -6582,7 +6582,7 @@ async fn assert_effectful_load_failure_clears_residency(backend: PyTorchBackend) }; gateway.start(&original).await.unwrap(); assert!(gateway.runtime_lifecycle_snapshot().await.active); - Python::with_gil(|py| { + Python::attach(|py| { super::pytorch_worker::worker_module(py) .unwrap() .setattr("_rt03_fail_load", true) @@ -6606,7 +6606,7 @@ async fn assert_effectful_load_failure_clears_residency(backend: PyTorchBackend) .last_error .unwrap() .contains("controlled replacement load failure")); - Python::with_gil(|py| { + Python::attach(|py| { let effects = super::pytorch_worker::worker_module(py) .unwrap() .getattr("_rt03_effects") @@ -6623,7 +6623,7 @@ async fn assert_effectful_load_failure_clears_residency(backend: PyTorchBackend) .allocation_state, crate::resident_lifecycle::ResidentAllocationState::Unknown ); - Python::with_gil(|py| { + Python::attach(|py| { super::pytorch_worker::worker_module(py) .unwrap() .setattr("_rt03_fail_stop", true) @@ -6638,7 +6638,7 @@ async fn assert_effectful_load_failure_clears_residency(backend: PyTorchBackend) .allocation_state, crate::resident_lifecycle::ResidentAllocationState::Unknown ); - Python::with_gil(|py| { + Python::attach(|py| { super::pytorch_worker::worker_module(py) .unwrap() .setattr("_rt03_fail_stop", false) @@ -6653,7 +6653,7 @@ async fn assert_effectful_load_failure_clears_residency(backend: PyTorchBackend) .allocation_state, crate::resident_lifecycle::ResidentAllocationState::Released ); - Python::with_gil(|py| { + Python::attach(|py| { let effects = super::pytorch_worker::worker_module(py) .unwrap() .getattr("_rt03_effects") @@ -6708,7 +6708,7 @@ async fn selected_text_production_loader_and_worker_retain_selection_until_termi let selected_device = decision.selected_device_id.as_ref().unwrap().to_string(); let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); let (release_tx, release_rx) = std::sync::mpsc::channel(); - let saved = Python::with_gil(|py| { + let saved = Python::attach(|py| { load_worker_module_with_stubbed_dependencies(py); py.run(c"import sys, types sys.modules['torch'].no_grad = lambda: (lambda f: f) @@ -6794,7 +6794,7 @@ def shutdown_worker_from_envelope(envelope): result = &mut operation => panic!("completed before worker barrier: {result:?}"), entered = entered_rx => entered.unwrap(), } - Python::with_gil(|py| { + Python::attach(|py| { let worker = super::pytorch_worker::worker_module(py).unwrap(); let load_json: String = worker .getattr("json") @@ -6865,7 +6865,7 @@ def shutdown_worker_from_envelope(envelope): // The selected execution already joined and reported its failed job. // Replacement must reach shutdown instead of replaying that old error. replacement.await.unwrap(); - Python::with_gil(|py| { + Python::attach(|py| { let worker = super::pytorch_worker::worker_module(py).unwrap(); assert_eq!( worker @@ -7388,7 +7388,7 @@ async fn selected_audio_actual_python_loader_projects_chunk_and_closed_policy_to let envelope = PyTorchBackend::selected_audio_load_envelope(&request, &target, &decision) .await .unwrap(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_stubbed_dependencies(py); let contract = load_worker_contract_module(py); module @@ -7514,7 +7514,7 @@ async fn selected_audio_production_load_forward_jobs_hold_custody_through_cancel let (release_tx, release_rx) = std::sync::mpsc::channel(); let backend = PyTorchBackend::new(); let worker_handle = backend.selected_audio_worker.clone(); - let saved = Python::with_gil(|py| { + let saved = Python::attach(|py| { let worker = prepare_selected_audio_worker(py, &worker_handle); let saved = [ "load_transformers_model_from_envelope", @@ -7583,7 +7583,7 @@ async fn selected_audio_production_load_forward_jobs_hold_custody_through_cancel .is_err(), "{phase}:{mode}" ); - Python::with_gil(|py| { + Python::attach(|py| { let worker = worker_handle.module(py).unwrap(); let load: serde_json::Value = serde_json::from_str( &worker @@ -7645,7 +7645,7 @@ async fn selected_audio_production_load_forward_jobs_hold_custody_through_cancel tokio::time::timeout(std::time::Duration::from_secs(2), gateway.is_ready()) .await .unwrap(); - Python::with_gil(|py| { + Python::attach(|py| { let worker = worker_handle.module(py).unwrap(); let effects = worker .getattr("_audio_effects") @@ -7676,7 +7676,7 @@ async fn selected_audio_production_cache_fences_revision_content_chunk_and_gener crate::selected_audio_execution::fixture(); let mut backend = PyTorchBackend::new(); let worker_handle = backend.selected_audio_worker.clone(); - let saved = Python::with_gil(|py| { + let saved = Python::attach(|py| { let worker = prepare_selected_audio_worker(py, &worker_handle); let saved = [ "load_transformers_model_from_envelope", @@ -7761,7 +7761,7 @@ async fn selected_audio_production_cache_fences_revision_content_chunk_and_gener .runtime_reused, Some(false) ); - Python::with_gil(|py| { + Python::attach(|py| { worker_handle .module(py) .unwrap() @@ -7775,7 +7775,7 @@ async fn selected_audio_production_cache_fences_revision_content_chunk_and_gener .unwrap_err() .to_string() .contains("unacknowledged ASR shutdown")); - Python::with_gil(|py| { + Python::attach(|py| { let worker = worker_handle.module(py).unwrap(); let effects = worker .getattr("_audio_effects") @@ -7801,7 +7801,7 @@ async fn selected_audio_two_live_owners_isolate_cache_custody_stop_and_module_re let worker_b = backend_b.selected_audio_worker.clone(); let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); let (release_tx, release_rx) = std::sync::mpsc::channel(); - let (name_a, name_b, generic_shutdown) = Python::with_gil(|py| { + let (name_a, name_b, generic_shutdown) = Python::attach(|py| { let a = prepare_selected_audio_worker(py, &worker_a); let b = prepare_selected_audio_worker(py, &worker_b); assert!(!a.is(&b)); @@ -7911,7 +7911,7 @@ async fn selected_audio_two_live_owners_isolate_cache_custody_stop_and_module_re .await .is_err() ); - Python::with_gil(|py| { + Python::attach(|py| { let a = worker_a.module(py).unwrap(); let effects = a .getattr("_audio_effects") @@ -7929,7 +7929,7 @@ async fn selected_audio_two_live_owners_isolate_cache_custody_stop_and_module_re }); release_tx.send(()).unwrap(); caller.await.unwrap().unwrap(); - Python::with_gil(|py| { + Python::attach(|py| { worker_a .module(py) .unwrap() @@ -7949,7 +7949,7 @@ async fn selected_audio_two_live_owners_isolate_cache_custody_stop_and_module_re gateway.runtime_lifecycle_snapshot().await.runtime_reused, Some(true) ); - Python::with_gil(|py| { + Python::attach(|py| { let a = worker_a.module(py).unwrap(); let load = a.getattr("_audio_load").unwrap(); assert_eq!( @@ -7979,7 +7979,7 @@ async fn selected_audio_two_live_owners_isolate_cache_custody_stop_and_module_re drop(backend_b); drop(worker_a); drop(worker_b); - Python::with_gil(|py| { + Python::attach(|py| { let modules = py.import("sys").unwrap().getattr("modules").unwrap(); assert!(!modules.contains(name_a).unwrap()); assert!(!modules.contains(name_b).unwrap()); @@ -8038,7 +8038,7 @@ async fn owned_audio_production_pybytes_jobs_retain_snapshot_through_caller_loss let worker_handle = backend.selected_audio_worker.clone(); let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); let (release_tx, release_rx) = std::sync::mpsc::channel(); - Python::with_gil(|py| { + Python::attach(|py| { let worker = prepare_selected_audio_worker(py, &worker_handle); patch_selected_audio_worker(py, &worker); py.run( @@ -8114,7 +8114,7 @@ def transcribe_owned_wav_from_envelope(envelope, wav_bytes, metadata): .is_err() ); if phase == "forward" { - Python::with_gil(|py| { + Python::attach(|py| { let worker = worker_handle.module(py).unwrap(); let meta: serde_json::Value = serde_json::from_str( &worker @@ -8172,7 +8172,7 @@ def transcribe_owned_wav_from_envelope(envelope, wav_bytes, metadata): weak.upgrade().is_none(), "snapshot released after actual completion" ); - Python::with_gil(|py| { + Python::attach(|py| { worker_handle .module(py) .unwrap() @@ -8192,7 +8192,7 @@ async fn selected_to_direct_audio_cleanup(caller_abort: bool) { let private = backend.selected_audio_worker.clone(); let (entered_tx, entered_rx) = tokio::sync::oneshot::channel(); let (release_tx, release_rx) = std::sync::mpsc::channel(); - let (generic, saved_private, saved_generic) = Python::with_gil(|py| { + let (generic, saved_private, saved_generic) = Python::attach(|py| { let worker = prepare_selected_audio_worker(py, &private); let save = |module: &Bound<'_, pyo3::types::PyModule>, names: &[&'static str]| { names @@ -8286,7 +8286,7 @@ def shutdown_worker_from_envelope(envelope): selected, crate::InferenceExecutionResult::AudioTranscription { .. } )); - Python::with_gil(|py| { + Python::attach(|py| { assert!( generic .bind(py) @@ -8338,7 +8338,7 @@ def shutdown_worker_from_envelope(envelope): "direct fixture transcript" ); // An unacknowledged generic shutdown must retain ownership for retry. - Python::with_gil(|py| { + Python::attach(|py| { generic.bind(py).setattr("_direct_fail_stop", true).unwrap(); }); assert!( @@ -8354,7 +8354,7 @@ def shutdown_worker_from_envelope(envelope): crate::resident_lifecycle::ResidentAllocationState::Released, "failed shutdown must not publish confirmed release" ); - Python::with_gil(|py| { + Python::attach(|py| { assert!(!generic.bind(py).getattr("_asr_pipeline").unwrap().is_none()); generic .bind(py) @@ -8372,7 +8372,7 @@ def shutdown_worker_from_envelope(envelope): .allocation_state, crate::resident_lifecycle::ResidentAllocationState::Released ); - Python::with_gil(|py| { + Python::attach(|py| { let worker = generic.bind(py); assert!( worker.getattr("_asr_pipeline").unwrap().is_none(), diff --git a/crates/inference/src/backend/pytorch_text_dependencies.rs b/crates/inference/src/backend/pytorch_text_dependencies.rs index ce72be96d..345bca5d6 100644 --- a/crates/inference/src/backend/pytorch_text_dependencies.rs +++ b/crates/inference/src/backend/pytorch_text_dependencies.rs @@ -28,7 +28,7 @@ pub const TEXT_GENERATION_PACKAGES: [&str; 7] = [ /// Returns a configuration error if Python metadata cannot be inspected. Only /// Python's `PackageNotFoundError` is treated as a missing distribution. pub fn observe_text_package_presence() -> Result, BackendError> { - Python::with_gil(|py| observe_distributions(py, &TEXT_GENERATION_PACKAGES)) + Python::attach(|py| observe_distributions(py, &TEXT_GENERATION_PACKAGES)) .map_err(|_| BackendError::Config("embedded Python text package observation failed".into())) } @@ -62,7 +62,7 @@ mod tests { #[test] fn linked_metadata_query_distinguishes_absence_from_observation_failure() { - Python::with_gil(|py| { + Python::attach(|py| { // Private module dictionary: no package imports, sys.path mutation, // process environment changes or shared metadata monkeypatching. let module = pyo3::types::PyModule::new(py, "text_metadata_fixture").unwrap(); @@ -82,7 +82,7 @@ mod tests { #[test] fn fixed_text_query_uses_linked_python_metadata() { let expected = - Python::with_gil(|py| observe_distributions(py, &TEXT_GENERATION_PACKAGES)).unwrap(); + Python::attach(|py| observe_distributions(py, &TEXT_GENERATION_PACKAGES)).unwrap(); assert_eq!(observe_text_package_presence().unwrap(), expected); } } diff --git a/crates/inference/src/backend/pytorch_worker.rs b/crates/inference/src/backend/pytorch_worker.rs index a58306594..a6446f965 100644 --- a/crates/inference/src/backend/pytorch_worker.rs +++ b/crates/inference/src/backend/pytorch_worker.rs @@ -136,7 +136,7 @@ impl Drop for IsolatedAudioWorker { } // Blocking closures retain an Arc to this registration. Retirement is // therefore after their actual completion, including caller loss. - Python::with_gil(|py| { + Python::attach(|py| { if let Ok(sys) = py.import("sys") { if let Ok(modules) = sys.getattr("modules") { if let Ok(module) = modules.get_item(self.name.as_str()) { diff --git a/crates/inference/src/backend/pytorch_worker_image_contract_tests.rs b/crates/inference/src/backend/pytorch_worker_image_contract_tests.rs index 9b2f6bf2a..c009d17d5 100644 --- a/crates/inference/src/backend/pytorch_worker_image_contract_tests.rs +++ b/crates/inference/src/backend/pytorch_worker_image_contract_tests.rs @@ -314,7 +314,7 @@ fn test_pytorch_worker_generate_image_request_maps_from_validated_plan() { #[test] fn test_python_worker_generate_image_contract_projects_planned_kwargs() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_image_contract_module(py); let envelope = include_str!( "../../tests/fixtures/pytorch_worker_contract/generate_image_request.json" @@ -372,7 +372,7 @@ fn test_python_worker_generate_image_contract_projects_planned_kwargs() { #[test] fn test_python_worker_generate_image_batch_contract_projects_member_kwargs() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_image_contract_module(py); let envelope = include_str!( "../../tests/fixtures/pytorch_worker_contract/generate_image_batch_request.json" @@ -437,7 +437,7 @@ fn test_python_worker_generate_image_batch_contract_projects_member_kwargs() { #[test] fn test_python_worker_generate_image_contract_rejects_unknown_payload_fields() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_image_contract_module(py); let mut envelope: serde_json::Value = serde_json::from_str(include_str!( "../../tests/fixtures/pytorch_worker_contract/generate_image_request.json" @@ -461,7 +461,7 @@ fn test_python_worker_generate_image_contract_rejects_unknown_payload_fields() { #[test] fn test_python_worker_generate_image_contract_requires_rust_selected_device() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_image_contract_module(py); let mut envelope: serde_json::Value = serde_json::from_str(include_str!( "../../tests/fixtures/pytorch_worker_contract/generate_image_request.json" diff --git a/crates/inference/src/backend/pytorch_worker_image_python_tests.rs b/crates/inference/src/backend/pytorch_worker_image_python_tests.rs index cee0f04b1..74a9d62b1 100644 --- a/crates/inference/src/backend/pytorch_worker_image_python_tests.rs +++ b/crates/inference/src/backend/pytorch_worker_image_python_tests.rs @@ -197,7 +197,7 @@ def load_diffusion_model(path, device=None, torch_dtype=None): #[test] fn test_python_worker_generate_image_batch_from_envelope_returns_worker_response() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); @@ -264,7 +264,7 @@ fn test_python_worker_generate_image_batch_from_envelope_returns_worker_response #[test] fn image_count_batch_partitions_images_and_expands_seed_generators_in_member_order() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); let mut envelope: serde_json::Value = serde_json::from_str(include_str!( @@ -350,7 +350,7 @@ worker._diffusion_pipeline.__class__.__call__ = marked_images #[test] fn test_python_worker_generate_image_from_envelope_returns_worker_response() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); @@ -386,7 +386,7 @@ fn test_python_worker_generate_image_from_envelope_returns_worker_response() { #[test] fn graph_guidance_option_reaches_actual_worker_pipeline_call_without_default_override() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); for guidance in [None, Some(-1.0), Some(0.0), Some(1.0), Some(7.5)] { @@ -438,7 +438,7 @@ fn graph_guidance_option_reaches_actual_worker_pipeline_call_without_default_ove #[test] fn test_python_worker_generate_image_from_envelope_reports_cuda_peak_vram() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); let locals = PyDict::new(py); @@ -498,7 +498,7 @@ worker.torch.cuda = _Cuda() #[test] fn test_python_worker_generate_image_from_envelope_reports_mps_metric_unimplemented() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); let locals = PyDict::new(py); @@ -551,7 +551,7 @@ worker.torch.backends = types.SimpleNamespace( #[test] fn test_python_worker_generate_image_from_envelope_reports_oom_failure() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); let locals = PyDict::new(py); @@ -598,7 +598,7 @@ worker._diffusion_pipeline = _FailingPipeline() #[test] fn scheduler_worker_envelopes_use_closed_choices_and_preserve_resident_default() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); let pipeline = module.getattr("_diffusion_pipeline").unwrap(); @@ -673,7 +673,7 @@ fn scheduler_worker_envelopes_use_closed_choices_and_preserve_resident_default() #[test] fn test_python_worker_generate_image_from_envelope_rejects_unsupported_denoising_scheduler() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); let mut envelope: serde_json::Value = serde_json::from_str(include_str!( @@ -706,7 +706,7 @@ fn test_python_worker_generate_image_from_envelope_rejects_unsupported_denoising #[test] fn test_python_worker_generate_image_from_envelope_rejects_unplanned_fields() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); attach_stub_diffusion_pipeline(&module); let mut envelope: serde_json::Value = serde_json::from_str(include_str!( @@ -739,7 +739,7 @@ fn test_python_worker_generate_image_from_envelope_rejects_unplanned_fields() { #[test] fn test_python_worker_real_diffusion_loader_enforces_closed_bundle_admission() { let _python_fixture = super::PYTHON_TEST_LOCK.blocking_lock(); - Python::with_gil(|py| { + Python::attach(|py| { let module = load_worker_module_with_image_stubs(py); let locals = PyDict::new(py); locals.set_item("worker", &module).unwrap(); diff --git a/crates/inference/src/managed_runtime/archive.rs b/crates/inference/src/managed_runtime/archive.rs index d7f84d9d7..1a7b63747 100644 --- a/crates/inference/src/managed_runtime/archive.rs +++ b/crates/inference/src/managed_runtime/archive.rs @@ -42,10 +42,12 @@ fn extract_zip_archive(archive_path: &Path, destination: &Path) -> Result<(), St let mut entry = archive .by_index(index) .map_err(|e| format!("Failed to read zip entry: {}", e))?; - let relative_path = entry - .enclosed_name() - .map(|path| path.to_path_buf()) - .ok_or_else(|| format!("Archive entry has invalid path: {}", entry.name()))?; + let relative_path = entry.enclosed_name().ok_or_else(|| { + format!( + "Archive entry has invalid path: {}", + zip_entry_label(&entry) + ) + })?; let output_path = validated_output_path(destination, &relative_path)?; if entry.is_dir() { @@ -67,7 +69,7 @@ fn extract_zip_archive(archive_path: &Path, destination: &Path) -> Result<(), St .map_err(|e| format!("Failed to read symlink target: {}", e))?; let target_path = Path::new(target.trim()) .file_name() - .ok_or_else(|| format!("Invalid symlink target in {}", entry.name()))?; + .ok_or_else(|| format!("Invalid symlink target in {}", zip_entry_label(&entry)))?; std::os::unix::fs::symlink(target_path, &output_path) .map_err(|e| format!("Failed to create symlink {:?}: {}", output_path, e))?; continue; @@ -129,8 +131,13 @@ fn validated_output_path(destination: &Path, relative_path: &Path) -> Result(entry: &zip::read::ZipFile<'_, R>) -> String { + String::from_utf8_lossy(entry.name_raw()).into_owned() +} + #[cfg(unix)] -fn zip_entry_is_symlink(entry: &zip::read::ZipFile<'_>) -> bool { +fn zip_entry_is_symlink(entry: &zip::read::ZipFile<'_, R>) -> bool { entry .unix_mode() .map(|mode| (mode & 0o170000) == 0o120000) @@ -139,7 +146,7 @@ fn zip_entry_is_symlink(entry: &zip::read::ZipFile<'_>) -> bool { #[cfg(test)] mod tests { - use super::validated_output_path; + use super::{extract_zip_archive, validated_output_path}; use std::path::Path; #[test] @@ -157,4 +164,44 @@ mod tests { assert!(error.contains("escapes extraction root")); } + + fn write_zip(path: &Path, entries: &[(&str, &[u8])]) { + let mut writer = zip::ZipWriter::new(std::fs::File::create(path).expect("create zip")); + for (name, contents) in entries { + writer + .start_file(*name, zip::write::SimpleFileOptions::default()) + .expect("start zip entry"); + std::io::Write::write_all(&mut writer, contents).expect("write zip entry"); + } + writer.finish().expect("finish zip"); + } + + #[test] + fn extract_zip_archive_writes_nested_entries() { + let temp = tempfile::tempdir().expect("tempdir"); + let archive = temp.path().join("runtime.zip"); + write_zip(&archive, &[("bin/server", b"binary"), ("README", b"notes")]); + let destination = temp.path().join("out"); + + extract_zip_archive(&archive, &destination).expect("extract zip"); + + assert_eq!( + std::fs::read(destination.join("bin/server")).unwrap(), + b"binary" + ); + assert_eq!(std::fs::read(destination.join("README")).unwrap(), b"notes"); + } + + #[test] + fn extract_zip_archive_rejects_entries_outside_the_destination() { + let temp = tempfile::tempdir().expect("tempdir"); + let archive = temp.path().join("runtime.zip"); + write_zip(&archive, &[("../escape", b"payload")]); + let destination = temp.path().join("out"); + + let error = extract_zip_archive(&archive, &destination).expect_err("escape rejected"); + + assert!(error.contains("invalid path: ../escape"), "{error}"); + assert!(!temp.path().join("escape").exists()); + } } diff --git a/crates/inference/tests/diffusers_guidance_native.rs b/crates/inference/tests/diffusers_guidance_native.rs index e1e6b33cb..a1e63457f 100644 --- a/crates/inference/tests/diffusers_guidance_native.rs +++ b/crates/inference/tests/diffusers_guidance_native.rs @@ -9,7 +9,7 @@ use pyo3::prelude::*; #[test] #[ignore = "explicit native qualification requires real CPU Torch and Diffusers"] fn actual_cpu_diffusers_guidance_matches_conditional_noise_oracle() { - Python::with_gil(|py| { + Python::attach(|py| { let source = CString::new( r#" import inspect @@ -88,7 +88,7 @@ print(f"native_guidance_torch={torch.__version__}; diffusers={diffusers.__versio #[test] #[ignore = "explicit native qualification requires real CPU Torch and Diffusers"] fn actual_cpu_diffusers_multiple_images_match_worker_batch_shape_and_seed_order() { - Python::with_gil(|py| { + Python::attach(|py| { let locals = pyo3::types::PyDict::new(py); locals .set_item("worker_source", include_str!("../torch/worker.py")) @@ -142,7 +142,7 @@ print(f'native_image_count_torch={torch.__version__}; diffusers={diffusers.__ver #[test] #[ignore = "explicit native qualification requires real CPU Torch and Diffusers"] fn actual_cpu_diffusers_scheduler_override_matches_explicit_pipeline_without_resident_mutation() { - Python::with_gil(|py| { + Python::attach(|py| { let module_source = CString::new(include_str!("../torch/worker_diffusion.py")).unwrap(); let module = pyo3::types::PyModule::from_code( py, diff --git a/crates/inference/tests/pytorch_cuda_inventory_native.rs b/crates/inference/tests/pytorch_cuda_inventory_native.rs index cfd4aef45..2653643d7 100644 --- a/crates/inference/tests/pytorch_cuda_inventory_native.rs +++ b/crates/inference/tests/pytorch_cuda_inventory_native.rs @@ -11,7 +11,7 @@ async fn actual_embedded_pytorch_inventory_preserves_gateway_and_cpu_candidates( let before = gateway.runtime_owned_device_candidates(); let backend_before = gateway.current_backend_name().await; let observation = gateway.observe_pytorch_cuda_inventory().await; - pyo3::Python::with_gil(|py| { + pyo3::Python::attach(|py| { use pyo3::prelude::*; let torch = py.import("torch").unwrap(); let version = torch From d17b87efdf46797992d060211ffb0e33f647973c Mon Sep 17 00:00:00 2001 From: MrScripty Date: Fri, 6 Nov 2026 04:04:12 -0700 Subject: [PATCH 2/2] style(inference): rustfmt the pyo3 0.29 cast chain Co-Authored-By: Claude Opus 5.5 --- crates/inference/src/backend/pytorch.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/crates/inference/src/backend/pytorch.rs b/crates/inference/src/backend/pytorch.rs index 09751de9d..87dd8ad92 100644 --- a/crates/inference/src/backend/pytorch.rs +++ b/crates/inference/src/backend/pytorch.rs @@ -1869,14 +1869,12 @@ impl PyTorchBackend { request_id: &str, usage_obj: &Bound<'_, PyAny>, ) -> Result, BackendError> { - let usage_dict = usage_obj - .cast::() - .map_err(|error| { - Self::stream_worker_failure_from_message( - request_id, - format!("Token usage extraction failed: {}", error), - ) - })?; + let usage_dict = usage_obj.cast::().map_err(|error| { + Self::stream_worker_failure_from_message( + request_id, + format!("Token usage extraction failed: {}", error), + ) + })?; let usage = InferenceUsage { prompt_tokens: Self::stream_usage_u32_field(request_id, usage_dict, "prompt_tokens")?, completion_tokens: Self::stream_usage_u32_field(