Omics-OSDocs
Guides

Re-run an exported notebook: lobster replay --verify

Run an exported Lobster AI notebook again and compare the files it writes with the files the session saved, with verdicts and exit codes.

lobster replay --verify runs a notebook exported from a Lobster AI session again and compares the files it writes with the files the session saved. It ships in Lobster AI 1.3.0.

What it does not do

Compares what the notebook writes against what the session saved, and detects changes it can see; it does not prove how the outputs were computed.

  • A notebook is your own code, run with your permissions. Lobster AI does not stop it from writing anywhere. It checks afterwards whether data/, the input file and the notebook itself changed, and if they did, it does not answer MATCH.
  • Only .h5ad and .h5mu outputs are compared. Other files the replay wrote are listed, not compared.
  • The check covers the notebook's code cells and the files they write. A change to the notebook's markdown text alone is not a change it can see.
  • A plot cell reports "ran without error; figure not compared". The replay checks that the cell ran, not what the figure shows.
  • A MATCH is about the files the session saved and the export recorded. It says nothing about whether the analysis was the right one.
  • lobster replay runs the notebook's code. The check before the run refuses known unsafe forms; it is not a complete barrier. Replay only notebooks you trust.
  • The check before the run reads only file paths written as text in the notebook's cells, so a path the notebook builds while it runs is not checked, nor a link it creates while it runs. It looks for a list of known ways to run a command, and other ways to run commands or code exist.
  • Running an exported notebook yourself, outside lobster replay (for example in Jupyter), writes to the paths it names, which can be the session's own files, such as its export file. Run it on a copy of the session's folder.

Usage

# Re-run a notebook and compare its output
lobster replay --verify my_analysis.ipynb --input pbmc.h5ad

# Name the workspace as well
lobster replay --verify my_analysis.ipynb --input pbmc.h5ad -w ./.lobster_workspace

# Machine-readable result, with a longer limit per cell
lobster replay --verify my_analysis.ipynb --input pbmc.h5ad --json --timeout 7200

For the notebook of a run made through lobster mcp --stdio, pass the run folder (the output_dir of the run) as the workspace: lobster replay --verify <run folder>/lobster_run.ipynb -w <run folder> --input <the run's input file>. Without -w, the replay looks in the project's .lobster_workspace, not in the run's. See Lobster AI as an MCP server.

OptionMeaning
--verify <notebook>The exported notebook to re-run. Required.
--input <file>The data file the session started from (.h5ad). Required, except for a notebook that starts from a single GEO dataset download (see below). Without it the replay stops before running anything, with exit code 2 and Give the notebook's input file with --input.
--policy <file>Comparison policy as a JSON file. Default: exact values, without the session's own provenance and lineage records. With a policy of your own, equal outputs answer MATCH_CUSTOM_POLICY (exit 6), never plain MATCH.
--workspace, -wWorkspace directory. Default: ./.lobster_workspace.
--jsonPrint the result as JSON.
--timeout <seconds>Time limit per cell. A cell that runs longer stops the check. Default: 3600. 0 means no limit.

The replay runs in its own folder, <workspace>/replays/<id>/, where <id> is 16 random hex characters. The folder holds executed.ipynb, the files the notebook wrote (out_<name>.h5ad) and replay_report.json. The notebook starts in that folder, so a file it writes with a relative path lands there. A custom-code cell writes its outputs there too (exports/ included), and a replay does not write into the session's workspace.

Verdicts and exit codes

Exit codeVerdictMeaning
0MATCHEvery saved file was compared or was the replay's own input, every reference still has the bytes recorded when the session saved it, and the notebook changed no data file in the workspace.
1MISMATCHA compared output differs from the file the session saved, under the default policy. This is reported only when the input is tied to the data the session loaded. If it is not, the answer is NOT_COMPARED, even when outputs differ.
2(usage error)The command was called wrongly: for example an unknown option, a notebook or input file that was not found, or a --policy file that could not be read.
3NOT_COMPAREDNothing could be compared. See below.
4REFUSEDThe check saw something that must not happen, or the check itself failed. See below.
5NOTEBOOK_FAILEDThe notebook failed to run, including a cell that ran longer than --timeout.
6MATCH_CUSTOM_POLICYThe outputs are equal only under a custom --policy. This is never reported as a plain MATCH.
130(interrupted)The command was interrupted.

