Skip to content

ensureMex: verify blosc.encode resolves to a copy with its MEX on every call - #153

Merged
stevevanhooser merged 2 commits into
mainfrom
claude/blosc-ensuremex-path-recheck
Nov 23, 2026
Merged

stevevanhooser merged 2 commits into
mainfrom
claude/blosc-ensuremex-path-recheck

Conversation

@stevevanhooser

@stevevanhooser stevevanhooser commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Bug

On macOS (R2024b, mexmaca64) an NDI lightsheet test failed with:

Undefined function 'blosc_mex' for input arguments of type 'uint8'.
Error in blosc.encode (line 42)
Error in ndr.format.blosc.encodeMany (line 48)
Error in ndr.format.blosc.encode (line 82)

Diagnosis: which -all blosc.encode resolved only to a source checkout of blosc-matlab (its +blosc/private had just coerceBytes.m, no compiled MEX), while ndr.util.blosc.ensureMex() still reported available: 1 for the downloaded v0.2.1 copy in prefdir, whose folder was no longer on the path.

Two bugs in ensureMex:

  1. The persistent cached shortcut returned the cached struct without re-checking the path, so after something removed the install folder from the path (a test path fixture restoring the path, restoredefaultpath, a path reset in an init script) every later call still said available.
  2. Availability was judged by exist('blosc.encode','file') == 2, which is true for any +blosc package, including one with no private/blosc_mex.<mexext>.

Fix

  • New ndr.util.blosc.checkMexResolution(): blosc.encode, blosc.encodeChunk and blosc.decode must each resolve (which) to a +blosc folder with private/blosc_mex.<mexext> (isfile). Cheap enough for the per-chunk hot path; never downloads.
  • ensureMex's cached shortcut now runs that check. If it fails and the cached install is still on disk, the install is moved back to the top of the path and re-checked; if it is still shadowed (e.g. the stray copy is in the current folder) it returns available=false with a reason naming the shadowing folder, so callers fall back to the Python path instead of erroring. If the install vanished from disk, the normal install flow runs.
  • Moving to the top is rmpath then addpath -begin (moveToTopOfPath): CI showed that addpath on a folder already on the path does not move it ahead of a +blosc copy added later.
  • The final availability check and discoverExistingMex use the same check.
  • Contract unchanged: never errors, info fields unchanged.

Tests

tools/tests/+ndr/+unittest/+util/+blosc/TestEnsureMex.m (temp folders; path and current folder restored at teardown):

  • stray +blosc without MEX ahead on the path → checkMexResolution not ok, reason names the folder (no network/MEX needed);
  • stray with a placeholder MEX file → ok;
  • stray in the current folder → ensureMex never reports available;
  • with a real MEX (assume-skipped otherwise): stray ahead on the path is overtaken by moving the install back to the top; stray in cwd → unavailable with reason; install removed from the path after a successful call → next call restores it.

Not run locally (no MATLAB here, per AGENTS.md). CI on Linux: 406 passed, 0 failed, 3 skipped (pre-existing sonpipe assumptions); all six new tests pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_011v7R5uZ1S7cptasH3CmUV8

The persistent cache returned available=true without re-checking the
path, and availability was judged by exist('blosc.encode','file'),
which is true for any +blosc package, including a source checkout of
blosc-matlab with no compiled MEX. After a path reset (or with a stray
checkout ahead on the path) callers then hit "Undefined function
'blosc_mex'" instead of falling back to the Python tool.

- Add ndr.util.blosc.checkMexResolution: blosc.encode, encodeChunk and
  decode must each resolve to a +blosc folder with
  private/blosc_mex.<mexext>.
- ensureMex re-checks this on every call (which + isfile, no
  download); if the cached install no longer resolves it is addpath'd
  to the top again, and if it is still shadowed available=false with a
  reason naming the shadowing folder.
- Use the same check for the final availability and in
  discoverExistingMex.
- Add TestEnsureMex covering stray copies without a MEX and an install
  removed from the path after a successful call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011v7R5uZ1S7cptasH3CmUV8
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

409 tests  +6   406 ✅ +6   37s ⏱️ +7s
 42 suites +1     3 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 66e1419. ± Comparison against base commit 00960f6.

♻️ This comment has been updated with latest results.

CI showed addpath(cached.path) leaving an already-on-path install behind
a +blosc copy added later, so testStrayAheadOnPathIsOvertakenByInstall
failed. Remove the folder from the path first, then add it with -begin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011v7R5uZ1S7cptasH3CmUV8
@codecov

codecov Bot commented Nov 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.00000% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.12%. Comparing base (00960f6) to head (66e1419).

Files with missing lines Patch % Lines
+ndr/+util/+blosc/ensureMex.m 76.66% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #153      +/-   ##
==========================================
- Coverage   55.34%   54.12%   -1.22%     
==========================================
  Files         165      166       +1     
  Lines        9708     9747      +39     
==========================================
- Hits         5373     5276      -97     
- Misses       4335     4471     +136     
Flag Coverage Δ
symmetry 17.53% <40.00%> (-1.31%) ⬇️
unittests 51.44% <86.00%> (-1.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stevevanhooser
stevevanhooser merged commit 75b4a08 into main Nov 23, 2026
8 checks passed
@stevevanhooser
stevevanhooser deleted the claude/blosc-ensuremex-path-recheck branch November 23, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants