Skip to content
Merged
9 changes: 7 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ releases daily, of which Orcapod uses two attributes that are not public API
To move the pin: change it there, run `uv lock`, and run the conformance tests live
(`tests/test_databases/test_spiraldb_connector_integration.py`, see its docstring). A refusal or a
value that changed is a change of `tests/test_databases/fake_spiral_sdk.py` (its `RULES`) first.
From 0.16.79 spiral-sdk warns on every keyed-table open; Orcapod's connector ignores that one
message for its own opens (`spiraldb_connector._ignore_keyed_table_deprecation`), and
`tests/test_databases/test_spiraldb_keyed_table_deprecation.py` fails if a new release changes
the message, the category or the module it is attributed to. The move off keyed tables is
ITL-1846.

### Migrating a SpiralDB dataset from pyspiral

Expand All @@ -358,12 +363,12 @@ uv run --no-project --isolated --python 3.12 \

uv run --no-project --isolated --python 3.12 \
--with "orcapod[spiraldb] @ git+https://github.com/metamorphic-labs/orcapod-python@<new>" \
--with spiral-sdk==0.16.74 scripts/migrate_spiral_schemas.py \
--with spiral-sdk==0.16.80 scripts/migrate_spiral_schemas.py \
write --project <project> --dataset <dataset> --plan plan.json --digest <printed digest>