Gate on the exit code in scripts and CI.

What is compared

The notebook's save cell writes out_<name>.h5ad. It is compared with the session's <name>.h5ad, found in the workspace's data/ folder or in the workspace root. The session's own bookkeeping records (uns/provenance and uns/lineage) are left out by the default policy, because a notebook does not write them.

1.3.0 stores an unnamed index unnamed and keeps empty settings, as a file written directly by anndata would. Files saved by earlier versions still load. If the session was saved before 1.3.0, lobster replay --verify can report uns/log1p/base as a difference: run the analysis again in 1.3.0 or later before verifying.

Sessions from Lobster 1.2

A session that Lobster 1.2 wrote can be exported as a notebook in 1.3. The session is called migrated: the cells are rebuilt from its record, and the record does not name the input file the session read.

  • The header of the notebook says: "Migrated from a Lobster 1.2.2 session: the cells were rebuilt from its record; the input file the session read was not recorded." The version is the one in the record. When the record names none, the header says "Lobster session of unknown version".
  • Custom code from the old session is shown as text and never run. A note above it says: "Not executed: custom code from a Lobster 1.2.2 session (it may use paths of the machine it ran on)".
  • Links that point nowhere. When links in the workspace point to files that are missing, the notebook header and pipeline export both say: "Links in the workspace that point to missing files: NAMES (restore or remove before replay)." (NAMES is the list of link names)
  • Replay of a migrated notebook answers NOT_COMPARED, exit code 3. It is a comparison per file, not a verdict. The console prints "migrated: input not recorded. Per file, not a verdict:" and then one line, NAME: RESULT, for each file. With --json, the report has migrated, with label (migrated: input not recorded) and files.
  • Custom-code cells in a migrated replay. From 1.3.1, the replay adds a note for each custom-code cell: Cell {n}: custom code from an earlier session is shown, not run. Files it changed are compared without its changes, and files only it wrote are not listed. This also covers notebooks exported by 1.3.0.
  • Migrated sessions run the code their version recorded. Steps recorded with a defect that 1.3 fixed (pseudobulk on sparse data) fail on replay.
  • Sessions that Lobster 1.3 wrote are not migrated. They carry record_format: "lobster-1.3" in their metadata.json.

