diff --git a/.zed/rules b/.zed/rules index 0131133c6..ded11c753 100644 --- a/.zed/rules +++ b/.zed/rules @@ -976,15 +976,16 @@ Every row Orcapod stores carries __data_context (constants.DATA_CONTEXT_COL, lar the key of the data context that wrote it (std:v1:default since v0.3). The key names one generation of hashing; rows of the current data context are the current entries. - Function pipeline — pdb_v1 (PIPELINE_DB_SCHEMA_VERSION) + Function pipeline — pdb_v2 (PIPELINE_DB_SCHEMA_VERSION) Function result — rdb_v1, after the type's revision rev1 (RESULT_DB_SCHEMA_VERSION) - Side-effect log — tdb_v1 (TRACKING_DB_SCHEMA_VERSION) - Operator cache — odb_v1 (OPERATOR_DB_SCHEMA_VERSION) + Side-effect log — tdb_v2 (TRACKING_DB_SCHEMA_VERSION) + Operator cache — odb_v2 (OPERATOR_DB_SCHEMA_VERSION) Cached source — sdb_v1 (SOURCE_DB_SCHEMA_VERSION) -- The layout version is the last component of a table path. Every layout marker starts at v1 - for the first release, 0.4.0 (developer, November 18, 2026, ITL-1259; 0.3.0 was withdrawn, - so nothing released uses v2). A change to the common bookkeeping columns of a table kind +- The layout version is the last component of a table path. Every layout marker started at v1 + for the first release, 0.4.0 (developer, November 18, 2026, ITL-1259; 0.3.0 was withdrawn). + The pipeline, side-effect log and operator cache layouts moved to v2 before that release, + with the three row ids (developer, November 25, 2026, ITL-1471; below, "Row ids"). A change to the common bookkeeping columns of a table kind moves its layout version, so the table gets a new path. Never add, rename or retype a stored column without it. - A function result table is at @@ -1001,7 +1002,7 @@ generation of hashing; rows of the current data context are the current entries. correct result for the same input? No: a new major. Yes: a new revision (the type's columns) or a new rdb version (the common columns). Components are delimited, never parsed out of one string; the major is not repeated. - - Pipeline tables carry no revision (.../python.function.v1/schema:/pdb_v1). A + - Pipeline tables carry no revision (.../python.function.v1/schema:/pdb_v2). A saved job names the type and major only (data_function_type_id); the revision comes from the installed library's declaration (declaration_for(type id)). - A data function type's declaration (PYTHON_FUNCTION, beside its class in core/data_function.py; @@ -1057,6 +1058,85 @@ generation of hashing; rows of the current data context are the current entries. contexts/logical_types.json, never in a data context manifest: a logical type is versioned by its own identifier, and that file is not frozen. +Row ids: entry, instance, record (developer, November 25, 2026, ITL-1466, ITL-1471) + +A row that passes through a node has three nested ids (docs/reference/hashing.md section 3). +All three, with their preimages, are defined in one module, core/row_ids.py; never build one of +these preimages anywhere else. + + entry id — hash of user tags, system tags, the labelled input data hash (__pipeline_entry_id) + instance id — hash of the entry id (labelled) and the input's source-info tokens in name + order (__pipeline_instance_id) + record id — hash of the node's content hash (labelled), the instance id (labelled) and + the result id, __data_id (__pipeline_record_id) + +- A function node identifies a row by its instance id (tokens included): it is the plain lookup + column of the pipeline table and the key of the node's in-memory cache. A new instance of a + known entry (same values, other tokens) writes a new row; its result normally comes from the + result store (same input hash), so nothing is computed. +- A pipeline row stores its record id (__pipeline_record_id). It is the table's key, and it + covers the content hash of the node that records the row (developer, November 26, 2026): + with the default pipeline-hash scope one table holds the rows of several nodes, told apart by + __node_content_hash, and two of them can record one instance with one cached result, each + under its own record id. Never take the node's content hash out of the record id: the second + node's row would be dropped as a duplicate. The row stores __node_content_hash, so it gives + its record id again from its own columns. A write skips only a row this node already stored under that record id; a recompute has a new + result id, so it writes a new row. There is no recomputation index: among the rows of one + instance, __recorded_at says which is the latest. +- Only side effects and functions that take the invocation context are keyed by the entry id: + the side-effect log's row key and its entry_id column, and + InvocationContext._entry_id_hash_ch (invocation_hash is pipeline_hash :: entry id). A token + never reaches that key, so a token-only change upstream delivers nothing again. +- The operator cache keeps its whole-row key (_record_hash) and stores, outside that key, the + row's entry id (__pipeline_entry_id) and its insertion time (__recorded_at); a row passed + again is skipped and keeps its first time. Every read of the cache drops both + (_STORED_ONLY_COLUMNS). +- The column names inside a preimage are part of its recipe: renaming one moves the ids made + from it (the golden cases pin a pipeline table's instance ids; a record id holds a random + result id and cannot be pinned). +- The placeholder of an ephemeral result that is gone (EmptyData) carries the source-info + tokens a real output would, with the sentinel row_ids.EPHEMERAL_RESULT_GONE in place of the + result id (one constant; built by data_function.output_source_info, as a real output's tokens + are). A node given a placeholder computes its instance id from those tokens, finds its result + in the result store by the input hash, calls nothing and writes no pipeline row (developer, + November 26, 2026; FunctionJobNode._empty_data_cache_hit is the one place that holds that + choice, to be reconsidered in ITL-1475). +- The instance id reads a row's tokens through `DataProtocol.source_info_table()`: one column + per data column, a data column with no token having a null token. THE INTENDED RULE + (developer, November 27, 2026): the type of every source-info token column is fixed by the + pipeline, like every other column type, and is not meant to be taken from values: each + source and operator determines its output token columns' types from its inputs' types, by + its own rule, in its own module. A data-tag that falls through a function pod is meant to + keep its source-info token with its type unchanged; a column a function returns is never a + pass-through, even with an input's name and value (its token points to the function). + TODAY (ITL-1471), in `source_info_table()`: a null token is a `large_string` null whatever + type its column declares; a non-null token of a row read from an Arrow table (a stream's + row) keeps the type that table declares, with a nullable field; a token given as a Python + value is typed from its value (`arrow_utils.source_info_arrow_type`). STOPGAP, not the + proper solution: today a token's declared type is, in some places, inferred again from its + value (`Data.as_table(columns={"source": True})` and so `_rows_to_table`, the row-built + form, and `with_columns_of`). It can narrow a declared type (example: `[None]` in a token + column a `Batch` declares with two list levels infers one). ITL-1491 removes it. Never + build on the re-typing, and never write "a function passes a column through". A rename + moves a column's token with it; a token held for the destination name before is dropped. A pipeline table keeps one type per token column: a row whose token column + has another type than the rows recorded (a list token beside a string or null token) is + refused, naming the column and both types (_require_one_type_per_token_column), and the write + fails as a database write error. A lookup must never fail on a row its stream holds as valid Arrow. The pipeline row + stores that same table (_add_pipeline_record), never the columns of + as_table(columns={"source": True}): every stored row gives its instance and record id again + from its own columns. +- A trace resolves a held row by its instance id, on every branch of a function step (over a + source and over another node): a function node says which instance it holds each row under + (FunctionJobNode.held_instance_ids), and provenance._entries_for keeps the stored records of + that instance. Never select by comparing token values. Another run's record of the same + entry, with other tokens, is not that row's; several records of one instance stay an + inconsistency. +- On the async path as on the sync path, a placeholder input goes to _empty_data_cache_hit, + never to the function or the pipeline writer, and under the same row failure policy and + events: the row starts before the lookup, and a placeholder with no stored result is one + failed row (continue) or stops the run (fail_fast). +- PostRunPayload.result_id is the result's id (a UUID, not a hash). + ### System tag evolution rules 1. Name-preserving — single-stream ops. Column name/value pass through unchanged. @@ -1068,8 +1148,8 @@ generation of hashing; rows of the current data context are the current entries. user tag list[T] and keeps it a tag, while GroupBy keeps its scalar keys and drops every other user tag (ITL-1070). No tag ever moves to the data group. Source-info columns become list[str] with one element per member. System tag columns must - stay scalar, because _build_record_id_preimage (core/nodes/function_node.py) hashes them - directly to derive record identity. They fold to a deterministic digest via + stay scalar, because entry_id_preimage (core/row_ids.py) hashes them directly to derive + a row's entry id. They fold to a deterministic digest via arrow_utils.fold_system_tag_values and their column name gains ::{pipeline_hash}. The fold is SHA-based (one helper for both system tags: the SHA-256 of the canonical JSON member list after the @@ -1717,11 +1797,13 @@ data. The rules: (`arrow_keys.polars_key_frame`, `arrow_keys.sort_key`) and the rows are taken from the table, so no value passes through Polars. A tag type with no rule (a map, an interval, a union, a list view) raises `TypeError` naming the column. -- Data source-info values may be str, None, or list[...], nested to any depth; Arrow/Python - types are derived from the value, with None mapping to large_string. That rule has one - definition, arrow_utils.source_info_arrow_type, and applies only to tokens supplied as - Python values: ArrowTableStream.iter_data hands each row's source info to Data as Arrow - columns, so a type the stream already has is never re-inferred. A many→one operator must +- `Data` source-info values may be `str`, `None`, or `list[...]`, nested to any depth; for a + token supplied as a Python value the Arrow and Python types are derived from the value, with + `None` mapping to `large_string`. That rule has one definition, + `arrow_utils.source_info_arrow_type`. `ArrowTableStream.iter_data` hands each row's source + info to `Data` as Arrow columns, and `source_info_table()` keeps the type the stream + declares for a non-null token. Today a declared type is, in some places, inferred again + from the value, a stopgap ITL-1491 removes (above, "Row ids"). A many→one operator must emit a list for EVERY row of a list-valued column — mixing in a bare None makes per-row as_table() schemas diverge and pa.concat_tables fail on the barrier path. - Operators that build lists (Batch, GroupBy, MergeJoin) build every list-valued column diff --git a/CLAUDE.md b/CLAUDE.md index 053e2539b..d7ec10c7b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1005,14 +1005,16 @@ current data context are the current entries. | Table | Layout (last path component) | Constant | |---|---|---| -| Function pipeline | `pdb_v1` | `PIPELINE_DB_SCHEMA_VERSION` | +| Function pipeline | `pdb_v2` | `PIPELINE_DB_SCHEMA_VERSION` | | Function result | `rdb_v1` (after the type's revision, `rev1`) | `RESULT_DB_SCHEMA_VERSION` | -| Side-effect log | `tdb_v1` | `TRACKING_DB_SCHEMA_VERSION` | -| Operator cache | `odb_v1` | `OPERATOR_DB_SCHEMA_VERSION` | +| Side-effect log | `tdb_v2` | `TRACKING_DB_SCHEMA_VERSION` | +| Operator cache | `odb_v2` | `OPERATOR_DB_SCHEMA_VERSION` | | Cached source | `sdb_v1` | `SOURCE_DB_SCHEMA_VERSION` | -- Every layout marker starts at `v1` for the first release, 0.4.0 (developer, November 18, - 2026, ITL-1259; 0.3.0 was withdrawn, so nothing released uses `v2`). A change to the common +- Every layout marker started at `v1` for the first release, 0.4.0 (developer, November 18, + 2026, ITL-1259; 0.3.0 was withdrawn). The pipeline, side-effect log and operator cache + layouts moved to `v2` before that release, with the three row ids (developer, November 25, + 2026, ITL-1471; below, "Row ids"). A change to the common bookkeeping columns of a table kind moves its layout version, so the table gets a new path. Never add, rename or retype a stored column without it. - A function result table is at @@ -1031,7 +1033,7 @@ current data context are the current entries. correct result for the same input? No: a new major. Yes: a new revision (the type's columns) or a new `rdb` version (the common columns). Components are delimited, never parsed out of one string; the major is not repeated. - - Pipeline tables carry no revision (`.../python.function.v1/schema:/pdb_v1`). + - Pipeline tables carry no revision (`.../python.function.v1/schema:/pdb_v2`). A saved job names the type and major only (`data_function_type_id`); the revision comes from the installed library's declaration (`declaration_for(type id)`). - A data function type's declaration (`PYTHON_FUNCTION`, beside its class in @@ -1087,6 +1089,85 @@ current data context are the current entries. `contexts/logical_types.json`, never in a data context manifest: a logical type is versioned by its own identifier, and that file is not frozen. +### Row ids: entry, instance, record + +A row that passes through a node has three nested ids (developer, November 25, 2026, +ITL-1466, ITL-1471; `docs/reference/hashing.md` section 3). All three, with their preimages, +are defined in one module, `core/row_ids.py`; never build one of these preimages anywhere else. + +| Id | Hash of | Column | +|---|---|---| +| entry id | user tags, system tags, the labelled input data hash | `__pipeline_entry_id` | +| instance id | the entry id (labelled), the input's source-info tokens in name order | `__pipeline_instance_id` | +| record id | the node's content hash (labelled), the instance id (labelled), the result id (`__data_id`) | `__pipeline_record_id` | + +- A function node identifies a row by its **instance id** (tokens included): it is the plain + lookup column of the pipeline table and the key of the node's in-memory cache. A new instance + of a known entry (same values, other tokens) writes a new row; its result normally comes from + the result store (same input hash), so nothing is computed. +- A pipeline row stores its **record id** (`__pipeline_record_id`). It is the table's key, + and it covers the content hash of the node that records the row (developer, November 26, + 2026): with the default pipeline-hash scope one table holds the rows of several nodes, told + apart by `__node_content_hash`, and two of them can record one instance with one cached + result, each under its own record id. Never take the node's content hash out of the record + id: the second node's row would be dropped as a duplicate. The row stores + `__node_content_hash`, so it gives its record id again from its own columns. A write skips only a row this node already stored under that record id; a + recompute has a new result id, so it writes a new row. There is no recomputation index: + among the rows of one instance, `__recorded_at` says which is the latest. +- Only side effects and functions that take the invocation context are keyed by the **entry + id**: the side-effect log's row key and its `entry_id` column, and + `InvocationContext._entry_id_hash_ch` (`invocation_hash` is `pipeline_hash :: entry id`). A + token never reaches that key, so a token-only change upstream delivers nothing again. +- The operator cache keeps its whole-row key (`_record_hash`) and stores, outside that key, + the row's entry id (`__pipeline_entry_id`) and its insertion time (`__recorded_at`); a row + passed again is skipped and keeps its first time. Every read of the cache drops both + (`_STORED_ONLY_COLUMNS`). +- The column names inside a preimage are part of its recipe: renaming one moves the ids made + from it (the golden cases pin a pipeline table's instance ids; a record id holds a random + result id and cannot be pinned). +- The placeholder of an ephemeral result that is gone (`EmptyData`) carries the source-info + tokens a real output would, with the sentinel `row_ids.EPHEMERAL_RESULT_GONE` in place of + the result id (one constant; built by `data_function.output_source_info`, as a real output's + tokens are). A node given a placeholder computes its instance id from those tokens, finds its + result in the result store by the input hash, calls nothing and writes no pipeline row + (developer, November 26, 2026; `FunctionJobNode._empty_data_cache_hit` is the one place + that holds that choice, to be reconsidered in ITL-1475). +- The instance id reads a row's tokens through `DataProtocol.source_info_table()`: one column + per data column, a data column with no token having a null token. THE INTENDED RULE + (developer, November 27, 2026): the type of every source-info token column is fixed by the + pipeline, like every other column type, and is not meant to be taken from values: each + source and operator determines its output token columns' types from its inputs' types, by + its own rule, in its own module. A data-tag that falls through a function pod is meant to + keep its source-info token with its type unchanged; a column a function returns is never a + pass-through, even with an input's name and value (its token points to the function). + TODAY (ITL-1471), in `source_info_table()`: a null token is a `large_string` null whatever + type its column declares; a non-null token of a row read from an Arrow table (a stream's + row) keeps the type that table declares, with a nullable field; a token given as a Python + value is typed from its value (`arrow_utils.source_info_arrow_type`). STOPGAP, not the + proper solution: today a token's declared type is, in some places, inferred again from its + value (`Data.as_table(columns={"source": True})` and so `_rows_to_table`, the row-built + form, and `with_columns_of`). It can narrow a declared type (example: `[None]` in a token + column a `Batch` declares with two list levels infers one). ITL-1491 removes it. Never + build on the re-typing, and never write "a function passes a column through". A rename + moves a column's token with it; a token held for the destination name before is dropped. A pipeline table keeps one type per token + column: a row whose token column has another type than the rows recorded (a list token + beside a string or null token) is refused, naming the column and both types + (`_require_one_type_per_token_column`), and the write fails as a database write error. A lookup must never fail on a row its stream holds as valid Arrow. The + pipeline row stores that same table (`_add_pipeline_record`), never the columns of + `as_table(columns={"source": True})`: every stored row gives its instance and record id + again from its own columns. +- A trace resolves a held row by its **instance id**, on every branch of a function step + (over a source and over another node): a function node says which instance it holds each + row under (`FunctionJobNode.held_instance_ids`), and `provenance._entries_for` keeps the + stored records of that instance. Never select by comparing token values. Another run's + record of the same entry, with other tokens, is not that row's; several records of one + instance stay an inconsistency. +- On the async path as on the sync path, a placeholder input goes to + `_empty_data_cache_hit`, never to the function or the pipeline writer, and under the same + row failure policy and events: the row starts before the lookup, and a placeholder with no + stored result is one failed row (`continue`) or stops the run (`fail_fast`). +- `PostRunPayload.result_id` is the result's id (a UUID, not a hash). + ### System tag evolution rules 1. **Name-preserving** — single-stream ops (filter, select, map). Column name and value pass @@ -1099,8 +1180,8 @@ current data context are the current entries. makes every user tag `list[T]` and keeps it a tag, while `GroupBy` keeps its scalar keys and drops every other user tag (ITL-1070). No tag ever moves to the data group. Source-info columns become `list[str]` with one element per member. System - tag columns must stay **scalar**, because `_build_record_id_preimage` - (`core/nodes/function_node.py`) hashes them directly to derive record identity. They fold + tag columns must stay **scalar**, because `entry_id_preimage` + (`core/row_ids.py`) hashes them directly to derive a row's entry id. They fold to a deterministic digest via `arrow_utils.fold_system_tag_values` and their column name gains `::{pipeline_hash}` — a blend of rules 2 and 3. @@ -1768,11 +1849,13 @@ data. The rules: (`arrow_keys.polars_key_frame`, `arrow_keys.sort_key`) and the rows are taken from the table, so no value passes through Polars. A tag type with no rule (a map, an interval, a union, a list view) raises `TypeError` naming the column. -- `Data` source-info values may be `str`, `None`, or `list[...]`, nested to any depth; the - Arrow and Python types are derived from the value, with `None` mapping to `large_string`. - That rule has one definition, `arrow_utils.source_info_arrow_type`, and applies only to - tokens supplied as Python values: `ArrowTableStream.iter_data` hands each row's source info - to `Data` as Arrow columns, so a type the stream already has is never re-inferred. A +- `Data` source-info values may be `str`, `None`, or `list[...]`, nested to any depth; for a + token supplied as a Python value the Arrow and Python types are derived from the value, with + `None` mapping to `large_string`. That rule has one definition, + `arrow_utils.source_info_arrow_type`. `ArrowTableStream.iter_data` hands each row's source + info to `Data` as Arrow columns, and `source_info_table()` keeps the type the stream + declares for a non-null token. Today a declared type is, in some places, inferred again + from the value, a stopgap ITL-1491 removes (above, "Row ids"). A many→one operator must emit a list for **every** row of a list-valued column — mixing a bare `None` into some rows makes per-row `as_table()` schemas diverge and `pa.concat_tables` fail on the barrier path. diff --git a/changelog.d/ITL-1471.md b/changelog.d/ITL-1471.md new file mode 100644 index 000000000..9cad7410f --- /dev/null +++ b/changelog.d/ITL-1471.md @@ -0,0 +1,74 @@ +### Breaking changes and migration + +- **Stored tables move to new layouts: `pdb_v2`, `odb_v2` and `tdb_v2`.** The function + pipeline table, the operator cache and the side-effect invocation log are written at a new + last path component. A table a release candidate wrote at `pdb_v1`, `odb_v1` or `tdb_v1` is + reported as a table of another layout and is not read; a node that delivers side effects (a + `SideEffectPod` node, or a function that takes the invocation context) refuses to run beside + one, before anything is delivered. Function results (`rdb_v1`) do not move, so a job run + again over a store of an earlier candidate records its rows again without calling a + function. (ITL-1471) +- **An operator cache can no longer be kept in a SQLite database.** Every row of an operator + cache is now stored with the time it was first stored (`__recorded_at`, a UTC timestamp), + and the SQLite connector has no column type for a timestamp. An operator node with caching + on (`CacheMode.LOG` or `REPLAY`) refuses a `SQLiteConnector` database when it is attached, + with `UnstorableColumnError` naming the node and the column, before anything runs. A + function node's pipeline table was already refused there. In-memory, Delta and PostgreSQL + databases are not affected by this. Timestamp support for the SQLite connector is + ITL-1482. (ITL-1471) +- **Every `invocation_hash` and every side-effect log key changes once.** A side effect and a + function that takes the invocation context are keyed by the row's entry id: the hash of its + tags, its system tags and its input data hash, with no other column. The side-effect log's + column `record_id_hash` is renamed `entry_id`. (ITL-1471) +- **`PostRunPayload.record_id_hash` is renamed `result_id`.** It holds the id of the result + (a UUID), not a hash. (ITL-1471) +- **`FunctionRun.entry_id` is renamed `record_id`** (the provenance record of + `explain()`): it holds the id of the pipeline table's row. (ITL-1471) +- **`FunctionJobNode.compute_base_entry_id` is renamed `compute_instance_id`, and + `compute_pipeline_entry_id` is removed.** The ids are computed by `orcapod.core.row_ids`. + (ITL-1471) +- **`DataProtocol` has a new required method, `source_info_table()`**, the one-row table of a + row's source-info columns; `Data` and `EmptyData` implement it. `EmptyData`'s unused + `empty_source_info` argument is replaced by `source_info`, the tokens it carries. + (ITL-1471) + +### Changed + +- **A row has three nested ids: entry, instance, record.** The entry id names what arrived + (tags, system tags, input data hash). The instance id names one arrival of it with its + provenance (the entry id and the input's source-info tokens), stored in + `__pipeline_instance_id`; a function node looks a row up by it. The record id names one + stored row (the content hash of the node that records it, the instance id and the result + id), stored in `__pipeline_record_id`; it is the table's key, so nodes that share a table + each keep their rows. See [Hashing](docs/reference/hashing.md), section 3. (ITL-1471) +- **The function pipeline table keeps every distinct record; the recomputation index is + gone.** The columns `__pipeline_base_entry_id` and `__pipeline_recomputation_index` are + removed, and nothing is read before a row is written. The same instance recorded again + with the same result is one row; a recompute writes a new row, and the row recorded last + (`__recorded_at`) is the current one. An input that arrives with other source-info tokens, + because its upstream result was computed again, is recorded as a new instance: the + function is not called (its result comes from the result store) and no side effect is + delivered again. (ITL-1471) +- **The operator cache records when a row was first stored, and its entry id.** Two columns + are stored beside the row key and are part of no key: `__recorded_at` and + `__pipeline_entry_id`. A row passed again keeps its first time. No read of the node shows + either column. (ITL-1471) +- **The placeholder of an ephemeral result that is gone carries source-info tokens.** Each is + the token the result's column would have, with `EPHEMERAL_RESULT_GONE` in place of the + result id. A node given a placeholder still calls nothing and writes no pipeline row; its + result comes from the result store. (ITL-1471) + +### Known limitations + +- **A source-info token's declared type is, in some places, inferred again from its value. + This is a stopgap, not the proper solution.** The intended rule: the type of every + source-info token column is fixed by the pipeline, like every other column type, and is + not meant to be taken from values. Each source and operator determines the types of its + output token columns from its inputs' types, by its own rule. A data-tag that falls through + a function pod is meant to keep its source-info token with its type unchanged. (A column a + function returns is never a pass-through, even with an input's name and value: its token + points to the function.) Today, where a data-tag falls through a function pod and where a + table is built from rows, a token's type is inferred again from its value. That can narrow + a declared type: a `fixed_size_list` token of a data-tag that falls through a function pod + becomes a `large_list`, and `[None]` in a token column a `Batch` declares with two list + levels infers one. ITL-1491 removes the re-typing. (ITL-1471) diff --git a/docs/concepts/function-pods.md b/docs/concepts/function-pods.md index 8aebfb95f..2541100ca 100644 --- a/docs/concepts/function-pods.md +++ b/docs/concepts/function-pods.md @@ -1079,7 +1079,7 @@ from that database, and no rows under that key is an empty result, not an error. over the same sources, not only the saved run's inputs. Rows come in the order the database returns them; sort them if order matters. The node itself (`as_table()`, `iter_data()`, `head()`) is empty: it has not run in this process. -- Operators (a join, a filter) store outputs only when caching is enabled, under `odb_v1`. +- Operators (a join, a filter) store outputs only when caching is enabled, under `odb_v2`. The saved file does not record an operator's cache mode (follow-up ITL-977), so attach a loaded operator node in `CacheMode.REPLAY` to read the rows its run stored: `loaded.nodes["joined"].attach_databases(pipeline_database=store.at(""), diff --git a/docs/concepts/pipeline-job.md b/docs/concepts/pipeline-job.md index 41a19df1b..fcb669197 100644 --- a/docs/concepts/pipeline-job.md +++ b/docs/concepts/pipeline-job.md @@ -243,15 +243,19 @@ type by type, is [Data types per database](../reference/database-types.md). Orcapod's own stored tables hold such columns. A function node's result table holds list-valued executor columns and `__`-prefixed columns. A side-effect node's log holds a UTC -timestamp and `__data_context`, and an operator cache and a cached source hold -`__data_context` too. So a job refuses these nodes when it is built, before anything runs: +timestamp and `__data_context`. An operator cache holds `__data_context`, the row's entry id +and a UTC timestamp, the time the row was first stored (`__recorded_at`). A cached source +holds `__data_context` too. So a job refuses these nodes when it is built, or when a database +is attached to them, before anything runs: - every function node, on SQLite and PostgreSQL; - every side-effect node, on SQLite; +- every operator node with caching on (`CacheMode.LOG` or `REPLAY`), on SQLite: the SQLite + connector has no column type for a timestamp (adding one is ITL-1482); - every node that stores anything, on SpiralDB. -An operator cache or cached source on a SQL connector is refused when it is written, before -anything is stored, if one of its columns has a type or name the connector does not store. On +An operator cache or cached source on a SQL connector is also refused when it is written, before +anything is stored, if one of its own columns has a type or name the connector does not store. On PostgreSQL that is every operator cache with caching on: its system-tag column names (`_tag_source_id::` and a 64-character hash) are longer than 63 bytes. A table's name is its Orcapod path joined by `__`, and every node table and cached source path diff --git a/docs/dev/plans/itl-1471-plan.md b/docs/dev/plans/itl-1471-plan.md new file mode 100644 index 000000000..c93fe2eaa --- /dev/null +++ b/docs/dev/plans/itl-1471-plan.md @@ -0,0 +1,145 @@ +# ITL-1471 plan: three nested row ids, v2 layouts (ITL-1466 stage 1) + +Stage 1 of ITL-1466. The design is `docs/dev/specs/itl-1466-as-source.md` (sections 13 and 14) +and the stage list is `docs/dev/plans/itl-1466-plan.md`, both on the ITL-1466 pull request. This +plan covers stage 1 only, with the decisions made after that plan was written (listed below). +Nothing of stages 2 to 5 is touched: `DerivedSource` serving, `as_source()` on other objects and +plain streams stay as they are. + +## Decisions this plan follows + +Developer, November 25 and 26, 2026: + +- Three nested ids: entry id, instance id, record id. Columns `__pipeline_entry_id`, + `__pipeline_instance_id`, `__pipeline_record_id`. +- Layouts `pdb_v2`, `odb_v2`, `tdb_v2`. +- The side-effect log column `record_id_hash` becomes `entry_id`; + `InvocationContext._record_id_hash_ch` becomes `_entry_id_hash_ch`. +- `PostRunPayload.record_id_hash` becomes `result_id` (it holds the result's id). +- The operator cache stores an entry-id column beside its row key, outside the key. +- An empty-data placeholder carries source-info tokens with a sentinel in place of the result id. +- A function node identifies a row by its instance id. Only side effects and functions that take + the invocation context key by the entry id. +- The 18 golden changes of `docs/dev/specs/itl-1466/golden-changes.md`, and no other. + +## The id module + +`src/orcapod/core/row_ids.py`, a leaf module (it imports the constants, `EmptyData` and pyarrow, +no node or pod module), so `function_pod.py`, `side_effects.py`, `function_node.py` and +`operator_node.py` import it at module level. It holds every preimage; no other place builds one. + +| Name | What it is | +|---|---| +| `ENTRY_ID_COL`, `INSTANCE_ID_COL`, `RECORD_ID_COL` | the three column names | +| `entry_id_preimage(tag, data)`, `entry_id(hasher, tag, data)` | user tags and system tags (`tag.as_table(columns={"system_tags": True})`), then `__input_data_hash` (`large_binary`, the labelled digest of `data.content_hash()`). Today's `_build_record_id_preimage`, moved; no index column | +| `instance_id_preimage(entry, data)`, `instance_id(hasher, tag, data)` | `__pipeline_entry_id` (`large_binary`, the entry id's labelled digest), then the input's `_source_*` columns in name order | +| `record_id_preimage(node_content_hash, instance, result_id)`, `record_id(hasher, node_content_hash, instance, result_id)` | `__node_content_hash` (`large_binary`, the labelled digest of the recording node's content hash), then `__pipeline_instance_id` (`large_binary`), then `__data_id` (`large_binary`, the result UUID's bytes). The node's content hash is in the record id by the developer's decision of November 26, 2026: the record id alone is the table's key, and two nodes sharing a table each keep their rows | + +Each id is a `ContentHash` of the data context's Arrow hasher (`arrow_v1`); it is fed onward as +`to_prefixed_digest()` and stored the same way. No new hash label. + +## Proposals to confirm + +1. **Operator cache entry-id column:** `__pipeline_entry_id` (`large_binary`, not null), the + coordinator's suggestion. It is `entry_id(hasher, tag, data)` of the output row: its tags, + system tags and the content hash of its data. It is computed in the loop that computes the row + key, and appended after the key with `__recorded_at`, so neither enters the key. +2. **Sentinel:** the text `EPHEMERAL_RESULT_GONE`, one constant in `core/row_ids.py` + (`EPHEMERAL_RESULT_GONE`). A placeholder's token for output column `c` is + `::EPHEMERAL_RESULT_GONE::`: a real output's token with the + sentinel where the result id (32 hex characters) stands. It is not hexadecimal, so it names no + result row, and it holds no `::`. The token is built by the function that builds a real + output's tokens (taken out of `PythonDataFunction` into one helper both call). +3. **Where the placeholder keeps its tokens:** `EmptyData` takes a one-row Arrow table of + `_source_*` columns and returns it from a new method; `source_info()` returns the same tokens. + Its unused field `empty_source_info` ("write logic deferred") is replaced by it. The emitting + node gives a token for each function output, and for a data-tag that falls through, the input's + stored token of that column (a real output keeps it too). +4. **A downstream node given a placeholder** computes its instance id the normal way from those + tokens. It still writes no pipeline row for a placeholder input, as today (the result comes + from the result store by input hash). Without tokens (an `EmptyData` built with none) the + instance id is the hash of the entry id alone. +5. **`FunctionRun.entry_id`** (`types/provenance.py`, public) holds the row key: renamed + `record_id`. No hash moves. + +## Files + +Library: + +- `core/row_ids.py` (new). +- `system_constants.py`: the three layout constants. `contexts/stored.py` follows through + `CURRENT_LAYOUTS`; its texts that name a layout are updated. +- `core/nodes/function_node.py`: + - `_pipeline_meta_schema`: `__pipeline_instance_id` in place of `__pipeline_base_entry_id`; no + `__pipeline_recomputation_index`. + - `compute_base_entry_id` becomes `compute_instance_id`; `compute_pipeline_entry_id`, + `_build_entry_id_preimage` and `_build_record_id_preimage` go. + - `_add_pipeline_record`: no query before the write; the row key is the record id. + - `__recorded_at` chooses among the rows of one instance (held rows, placeholders, + cross-session misses), where the index did. + - Every `base_entry_id` name becomes `instance_id`. + - The placeholder gets its tokens. +- `side_effects.py`, `core/function_pod.py`, `invocation.py`: the entry id from the module; + `_SIDE_EFFECT_RECOMPUTATION_INDEX_COL` goes; the log column and the context field are renamed. +- `hooks.py`, `core/function_pod.py`: `PostRunPayload.result_id`. +- `core/nodes/operator_node.py`: `__recorded_at` and `__pipeline_entry_id`, added after the row + key; one list of the bookkeeping columns every serving read drops. +- `core/data_function.py`: the token helper. `core/datagrams/tag_data.py`: `EmptyData`. +- `pipeline/provenance.py`, `types/provenance.py`: the row key read as `__pipeline_record_id`. +- `scripts/hash_audit_example.py`: the entry, instance and record ids in place of sites 7 and 8. + +Documents: + +- `docs/reference/hashing.md`: sites 7 to 10, the label table, the hash site inventory, the + worked example values. +- `docs/concepts/function-pods.md`, `docs/reference/data-function-types.md`, and every page under + `docs/` outside `docs/dev/` that names an old column, layout or `record_id_hash`. +- `CLAUDE.md` and `.zed/rules` together: the stored-tables table, the + `_build_record_id_preimage` mention. +- `changelog.d/ITL-1471.md`. +- The design issues log: an entry is edited only if one covers the recomputation index. + +Golden: `tests/test_hashing/golden/cases.py`, the five places that pin a table; then the commands +of `golden-changes.md`, exactly. + +## Tests + +New (`tests/test_core/test_row_ids.py`, `tests/test_core/nodes/`, the side-effect and operator +node directories), each with several rows, two or more tags and two or more data columns, token +columns in two orders, sync and async: + +- each id recomputed from a stored row (instance and record id of every pipeline row); +- the side-effect log's keys and its `entry_id` column equal the entry ids; +- a token-only change upstream records new instances, with 0 calls and 0 deliveries; +- `tdb_v1` and `pdb_v1` beside a side-effecting node are refused before any delivery; +- a recompute writes a new row; an identical repeat is skipped; +- the operator cache's `__pipeline_entry_id` equals the recomputed entry id, a re-passed row + keeps its first `__recorded_at`, and no serving read shows either column; +- the placeholder's tokens hold the sentinel, and a downstream instance id is computed from them; +- `PostRunPayload.result_id` equals the output's result id. + +Updated, counted by class in the pull request: tests that read the old columns, tests that name a +layout, tests that inject into the removed index query (removed), tests that compare stored +operator tables (compared without the time and the entry id), and the two behaviour changes by +design (one row for a repeated input; a corrected token recorded as a new instance). + +Locally: targeted tests only, one pytest process at a time. CI runs the full suite. + +## Order of commits + +1. `docs(plans)`: this plan. +2. `feat(nodes)`: `core/row_ids.py` with its unit tests. +3. `feat(nodes)!`: the function node on instance and record ids, `pdb_v2`. +4. `feat(side-effects)!`: the entry key, `tdb_v2`, the `entry_id` and `result_id` renames. +5. `feat(nodes)!`: the operator cache's `__recorded_at` and entry id, `odb_v2`. +6. `feat(nodes)`: the placeholder's sentinel tokens. +7. `test`: the existing tests updated. +8. `test(golden)`: the cases pin instance ids; the approved golden changes. +9. `docs`: the reference and concept pages, `CLAUDE.md`, `.zed/rules`, the changelog fragment. + +## Stop conditions + +- `generate_golden_hashes.py --check` shows an entry outside the approved list moving, or an + approved value differing from the listed one: no golden file is changed, and the entries and + values go to the coordinator. +- A design point this plan does not settle: asked before it is implemented. diff --git a/docs/dev/specs/itl-939-experiments/exp05_hash_comparison.py b/docs/dev/specs/itl-939-experiments/exp05_hash_comparison.py index f5f10c82d..6eca90da1 100644 --- a/docs/dev/specs/itl-939-experiments/exp05_hash_comparison.py +++ b/docs/dev/specs/itl-939-experiments/exp05_hash_comparison.py @@ -29,7 +29,7 @@ CopyTagsToData = importlib.import_module("exp03_copy_tag_prototype").CopyTagsToData from orcapod import contexts, function_pod -from orcapod.core.nodes.function_node import _build_record_id_preimage +from orcapod.core.row_ids import entry_id_preimage as _build_record_id_preimage from orcapod.operators import MapData COLS = ["session_start", "experiment_start_timestamp"] diff --git a/docs/reference/data-function-types.md b/docs/reference/data-function-types.md index 82017abb1..35b81a9ad 100644 --- a/docs/reference/data-function-types.md +++ b/docs/reference/data-function-types.md @@ -35,7 +35,7 @@ columns): a new result table, and no hash moves. The function's pipeline table carries no revision: ```text -///v/python.function.v1/schema:/pdb_v1 +///v/python.function.v1/schema:/pdb_v2 ``` A saved job names the type and its major only (`"data_function_type_id": @@ -69,7 +69,7 @@ print(describe_pair.pod.uri[-1]) for path in sorted(types_store.list_sources()): print(path[-4:]) # ('v0', 'python.function.v1', 'rev1', 'rdb_v1') -# ('v0', 'python.function.v1', 'schema:...', 'pdb_v1') +# ('v0', 'python.function.v1', 'schema:...', 'pdb_v2') ``` ## The Python function type, `python.function.v1` @@ -148,7 +148,7 @@ print([name for name in stored.column_names if name.startswith("__pf_var_")]) # ['__pf_var_function_name', '__pf_var_function_version', '__pf_var_function_module', '__pf_var_function_signature_hash', '__pf_var_function_content_hash', '__pf_var_git_hash'] ``` -## The pipeline columns, `pdb_v1` +## The pipeline columns, `pdb_v2` A function node's pipeline table stores the input tags and source-info tokens, the input and output hashes, the referenced result record ID, and bookkeeping @@ -156,6 +156,8 @@ for the entry, including: | Column | Arrow type | Nullable | Meaning | |---|---|---|---| +| `__pipeline_instance_id` | `large_binary` | yes | The row's instance id: the hash of its entry id (tags, system tags, input data hash) and the input's source-info tokens. The node looks a row up by it. | +| `__pipeline_record_id` | `large_binary` | yes | The row's record id: the hash of the node's content hash (`__node_content_hash`), its instance id and the id of its result. It is the table's key. | | `__pipeline_run_id` | `large_string` | yes | The ID of the job run that recorded the entry. A node run outside a job stores null. | | `__recorded_at` | `timestamp[us, tz=UTC]` | no | The UTC time the node recorded the entry. | @@ -166,16 +168,52 @@ Reusing a pipeline entry preserves its original run ID and recording time. If the result is lost and the node recomputes it, the new entry has its own run ID and recording time. +A row is named by its record id, the hash of the node's content hash, its +instance id and the id of its result +([the three ids](hashing.md#3-pipeline-db-entry-keys)), stored in +`__pipeline_record_id`; it is the table's key. One table holds the rows of every +node with one pipeline hash, told apart by `__node_content_hash`, and the record +id covers that hash: two such nodes that record one instance with one stored +result have two record ids, and each keeps its row. A row is written unless this node already +stored that record, so the table keeps every distinct record of every node: + +- the same instance recorded again with the same result is one row; +- a recompute has a new result, so it is a new row, and the row recorded last is + the instance's current one; +- an input that arrives with other source-info tokens (its upstream result was + computed again) is a new instance: it gets a new row. Its result is looked up + in the result database by the input data hash: when a result is stored there + the function is not called, and when none is (it was removed, or was an + ephemeral result that is gone) the function is called. + +"Recorded last" is read from `__recorded_at`, the recording process's UTC clock at +the write. So among the records of one instance the current one is the one with +the latest time: a clock set back between two writes of one instance leaves the +earlier record current until a later write. + During a sync run, a repeated identical input without system tags reuses the first entry. During an async run, both copies can be scheduled before either -entry is available, producing two entries with successive recomputation indices. +entry is available; when each then computes its own result, each has its own row. A load-only run writes nothing. Neither recording column enters any hash. -Read these columns on joined records with -`node.get_all_records(columns={"meta": True})` or `node.get_all_records(all_info=True)`. -Pipeline tables written by 0.4.0rc1 through 0.4.0rc3 lack these columns. Rebuild -those tables before appending, even if their rows have been deleted. The layout -name stays `pdb_v1`. +Read the two recording columns (`__pipeline_run_id`, `__recorded_at`) on joined +records with `node.get_all_records(columns={"meta": True})` or +`node.get_all_records(all_info=True)`. The joined records do not hold the two +ids: `__pipeline_instance_id` and `__pipeline_record_id` are columns of the +pipeline table itself, read from the database by the table's path: + +```python +pipeline_path = next(p for p in types_store.list_sources() if p[-1] == "pdb_v2") +pipeline_rows = types_store.get_all_records(pipeline_path) +print([name for name in pipeline_rows.column_names if name.startswith("__pipeline_")]) +# ['__pipeline_instance_id', '__pipeline_record_id', '__pipeline_run_id'] +joined = types_job.nodes["describe"].get_all_records(all_info=True) +print([name for name in joined.column_names if name.startswith("__pipeline_")]) +# ['__pipeline_run_id'] +``` + +Pipeline tables written by a release candidate before the three ids are at the +layout `pdb_v1`: they are reported as tables of another layout and are not read. ## Where it is declared, and how a released declaration is kept diff --git a/docs/reference/hashing.md b/docs/reference/hashing.md index 6130f2dd5..e05ee87b3 100644 --- a/docs/reference/hashing.md +++ b/docs/reference/hashing.md @@ -27,10 +27,11 @@ appended, because it is a variant of the same system tag mechanism.) | 5 | Per-row `record_id` (system tag value) | the row identifier itself: `row_`, or the canonical JSON of the key columns (`key_row_identifier`) | `str` (`large_string`) | Names the row within its source; stable as long as its position or its key is | | 6 | Join system tag suffix | `stream.pipeline_hash().to_hex(n)` + `:{idx}` appended to column name | Column name suffix | Unique per `(input topology, canonical join position)`; encodes full join lineage in column name | | 6b | Aggregating operator system tag fold | SHA-256 of the canonical JSON list of member values, after the operation's label, for both system tags | `":"` `str`, plus a column name suffix | Deterministic per ordered member set; keeps system tags scalar through a many-to-one reduction | -| 7 | `compute_base_entry_id()` | `StarfixArrowHasher.hash_table(system_tags + INPUT_DATA_HASH_COL)` | `bytes` (`b"method:digest"`) | Unique per `(node, tag lineage, input_data content)` across all recomputation attempts | -| 8 | `compute_pipeline_entry_id()` | `StarfixArrowHasher.hash_table(system_tags + INPUT_DATA_HASH_COL + recomputation_index)` | `bytes` (`b"method:digest"`) | Unique per `(node, tag lineage, input_data content, recomputation attempt)` | -| 9 | Side-effect `record_id` | `StarfixArrowHasher.hash_table(system_tags + INPUT_DATA_HASH_COL + recomputation_index=0)` | `bytes` | Unique per `(tag lineage, input_data content)`; pod-version scoped via table path (`uri` + `pipeline_hash()`) | -| 10 | `invocation_hash` | `f"{serialize(pipeline_hash_ch)}::{serialize(record_id_hash_ch)}"` | `str` | Unique per `(pod topology, tag lineage, input_data content)`; pod-version scoped via table path | +| 7 | Entry id (`row_ids.entry_id`) | `StarfixArrowHasher.hash_table(tags + system_tags + INPUT_DATA_HASH_COL)` | `ContentHash`; stored as `bytes` (`b"method:digest"`) | Unique per `(tag lineage, input_data content)`: an entry of the pipeline table | +| 8 | Instance id (`row_ids.instance_id`) | `StarfixArrowHasher.hash_table(entry id + source-info tokens in name order)` | `ContentHash`; stored as `bytes` | Unique per `(entry, provenance of the input)`: one arrival of an entry; the pipeline table's lookup column | +| 8b | Record id (`row_ids.record_id`) | `StarfixArrowHasher.hash_table(node content hash + instance id + result id)` | `ContentHash`; stored as `bytes` | Unique per `(node, instance, result)`: names a pipeline table row and is the table's key | +| 9 | Side-effect log key | the entry id (site 7) of the delivered row | `bytes` | Unique per `(tag lineage, input_data content)`; pod-version scoped via table path (`uri` + `pipeline_hash()`) | +| 10 | `invocation_hash` | `f"{serialize(pipeline_hash_ch)}::{serialize(entry_id_hash_ch)}"` | `str` | Unique per `(pod topology, tag lineage, input_data content)`; pod-version scoped via table path | | 11 | Output schema hash | `SemanticAwarePythonHasher.hash_object((hash_schema(output Arrow schema),)).to_hex()` | `str` (bare hex digest) | Unique per Arrow schema of the declared outputs; embedded in function URI | | 12 | `run_id` | `uuid.uuid4().hex[:16]` | 16-char hex `str` | Non-deterministic; unique per pipeline execution | | 13 | `snapshot_hash` | `hashlib.sha256(sorted labelled leaf content hashes joined by newline).hexdigest()[:16]` | 16-char hex `str` | Unique per `(DAG leaf topology + data state)` at run time | @@ -98,8 +99,8 @@ Where a hash appears, and in which form: | Form | Where | |---|---| -| Labelled value | `__input_data_hash`, `__output_data_hash`, `__node_content_hash`, `__pipeline_base_entry_id`, the pipeline table's record id, the side-effect log's `record_id` and `record_id_hash`, the record id (`_record_hash`) of operator-node and cached-source tables, the `_content_hash` column, the hashes in a saved job file, `InvocationContext.invocation_hash` | -| Labelled, inside a hash input | a nested hash in a structure: `{"__type__": "hash", "label": "