Skip to content

fix(dicom): preserve slices across incremental imports - #935

Merged
PaulHax merged 1 commit into
mainfrom
dicom-chunk-index
Sep 4, 2026
Merged

fix(dicom): preserve slices across incremental imports#935
PaulHax merged 1 commit into
mainfrom
dicom-chunk-index

Conversation

@PaulHax

@PaulHax PaulHax commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Builds on #934, which is now merged.

Summary

Importing more files for an already open DICOM series reallocates and re-sorts the volume. The old path could lose loaded pixels, write an in-flight decode into the wrong slice, or leave newly added chunks unloaded.

This change preserves existing slices across reallocation and keeps decode results tied to the current buffer and chunk order.

Import flow

incoming chunks
    |
    v
load metadata and remove duplicates
    |
    +-- no new chunks -------------------> no-op
    |
    v
serialize additions and sort the combined chunk list
    |
    v
allocate the new buffer
    |
    v
redecode loaded chunks and start new chunks
    |
    +-- stale decode result -------------> discard
    +-- current decode fails ------------> mark that chunk errored
    +-- current decode succeeds ---------> write its current slice

What changed

Reallocation

Before:

  1. New chunks were appended.
  2. The volume was sorted and reallocated.
  3. Previously loaded slices became zeroes, but their status stayed Loaded.
  4. A decode that started before the sort could write using its old slice index.

Now:

  1. Chunk additions are serialized so overlapping additions cannot drop chunks.
  2. Loaded chunks are marked Loading and decoded into the new buffer.
  3. A decode resolves its slice from the current chunk order.
  4. Results from an older allocation generation are discarded.
  5. An already registered image starts loading chunks added by a re-import.

Tests

Coverage includes serialized additions, sorted slice placement, stale decode success and failure, loading state during reallocation, and starting newly added chunks.

@netlify

netlify Bot commented Sep 2, 2026

Copy link
Copy Markdown

Deploy Preview for volview-dev ready!

Name Link
🔨 Latest commit 6a2c30f
🔍 Latest deploy log https://app.netlify.com/projects/volview-dev/deploys/6a9b4a07882a4f0008f5ee99
😎 Deploy Preview https://deploy-preview-935--volview-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Base automatically changed from dicom-volume-buffer to main September 4, 2026 22:44
Adding chunks to an existing DICOM image re-sorts the list and reallocates
the volume buffer. Slices already decoded were zeroed by the reallocation
and never rewritten while their status still said Loaded. A decode in
flight across that reallocation wrote through the slot it captured before
the sort, so its pixels or its error could land on another chunk's slice.
Two overlapping additions each awaited a sort of the shared list, and the
sort that settled last won, dropping the newer call's chunks. The image
cache also starts a load only when it first registers an image, so chunks
added on a re-import were allocated for but never asked to load.

Redecode every chunk that holds data after a reallocation and report those
slices as Loading until the rewrite lands. Resolve a chunk's slot after its
decode settles, and discard any result from a previous allocation
generation, so completion order cannot overwrite current state. Address
failures by chunk rather than by captured index. Serialize additions
through a promise queue. Ask an already-registered image to start loading
after a re-import adds to it.
@PaulHax
PaulHax force-pushed the dicom-chunk-index branch 2 times, most recently from 7c45b63 to 6a2c30f Compare September 4, 2026 22:45
@PaulHax
PaulHax added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit 6c6cead Sep 4, 2026
8 checks passed
@PaulHax
PaulHax deleted the dicom-chunk-index branch September 4, 2026 23:01
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.

1 participant