What the notebook runs, and known limits

  • The notebook writes every file the session saved, at the point the session saved it. A step runs on the data it read when the session branched or assessed quality again. A step that does not record which data it read (for example annotation, differential expression or plots) runs on the result of the cells above; the notebook says so where it matters.
  • Writer. The notebook saves its output with the same writer the session uses. When Lobster is not importable in the notebook's kernel, the notebook writes the file plainly and prints one line: "Written without the session writer (lobster not importable); the saved file may differ from the session's."
  • An input that is not an h5ad file (for example a CSV the session loaded through its adapter) is accepted. From 1.3.1, so is a bulk count table imported from a plain CSV or TSV: give the table with --input, and the import step reads it as the session did; a later count table import in the same notebook reads its own file. The replay says "The input is not an h5ad file: its shape and columns were not checked." A file the session's adapter cannot read fails the notebook (NOTEBOOK_FAILED); a different file it can read is REFUSED. Neither is a match.
  • A GEO session where the model did not save the imported data itself replays to MATCH when its outputs match. The import's auto-save is listed as "Saved copy of the input, not compared". The same listing appears when the model saves the imported data before the download step has finished: the notebook has no cell for that save, and the answer is still MATCH when the outputs match.
  • Tiny or degenerate data. Data with fewer independent dimensions than the principal components requested can give a MISMATCH on PCA in the last digits. The replay reports it and does not hide it.
  • Custom-code cells. A replayed custom-code cell reads the notebook's own results, not the session's files, and writes its outputs into the replay's folder. It reads them through anndata, scanpy (read_h5ad/read) and h5py only. A cell that reads a workspace file by a relative path (data/…, raw/…) through pandas, open() or numpy is not refused: the replay stops when that cell runs (NOTEBOOK_FAILED, exit code 5) and names the file only in the error. A cell that reads or runs on a dataset made by a step the notebook cannot name stops the replay with custom code reads <name>, which this notebook does not compute (or custom code runs on <name>, …). This happens for sessions recorded before 1.3.0 that use bulk gene filtering, bulk differential expression results, or proteomics and metabolomics analysis results, and for drug-discovery combination scoring.
  • Custom code that loads data. When a session loaded its data through custom code (for example, several 10x folders combined by the model), a custom-code cell that reads a file outside the replay's folder by its absolute path, in the workspace or elsewhere on this computer, is refused before the run (REFUSED, exit code 4), and the report names the file. To replay with the input checked and named, load data with Lobster's import (a GEO accession or a single file).
  • A load step that reads a file by path. A notebook whose load step names a file outside the replay's folder that exists on this computer is refused, unless it is the file given with --input; nothing is run and that file is not opened. For a file outside the workspace, the message says: Code cell {n} uses the path {path}, outside this replay's folder; a replay reads only its own folder and the file given with --input. If this is the notebook's input file, give it with --input. The notebook was not run. For a file in the workspace it says: Code cell {n} reads or writes {path} in the workspace; a replay uses only its own folder. The notebook was not run. A replay reads the file given with --input where it is: a cell that names it and writes files is refused before anything runs, but a custom-code cell or a hand-edited cell that changes it in a way Lobster does not recognise is caught only after the run.
  • 10x .h5 files. A session cannot load a 10x .h5 file in this version ("Pandas HDF loading is not supported."); a notebook whose recorded load step uses such a file fails in its load cell.
  • Sessions that cannot be verified.
    • A notebook with a sample concatenation or a cross-platform concordance step is refused before it runs (REFUSED, exit code 4): This notebook has steps that read two or more modalities (step N: <tool>), and a replay starts from one input; it was not run. The exported notebook marks the step "Not replayed". In 1.3.0 the replay stopped at that step instead (NOTEBOOK_FAILED, exit code 5).
    • A session that merged a sample sheet (merge_sample_metadata) cannot be checked: the replay refuses the notebook (REFUSED) and names the sheet. The exported notebook keeps the sheet's path, never its content.
    • Proteomics and metabolomics steps other than quality control, filtering, normalization and imputation (for example PLS-DA or OPLS-DA) have not been checked on replay; they can stop (NOTEBOOK_FAILED) or differ (MISMATCH). The check never reports a false MATCH for them.
  • Fixed in 1.3.1. From 1.3.1 these replay to MATCH when their outputs match: notebooks from sessions that ran the Wilcoxon or t-test method on bulk counts or pseudobulk data, also with a later differential expression step on the same data; sessions that build pseudobulk profiles from single-cell data; sessions that imported a plain CSV or TSV count table, with the table given as --input; proteomics sessions with quality control, filtering, normalization and imputation; and metabolomics sessions with quality control, filtering, imputation and normalization.
  • The same differential expression comparison run again in a new session in the same workspace keeps the earlier result file from 1.3.1: a save never overwrites a file the session loaded, so the new result is stored under a name ending in _2, and the reply names it. In 1.3.0 the earlier file was rewritten, and a replay of the earlier session's notebook then answered REFUSED ("The saved file changed after the session").
  • Replay when no Lobster session is writing in that workspace. A replay that sees another workspace file change answers REFUSED and names the file. If a Lobster session is using that workspace, close it, or replay with -w pointing at a copy of the workspace, and run the replay again.
  • Files in other replay folders are not watched: a notebook that writes into another replay's folder is not refused.

