Skip to content

Architecture, transactions, and recovery

biomero-schema owns only portable contracts. biomero-shallower owns NGFF discovery, ISCC-BIO filesystem identity and transactional shallowing. biomero-importer.utils.result_zarr exports the shared implementation for existing callers; its identity subclass keeps the OMERO reader adapter in the importer. Registration planning and managed-source resolution retain their established semantics.

biomero acquires a versioned SIF through its image runner and starts a CPU job. biomero-scripts selects the stage only when shallow storage and compatible importer capabilities are enabled. Within that enabled feature, remote shallowing is preferred unless the administrator selects the local path with BIOMERO_REMOTE_SHALLOW_ZARR=false. It runs before ZIP creation. The import order carries receipts read from completed event-sourced shallower tasks, rather than trusting a batch file found in a workflow archive.

Transaction

  1. Acquire a kernel file lock for the returned store; recover any earlier intent.
  2. Resolve input markers or artifact names and compare the returned root format with the canonical snapshot. If no compatible source remains, retain the full result without field discovery or pixel hashing. Otherwise discover nodes and choose run-bound output interpretation, the independent workflow policy, or selected-resolution pixel comparison with semantic guards. Only comparison reads original pixels; label handling remains independent.
  3. Save original image attributes and every planned move in a durable sibling .STORE.biomero-prune-TOKEN/journal.json before moving arrays.
  4. Move duplicate image arrays and inherited label trees into that sibling journal on the same filesystem. Retained trees are never copied.
  5. Write shallow metadata and the operation report, and validate the complete reference inventory and retained label structure.
  6. Persist the committed journal state, then unlink the arrays replaced by source references under the recorded decision basis.

An exception before commit restores arrays and original attributes. A killed process leaves durable intent: on resume, uncommitted intent is rolled back; committed intent only finishes cleanup.

Cleanup order is a safety property. Every journal write is atomic (stage as journal.json.tmp, fsync, rename, sync the directory). Cleanup deletes the rollback folder's arrays first, syncs the folder, and removes journal.json last, then the folder itself. A kill at any step therefore leaves either a journal that recover completes, or a folder that holds only an unfinished journal write and is removed as empty. remove_rollback refuses a folder whose journal is uncommitted; those arrays go back through recover. Recovery after a rollback restores the arrays, then the saved attributes, then deletes the shallow manifest and report. A valid committed report can be reused without generating identities again. The canonical store is never mutated or mounted by the Slurm helper. Returned symlink trees are rejected.

The completed workflow must have stopped writing its output before this stage. POSIX locks, atomic rename, and fsync on the mounted filesystem are required. The helper does not claim durability on filesystems that ignore these primitives. Never remove a prune journal to free space: it may contain the only remaining copy of a pre-commit array.

A shallow result is deliberately not a valid OME-Zarr until it is reconstructed: the duplicate arrays and the multiscales metadata are removed, so generic readers fail instead of showing pixels. Keeping the metadata and dropping only the chunk files would pass validators, but readers would silently return blank images and a shallow result could be treated as a canonical input. That variant is deferred to the RFC-8 work in BIOMERO.shallower#36. See Why BIOMERO shallows results for the rationale.

Slurm events and detached resume

The _SLURM_Remote_Shallower task records its configured image/version and input directory. TaskCreated/TaskAdded/TaskStarted precede submission; JobIdAdded is saved immediately after the remote submission ledger returns. TaskCompleted stores the validated batch report. Workflow progress projections ignore this internal task; analytics still retain its provenance.

The remote submission ledger sits outside archived output under .biomero-shallower/TASK/. flock serializes submission. A saved job ID is adopted. An intent without an ID is reconciled through the unique task job name in sacct; an empty or ambiguous accounting result blocks retrieval rather than submitting another job. Retry once accounting is available. Operators can reconcile a proven job ID into the ledger if accounting retention has expired.

A valid batch report is adopted even if the orchestration process died before recording TaskCompleted. A failed helper launches a CPU recovery job with the same image: interrupted stores roll back and completed stores retain receipts. Only after recovery completes can the mixed full/shallow output be archived. Unresolved submission, unknown scheduler state, or failed rollback preserves the output and stops retrieval for safe operator recovery.

Image acquisition failures precede all result mutation and safely fall back to the existing full-result transfer. The only supported policy is keep-full; there is no new strict scientific-result policy.

Trust and portability

Managed storage root IDs, relative paths, generations, and canonical pixel identities travel unchanged from workflow input tracking. OMERO-side registration resolves them using its authoritative local storage mappings. Slurm paths are only operational job parameters, never portable source references.

The importer requires administrator enablement and matching configured image and package versions. It checks the receipt's report SHA-256, canonical snapshot, task/job, manifest equality, reference membership, and retained structure. User renaming after transfer can bind through the unchanged report checksum. It does not hash pixel chunks again. SHA-256 here binds small metadata; it is not a cryptographic signature or a pixel integrity scan.

