Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0c518d1
build(deps): spiral-sdk 0.16.78, and table metadata in the fake (ITL-…
eywalker Nov 26, 2026
bf8de9c
feat(databases): short SpiralDB store table names derived from the pa…
eywalker Nov 26, 2026
2bf88ca
fix(databases): review findings on store table names and the fake (IT…
eywalker Nov 26, 2026
6646270
feat(databases): the codec of a SpiralDB store table, on spiral-sdk (…
eywalker Nov 26, 2026
03bbac4
refactor(databases): fewer type warnings in the store codec and its t…
eywalker Nov 26, 2026
548344d
docs(plans): the SpiralDB connector's store mode, proposal (ITL-1498)
eywalker Nov 26, 2026
276b50f
fix(databases): review findings on the store codec and the fake (ITL-…
eywalker Nov 26, 2026
37d659a
Merge branch 'eywalker/itl-1497-spiraldb-store-stage-2-the-codec-of-a…
eywalker Nov 26, 2026
fe4145c
feat(databases): the SpiralDB connector's store mode (ITL-1498)
eywalker Nov 26, 2026
20640ea
docs(scripts): end-to-end evaluation of the SpiralDB store (ITL-1446)
eywalker Nov 26, 2026
d6efbf0
fix(databases): CodeRabbit's review of store table names and the fake…
eywalker Nov 26, 2026
b433047
fix(databases): the fake keeps a column's flag when it cuts nested na…
eywalker Nov 26, 2026
d285e61
Merge branch 'eywalker/itl-1497-spiraldb-store-stage-2-the-codec-of-a…
eywalker Nov 26, 2026
f5b3607
fix(databases): review findings on the SpiralDB store mode (ITL-1498)
eywalker Nov 26, 2026
0a4189c
fix(databases): type-check the store module without the spiraldb extr…
eywalker Nov 26, 2026
3886299
fix(databases): never overwrite another writer's store record; make o…
eywalker Nov 26, 2026
eda6771
fix(databases): CodeRabbit's review of the store codec and the fake (…
eywalker Nov 26, 2026
85f2622
Merge branch 'eywalker/itl-1497-spiraldb-store-stage-2-the-codec-of-a…
eywalker Nov 26, 2026
0dc34c9
fix(databases): CodeRabbit's second round on the store codec and the …
eywalker Nov 26, 2026
2aef2bd
Merge branch 'eywalker/itl-1497-spiraldb-store-stage-2-the-codec-of-a…
eywalker Nov 26, 2026
c43faa0
fix(databases): the fake matches the service on encoded and extension…
eywalker Nov 26, 2026
7a50c9d
fix(databases): equivalent manifests are one; names of bytes kept as …
eywalker Nov 26, 2026
a6a0663
feat(databases): keyed reads, one existence answer and one listing pe…
eywalker Nov 26, 2026
c047e64
fix(databases): store manifests compared by name, never by column ord…
eywalker Nov 26, 2026
4a0e1de
Merge branch 'eywalker/itl-1498-spiraldb-store-stage-3-the-connectors…
eywalker Nov 26, 2026
a236e6c
fix(databases): narrowed reads give exactly the results and errors of…
eywalker Nov 26, 2026
49f1642
fix(databases): a store manifest that cannot be decoded is never equa…
eywalker Nov 26, 2026
eb31844
Merge branch 'eywalker/itl-1498-spiraldb-store-stage-3-the-connectors…
eywalker Nov 26, 2026
2e798c2
fix(databases): no pushdown of equality on unsigned integers (ITL-1502)
eywalker Nov 26, 2026
c890fb3
fix(databases): answer CodeRabbit on PR 595 (ITL-1498)
eywalker Nov 26, 2026
56dd8d3
Merge branch 'eywalker/itl-1498-spiraldb-store-stage-3-the-connectors…
eywalker Nov 26, 2026
5305f70
fix(databases): answer CodeRabbit on PR 599 (ITL-1502)
eywalker Nov 26, 2026
6c71bb2
style(databases): format test_table_names (ITL-1498)
eywalker Nov 26, 2026
cdf45f8
Merge branch 'eywalker/itl-1498-spiraldb-store-stage-3-the-connectors…
eywalker Nov 26, 2026
c36efbe
docs(databases): the draft manifest format is fixed at stage 5, not s…
eywalker Nov 26, 2026
9b5e37c
Merge branch 'eywalker/itl-1498-spiraldb-store-stage-3-the-connectors…
eywalker Nov 26, 2026
f9bb2aa
fix(databases): evaluation result database scoped to its run; the sto…
eywalker Nov 26, 2026
d45e7cf
Merge branch 'eywalker/itl-1498-spiraldb-store-stage-3-the-connectors…
eywalker Nov 26, 2026
4ceb67a
fix(databases): run_scope and read_candidates refuse a closed store c…
eywalker Nov 26, 2026
3a19050
fix(databases): a data context key this Orcapod cannot resolve is ref…
eywalker Nov 26, 2026
80a58d0
fix(databases): rows of another data context than a store table recor…
eywalker Nov 26, 2026
7162dfe
Merge branch 'eywalker/itl-1498-spiraldb-store-stage-3-the-connectors…
eywalker Nov 26, 2026
6d11f4a
fix(databases): an empty data context key, and a table of another dat…
eywalker Nov 26, 2026
8848772
Merge branch 'eywalker/itl-1498-spiraldb-store-stage-3-the-connectors…
eywalker Nov 26, 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
4 changes: 2 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,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.78 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.78 scripts/migrate_spiral_schemas.py \
verify --project <project> --dataset <dataset> --plan plan.json
```

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

- The `spiraldb` extra pins `spiral-sdk==0.16.78` (was `0.16.74`), the release that reads and writes a SpiralDB table's metadata. Orcapod still only reads SpiralDB; the conformance tests pass on the service with it.
4 changes: 4 additions & 0 deletions changelog.d/ITL-1498.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Breaking changes and migration

- `DBConnectorProtocol` has three more required methods: `table_name(path)`, `has_table(table_name)` and `table_paths(prefix, pending)`. `ConnectorArrowDatabase` now asks the connector to name its tables, test their existence and list their paths. SQLite, PostgreSQL and SpiralDB keep the names and listings they had. A connector of your own implements the three methods; `orcapod.databases.table_names` has the rule the built-in connectors use.
- `DBConnectorProtocol.validate_records` takes a required keyword argument, `table_name` (the name `table_name(path)` gave, or `None` for rows checked for no table in particular). `ConnectorArrowDatabase` passes it, so a connector that records something per table checks the rows against that table before they are buffered: a SpiralDB store refuses rows of another data context than the table records. SQLite and PostgreSQL ignore it. A connector of your own adds the argument.
4 changes: 4 additions & 0 deletions changelog.d/ITL-1502.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Breaking changes and migration

- `ArrowDatabaseProtocol` and `DBConnectorProtocol` each have a required `run_scope()`: the scope of one run, which `job.run()`, `run_async()` and a job node's `run()` enter once per database. A database or connector of your own returns an empty scope (`contextlib.nullcontext()`) unless it holds something for a run.
- `DBConnectorProtocol` has a required `read_candidates(table_name, *, keys=None, equal=None)`: the rows a lookup may match, which `ConnectorArrowDatabase` then filters exactly. A connector of your own returns the whole table, as the built-in relational connectors do (`orcapod.databases.table_names.whole_table`).
36 changes: 36 additions & 0 deletions docs/dev/plans/2026-11-26-itl-1495-spiral-store-names.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# ITL-1495: SpiralDB store, stages 0 and 1

Stages 0 and 1 of `docs/dev/specs/itl-1446-round2-spiral-sdk.md` (PR 588), approved by the
coordinator on the developer's behalf (decisions 1, 2, 3, 4 and 6). One pull request.

## Stage 0: spiral-sdk 0.16.78

1. `pyproject.toml`: `spiral-sdk==0.16.78`; `uv lock --upgrade-package spiral-sdk`. The version
in `RELEASING.md`'s migration commands follows.
2. `tests/test_databases/fake_spiral_sdk.py`: `get_metadata` / `set_metadata` on the fake keyed
table, as measured live with 0.16.78 (rule `table-metadata`): an upsert, never a deletion,
not versioned, readable before any row, a key over 255 UTF-8 bytes, or an entry whose key
and value together are over 8,192 bytes, refused with `status 400` and nothing written.
3. Tests first: a conformance test of table metadata in
`tests/test_databases/test_spiraldb_connector_integration.py`, run on the fake always and
live opt-in, with fixed keys so a live table does not grow. The live conformance suite is
rerun with 0.16.78 (`itl-1186-switch.md` section 7: a bump reruns it).

## Stage 1: store table names

`src/orcapod/databases/spiral_store_names.py`, pure, imports no client:

- `SPIRAL_TABLE_NAME_LABEL = "spiral_table_name_v1"`, beside `store_table_digest(path)`: SHA-256
of the canonical JSON array of the full path components, bare hex (a hash in a name).
- `table_name_hint(path)`, `store_table_name(path)` (`o1_<hint>_<digest>`), and
`store_table_name_prefix(prefix)`, the name prefix every table under a path prefix has.
- `store_table_metadata(path, data_context_key)`: the four entries of spec 2.2.
- `classify_store_table(metadata, path)`: this path's table, or an unmarked one (2.5); any other
path, format or a partial record raises `SpiralStoreTableCollisionError`.

Then: the hash site inventory row in `docs/reference/hashing.md` ("in a name"); a golden group
`spiral_table_name` in `tests/test_hashing/golden/cases.py`, written by the generator into a new
file (the diff adds only that file and its history entry). Tests: determinism, the length bound,
the alphabet, prefix property of the hint, injectivity on adversarial paths, refusals.

Nothing calls the module yet; no other hash, stored path or golden value moves.
51 changes: 51 additions & 0 deletions docs/dev/plans/2026-11-26-itl-1497-spiral-store-codec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ITL-1497: the codec of a SpiralDB store table, on spiral-sdk

Stage 2 of `docs/dev/specs/itl-1446-round2-spiral-sdk.md` (PR 588), approved by the
coordinator on the developer's behalf (decision 4). It stacks on PR 589 (ITL-1495: spiral-sdk
0.16.78 and its fake).

## What is carried over from PR 545

`src/orcapod/databases/spiral_store.py` and `tests/test_databases/test_spiral_store.py`, from
PR 545's branch, with these changes:

- **The manifest is one payload**: `manifest_bytes` gives its bytes and `read_manifest_bytes`
reads them back. Kept in a table's metadata, it is `manifest_entries` (the chunks and their
header), read back by `read_manifest`, which takes the table's whole metadata mapping, never
raw payload bytes. Where it is kept is
stage 3's: decision 4 was revised on 2026-11-26 (ITL-1498), and stage 3 keeps it in the
table's own metadata, in chunks of at most 8 KiB (a key and its value together), beside the
identity record (`spiral_store_names`, PR 589). It is not kept in the dataset's schema table,
which is all or nothing under one completion marker. The format stays a draft
(`orcapod.spiral_store.draft`, version 0) while store mode is private: the format and
version are fixed when the store is switched on (stage 5), with a decision then on reading
draft tables (N57).
- **Timestamps are written as they are**, not as integers.
- **A null fixed-size list of structs is kept**, no longer refused.
- Everything else is unchanged: names, types, nullability, refusals before anything is written,
reading by the manifest's stored names, no row order.

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

| 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 (`datetime.max` and `.min` included) | kept bit for bit: **written as they are** (pyspiral's service refused instants after 9999-12-30) |
| `time32` / `time64` within a day | kept; **outside one day: the whole write refused**, so times stay 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** (the refusal is lifted) |
| a null struct item inside a list | kept by the service; still refused by the codec, which does not yet carry a struct's validity (a later lift) |
| 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. Kept: `$`, `*` and `;` inside a name, control characters, case and Unicode normal forms apart, 1,024 characters. NUL is cut silently. The codec's escape rule covers every refusal and NUL, so it is unchanged |
| a write of no rows | publishes nothing; a key-only write is refused |

The fake (`tests/test_databases/fake_spiral_sdk.py`) now refuses the empty name, `*` and times
outside a day as the service does. The conformance tests (`test_spiraldb_connector_integration.py`)
run the codec through spiral-sdk on the fake and live: the rows written are the rows read. They
also check that the service refuses each name and value listed in the refusal test
(`test_what_the_store_codec_avoids_is_refused`). Not every value the codec avoids is refused by
the service: the codec also refuses what the service keeps but the codec cannot yet carry back
(a null struct item inside a list).
89 changes: 89 additions & 0 deletions docs/dev/plans/2026-11-26-itl-1498-spiral-store-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# ITL-1498: the SpiralDB connector's store mode (stage 3)

Stage 3 of `docs/dev/specs/itl-1446-round2-spiral-sdk.md` (PR 588), stacked on PR 590
(ITL-1497, the codec) and PR 589 (ITL-1495, names and metadata). Q1 to Q4 approved as
recommended by the coordinator on the developer's behalf (2026-11-26); Q2 revises decision 4.
Implemented in `databases/table_names.py`, `databases/spiraldb_store_tables.py`, the
connector's `_store` flag, and the chunked manifest of `spiral_store.manifest_entries`.

## What the code does today

- `ConnectorArrowDatabase` owns the path-to-name rule (`_path_to_table_name`: sanitize, join
with `__`), tests existence with `name in connector.get_table_names()`, and lists paths by
splitting names back (`list_table_paths`). A connector sees table names only, never a path.
- Every read is a whole-table read (`SELECT * FROM "<name>"`, then filtered in Arrow); there
is no keyed read.
- `SpiralDBConnector` reads only; every write raises `SpiralDBWriteNotSupportedError`.

## Proposal

**Q1. Naming moves into the connector.** `DBConnectorProtocol` gains three required methods
(protocols are internal, so no optional capability):

- `table_name(path) -> str`: the stored name of the table at a full path;
- `has_table(table_name) -> bool`: whether it exists;
- `table_paths(prefix, pending_names) -> list[path]`: the paths of the stored tables under
`prefix`.

`ConnectorArrowDatabase` calls these instead of its own rule. SQLite, PostgreSQL and a plain
SpiralDB connector implement them with today's rule, moved unchanged into one shared helper,
so nothing they do changes. The other shape, a separate database class for SpiralDB that
copies `ConnectorArrowDatabase`'s pending, flush and guard machinery, is not recommended: two
copies of that machinery can drift.

**Store mode** (`SpiralDBConnector(project, dataset, _store=True)`):

- `table_name(path)`: `spiral_store_names.store_table_name`. The connector remembers each
name's path. A name it has not computed is not resolved from the table's metadata: the
calls that look a table up by name (`has_table`, the column info and schema, reads,
`create_table_if_not_exists`, `upsert_records`) raise `KeyError` for a name this
connector's `table_name(path)` has not computed. `ConnectorArrowDatabase` always computes
the name first. `get_pk_columns` needs no lookup and answers the store's key for any name.
- `has_table(name)`: opens the table by name, with no listing. Its record is read and checked:
another path or format raises `SpiralStoreTableCollisionError`.
- `table_paths(prefix)`: one listing, then the names starting with
`store_table_name_prefix(prefix)`, then each candidate's metadata (cached by table id), then
the recorded paths under `prefix`. Stale-layout checks use this unchanged (ITL-954).
- `create_table_if_not_exists`: checks the key column and that the name is one this connector
computed; it creates no table (as built, after the review of fe4145c7: every check runs
before a table is created).
- First non-empty `upsert_records` on a table: after every check of the rows, create the table
(`create_keyed_table` with the key column; a 409 means it was made meanwhile and is judged
again), or adopt the empty one found; write the identity record and the manifest together,
in one metadata upsert; then append the rows. If that write stops part way, what can remain
is an empty table with no record, or a recorded table with no rows: a later first writer
adopts either one, since a table with no rows is new (N42). **Q4**: the data context recorded is the one of the rows' `__data_context`, which must
be a single value. A table found without a record, and with no rows and the expected key, is
adopted; otherwise it is refused (decision 3).
- `upsert_records`: rows through `spiral_store.encode_rows`; `skip_existing` reads the key
column once. A write of no rows is never sent.
- `get_column_info` and `iter_batches`: the logical columns, rows through
`spiral_store.decode_rows` against the manifest.
- Plain tables are not store tables: a store-mode connector sees only `o1_` tables.

**Q2. Where the manifest lives (revisits decision 4).** On main, the dataset's schema table
(`__orcapod_schemas__`) is all or nothing: one completion marker holds a digest of every
row, and a dataset whose marker does not fit its rows is refused for every read. Adding a
store table would mean reading the whole schema table and writing its row plus a new marker
(one append, so atomic), and every plain reader would parse store rows too. Recommended: keep
the manifest in the table's own metadata, in chunks of at most 8 KiB (PR 545's chunked format,
which PR 590 replaced with one record), beside the identity keys. Store tables then stay
independent of each other and of the schema table. Measured: there is no total metadata limit
in sight; reads slow down only past a megabyte.

**Q3. Store mode stays private until stage 5.** The flag is underscored, `to_config` refuses a
store-mode connector, and there is no lease yet (stage 4). Writes happen only in tests on the
fake and in the live conformance dataset.

## Measured (live, spiral-sdk 0.16.78)

- A key-range scan returns no row for an absent key, and rows in the order of the ranges
asked: no null rows (ITL-1476's second finding does not apply to spiral-sdk).
- Table names: the store's names are at most 164 characters in `[a-z0-9_]`, within the
service's 255 (ITL-1476's first finding).
- A write of no rows publishes nothing (ITL-1476's third finding); the store sends none.

## Not in this stage

The lease (stage 4), keyed reads in place of whole-table reads (a later performance stage),
and job integration with switch-on (stage 5).
72 changes: 72 additions & 0 deletions docs/dev/plans/2026-11-26-itl-1502-keyed-reads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ITL-1502: keyed reads, one existence answer per run, one listing per run

Stacked on PR 595 (ITL-1498). Decided on the developer's behalf (N43): the three parts below;
Q1 approved as `run_scope()` on the protocols (N44: re-entrant, one held state until the
outermost scope exits, dropped also when the run raises).
The gate: `docs/dev/scripts/itl_1446_store_evaluation.py` compares every hash, row and record
id with Delta, on the fake and live, exactly as at 0a4189c3.

## What the job reads today (traced on the fake)

| Run | `get_all_records` | `get_records_with_column_value` | `get_record_by_id` | `list_table_paths` |
|---|---|---|---|---|
| first | 33 | 60 | 3 | 5 |
| unchanged rerun | 5 | 0 | 3 | 3 |
| two rows added | 13 | 16 | 3 | 5 |

`ConnectorArrowDatabase` answers every one of them by reading the whole table and filtering in
Arrow. `get_records_with_column_value` filters on value columns (a result's input hash, a
pipeline entry's base id or node hash, the data context), not on the key; `get_record_by_id`
and `get_records_by_ids` filter on the key.

## 1. Reads narrowed at the scan

- `DBConnectorProtocol` gets one more required method:
`read_candidates(table_name, *, keys=None, equal=None) -> pa.Table | None`. It returns the
table's rows that may match: at least every row whose key is in `keys` and whose columns
equal `equal`. It returns `None` when the table is absent.
- `ConnectorArrowDatabase` still applies its exact Arrow filter to what comes back, so no
result can change; a connector may only read less.
- SQLite, PostgreSQL and a plain SpiralDB connector read the whole table, as today.
- A store scans with one key range per asked key, and with a pushed-down equality filter on
the stored names of the string, binary, integer and boolean columns. Floats, temporal and
nested columns are not pushed down; the Arrow filter applies to them.
- `get_all_records` is unchanged: it means every row.
- `skip_existing` reads only the keys being written (key ranges), not the whole key column.

## 2. One existence answer per table per run

- An existence map is kept per store connector, per run: in one place, `StoreTables`.
- A run's scope, opened by `job.run`, `run_async` and a job node's `run`, starts it; leaving
the scope drops it.
- **Q1**: the scope needs a run boundary that databases do not get today. Proposed: a
required `run_scope()` context manager on `ArrowDatabaseProtocol`.
- It is a no-op for in-memory, Delta and no-op databases, and for the test doubles.
- `ExtensionAwareDatabase` and `ConnectorArrowDatabase` pass it to their backend or
connector; a store connector's opens the map.
- The job enters it once per distinct database of the run.
- Outside a run (a database used alone), nothing is held: today's behaviour (N42).
- Within a run, the map records:
- a table found, as present;
- a table this process creates, as present;
- a table found absent, as absent until this process creates it.
- A listing never records an absent table.
- Docstring: a second writer is not supported until the lease (O37); with one, an absent
answer may be stale for the rest of the run.

## 3. One listing per run

The store's dataset listing is held in the same run map: one listing per run. It gains the
tables this process creates during the run. Outside a run, each `list_table_paths` lists the
dataset, as today.

## Tests

- Call-count tests on the fake:
- a lookup by key and by value reads no whole table;
- `skip_existing` reads only its keys;
- one opening by name per absent table per run;
- one listing per run;
- nothing is held after the run.
- Equality of results: the existing suites and the evaluation, fake and live, before and
after.
Loading
Loading