When the answer is NOT_COMPARED

The replay must start from the file the session loaded. Lobster AI records that file's SHA-256 and size when it loads it. Since 1.3.0, a session can reach MATCH when it loaded its data from a file or from a GEO download.

  • A GEO download is checked against the raw file it saved: the replay starts from the <name>_raw.h5ad the download saved, checks its SHA-256 first and needs no network. --input is optional for such a notebook; given, it must be that file. A changed or missing raw file answers REFUSED.
  • A GEO session continued in a new process (a later MCP run that continues it, or lobster command "pipeline export …" --session-id …) replays to MATCH. The import's raw file and auto-save are kept on the session record with their SHA-256 and are restored only from files that still match. A notebook exported this way names the file the session loaded, so --input is checked against it: the right file can MATCH, a different file is REFUSED ("The input is not a file the session loaded: …").
  • In a project with the catalog on, replay finds the files the session saved, also when the session ran over several processes, including a GEO run: MATCH without --input.
  • Other data loaded in memory instead of from a file cannot be tied to its source in this version. The answer is NOT_COMPARED with the text "In-memory input not anchorable in this version".
  • Notebooks exported before 1.3.0 carry no input record and answer NOT_COMPARED. Export the notebook again. One with a custom-code cell is refused instead (see below).
  • A migrated session (written by Lobster 1.2) answers NOT_COMPARED: see Sessions from Lobster 1.2.

When the answer is REFUSED

  • --input is a file the session saved as a result, or is not the file the session loaded.
  • The raw file of a GEO import is not the file the session imported (its SHA-256 differs), or is not in the workspace.
  • The notebook changed a file it should only read: its input, the notebook itself, anything under data/, or any .h5ad or .h5mu file in the workspace.
  • A saved file no longer holds the bytes recorded at session time.
  • The notebook failed its check before the run and was not run. This includes:
    • a notebook with a custom-code cell exported before 1.3.0 final: "A custom-code cell was exported before 1.3.0 final and reads the session's workspace. Re-export the notebook." Nothing is run;
    • a typed absolute path outside the replay's folder, in a custom-code or template cell; the report names the path;
    • a load step that names a file outside the replay's folder that exists on this computer and is not the --input file;
    • a step that reads two or more modalities (a sample concatenation or a cross-platform concordance step), or a merged sample sheet.
  • The input is the snapshot a resumed session autosaves (data/<name>_autosave.h5ad): from 1.3.1 a resumed session's autosave updates that snapshot, so a replay of an older notebook that started from it answers REFUSED.
  • Another file in the workspace changed while the replay ran (for example, a Lobster session writing there); the message names the file.
  • The check itself failed. The message starts with "The check could not run:".

JSON output

With --json, the command prints exactly one JSON document on stdout. Everything the notebook run prints, the "Interrupted." line and refusal messages go to stderr. The document has these keys:

KeyContent
verdictThe verdict word, for example MATCH.
exit_codeThe exit code of the process.
reportThe replay report.
report_filePath of replay_report.json.
replay_dirPath of the replay folder.
notesExtra lines, as text.

Three cases print a shorter document with only verdict, exit_code and error:

  • a usage error: verdict is null, exit code 2;
  • an interrupt: verdict is null, exit code 130;
  • a check that itself failed: verdict is REFUSED, exit code 4.

A notebook that fails or runs over the time limit prints the full document, with the verdict NOTEBOOK_FAILED and exit code 5.

With the LaminDB catalog

The LaminDB catalog is optional and off by default. With it on, each replay is recorded as its own run of the notebook, linked to the session it replays, with the verdict and the report attached. Its folder is then named after that run: <workspace>/replays/<run_uid>/. A catalog problem is a warning on stderr and never changes the verdict. In a project, the catalog is the project's own: see The LaminDB catalog in a project.

On this page