This assumes trusted BIOMERO orchestration, its event store and import-order writers, configured container images, and the Slurm account/filesystem. Workflows must not forge reserved .biomero-* metadata. It is not an attestation protocol against a malicious workflow sharing that account. Deployments requiring that threat model need isolated ownership and signed receipts before enabling it.

The report formats and receipt compatibility rules are documented in BIOMERO Schema. For deployment flags and image initialization, use the NL-BIOMERO administration guide.

The archive extension point is after shallower completion and before zip_data_on_slurm_server; a later archive adapter can replace ZIP independently.

Adding a contract adapter

Add versioned models to biomero-schema, then a filesystem adapter with parity, rollback, and import-validation tests. Dispatch it from operations.ADAPTERS and expose its version in the CLI. Contract 1 selects the NGFF 0.4 / Zarr v2 or NGFF 0.5 / Zarr v3 adapter from the returned store's metadata. The schema contract documentation explains why its portable graph is not currently written as RFC-8 metadata.

The v3 adapter updates zarr.json while preserving its envelope and unrelated attributes. Array directories, including encoded shards, use the same move, journal, rollback and commit mechanism as v2. Reconstruction keeps the canonical format and creates the matching labels-group metadata. It does not convert existing v2 stores. V2-only callers can retain the read_zarr_v2_semantic_guard API; v3-capable callers use read_zarr_semantic_guard and record its actual interchange profile.

Stores with consolidated v3 metadata, unsupported NGFF versions, mixed-format image/label trees, or a different canonical format remain full. Rewriting consolidated metadata and converting retained components across formats are outside this adapter's scope.

For renamed results without an input marker or matching artifact name, identity matching considers only canonical inputs of the same format. An explicit marker or artifact binding to a different format retains the full result, even when another compatible input exists. Ambiguous artifact names still retain full results. These checks skip equality work; ordinary safety checks, transfer and import still run.

Prerelease schema-1 migration

Schema-1 shallow stores are upgraded only through the explicit one-time command; normal readers do not silently reinterpret them:

biomero-shallower migrate-v1 --returned-zarr /results/result.ome.zarr

The migration validates the complete old manifest, creates deterministic graph node IDs, separates graph nodes from storage bindings, rewrites the embedded operation report and image-node metadata, and keeps an adjacent rollback copy. It rejects older manifests that lack the label-component identities required by schema 2. Because the report checksum changes, migrate only settled data, not an artifact covered by an in-flight remote receipt.

The filesystem-only command intentionally has no OMERO dependency. Complete BIOMERO deployments provide the administrator script BIOMERO Migrate Shallow Storage, which discovers schema-1 MapAnnotations, validates their storage targets, upgrades each store once, and updates all linked OMERO projections. It defaults to a dry run and writes recovery snapshots when applied.

Python API

These filesystem interfaces are shared with BIOMERO.importer. They do not accept OMERO connections.

biomero_shallower.operations

Version-dispatched normalization and cheap receipt validation.

normalize(root, manifest, *, contract=DEFAULT_CONTRACT, identity_workers=1, failure_policy=KEEP_FULL_POLICY, image=None, task_id=None, identity_provider=None, measure_bytes=False, storage_roots=None)

Shallow one returned store, or keep it full, and return the operation report.

Recovers any interrupted prune first and reuses an already committed report, so rerunning after an interruption is safe.

Parameters:

Name Type Description Default
root str | Path

The returned store to normalize.

required
manifest CanonicalInputManifest

The canonical input snapshot of the run.

required
contract int

The contract version selecting the adapter.

DEFAULT_CONTRACT
identity_workers int

Number of pixel identity workers.

1
failure_policy str

What to do on failure; only keep-full is supported.

KEEP_FULL_POLICY
image str

The helper image recorded in the report.

None
task_id str

The task identifier recorded in the report.

None
identity_provider Any

Pixel identity provider override.

None
measure_bytes bool

Whether to record the bytes before and after normalization.

False
storage_roots Any

Storage roots used to resolve canonical sources.

None

Returns:

Name Type Description
ShallowOperationReport ShallowOperationReport

The operation report of the (possibly reused) result.

Raises:

Type Description
ValueError

If the contract version or failure policy is unknown, the store is or contains a symlink, or a shallow result has no committed trusted report.

validate_report(root, manifest, *, image=None, tool_version=None, artifact=None)

Check a committed operation report against its run and the stored result.

Verifies the canonical snapshot, artifact, helper image and version, and, for a normalized result, that the stored shallow manifest, image metadata and label inventory match the report. Cheap: no pixels are read.

Parameters:

Name Type Description Default
root str | Path

The returned store holding the committed report.

required
manifest CanonicalInputManifest

The canonical input snapshot of the run.

required
image str

The expected helper image; not checked when None.

None
tool_version str

The expected helper version; not checked when None.

