← Back to Pull requests

Build the wheel with a single copy of libcucim #1220

Closed
unknown closed this pull request without merging on Nov 23, 2026 20:48 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 18:07 UTC
Author

Summary


closes #1213

The pip wheels load two copies of libcucim. After opening a file, /proc/self/maps lists both:

  • cucim/clara/_cucim.so needs libcucim.so.26, found next to it in cucim/clara/.

  • The plugins (cucim.kit.cuslide@.so, cucim.kit.cuslide2@.so, cucim.kit.cumed@.so) need

  • libcucim-<hash>.so.<version> in cucim_cu13.libs/, a renamed copy that auditwheel repair
    vendored.

    Each copy has its own global state, so the cache configured from Python is not the one the plugins
    use. With a per-process cache and statistics recording on, a cold read_region records neither hits
    nor misses, for both cuslide and cuslide2:

    CuImage.cache("per_process", memory_capacity=256)
    CuImage.cache().record(True)
    CuImage("slide.svs").read_region((0, 0), (512, 512), level=0)
    print(CuImage.cache().hit_count, CuImage.cache().miss_count)   # wheels: 0 0
    

    I saw this with cucim-cu13==26.10.0 and the 26.12.0a34 nightly. The conda packages and a source
    build load one copy and record misses. It also makes the caching step of
    scripts/test_aperio_svs.py and scripts/test_philips_tiff.py fail with wheels.

    Cause

    The wheel is assembled from the CMake build tree (run build_local copies
    build-release/lib/cucim into python/cucim/src/cucim/clara/). In the build tree, the plugins'
    RUNPATH is the absolute path of the libcucim build directory and has no $ORIGIN, because
    CMAKE_INSTALL_RPATH ($ORIGIN) only applies to the installed copy. The Python extension finds
    libcucim.so.26 through $ORIGIN, so auditwheel sees it as part of the wheel. For the plugins it
    resolves libcucim.so.26 to the build directory, copies that file into cucim_cu13.libs/ with a
    hashed name, and rewrites the plugins' NEEDED entry to the new name.

    Changes

  • Set BUILD_WITH_INSTALL_RPATH on the three plugin targets, so the plugins in the build tree have

  • RPATH $ORIGIN, like the installed ones. auditwheel then finds the libcucim.so.26 that is
    already in the wheel.
  • ci/validate_wheel.sh fails if a wheel contains a vendored .libs/libcucim-.

  • New unit test test_libcucim_loaded_once.py: after a read by a plugin, exactly one libcucim is

  • mapped into the process, and the cache configured from Python has recorded the read. It uses a
    generated TIFF, so no download is needed.

    Testing

    I reproduced the problem with auditwheel 6.8.2 on a wheel assembled from a local source build of
    main:

    | Plugins' RUNPATH in the wheel | auditwheel repair result |
    |---|---|
    | absolute build path (current) | adds cucim.libs/libcucim-f2d0d9dd.so.26.12.00 |
    | $ORIGIN (the new RPATH) | adds nothing; one libcucim.so.26 in the wheel |

    The second row was made with patchelf --set-rpath '$ORIGIN' on the plugins, which is what the
    CMake property does to the files in the build tree. I did not rebuild the plugins with the changed
    CMake files and then make a wheel. The new check in validate_wheel.sh flags the first wheel and
    accepts the second. The new unit test passes with a source build.

    CI builds the wheels, so the wheel build, validate_wheel.sh and the wheel tests are the final
    check.

    Diff: 395 lines (+296 / -99) across 4 files Reviewer: gigony Review duration: 20321m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 395 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.358
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1220"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 43.2% (MEDIUM) · Higher = larger blast radius
    43.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.1% · Safe to merge
    17.1%
    Repository