Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,11 @@ Orcapod pins the hashes it stores or embeds in names in the golden folder of the
its identity, firing rule, stored tables, and downstream hashes are outside the freeze.
Golden cases declare provisional=("FunctionPod with a context argument",).
Ordinary function pods retain their 0.4.0 freeze.
- `PipelineJob.load(read_only=True)` is provisional (ITL-1966). It uses
`utils/provisional.warn_provisional_use` with `record_identity=False`; the load
interface introduces no hash recipe. The view lists every saved label, exposes
stored sources for available nodes, and refuses execution. It skips rebuilding
original sources and never uses stored source rows as current-run output.
- Provisional sources are outside the freeze too (developer, November 21, 2026, ITL-1314:
"make polling source provisional"; ITL-1331: "Let's also make DerivedSource as
provisional?", both forms): `orcapod.sources.PROVISIONAL_SOURCES`
Expand Down
5 changes: 5 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@ Orcapod pins the hashes it stores or embeds in names in the golden folder of the
its identity, firing rule, stored tables, and downstream hashes are outside the freeze.
Golden cases declare `provisional=("FunctionPod with a context argument",)`.
Ordinary function pods retain their 0.4.0 freeze.
- `PipelineJob.load(read_only=True)` is provisional (ITL-1966). It uses
`utils/provisional.warn_provisional_use` with `record_identity=False`; the load
interface introduces no hash recipe. The view lists every saved label, exposes
stored sources for available nodes, and refuses execution. It skips rebuilding
original sources and never uses stored source rows as current-run output.
- Provisional sources are outside the freeze too (developer, November 21, 2026, ITL-1314:
"make polling source provisional"; ITL-1331: "Let's also make DerivedSource as
provisional?", both forms): `orcapod.sources.PROVISIONAL_SOURCES`
Expand Down
7 changes: 7 additions & 0 deletions changelog.d/ITL-1966.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Added

- `PipelineJob.load(..., read_only=True)` provisionally exposes saved function results and cached operator outputs as read-only sources. The view lists every saved node label and explains when stored results are unavailable.

### Known limitations

- Loading a saved job may create a missing local Delta directory (ITL-1967).
2 changes: 2 additions & 0 deletions docs/api/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ blueprint; `PipelineJob` binds a pipeline to sources and a database and runs it.

::: orcapod.pipeline.PipelineJob

::: orcapod.pipeline.SourceOnlyPipelineJob

::: orcapod.pipeline.PipelineDiagram

::: orcapod.pipeline.LoadStatus
Expand Down
36 changes: 36 additions & 0 deletions docs/concepts/pipeline-job.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,42 @@ outside the job over one of its own slots. Build the step from the slot inside
the job, or pass the source itself. A schema-only `SourceNode` declares an
independent slot for each job.

## Inspecting a saved job as sources

Pass `read_only=True` to `PipelineJob.load()` to inspect stored results without the
original function code or source data. This provisional option warns when first used
in a process. The view refuses `run()` and `run_async()`, including load-only runs.
Opening the view and reading from it make no writes to any database table.

```python
from pathlib import Path
from tempfile import TemporaryDirectory

with TemporaryDirectory() as directory:
saved = Path(directory) / "bmi.json"
job.save(saved)
view = PipelineJob.load(saved, database=database, read_only=True)
print(sorted(view.labels))
# ['bmi', 'mice']
print(sorted(view.nodes))
# ['bmi']
print(sorted(view.unavailable))
# ['mice']
print(view.nodes["bmi"].as_table().sort_by("subject_id").to_pylist())
# [{'subject_id': 'mouse_01', 'bmi': 1756.9444444444446}, {'subject_id': 'mouse_02', 'bmi': 2209.9999999999995}]
```

`view.labels` lists every saved label. `view.nodes` holds the stored sources for
function nodes with a saved run key and a result database and operators with an
existing cache. The sources preserve the identity, Arrow schemas, provenance and
row selection of `node.as_source()` and can feed another job.
`view.unavailable` explains excluded labels, such as source slots, functions with
no saved run key and uncached operators. Looking up an excluded label raises
`KeyError` with that reason. A source whose database has no matching rows raises
`RuntimeError` when read.
Pass the original database instance for in-memory results and supply connector
databases explicitly. A saved Delta database can be reopened from its configuration.

## The database

Any Orcapod database can hold a job's results. Two are used most:
Expand Down
78 changes: 78 additions & 0 deletions docs/dev/specs/itl-1966-source-only-load.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Load a saved pipeline job as sources (ITL-1966)

`PipelineJob.load(path, database=None, *, result_database=None, read_only=False)`
keeps the existing `PipelineJob` return type. With `read_only=True` it returns a
separate `SourceOnlyPipelineJob`, exported alongside `PipelineJob`. A separate
class exposes stored sources without the binding and execution interface of a job.

The view exposes `name` as the saved name tuple and `labels` as all saved node
labels in saved order. Its read-only `nodes` mapping contains derived sources for
function nodes with a saved run key and attached result bindings and operators
with an existing cache table. Availability uses saved keys, bindings and table
metadata. Rows are read on demand.
`unavailable` maps excluded labels to reasons, including source slots, side-effect
nodes, functions with no saved run key and operators without a cache. It also
explains when a job name cannot form a default derived source ID. Looking up an
excluded label in `nodes` raises `KeyError` with
`Node '<label>' has no stored results: <reason>`.
An unknown label raises `KeyError(label)`. Reading a present source whose store
has no matching rows raises `RuntimeError` naming the label. Existing schema and
storage validation failures retain their types and identify the affected label.

## Stored reads and execution

Use the saved job's descriptors and database bindings. Share the existing load
validation and database overrides, including separate result databases. In this
mode skip reconstructing original source bindings and operator implementations.
Function nodes already load without their function. Build each supported value
through the same stored-result derivation as the node's `as_source()`. A stored
source uses the saved hash and declared schema for its identity and can feed
another job. Read Arrow field metadata at every depth from the stored schema on
demand, while keeping the saved field declarations and dropping storage annotations.
Preserve provenance, source IDs and the most recent readable row per lineage.
For operator nodes use the existing stored output lookup for the saved run key
and data context. A matching cache works for both LOG and REPLAY. The saved
blueprint does not encode the cache mode, so availability comes from the stored
rows. The saved file format and storage layout stay the same.

`view.run(...)`, `view.run_async(...)` and `view.nodes[label].run()` raise
`RuntimeError("A source-only pipeline job cannot run")`. The view's run methods
also refuse `load_only=True`. Loading and source reads make no writes to any
table in any database. The view and its sources expose no backing node, binding
or execution graph and never install stored rows as current-run output. Loading
can create a missing local Delta directory (ITL-1967).
Normal loaded jobs continue to show their current run on direct node reads.

## Provisional API and repository loading

On constructing the view call `warn_provisional_use` with the feature name
`"PipelineJob source-only load"` and `record_identity=False`. This emits
`ProvisionalHashWarning` once per process for the API, independently of the
existing `DerivedSource` warning and identity rules. List the API with the other
provisional features in `CLAUDE.md` and mirror it in `.zed/rules`.

ITL-1965 can expose `PipelineRepository.load(name, ..., read_only=True)` with
the same return type. After selecting the publication by name and version, it
passes the saved job text, database overrides and `read_only` into the same loader the
file API uses. Publication selects the saved definition. Its results still come
from the databases named by that definition or the supplied overrides.

## Verification

- Through the public loader, compare several function and cached operator
outputs to the original nodes' `as_source()` tables on in-memory, Delta and fake
keyed SpiralDB databases. Exercise unavailable nodes on SQLite, whose connector
cannot store the timestamp in either output layout. Cover LOG and REPLAY, string and tuple job names,
and at least two tag and two data columns. Compare rows with `all_info=True`
and compare Arrow metadata explicitly. Exercise data-tag permutations, multiple
versions of a stored lineage, downstream use on both execution paths and the
result database override.
- Save a job and its expected results, remove its function module and source
data, then load in a fresh subprocess using persistent storage. Compare rows,
provenance values and Arrow metadata. Verify source and operator factories
are skipped, and the database receives no write calls.
- Check all labels are listed, unknown labels raise `KeyError`, unavailable
labels raise with their names, and every exposed `run` entry point refuses.
Check the provisional warning at load time and the normal loader's current-run
behavior. Add an executable example in `docs/concepts/pipeline-job.md` and
`changelog.d/ITL-1966.md` during implementation.
2 changes: 1 addition & 1 deletion docs/reference/hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ test session with `-p tests.test_hashing.hash_site_trace`.
|---|---|
| function `uri` (output-schema digest) | `core/data_function.py:function_output_schema_hash` |
| operator `uri` | `core/operators/static_output_pod.py:StaticOutputOperatorPod.uri` |
| `schema:` / `instance:` / `node:` path components | `core/nodes/function_node.py:FunctionNodeBase.node_identity_path`, `core/nodes/operator_node.py:OperatorNodeBase.node_identity_path`, `side_effects.py:SideEffectJobNode.attach_databases`, `core/sources/cached_source.py:CachedSource._unversioned_cache_path` |
| `schema:` / `instance:` / `node:` path components | `core/nodes/function_node.py:FunctionNodeBase.node_identity_path`, `core/nodes/operator_node.py:OperatorNodeBase._identity_path_from_hashes`, `side_effects.py:SideEffectJobNode.attach_databases`, `core/sources/cached_source.py:CachedSource._unversioned_cache_path` |
| listed function pipeline table's `schema:` and `instance:` components | `core/sources/discovery.py:_pipeline_path`, `core/sources/discovery.py:_pipeline_records_by_node`, `core/sources/discovery.py:_entry` |
| `tag_copies_<hex>` path component for an explicit source cache (semantic hash of the sorted tag-copy pairs) | `core/sources/cached_source.py:CachedSource._cache_table_base_path` |
| implicit source-node slot names for streams with no source name | `core/nodes/source_node.py:slot_name_for` |
Expand Down
3 changes: 2 additions & 1 deletion src/orcapod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
)
from .core.nodes.source_node import SourceNode
from .core.sources.discovery import discover_function_results
from .pipeline import Pipeline, PipelineJob
from .pipeline import Pipeline, PipelineJob, SourceOnlyPipelineJob

# Subpackage re-exports for clean public API
from . import databases # noqa: F401
Expand Down Expand Up @@ -99,6 +99,7 @@
"side_effect_function_pod",
"Pipeline",
"PipelineJob",
"SourceOnlyPipelineJob",
"discover_function_results",
"SourceNode",
"databases",
Expand Down
14 changes: 14 additions & 0 deletions src/orcapod/core/nodes/function_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3798,6 +3798,20 @@ def get_all_records(

return joined if joined.num_rows > 0 else None

def _stored_source_schema(self) -> "pa.Schema | None":
"""Inspect the stored tags' field metadata without fetching function rows."""
if self._pipeline_database is None:
return None
return self._pipeline_database.get_table_schema(self._versioned_pipeline_path)

def _stored_source_unavailable_reason(self) -> str | None:
"""Return why the node cannot present a stored source, without reading rows."""
if self._stored_content_hash is None:
return "no run key was saved for the function"
if self._pipeline_database is None:
return "no pipeline and result database binding is available"
return None

def as_source(
self,
tags_as_data: "Mapping[str, str] | None" = None,
Expand Down
39 changes: 35 additions & 4 deletions src/orcapod/core/nodes/operator_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,16 @@ def node_identity_path(self) -> tuple[str, ...]:
isolated = isolating_identity_hashes()
if not isolated and self._node_identity_path_cache is not None:
return self._node_identity_path_cache
# Hashes inside a path are bare hex digests: a label never enters a name.
path = self._identity_path_from_hashes()
if self._table_scope == "pipeline_hash" and not isolated:
self._node_identity_path_cache = path
return path

def _identity_path_from_hashes(self) -> tuple[str, ...]:
"""Build a table path from the URI, scope and live or saved hashes."""
path = self.node_uri + (f"schema:{self.pipeline_hash().to_hex()}",)
if self._table_scope != "pipeline_hash":
if self._table_scope == "content_hash":
return path + (f"instance:{self.content_hash().to_hex()}",)
if not isolated:
self._node_identity_path_cache = path
return path

@property
Expand Down Expand Up @@ -1160,6 +1164,8 @@ def from_descriptor(
databases: dict[str, Any],
job_content_hash: str | None = None,
expected_row_count: int | None = None,
*,
restore_cache_path: bool = False,
) -> OperatorJobNode:
"""Construct an OperatorJobNode from a serialized descriptor.

Expand All @@ -1184,6 +1190,8 @@ def from_descriptor(
the job was saved, from the job file's optional ``run.expected_rows``;
``None`` when not recorded. Advisory: a read returns what the database
holds and only warns (``OrcapodDatabaseContentWarning``) when it differs.
restore_cache_path: Derive the cache path from saved hashes for a source-only
load that skips reconstructing the operator.

Returns:
A new ``OperatorJobNode`` instance.
Expand Down Expand Up @@ -1281,6 +1289,13 @@ def from_descriptor(
node._table_scope = table_scope
node._node_identity_path_cache = None

if (
restore_cache_path
and not node._stored_pipeline_path
and job_content_hash is not None
):
node._stored_pipeline_path = node._identity_path_from_hashes()

# Determine load status based on DB availability and cache mode.
# An uncached operator (cache_mode=OFF) never writes records to the
# database, so even when a pipeline_db exists there is nothing to
Expand Down Expand Up @@ -2424,6 +2439,22 @@ def get_all_records(
# DerivedSource
# ------------------------------------------------------------------

def _stored_source_schema(self) -> "pa.Schema | None":
"""Inspect stored field metadata without fetching the operator's rows."""
if self._pipeline_database is None:
return None
return self._pipeline_database.get_table_schema(self._stored_table_path)

def _stored_source_unavailable_reason(self) -> str | None:
"""Return why the node cannot present a stored source, without reading rows."""
if self._pipeline_database is None:
return "no pipeline database binding is available"
if self._saved_run_content_hash is None:
return "no cache key was saved for the operator"
if not self._pipeline_database.table_exists(self._stored_table_path):
return "no cache table exists for the saved operator"
return None

def as_source(
self,
tags_as_data: "Mapping[str, str] | None" = None,
Expand Down
Loading
Loading