Skip to content

CED reader: detect and diagnose sonpipe/sonpy crashes on .smrx reads - #114

Merged
stevevanhooser merged 3 commits into
mainfrom
claude/ndr-matlab-sonpipe-crashes-o6hnvx
Jul 21, 2026
Merged

stevevanhooser merged 3 commits into
mainfrom
claude/ndr-matlab-sonpipe-crashes-o6hnvx

Conversation

@stevevanhooser

Copy link
Copy Markdown
Contributor

Summary

Reading certain 64-bit CED Spike2 files through the sonpipe bridge crashed CED's
sonpy reader (SIGABRT) with no error surfaced in MATLAB — the reader
returned silently truncated/empty data. This PR makes the CED reader detect such
a crash and turn it into a clear error, and documents how to diagnose it. The
actual crash fix lives in the companion sonpipe PR (VH-Lab/sonpipe#5); this side
is the MATLAB-facing detection and docs.

What changed

  • +ced/+sonpipe/private/invoke_binary.m — captures stderr separately and
    requires the CLI's completion sentinel (sonpipe: wrote N …), checking that
    N matches the bytes captured. A missing sentinel or a count mismatch raises
    sonpipe:crash / sonpipe:truncated naming the exact command, instead of
    returning short data. This holds even when an intermediate arch -x86_64
    wrapper (Apple Silicon) masks the child's non-zero exit status.
  • +ced/+sonpipe/private/invoke_text.m — captures stderr to its own file so
    a warning or crash text can no longer corrupt the JSON passed to jsondecode,
    and surfaces it on failure.
  • +ndr/+setup/sonpipe.m — adds a Troubleshooting section documenting the
    SONPIPE_LOG breadcrumb log (setenv('SONPIPE_LOG','1')) for pinpointing a
    crashing sonpy call, the natural discovery point for MATLAB users.
  • tools/tests/.../fake_sonpipe.py — the self-contained test double now
    emits the same completion sentinel as the real CLI, so the unit tests exercise
    the new contract.

Why

sonpy aborts inside its compiled binary, which a MATLAB try/catch cannot
intercept. The reader previously trusted the child process's exit status alone;
across the Apple-Silicon wrapper a signal death could look like success, so bad
data flowed back with no error. Validating the CLI's own completion sentinel
makes a mid-read crash impossible to miss.

Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01C1UYvbvczg9QvqKg8YNr4k


Generated by Claude Code

tmp = [tempname() '.bin'];
cleaner = onCleanup(@() deletefile(tmp));
errfile = [tempname() '.err'];
cleaner = onCleanup(@() deletefile(tmp)); %#ok<NASGU>
cleaner = onCleanup(@() deletefile(tmp));
errfile = [tempname() '.err'];
cleaner = onCleanup(@() deletefile(tmp)); %#ok<NASGU>
cleanerErr = onCleanup(@() deletefile(errfile)); %#ok<NASGU>
'Could not read sonpipe output file: %s', tmp);
end
closer = onCleanup(@() fclose(fid));
closer = onCleanup(@() fclose(fid)); %#ok<NASGU>
exe = ndr.format.ced.sonpipe.executable();
cmd = [exe ' ' args];
errfile = [tempname() '.err'];
cleanerErr = onCleanup(@() deletefile(errfile)); %#ok<NASGU>
@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

199 tests  ±0   196 ✅ ±0   9s ⏱️ +2s
 29 suites ±0     3 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 9642092. ± Comparison against base commit 3202053.

♻️ This comment has been updated with latest results.

claude added 2 commits July 21, 2026 21:07
CED's sonpy (used to read 64-bit .smrx files via the sonpipe bridge) can
fail an internal C++ assertion and abort() (SIGABRT) on certain
files/channels. That kills the reader process mid-stream; previously the
MATLAB layer could return silently truncated or empty data with no error,
because it trusted the process exit status alone -- unreliable when the
Apple Silicon 'arch -x86_64' wrapper masks a signal death as exit 0.

invoke_binary now captures stderr separately and requires the CLI's
completion sentinel ("sonpipe: wrote N ..."); a missing sentinel or a
count that does not match the captured bytes raises sonpipe:crash /
sonpipe:truncated naming the exact command, instead of returning short
data. invoke_text captures stderr to its own file so a warning or crash
text can no longer corrupt the JSON passed to jsondecode, and surfaces it
on failure. The doc notes point users at SONPIPE_LOG for breadcrumb
logging that pinpoints the crashing sonpy call.

The self-contained fake_sonpipe.py test double now emits the same
completion sentinel as the real CLI so the unit tests exercise the new
contract.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C1UYvbvczg9QvqKg8YNr4k
Add a Troubleshooting section to the ndr.setup.sonpipe help text pointing
users at the SONPIPE_LOG breadcrumb log for diagnosing a sonpy crash
while reading a CED file, and noting that the reader now surfaces a
mid-read abort as a sonpipe:crash/sonpipe:truncated error. This is the
natural discovery point for NDR/MATLAB users, who invoke sonpipe
indirectly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01C1UYvbvczg9QvqKg8YNr4k
@stevevanhooser
stevevanhooser force-pushed the claude/ndr-matlab-sonpipe-crashes-o6hnvx branch from 66e8a79 to 9642092 Compare July 21, 2026 21:08
@stevevanhooser
stevevanhooser merged commit 18d74b0 into main Jul 21, 2026
@stevevanhooser
stevevanhooser deleted the claude/ndr-matlab-sonpipe-crashes-o6hnvx branch July 21, 2026 21:14
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.

3 participants