Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
0a5f001
feat(spiraldb): present Vortex-encoded columns as entry references (I…
eywalker Nov 30, 2026
425d7a1
fix(spiraldb): address review of the encoded-column references (ITL-1…
eywalker Nov 30, 2026
3bdae57
feat(spiraldb): hash entry references by content and fetch entries in…
eywalker Dec 2, 2026
96c8ae4
Merge origin/main into eywalker/itl-1789-spiraldb-source-a-table-with…
eywalker Dec 2, 2026
05c0502
docs(api): list SpiralDBEntryMissingError in the errors reference (IT…
eywalker Dec 2, 2026
6f629f3
fix(spiraldb): address review of entry hashing and batched fetches (I…
eywalker Dec 2, 2026
ea10790
fix(spiraldb): keep fetched entries only under the sign-in still curr…
eywalker Dec 2, 2026
fd64224
fix(spiraldb): charge held values their overhead; prefetch holds no v…
eywalker Dec 2, 2026
4ce0a09
fix(spiraldb): address the independent review of entry references (IT…
eywalker Dec 2, 2026
f559ef7
test(spiraldb): make the async order checks hold under parallel CI (I…
eywalker Dec 2, 2026
513d036
fix(spiraldb): address CodeRabbit's review of 4ce0a09 (ITL-1789)
eywalker Dec 2, 2026
836fb1f
fix(spiraldb): reset reference state in a forked child (ITL-1789)
eywalker Dec 2, 2026
b4a1c3a
fix(spiraldb): address the delta review and CodeRabbit's review of 83…
eywalker Dec 2, 2026
c92e1c6
fix(spiraldb): bind a nested batch to its first process; scope the as…
eywalker Dec 2, 2026
b271b70
Merge remote-tracking branch 'origin/main' into eywalker/itl-1789-spi…
eywalker Dec 3, 2026
9905e20
fix(spiraldb): address CodeRabbit's review of b271b70 (ITL-1789)
eywalker Dec 3, 2026
614552d
fix(spiraldb): address CodeRabbit's review of 9905e20 (ITL-1789)
eywalker Dec 3, 2026
629cf51
Merge remote-tracking branch 'origin/main' into eywalker/itl-1789-spi…
eywalker Dec 3, 2026
7089f1f
fix(spiraldb): address CodeRabbit review of 629cf51 (ITL-1789)
eywalker Dec 3, 2026
1e627fc
fix(spiraldb): address the delta review of 7089f1f (ITL-1789)
eywalker Dec 3, 2026
bcd4f10
fix(spiraldb): address CodeRabbit review of 1e627fc (ITL-1789)
eywalker Dec 3, 2026
74be83f
test(pipeline): compare an async load-only trace in the order the run…
eywalker Dec 3, 2026
42e404f
chore(merge): bring origin/main into SpiralDB entry references
eywalker Dec 3, 2026
d8da4e1
fix(pipeline): preserve async result hash errors during crash reporting
eywalker Dec 3, 2026
a3d48aa
fix(pipeline): validate held outputs before exposing cached results
eywalker Dec 3, 2026
705e1c7
fix(pipeline): preserve fail-fast errors when crash observers raise
eywalker Dec 3, 2026
8b70f7f
fix(pipeline): preserve fail-fast missing input errors
eywalker Dec 3, 2026
ea5d5dd
chore(merge): bring origin/main into SpiralDB entry references
eywalker Dec 3, 2026
0730bed
test(pipeline): check async fail-fast storage guarantees
eywalker Dec 3, 2026
edb0f48
fix(spiraldb): preserve reference schema and recording guarantees
eywalker Dec 3, 2026
722387d
fix(spiraldb): address encoded source review findings
eywalker Dec 3, 2026
f606a23
fix(pipeline): report failed rows when finishing a batch aborts
eywalker Dec 4, 2026
0b592d8
fix(pipeline): finish held sync results after observer errors
eywalker Dec 4, 2026
344374f
chore: merge main into the SpiralDB source branch
eywalker Dec 4, 2026
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
75 changes: 75 additions & 0 deletions changelog.d/ITL-1789.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
### Added

- `orcapod.SpiralDBEntry`, a reference to one entry of a SpiralDB table: the table's id,
the version read, the row's primary-key values, the column and the address of the
SpiralDB service (never a credential). Its logical type is `orcapod.spiraldb.entry`,
hashed by the content of the entry it names (label `spiraldb_entry_v1`), so an entry
that is the same in two table versions hashes alike. A function pod can reuse a stored
result after the source's pin moves when its other cache-key inputs also match.
`entry.read()` returns the entry as a
one-row `pyarrow.Table` from the version it names, and `entry.scan()` returns
spiral-sdk's scan of that one key and column. Both take an optional `client`; without
one they connect to the recorded service address with spiral-sdk's own sign-in, only
when this process reached that address through a `SpiralDBConnector` or SpiralDB
source it built (or its parent did, for a forked process); `SpiralDBEntry.prefetch`
refuses any other address the same way. The table `read()` returns is the caller's own.
- A job reads the entries a function node is about to hash together: one SpiralDB scan
per table version for the rows the node takes at once (at most 256 when an
asynchronous run executes; a load-only run takes its whole input), never one per row, and hashes
those rows from that batch; the references a function returns are read the same way
before its results are recorded (on the synchronous path one row at a time under
`fail_fast` or for a function that takes an invocation context to deliver side effects;
the asynchronous path reads the results that have arrived together, up to
256, before it raises). A reference that
names a missing entry fails its row; any other error reading one stops the run. Entries
read are also kept in a cache for the process, per sign-in (up to a million hashes and
512 MiB of values); a read through a given `client` neither uses nor fills it, and
computes no hash.
- `orcapod.errors.SpiralDBUntrustedServiceError` (a `PermissionError`), raised before any
client is made when a reference names a service address this process did not reach
through a connector or source it built.
- `orcapod.errors.SpiralDBEntryMissingError` (a `LookupError`), raised when the version a
reference names holds no row with its key, or the table or exactly that version can no
longer be opened. In a job it fails that input row under the node's error policy.

### Changed

- `ReadableChannel.take_ready(max_items)` is a required member of the channel protocol:
it returns the items already waiting, up to `max_items`, without waiting. A custom
readable channel must implement it (returning `[]` is allowed). The record-batch
input protocol has it too.

### Fixed

- `SpiralDBTableSource` no longer refuses a table that stores a column in a Vortex
encoding (such as `vortex.turboquant`), at the top level or as a struct field. Such a
column is presented as a column of `SpiralDBEntry` references with the same name and
position, and the scan does not read it. A struct column with an encoded field becomes
one reference to the whole struct column. Every other column reads as from the same
table without the encoded columns. An encoded column cannot be a tag or key column.
Orcapod checks the schema record when it prepares a snapshot and raises
`TableSchemaError` if the record's Vortex encoding metadata disagrees with the
service. Scans on an existing handle reuse that handle's prepared snapshot.
- When an observer fails on the next input of a synchronous batch, earlier results
are recorded and can still be loaded. If finishing the batch also fails, the
remaining held rows are reported as crashed and the original error propagates.

### Known limitations

- A source over `SpiralDBEntry` references built from in-memory data (`ArrowTableSource`,
`DictSource`, `ListSource` and the like), also references inside a list, has no
default source id, since the default would read every entry: it must be given a
`source_id`.
- A `SpiralDBEntry` is supported only as a column's type or inside `list[...]` there. As
a field of a user class (a dataclass, a pydantic model or an `orcapod.dataclass`, at
any depth) it is refused where the class is declared (`NestedTypeNotStorableError`),
and inside an Arrow struct or map column when the source is built
(`InputValidationError`).
- `read()` never falls back to a newer version when the recorded one is gone: it raises
`SpiralDBEntryMissingError` (ITL-1872).
- A cached result that names a missing entry stays stored, so the row keeps failing
on subsequent runs until that result is removed.
- `orcapod.spiraldb.entry` is provisional: its value hash and stored identity may change
in a later release, and using it issues `ProvisionalHashWarning`.
- Other stored extension types that are not Vortex encodings are still refused with
`InputValidationError`.
4 changes: 4 additions & 0 deletions docs/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ These exceptions and warnings report storage, schema, and connector problems.

::: orcapod.errors.SpiralDBSignInError

::: orcapod.errors.SpiralDBEntryMissingError

::: orcapod.errors.SpiralDBUntrustedServiceError

## Feature availability and stability

These exceptions and warnings report optional dependencies and features still in development.
Expand Down
4 changes: 4 additions & 0 deletions docs/api/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ Core type definitions used throughout Orcapod.

::: orcapod.enable_file_hash_caching

## SpiralDB entries

::: orcapod.SpiralDBEntry

## Custom types and extensions

::: orcapod.dataclass
Expand Down
7 changes: 5 additions & 2 deletions docs/concepts/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ for tag, data in scale.pod(source):

The value hashes and stored identities of the library value types are provisional in v0.3:
`numpy.ndarray`, `torch.Tensor`, and the pandas and polars `DataFrame` and `Series`. They are
provisional until the library value type audit (after 0.4.0rc1) and may change then. Every other type, and the hashing of everything
else in a pipeline, is unaffected.
provisional until the library value type audit (after 0.4.0rc1) and may change then. So are
references to SpiralDB entries, `orcapod.SpiralDBEntry` (see
[Columns stored in a Vortex encoding](sources.md#columns-stored-in-a-vortex-encoding)), and the
same warning names them, `orcapod.spiraldb.entry`. Every other type, and the hashing of
everything else in a pipeline, is unaffected.

Using one of these types issues `orcapod.errors.ProvisionalHashWarning` once per type per
process, on whichever use comes first: a value hashed, a source column of the type, a function
Expand Down
170 changes: 169 additions & 1 deletion docs/concepts/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,8 @@ whose schema is known without a scan.
#### The schema of a Spiral table

SpiralDB reports every column as nullable, key columns included, and every field of a struct
column too, whatever nullability the data was written with; and it keeps no Arrow metadata.
column too, whatever nullability the data was written with; and it keeps no Arrow metadata
(except a Vortex encoding's, see [below](#columns-stored-in-a-vortex-encoding)).
Orcapod therefore reads each table with a schema that is recorded in one more table of its
dataset, `__orcapod_schemas__`: a row per table, with its column names, types, nullability at
every depth and metadata. The name is reserved, and listings leave it out.
Expand Down Expand Up @@ -1092,6 +1093,173 @@ which spiral-sdk does not read. Until their dataset is migrated they read as not
schema that release read it with, so schemas, hashes and source ids stay the same
([the steps](https://github.com/metamorphic-labs/orcapod-python/blob/main/RELEASING.md#migrating-a-spiraldb-dataset-from-pyspiral)).

#### Columns stored in a Vortex encoding

SpiralDB can store a column in an encoding of its own, such as `vortex.turboquant`, a lossy
quantized form of a float vector. SpiralDB reports such a column with its encoding's Arrow
extension name and parameters on the field, at the top level or on a field of a struct
column. Orcapod does not decode such a value, and does not copy it. It presents the column
as **references** to its entries, one per row:

- The column keeps its name and position, and its type is `orcapod.SpiralDBEntry` (Arrow
extension `orcapod.spiraldb.entry`), never null. A struct column with an encoded field
becomes one reference column: the reference names the whole struct column, because
Orcapod puts no logical type inside a struct field.
- A reference names exactly one entry: the table's id (`table_id`), the version the source
read (`version`, the snapshot SpiralDB resolved the source's `pinned_version` to), the
row's primary-key values (`key`, the canonical JSON of the key columns in key order, the
form of a record ID), the column (`column`) and the address of the SpiralDB service the source read from (`service`, such
as `https://spiral.example.invalid`; never a credential). The entry it names may itself
hold a null.
- The scan does not read the encoded columns. Every other column, and every record ID, is
read exactly as from the same table without them.
- `entry.read()` returns the entry: a `pyarrow.Table` of one row and one column, the value
as SpiralDB stores it, with its encoding's extension name and parameters on the field.
It reads the table by its id at exactly the reference's version, so it returns the same
value whenever it is called. While the process still holds an entry it hashed or read
(a value is held up to a budget of 512 MiB, least recently used first), it is not read
again; otherwise it is read again at that version. The table returned is yours:
changing it changes nothing the process holds. `entry.scan()` returns spiral-sdk's
own scan of that one key and that one column, to use the SDK's functions on it. Both
take an optional `client` (a `spiral.Client`); without one they connect to the
reference's service address and sign in as spiral-sdk does (the `SPIRAL_*` environment
variables, or a saved `spiral login`), and never ask a person to sign in. A read through
a given `client` always goes to SpiralDB and computes no hash, and entries are held per
sign-in.
- A reference's service address is data, and can name any host. Without a `client`,
Orcapod signs in only to an address this process reached through a `SpiralDBConnector`
or a SpiralDB source it built (compared without regard to the case of the scheme and
host, a default port or a trailing `/`). Reading, scanning or hashing a reference to
any other address raises `orcapod.errors.SpiralDBUntrustedServiceError` before a client
is made or a credential taken (`SpiralDBEntry.prefetch` included): build a source of
that service first, or pass a client of it (`entry.read(client=...)`). A process forked
from one that reached an address trusts it too, as the same program with the same
credentials, but holds none of its parent's clients or entries. The address check controls
where Orcapod uses the worker's sign-in. Accept references only from producers you trust
to select data the worker can read, including the table, version, key, and column.
- When the version no longer holds a row with the key, or the table or that exact
version no longer exists, `entry.read()` raises `orcapod.errors.SpiralDBEntryMissingError`
(a `LookupError`) naming the reference; a newer version is never read in its place.
`entry.scan()` raises it only when the table or the version does not exist: the scan
is lazy, and for a key the version does not hold it yields no row, which its caller
must handle. A failure to reach the service or to sign in is not a missing entry: it
is raised as itself, by `read()`, `scan()` and hashing alike.
- A function pod over the source receives `SpiralDBEntry` objects, and can return one: it is
stored as the reference. An encoded column cannot be a tag or key column, and `where`
cannot name it.

<!-- docs-test: skip -->
```python
import orcapod as op
from orcapod import function_pod
from orcapod.sources import SpiralDBTableSource

# The encoded cells and their block_0, norms, and count fields must be non-null.
# "rate" is a nullable plain column.
items = SpiralDBTableSource("my-project-123456", "items")


@function_pod(output_keys=("first_norm", "count"))
def summarize(
vector: op.SpiralDBEntry, embeddings: op.SpiralDBEntry, rate: float | None
) -> tuple[float, int]:
vector_value = vector.read().column("vector")[0].as_py()
embedding_value = embeddings.read().column("embeddings")[0].as_py()
if vector_value is None:
raise ValueError("vector must be non-null")
if embedding_value is None:
raise ValueError("embeddings must be non-null")
block = vector_value["block_0"]
if block is None:
raise ValueError("vector.block_0 must be non-null")
norm = block["norms"]
if norm is None:
raise ValueError("vector.block_0.norms must be non-null")
count = embedding_value["count"]
if count is None:
raise ValueError("embeddings.count must be non-null")
return norm * (1.0 if rate is None else rate), count


summaries = summarize.pod(items.select_data_columns(["vector", "embeddings", "rate"]))
```

This sample needs a SpiralDB service. The test suite runs it against a fake SpiralDB
(`test_the_documented_sample_runs` in
`tests/test_core/sources/test_spiraldb_table_source_encoded.py`).

**A reference is hashed by its entry's content.** The hash of a reference is the hash of
the entry it names (its value, bit for bit, and its encoding's extension name and
parameters), not of the reference's fields. When a run's check (`check_for_new_data()`)
pins a newer table version, unchanged entry content keeps the same hash. The function pod
can reuse a stored result when all inputs used for cache lookup also match, including plain
inputs such as `rate`. References with equal content can reuse a result across different
keys, versions, or columns. If the result depends on a locator field such as `entry.key`,
pass that locator field as a separate plain input so it participates in cache lookup.
Hashing needs the content, so a job first reads the entries it is
about to hash, together: one SpiralDB scan per table version for the rows a function node
takes at once (all its input rows on the synchronous path and in a load-only run,
`run(load_only=True)`, on either path; when an asynchronous run executes, the rows that
have arrived, at most 256 at a time, so 257 rows waiting in one version take two scans,
of 256 and 1 keys), and hashes those rows from what that scan read. The
bound is per function-node batch, not per batch a source reads. The references a
function returns are read the same way before its results are recorded (each result's
hash is part of its record): one scan per table version for the results a node holds at
once. Synchronous runs can hold up to 256 results under `continue`. Under `fail_fast`
or for a function that takes an invocation context to deliver side effects, a synchronous
run finishes one row before computing the next. An asynchronous run reads up to 256
results that have arrived under either policy. Under `fail_fast`, this can include
results computed beside a failing one. A row is reported as ended only
once its result is hashed and recorded. A node whose inputs hold no reference takes its
rows one by one, as before. The entries read also stay in a cache for the process, per sign-in (up to a
million hashes and 256 MiB charged for them, and 512 MiB of values, least recently used
first; each charged its key, its missing reason or its bytes with their field metadata).
An entry that is no longer held is read again on its own, at its version, when it is
hashed outside such a batch or read; when the process's sign-in cannot be told apart,
nothing is kept after the batch. Building the source, a plain read (`as_table()`, `iter_data()`), `head()` and
the preview read no entry; a read that asks for row hashes
(`as_table(columns={"content_hash": True})`) hashes the references, and so reads their
entries.

Entries are kept per sign-in as Orcapod sees it when a read starts and ends: the
environment and the saved login. What a batch read serves only that sign-in: after a
change, an entry is read again under the new one. A kept entry is served without asking
the service again (a table version never changes), so a change of permissions under the
same sign-in is not seen while the process keeps it. Changing the sign-in while reads run in other threads of
the same process is not supported: spiral-sdk does not say which sign-in a client used, so
a read that saw the sign-in change and change back could keep what it read under the
earlier one.

In a job, an entry that cannot be read (`SpiralDBEntryMissingError`) fails its own input
row, under the node's error policy (`continue` records it and goes on; `fail_fast` stops
the run); so does a returned reference whose entry cannot be read. Any other error (a
failed scan, a refused service address, a reference to a column the table's version does
not have, which concerns that reference only) stops the run, whatever the policy: for an input,
at the first row whose hash needs that entry, with the column named; for a returned
reference, at the row whose result names it. The run keeps results recorded before it
stops. On the asynchronous path, results reach the recorder in arrival order, so an
earlier input row can still be computing when a later row stops the run.

**A source over references needs a source id.** A source built from a table, rows or
Python values that hold `SpiralDBEntry` references (an `ArrowTableSource`, `DictSource`,
`ListSource` and the like), also inside a list, has no default source id, because the
default hashes every value, which would read every entry: give it a `source_id`. The error
names the columns.

**A reference lives in a column of its own.** A `SpiralDBEntry` is supported as a column's
type, and inside `list[...]` there. It is refused anywhere else: as a field of a dataclass,
a pydantic model or an `orcapod.dataclass` (at any depth, also in a list field), raised
where the class is declared for a source or a function pod
(`NestedTypeNotStorableError`, a `ValueError`); as a dict key or value or a tuple field,
as any logical type there; and inside an Arrow struct or map column, raised when the source
is built (`InputValidationError`). A class is stored and hashed as its fields are stored,
so a reference inside one would be hashed by its fields, not by its entry's content.

References are [provisional](arrays.md#provisional-value-hashes): their value hash and stored
identity may change in a later release, and using them issues `ProvisionalHashWarning`. Any
other stored extension type that is not a Vortex encoding is still refused when the source
is built (`InputValidationError`).

### `CachedSource`: a record id names one row

A `CachedSource` (`source.cached(cache_database=...)`) keeps every row its wrapped source
Expand Down
Loading
Loading