Repository navigation
fix(python): keep the extension out of the CLI release build; v4.2.4-beta.2 - #2036
Conversation
cargo-dist builds the CLI release with `cargo build --workspace` under the dist profile's fat LTO, so it also built fluree-db-python: a cdylib that links the whole engine again, which the CLI release never ships. The v4.2.4-beta.1 aarch64 Linux build was stopped by its runner (exit 143) at the same point on both attempts, minutes into that crate's build, where v4.2.3 built in 24 minutes. Most likely the 32 GB runner, already linking the CLI and server binaries side by side, ran out of memory on the third full-engine link. The module and its dependencies are now the `extension` feature, which pyproject.toml has maturin turn on, so wheels, `maturin develop` and the CI python job build exactly as before, and the workspace clippy run (--all-features) still lints it. A plain workspace build sees an empty crate. The Python crate added no features to anything the CLI ships, so the CLI release builds as it did for v4.2.3.
v4.2.4-beta.1 published fluree 4.2.4b1 to PyPI, but its CLI release failed on aarch64 Linux before creating a GitHub release. beta.2 carries the fix for that build; its tag publishes the CLI pre-release and fluree 4.2.4b2 together.
The Concurrency section said several processes may share one directory, and its fork advice (fork workers before Fluree starts, as gunicorn does) led to one engine per worker on the same directory. Neither process sees the other's commits and both index and sweep the same files, so the section now says one process, through one shared connection, owns a directory; to share across processes, run a server; and serve a web app from one worker with threads or asyncio.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz quick one: the feature gate is the right fix, and I went through the --all-features, nextest and wheel sides and nothing else moves. One headline note, which isn't for this PR: this is the same --workspace fat-LTO release build that has fallen over on memory twice before (c11b828, 89081d6), and I suspect the root is that the CLI release is defined by the whole workspace rather than by fluree-db-cli. Every bin and cdylib gets linked whether it ships or not, and the CLI picks up features from its neighbors (the released binary carries HNSW vector search only because fluree-search-httpd turns it on). If the CLI declared its own features, precise-builds = true would take all of that out of the release, and we could stop sizing runners around it. That turns on whether the CLI is meant to ship vector search, so it's a question below rather than an ask.
Full review below:
✅ Approve.
Thanks for chasing this down so quickly, @bplatz, and for writing the diagnosis into the manifest where the next person will trip over it. I went through the --all-features side, since that's where a feature gate usually bites: extension is the only thing --all-features turns on here (the dep: syntax means no implicit per-dependency features), which is exactly the shape #2025 had. The Clippy step on this head still checks the whole module, the default-features cargo check --workspace --all-targets step now sees the empty crate, and nextest never builds the crate at all because test = false is still there, so nothing tries to link a test binary against libpython. The wheel side is fine too: the python job logs "Using build options features from pyproject.toml", and python-release.yml passes no --features, so maturin picks extension up in both places.
A few things below, all questions rather than asks for this PR:
❓ The release CLI's features are decided by its neighbors. This is more of a question than a suggestion. Your note about precise-builds checks out: diffing cargo tree -p fluree-db-cli against the workspace resolution, the only real difference is fluree-db-query/vector, and it reaches the CLI through fluree-search-httpd's default = ["vector"] (fluree-search-httpd/Cargo.toml:49) → fluree-search-service/vector. So the released binary carries usearch while a cargo build -p fluree-db-cli doesn't. It's also the same shape as the bug this PR fixes: the --workspace build still compiles and fat-LTO-links fluree-server, fluree-events-token, fluree-search-httpd, vbench, bench-baseline and the native fluree_db_wasm cdylib, none of which ship (four of those crates are already dist = false, which only stops packaging). The runner notes in dist-workspace.toml record two earlier link-time memory failures on this same build (c11b828, 89081d6); I haven't verified the extra links caused those, only that it's the same build. If the CLI is meant to ship HNSW vector search, declaring it in fluree-db-cli's own features would make precise-builds = true safe and take all of those links out of the release; if it isn't, the release is carrying usearch by accident. Either way that's a call on what the CLI ships, which is the only reason I'm not suggesting it here.
❓ The tag fires both releases, but neither waits for the other. release.yml and python-release.yml both trigger on the tag independently. On beta.1 the aarch64 CLI build died at 02:48 UTC and the wheels still published at 02:57, and since build-local-artifacts is skipped on pull requests, the beta.2 tag run is also the first real test of the memory diagnosis. If that build falls over for some other reason, 4.2.4b2 lands on PyPI without a GitHub release, the same as b1. Probably fine for a beta, but before the first non-beta tag it seems worth deciding whether the PyPI publish (the half we can't take back) should wait on the CLI release.
❓ Following up on the PyPI gate from my #2025 review. Thanks for getting most of it in: the pypi environment exists and admits only v* tags, the wheels job checks the tag against the built version (python-release.yml:73), only a tag push publishes (:102), and the publish action is pinned to a SHA (:116). The piece still open is who can push a v* tag. There's no tag ruleset (the repo's only ruleset protects main) and no required reviewer on pypi, so any writer's v* tag on any commit whose Cargo.toml carries a version PyPI doesn't have yet publishes that commit. A tag ruleset that restricts creating v* tags, or a required reviewer on the environment, would close it. It's a settings change, so nothing for this PR.
Adherence to repo commitments:
- Patterns/abstractions: ✔ a crate feature that maturin turns on is the standard way to keep an extension module out of plain cargo builds;
dist = falseordefault-memberswouldn't have helped, since dist passes--workspaceitself. - Performance (speed first, memory second): ✔ no engine or binding code changed (the module is the same source behind a crate-level
cfg), and the release build drops one fat-LTO engine link. No performance-degradation risk. - Deployment targets: ✔ wheels are covered by the
pythonjob (built via maturin withextension, pytest green on Ubuntu, macOS and Windows); the CLI release is covered structurally (no package's features change) rather than by a run, since dist only builds on tags; embedded, server and wasm32 are n/a, since no engine source changed and no wasm32 job selects this crate. - Testing: ✔ nothing new to test;
clippy(both feature shapes),testandpythonare green on3b7bb1551. - Conventions: ✔ commit bodies carry the diagnosis; the version bump is consistent across
Cargo.toml, both testsuite manifests and all three lockfiles (version lines only), andpyproject.tomltakes it dynamically (4.2.4-beta.2normalizes to4.2.4b2, so the tag check passes).
Verified locally at branch HEAD: cargo check -p fluree-db-python with and without --features extension (both clean), cargo clippy -p fluree-db-python --all-targets -- -D warnings on the empty shape, cargo build -p fluree-db-python --profile dist without the feature, and cargo tree feature diffs with and without fluree-db-python/extension across all targets.
Approving so you can merge and tag beta.2 when ready — none of the three questions needs to hold it up.
| //! | ||
| //! The module is the `extension` feature, which maturin turns on; without it | ||
| //! the crate is empty (see Cargo.toml). | ||
| #![cfg(feature = "extension")] |
There was a problem hiding this comment.
👍 This one line is the whole fix, and I checked what it buys.
Without extension, cargo build -p fluree-db-python --profile dist takes about two seconds on my Mac and produces a 16 KB cdylib with no exported symbols, so the release's --workspace build no longer pays for a third full-engine fat-LTO link.
And cargo tree --workspace with and without fluree-db-python/extension (all targets, normal/build/dev edges) differs only by the extension's own packages (pyo3*, pythonize, stacker and a few of their deps), so no package the CLI links changes features, which matches what the body says.
The v4.2.4-beta.1 tag published
fluree4.2.4b1 to PyPI, but its CLI release never produced a GitHub release. The aarch64 Linux build was stopped by its runner (exit 143) at the same point on both attempts, minutes afterfluree-db-pythonstarted compiling. The other three platforms built.Cause, most likely memory. cargo-dist builds the CLI release with
cargo build --workspaceunder the dist profile's fat LTO, so since #2025 it also built the Python extension: a cdylib that links the whole engine a third time, beside the CLI and server binaries, and that the CLI release never ships. The 32 GB aarch64 runner built v4.2.3 in 24 minutes without it.Fix. The extension module and its dependencies are now the crate's
extensionfeature.pyproject.tomlhas maturin turn it on, so wheels,maturin developand the CIpythonjob build exactly as before, and the workspace clippy run (--all-features) still lints the crate. A plain workspace build sees an empty crate, so cargo-dist builds what it built for v4.2.3. The Python crate adds no features to anything the CLI ships (compared per package withcargo tree), so the CLI binary is unaffected.Building only the CLI package (cargo-dist's
precise-builds) would also have kept it out, but it would drop features the CLI binary gets today from other workspace members,fluree-db-query/vectoramong them.Release. The workspace version goes to
4.2.4-beta.2. Tagging the merge commitv4.2.4-beta.2publishes the CLI pre-release andfluree4.2.4b2 together. 4.2.4b1 stays on PyPI; no GitHub release exists for beta.1.Docs. The Python README's Concurrency section no longer says several processes may share one database directory. Two processes on one directory don't see each other's commits, and both index and sweep the same files. Its fork advice also led to the same setup: forking gunicorn workers before Fluree starts gives each worker its own engine on that directory. The section now says one process owns a directory through one shared connection. To share data across processes, run a server; to serve a web app, use one worker with threads or asyncio.
Partially addresses #2040: this fixes the docs, and the exclusive directory lock that refuses a second process remains.