uv run --no-project --isolated --python 3.12 \
--with "orcapod[spiraldb] @ git+https://github.com/metamorphic-labs/orcapod-python@<new>" \
--with spiral-sdk==0.16.74 scripts/migrate_spiral_schemas.py \
--with spiral-sdk==0.16.80 scripts/migrate_spiral_schemas.py \
verify --project <project> --dataset <dataset> --plan plan.json
```

Expand Down
16 changes: 16 additions & 0 deletions changelog.d/ITL-1837.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### Changed

- The `spiraldb` extra pins `spiral-sdk==0.16.80` (was `0.16.74`), a release that reads
and writes a SpiralDB table's own metadata. spiral-sdk 0.16.79 and later mark the keyed
tables Orcapod reads as deprecated and warn on every open; Orcapod ignores that one
warning for its own opens only, so a direct call to spiral-sdk still warns. The move to
spiral-sdk's newer table format is ITL-1846. Orcapod still only reads SpiralDB.
(ITL-1837)

### Known limitations

- Orcapod cannot yet use SpiralDB as a job's database: `SpiralDBConnector` still refuses
every write. The groundwork for it (the encoding of a stored table's columns and the
identity record kept in a table's metadata) is internal and its format is provisional:
outside the 0.4.0 freeze, it may change before the store is offered, and tables written
in it may then need to be written again. (ITL-1837)
139 changes: 139 additions & 0 deletions docs/dev/plans/2026-12-01-itl-1837-spiral-store-stage-a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# ITL-1837: SpiralDB store, stage A (dependency, identity record, codec)

Stage A of using SpiralDB as a job's pipeline and result database (ITL-1446). It carries
the still-valid parts of PRs 589 (ITL-1495) and 590 (ITL-1497) onto current `main`, and the
manifest-in-metadata part of PR 595 (ITL-1498). Those branches were sources to copy from;
none is merged. Nothing here is public: no way to open a store exists, and
`SpiralDBConnector` still refuses every write (`SpiralDBWriteNotSupportedError`).

## The store format is provisional

Everything this stage defines about what a store table holds is **provisional**: outside
the 0.4.0 freeze, free to change until the store is switched on (a later stage, with a
developer decision). That covers the identity record's keys and values, the manifest's
header and chunking, the codec's physical encoding and its name escape. Both markers say
so: the identity record's format is `orcapod.spiral_store.draft`
(`spiral_store_identity.STORE_FORMAT`), the manifest's `orcapod.spiral_store.draft`
version 0 (`spiral_store.MANIFEST_FORMAT`). When the format is fixed it gets a new marker,
and what to do with draft tables is decided then. No golden value pins any of it.

## 1. spiral-sdk 0.16.80

Table metadata arrives in two steps: `KeyedTable.get_metadata` first appears in 0.16.76,
and `set_metadata` in 0.16.77 (neither is in 0.16.74 or 0.16.75). The table metadata, the
type rules and the entry limits were measured live with 0.16.78 (2026-11-26). Compared with
`main`'s 0.16.74, the Python layer changes only those two methods (and the generated service
schemas); the snapshot pinning (`keyed_table_by_id(..., asof=)`), projection
(`scan(columns=)`) and key ranges `main` uses are untouched.

The pin is 0.16.80 (2026-12-01), the newest release, at the developer's request: the newest
SDK, provided the keyed-table deprecation can be silenced in a targeted way. 0.16.79 marks
keyed tables deprecated: `Client.keyed_table`, `keyed_table_by_id` and
`Project.create_keyed_table` each call `warn("Keyed tables are deprecated.",
DeprecationWarning, stacklevel=3)`, so the warning is attributed to the module that calls
the SDK. 0.16.80 changes nothing else Orcapod uses (it removes the duration types, which
the store already refuses). Orcapod's only module that opens or creates keyed tables is
`orcapod.databases.spiraldb_connector` (the schema migration script opens and creates
through its helpers `_open_keyed_table` and `_create_keyed_table`); before each open or
creation it puts one filter FIRST in the filter list: action `ignore`, that exact message,
`DeprecationWarning`, and that module only (`_ignore_keyed_table_deprecation`). First, not
merely present, because the first matching filter wins: a filter added after an earlier
open (`simplefilter("error")`, `pytest.warns`, a recording `catch_warnings`) would
otherwise rank ahead of it. `filterwarnings` removes the older copy before inserting, so
the list never grows. A user's own call to the SDK, another message and another category
still warn. It is installed before each open, not once at import, because a
`warnings.catch_warnings` block (pytest wraps every test in one) drops a filter added
inside it, and it uses no `catch_warnings` itself, which is not safe with threads.
`tests/test_databases/test_spiraldb_keyed_table_deprecation.py` checks both sides with the
real SDK client over a stub native client, and the fake SDK warns as 0.16.80 does (rule
`deprecated`). Not tested: Python 3.14's context-aware warnings (the default of the
free-threaded build), where `catch_warnings` filters are context-local; CI covers Python
3.11 to 3.13 only.

The live conformance run on 0.16.80 (2026-12-01, as the agent workload, in the
conformance dataset of the test project) found one measured rule change: a keyed-table
write of a `duration[s]` column, which 0.16.78 refused, is accepted and read back with the
same unit and value (the same case run again with 0.16.78 is still refused, so the change
comes with the SDK, not the service). The fake follows 0.16.80 (rule `unsupported`), the
refusal test no longer lists durations, and
`test_a_duration_is_stored_and_read_back_as_given` checks the read-back. The store codec
still refuses durations: whether it stores them is ITL-1852. `main`'s CI keeps the 0.16.78
rules until this pin merges. Side effect of the run: the existing fixed table
`store_codec_refusals` got a new version at 2026-12-01 23:41:50 UTC with a new column
`d: duration[s]` and one row (`k = "r0"`, one second), and the read-back check wrote that
same row again at 23:44:22 UTC. No table was created. A SpiralDB source over a duration
column reads it as any source does: the Arrow type is kept and the Python type is `Any`;
no test pins it.

Keyed tables are on their way out; their replacement (Tables, with branches and commits)
has no primary key and no table metadata. The move is ITL-1846. The conformance tests ran
live on 0.16.80 before the pin moved.

The bump is a dependency change for the developer to approve; it is one commit of its own
(`pyproject.toml`, `uv.lock`, `RELEASING.md`, the filter and its tests).

## 2. The fake's table metadata

`tests/test_databases/fake_spiral_sdk.py`, rule `table-metadata` (measured live with
0.16.78 on 2026-11-26): bytes by text key; an upsert that never deletes (an empty value is
stored); not versioned (every snapshot, `asof` included, sees the latest; a metadata write
makes no snapshot); readable before any row; a key over 255 UTF-8 bytes, or a key and value
together over 8,192 bytes, is refused with status 400 and nothing is written. Upserts of
different keys from two clients are all kept, and a reader never sees a half-written file.

## 3. The identity record

`src/orcapod/databases/spiral_store_identity.py`, on `main`'s shared rule
(`store_table_names.py`, ITL-1552): the table name is
`store_table_name(path, hint_length=96, digest_length=64)`. The label
`SPIRAL_TABLE_NAME_LABEL` stays defined there only, and no golden group is added (PR 589's
`spiral_table_name` group is not carried over); `test_store_table_names.py` keeps the test
vector.

The table's metadata records, as four entries: the store format, the full path (compact
UTF-8 JSON array), the layout (the path's last component) and the data context of the
writer that created it. A table whose record is partial, of another format, unreadable, or
of another path than the one looked up raises `SpiralStoreTableCollisionError`; a table with
none of the entries is unmarked (`None`), for the caller to judge.

## 4. The codec

`src/orcapod/databases/spiral_store.py` (pure; no client), from PR 590 with PR 595's
manifest functions. Names (`encode_name`), types (`physical_schema`, `encode_rows`,
`decode_rows`), refusals before anything is written (`REFUSALS`), and the manifest: the
record path, the kind, the logical schema and the stored names at every depth, as one
payload (`manifest_bytes`) cut into metadata entries of at most 8,000 bytes
(`manifest_entries`) under a header naming the format, version, chunk count and a SHA-256 of
the payload (`payload_digest`; renamed from PR 595's `sha256` key, which the hash label rule
reads as a label literal). A header names exactly its chunks, so chunks of an earlier,
longer manifest are never read.

`main`'s type matrix gained four rows after PR 590 (ITL-1372): a live logical type in a
struct child, a list item and a map value, and in dictionary values. The codec refuses all
four, naming the column: it records a logical type only on a whole column, and a dictionary
is an encoding it refuses. They are now listed as expected refusals; the four rows and the
round trip of every other row in one manifest pass.

### Measured live with spiral-sdk 0.16.78 (2026-11-26, throwaway tables; PR 590)

| What | Result |
|---|---|
| booleans, integers (`uint64` max), floats (signed zeros and NaN payloads, `float16` too), `decimal128/256`, `date32`, `date64` off midnight, `null` | kept bit for bit |
| timestamps of every unit, with and without a zone, every `int64` value | kept bit for bit: written as they are |
| `time32` / `time64` within a day | kept; outside one day the whole write is refused, so times are written as integers |
| `decimal32/64` | come back as `decimal128`: written as such, restored |
| strings, binaries, lists | come back in their small variants: normalized on read |
| struct fields | sorted by name at the top level (not inside a list): restored by name |
| map `keys_sorted` | dropped: restored from the manifest |
| a null fixed-size list of structs | kept |
| a null struct item inside a list | kept by the service; refused by the codec, which does not carry a struct's validity yet |
| a null struct at the top level, an empty struct, `fixed_size_binary`, `duration`, `interval` | refused |
| column and struct field names | refused: a `__` or `$` prefix, any `.`, exactly `*`, the empty name; NUL is cut silently. The codec's escape covers each |
| a write of no rows | publishes nothing; a key-only write is refused |

## What is left (later stages of ITL-1446)

Store mode in `SpiralDBConnector` and `ConnectorArrowDatabase` (create on first write, find
by name, the identity and manifest checks, data-context checks, listing for stale layouts),
the write rules of ITL-1386 for the store, the one-writer lease, the public switch-on with
save and load, and every table kind end to end.
1 change: 1 addition & 0 deletions docs/reference/hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ test session with `-p tests.test_hashing.hash_site_trace`.
| user-class identity | a class's identity record | SHA-256 hex prefix | extension name `name@<fingerprint>` (a name) | `logical_types/user_class_identity.py:identity_string` |
| database registry key | a database config, canonical JSON | SHA-256 hex, 8 digits | `db_<hex>` key in a saved job (a name) | `pipeline/serialization.py:DatabaseRegistry._make_key` |
| SpiralDB schema table digest | the scope and the rows of a dataset's schema table, canonical JSON with the stored schema bytes | SHA-256 hex | completion marker of the schema table (a checksum of stored rows) | `databases/spiraldb_schema_table.py:rows_digest` |
| SpiralDB store manifest checksum | a store table's manifest payload (record path and Arrow schemas, canonical JSON); the store is provisional | SHA-256 hex | the manifest header's check of its chunks in the table's metadata (a checksum of a stored record) | `databases/spiral_store.py:_checksum` |
| Connector store table name | the full store path, as a compact UTF-8 JSON array of path components | SHA-256 hex, `spiral_table_name_v1` (`SPIRAL_TABLE_NAME_LABEL`) | the bare hexadecimal suffix in a table name, with a length set by the backend | `databases/store_table_names.py:store_table_digest` |
| synthesized struct class name | the field signature | MD5 hex, 8 digits | a Python class name (a name) | (not reached by a traced test) `semantic_types/universal_converter.py` |
| random ids | nothing | `uuid4`, `uuid7` | run ids, datagram and record uuids, observer ids, correlation keys | (not hashes) |
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ postgresql = ["psycopg[binary]>=3.1.17"]
spiraldb = [
# Exact: a pre-alpha that releases daily, and Orcapod reads two attributes that are
# not its public API (ITL-1186). How to move it: RELEASING.md.
"spiral-sdk==0.16.74",
"spiral-sdk==0.16.80",
]
# Convenience extra that installs PyTorch. Orcapod's torch.Tensor support depends only on
# torch being importable, however it was installed (ITL-871). 2.6 is the first version whose
Expand Down
19 changes: 15 additions & 4 deletions scripts/migrate_spiral_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ def require_unchanged(
rows: list[Any],
) -> None:
"""Refuse unless every table of the dataset is as the plan found it."""
from orcapod.databases.spiraldb_connector import _list_keyed_tables
from orcapod.databases.spiraldb_connector import (
_list_keyed_tables,
_open_keyed_table,
)
from orcapod.databases.spiraldb_schema_table import (
compared_columns,
describe_difference,
Expand All @@ -358,8 +361,10 @@ def require_unchanged(
f"{sorted(set(names) ^ set(planned))}"
)
for table, row in zip(tables, rows):
handle = client.keyed_table(project, dataset, row.table_name)
handle = _open_keyed_table(client, project, dataset, row.table_name)
where = f"{dataset}/{row.table_name}"
if handle is None:
raise MigrationError(f"{where} was removed since it was listed")
if handle.resource_id != row.table_id:
raise MigrationError(f"{where} is another table than in the dry run")
if int(handle.version_id) != table["row"]["captured_version"]:
Expand Down Expand Up @@ -459,6 +464,7 @@ def write(args: argparse.Namespace) -> None:
import pyarrow as pa

from orcapod.databases import spiraldb_schema_table as st
from orcapod.databases.spiraldb_connector import _create_keyed_table

plan = read_plan(args.plan)
require_scope(plan, args)
Expand Down Expand Up @@ -499,8 +505,13 @@ def put(dataset: str, values: dict[str, Any]) -> None:
# Created once, exclusively; the note is there before and after.
write_note(args, dataset, CREATING)
try:
handle = client.project(project).create_keyed_table(
dataset, SCHEMA_TABLE, st.KEY_SCHEMA, exist_ok=False
handle = _create_keyed_table(
client,
project,
dataset,
SCHEMA_TABLE,
st.KEY_SCHEMA,
exist_ok=False,
)
except Exception as exc:
if "status 409" not in str(exc):
Expand Down
Loading
Loading