None
artifact str

The expected artifact name; defaults to the store directory name.

None

Returns:

Name Type Description
ShallowOperationReport ShallowOperationReport

The validated report.

Raises:

Type Description
ValueError

On any mismatch between the report, the run and the store.

The importer decides after a failed prune whether it had committed, and how to classify a keep-full reason, with these helpers instead of reading the journal layout itself:

biomero_shallower.transaction

Durable intent journal for same-filesystem moves; no retained-tree copies.

A prune moves duplicate arrays into a sibling rollback folder and records its intent in journal.json there. Cleanup deletes the journal last, so an interrupted prune always leaves a journal that recover can finish or undo.

PruneJournal dataclass

The recorded intent of one prune: arrays moved, attributes saved, commit state.

Attributes:

Name Type Description
committed bool

Whether the prune committed (only cleanup remains).

moves tuple[str, ...]

Store-relative paths of the arrays moved out.

attrs dict[str, str]

Store-relative metadata file paths mapped to their original bytes, base64-encoded.

rollback Path

The rollback folder holding the journal.

from_dict(document, rollback) classmethod

Parse a journal.json document, rejecting unknown or malformed ones.

Parameters:

Name Type Description Default
document dict[str, Any]

The parsed journal.json content.

required
rollback Path

The rollback folder the document was read from.

required

Returns:

Name Type Description
PruneJournal PruneJournal

The parsed journal.

Raises:

Type Description
ValueError

If the schema version is unknown or the document is malformed.

to_dict()

Return the journal.json document.

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The JSON-serialisable journal document.

pending_prune_journals(root)

Return the journals of prunes of root that are not yet cleaned up.

Folders without a journal are skipped; this never modifies anything.

Parameters:

Name Type Description Default
root str | Path

The store root.

required

Returns:

Type Description
list[PruneJournal]

list[PruneJournal]: The journals found beside root.

Raises:

Type Description
ValueError

If a rollback folder holds a malformed journal.

prune_was_committed(root)

Whether a prune of root committed: the shallow manifest exists and no pending journal is uncommitted.

Committed journals only await cleanup. An uncommitted journal means the prune is unfinished and recover will roll it back, so this is False.

Parameters:

Name Type Description Default
root str | Path

The store root.

required

Returns:

Name Type Description
bool bool

True if the prune committed.

Raises:

Type Description
ValueError

If a rollback folder holds a malformed journal.

recover(root)

Finish or undo every interrupted prune of root.

An uncommitted prune is rolled back; a committed one only has its rollback folder removed. Safe to rerun after an interruption at any step.

Parameters:

Name Type Description Default
root str | Path

The store root.

required

Raises:

Type Description
ValueError

If a journal is malformed, a rollback folder is incomplete or recovery paths conflict.

remove_rollback(rollback)

Delete the rollback folder of a committed prune, journal last.

Refuses a folder whose journal is uncommitted: its arrays may be the only copy and must go back through recover.

Parameters:

Name Type Description Default
rollback str | Path

The rollback folder to delete.

required

Raises:

Type Description
ValueError

If the journal is uncommitted, or unreadable.

biomero_shallower.evaluation

Decide whether a returned store's pixels may be replaced by canonical references.

Evaluation only reads: it never deletes, rewrites or registers anything, so a caller can always keep every result full when discovery or identity matching is incomplete. Each decision is logged with its reason.

The steps of evaluate_returned_zarr raise _KeepFull with the reason when they cannot go on; the public function turns it into a keep-full decision.

ReturnedZarrDecision dataclass

Keep-only result of comparing one returned store with workflow inputs.

Attributes:

Name Type Description
store_path Path

The returned Zarr store that was evaluated.

outcome Outcome

eligible, keep-full or skip-passthrough.

reason str

Why the outcome was reached.

image_identities tuple[PixelIdentity, ...]

The identities of the returned image nodes.

label_identities tuple[PixelIdentity, ...]

The identities of the returned label nodes.

label_components tuple[ZarrLabelComponent, ...]

The returned labels, each with the input source it is identical to, if any.

label_node_paths tuple[str, ...]

The node paths of the returned labels.

matched_inputs tuple[CanonicalInput, ...]

The canonical input the store matches.

decision_basis DecisionBasis

How the input was established.

refreshed_inputs tuple[CanonicalInput, ...]

The inputs whose sources were refreshed during the evaluation.

eligible property

Whether the store may be pruned.

unchanged_passthrough property

Whether the store is an unchanged passthrough of its input.

is_failure_reason(reason)

Whether a keep-full reason reports a failure, unsupported layout or untrusted input.

Reasons such as pixels-changed or no-input-identity-match are expected outcomes and return False.

Parameters:

Name Type Description Default
reason str

The reason of a keep-full decision, possibly with a : <detail> suffix.

required

Returns:

Name Type Description
bool bool

True when the reason is one of FAILURE_REASON_PREFIXES.