From 4205619cea275677b116066eb7b33158cc7c3e58 Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" Date: Thu, 26 Nov 2026 00:27:32 -0800 Subject: [PATCH 001/142] docs(plans): plan stage 1 of ITL-1466, three nested row ids (ITL-1471) Co-Authored-By: Claude Fable 5.2 --- docs/dev/plans/itl-1471-plan.md | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 docs/dev/plans/itl-1471-plan.md diff --git a/docs/dev/plans/itl-1471-plan.md b/docs/dev/plans/itl-1471-plan.md new file mode 100644 index 000000000..486d2eded --- /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(instance, result_id)`, `record_id(hasher, instance, result_id)` | `__pipeline_instance_id` (`large_binary`), then `__data_id` (`large_binary`, the result UUID's bytes) | + +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. From e64c73c4c06964ab4db801e7e9ef97bb38f0a86a Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" Date: Thu, 26 Nov 2026 01:14:20 -0800 Subject: [PATCH 002/142] feat(nodes): define the entry, instance and record ids in one module (ITL-1471) core/row_ids.py holds the three nested row ids and their preimages. A data datagram gives its source-info tokens as a one-row table (source_info_table), and the EmptyData placeholder carries tokens built as a real output's are, with the sentinel EPHEMERAL_RESULT_GONE in place of the result id. Co-Authored-By: Claude Fable 5.2 --- src/orcapod/core/data_function.py | 32 +- src/orcapod/core/datagrams/tag_data.py | 66 +++- src/orcapod/core/row_ids.py | 172 +++++++++ .../protocols/core_protocols/datagrams.py | 16 + tests/test_core/test_empty_data.py | 26 +- tests/test_core/test_row_ids.py | 347 ++++++++++++++++++ 6 files changed, 628 insertions(+), 31 deletions(-) create mode 100644 src/orcapod/core/row_ids.py create mode 100644 tests/test_core/test_row_ids.py diff --git a/src/orcapod/core/data_function.py b/src/orcapod/core/data_function.py index fc124c478..acf8e48ac 100644 --- a/src/orcapod/core/data_function.py +++ b/src/orcapod/core/data_function.py @@ -734,6 +734,30 @@ def declaration_for(type_id: str) -> DataFunctionTypeDeclaration: ) from None +def output_source_info( + uri: tuple[str, ...], result_id: str, columns: Iterable[str] +) -> dict[str, str]: + """Build the source-info token of each output column of one result. + + A token is ``::::``, the uri's parts joined + by ``:``. This is the one place an output's tokens are built: a computed + result gives its id as hex text, and the placeholder of an ephemeral result + that is gone gives the sentinel ``row_ids.EPHEMERAL_RESULT_GONE`` in its + place (ITL-1471). + + Args: + uri: The data function's uri. + result_id: The text that names the result: the hex of its id, or the + sentinel. + columns: The output columns. + + Returns: + The token of each column, by column name, in the order given. + """ + source = ":".join(uri) + return {column: f"{source}::{result_id}::{column}" for column in columns} + + class PythonDataFunction(DataFunctionBase[PythonFunctionExecutorProtocol]): @property def data_function_type_id(self) -> str: @@ -1008,14 +1032,8 @@ def _build_output_data(self, values: Any) -> DataProtocol: "unchanged. Return value.detach().cpu() to avoid this warning.", ) - def combine(*components: tuple[str, ...]) -> str: - inner_parsed = [":".join(component) for component in components] - return "::".join(inner_parsed) - new_record_uuid = uuid.UUID(bytes=uuid7().bytes) - source_info = { - k: combine(self.uri, (new_record_uuid.hex,), (k,)) for k in output_data - } + source_info = output_source_info(self.uri, new_record_uuid.hex, output_data) if not output_data: return Data( diff --git a/src/orcapod/core/datagrams/tag_data.py b/src/orcapod/core/datagrams/tag_data.py index 8bdf566bd..94c6c973a 100644 --- a/src/orcapod/core/datagrams/tag_data.py +++ b/src/orcapod/core/datagrams/tag_data.py @@ -560,6 +560,18 @@ def source_info(self) -> "dict[str, SourceInfoValue]": """Return source info for all data-column keys (None for unknown).""" return {k: self._source_info.get(k) for k in self.keys()} + def source_info_table(self) -> "pa.Table": + """Return the source-info tokens as a one-row table. + + The columns ``as_table(columns={"source": True})`` appends to the data + columns: one ``_source_`` per data column, in their order. + + Returns: + The one-row table, or a table with no column when no data column has + a token. + """ + return self._ensure_source_info_table() + def with_source_info(self, **source_info: "SourceInfoValue") -> Self: """Create a copy with updated source-information entries.""" current = dict(self._source_info) @@ -792,18 +804,20 @@ class EmptyData(Data): pipeline DB row lacking the stored hash column), ``content_hash()`` raises ``EmptyDataHashMissingError`` loudly. - ``empty_source_info`` is an optional provenance field for the future - tag-row reconstruction follow-up. This release defines the field; the write - logic is deferred. + A placeholder carries source-info tokens (ITL-1471): one for each data column + of the result that is gone, built as that result's would be, with the sentinel + ``EPHEMERAL_RESULT_GONE`` (``core/row_ids.py``) where the result id would + stand. A node that receives the placeholder computes the row's instance id + from them. ``source_info()`` and ``source_info_table()`` return them; they + are the only part of the placeholder that reads like a row. Args: cached_content_hash: The content hash of the missing data payload this token represents — typically the upstream node's output hash, which equals the downstream node's input hash. ``None`` for old-format rows lacking the stored hash column. - empty_source_info: Optional provenance dict for tag-row reconstruction - (follow-up). Keys match tag-row source columns; ``record_id`` may - be ``None``. + source_info: The source-info tokens of the missing result, by data column + name. ``None`` or empty when none is known. python_schema: Optional schema hint (passed to parent). data_context: Data context key or instance (passed to parent). record_uuid: Optional explicit UUID for this token. @@ -812,7 +826,7 @@ class EmptyData(Data): def __init__( self, cached_content_hash: ContentHash | None = None, - empty_source_info: dict[str, str | None] | None = None, + source_info: "Mapping[str, SourceInfoValue] | None" = None, python_schema: SchemaLike | None = None, data_context: str | contexts.DataContext | None = None, record_uuid: uuid.UUID | None = None, @@ -825,7 +839,7 @@ def __init__( record_uuid=record_uuid, ) self._cached_content_hash: ContentHash | None = cached_content_hash - self._empty_source_info: dict[str, str | None] | None = empty_source_info + self._source_info = dict(source_info or {}) # ------------------------------------------------------------------ # Content identity @@ -923,10 +937,10 @@ def arrow_schema( def copy(self, include_cache: bool = True, preserve_id: bool = True) -> Self: """Return a shallow copy of this token, preserving EmptyData-specific fields. - Overrides ``Datagram.copy()`` so that ``_cached_content_hash`` and - ``_empty_source_info`` are carried across (the base implementation uses - ``object.__new__`` and only copies ``Datagram`` fields, which would - silently drop our extra attributes). + Overrides ``Datagram.copy()`` so that ``_cached_content_hash`` is carried + across (the base implementation uses ``object.__new__`` and only copies + ``Datagram`` fields, which would silently drop the extra attribute). The + tokens are copied by ``Data.copy``. Args: include_cache: Forwarded to ``super().copy()``. @@ -937,7 +951,6 @@ def copy(self, include_cache: bool = True, preserve_id: bool = True) -> Self: """ new_p = super().copy(include_cache=include_cache, preserve_id=preserve_id) new_p._cached_content_hash = self._cached_content_hash - new_p._empty_source_info = self._empty_source_info return new_p # ------------------------------------------------------------------ @@ -949,7 +962,26 @@ def cached_content_hash(self) -> ContentHash | None: """The stored content hash, or ``None`` if absent (old-format row).""" return self._cached_content_hash - @property - def empty_source_info(self) -> dict[str, str | None] | None: - """Optional provenance dict for future tag-row reconstruction.""" - return self._empty_source_info + def source_info(self) -> "dict[str, SourceInfoValue]": + """Return the tokens the placeholder carries, by data column name.""" + return dict(self._source_info) + + def source_info_table(self) -> pa.Table: + """Return the tokens as a one-row table of source-info columns. + + The columns are typed as a row's own source-info columns are + (``_source_info_field``), in the order the tokens were given. + + Returns: + The one-row table, or a table with no column when the placeholder + carries no token. + """ + if not self._source_info: + return pa.table({}) + prefixed = { + f"{constants.SOURCE_PREFIX}{k}": v for k, v in self._source_info.items() + } + return pa.Table.from_pylist( + [prefixed], + schema=pa.schema([_source_info_field(k, v) for k, v in prefixed.items()]), + ) diff --git a/src/orcapod/core/row_ids.py b/src/orcapod/core/row_ids.py new file mode 100644 index 000000000..dc125f4e9 --- /dev/null +++ b/src/orcapod/core/row_ids.py @@ -0,0 +1,172 @@ +# pyright: reportImportCycles=false +# The existing cycle core_protocols -> side_effect_pod -> side_effects, which this module's +# type-only import of the protocols brings into pyright's view because side_effects imports +# it (a file-level diagnostic: no line-level ignore reaches it; as for core/data_tags.py). +# Breaking it is ITL-1206. +"""The three nested ids of a row that passes through a node (ITL-1466, ITL-1471). + +Each id is the hash of a one-row Arrow table, its preimage, made by the data +context's Arrow hasher, and each is built from the one before: + +- The **entry id** names an entry of the pipeline table: the row's user tags, + its system tags and the hash of its data. Side effects and functions that take + the invocation context are keyed by it, and the operator cache stores it. +- The **instance id** names one arrival of an entry, with its provenance: the + entry id and the source-info tokens of the row's data. A function node looks a + row up by it. +- The **record id** names one stored row of a function node's pipeline table: + the instance id and the id of the result the row points at. + +Every preimage is built here and nowhere else. The column names inside a +preimage are part of its recipe: changing one moves every id made from it. + +A nested id enters the next preimage as its labelled digest +(``ContentHash.to_prefixed_digest()``): a hash fed into another hash carries the +name of the algorithm that produced it. +""" + +from __future__ import annotations + +import uuid +from typing import TYPE_CHECKING + +import pyarrow as pa + +from orcapod.system_constants import constants + +if TYPE_CHECKING: + from orcapod.protocols.core_protocols import DataProtocol, TagProtocol + from orcapod.protocols.hashing_protocols import ArrowHasherProtocol + from orcapod.types import ContentHash + +# The entry id's column: in the instance id's preimage, and in the operator cache. +ENTRY_ID_COL = "__pipeline_entry_id" + +# The instance id's column: the pipeline table's lookup column, and in the record +# id's preimage. +INSTANCE_ID_COL = "__pipeline_instance_id" + +# The record id's column: the name the pipeline table's row key is read under. +RECORD_ID_COL = "__pipeline_record_id" + +# What stands in a source-info token where the result id would be, when the token +# belongs to the placeholder of an ephemeral result that is gone (``EmptyData``). +# A result id is 32 hexadecimal characters, so this text names no row of any +# result table; it holds no ``::``, so the token still splits into its three parts. +EPHEMERAL_RESULT_GONE = "EPHEMERAL_RESULT_GONE" + + +def entry_id_preimage(tag: "TagProtocol", data: "DataProtocol") -> "pa.Table": + """Build the preimage of a row's entry id. + + Args: + tag: The row's tag. + data: The row's data. Only its content hash is read, so a placeholder + (``EmptyData``) is accepted. + + Returns: + A one-row table: the user tag and system tag columns, then + ``__input_data_hash`` (``large_binary``), the labelled digest of the + data's content hash. + """ + return tag.as_table(columns={"system_tags": True}).append_column( + constants.INPUT_DATA_HASH_COL, + pa.array([data.content_hash().to_prefixed_digest()], type=pa.large_binary()), + ) + + +def entry_id( + hasher: "ArrowHasherProtocol", tag: "TagProtocol", data: "DataProtocol" +) -> "ContentHash": + """Return a row's entry id: the hash of its tags, system tags and data hash. + + Args: + hasher: The Arrow hasher of the row's data context. + tag: The row's tag. + data: The row's data. + + Returns: + The entry id. + """ + return hasher.hash_table(entry_id_preimage(tag, data)) + + +def instance_id_preimage(entry: "ContentHash", data: "DataProtocol") -> "pa.Table": + """Build the preimage of a row's instance id. + + Args: + entry: The row's entry id. + data: The row's data, whose source-info tokens are read. + + Returns: + A one-row table: ``__pipeline_entry_id`` (``large_binary``, the labelled + digest of the entry id), then the source-info columns of the data in name + order. A placeholder that carries no token gives the entry id alone. + """ + preimage = pa.table( + {ENTRY_ID_COL: pa.array([entry.to_prefixed_digest()], type=pa.large_binary())} + ) + # A placeholder (``EmptyData``) gives the tokens it carries here, and no column + # when it carries none. + tokens = data.source_info_table() + for name in sorted(tokens.column_names): + preimage = preimage.append_column( + tokens.schema.field(name), tokens.column(name) + ) + return preimage + + +def instance_id( + hasher: "ArrowHasherProtocol", tag: "TagProtocol", data: "DataProtocol" +) -> "ContentHash": + """Return a row's instance id: the hash of its entry id and its tokens. + + Args: + hasher: The Arrow hasher of the row's data context. + tag: The row's tag. + data: The row's data. + + Returns: + The instance id. + """ + return hasher.hash_table(instance_id_preimage(entry_id(hasher, tag, data), data)) + + +def record_id_preimage(instance: "ContentHash", result_id: uuid.UUID) -> "pa.Table": + """Build the preimage of a stored row's record id. + + Args: + instance: The row's instance id. + result_id: The id of the result the row points at. + + Returns: + A one-row table: ``__pipeline_instance_id`` (``large_binary``, the + labelled digest of the instance id), then ``__data_id`` + (``large_binary``, the bytes of the result id). + """ + return pa.table( + { + INSTANCE_ID_COL: pa.array( + [instance.to_prefixed_digest()], type=pa.large_binary() + ), + constants.DATA_RECORD_ID: pa.array( + [result_id.bytes], type=pa.large_binary() + ), + } + ) + + +def record_id( + hasher: "ArrowHasherProtocol", instance: "ContentHash", result_id: uuid.UUID +) -> "ContentHash": + """Return a stored row's record id: the hash of its instance id and result id. + + Args: + hasher: The Arrow hasher of the row's data context. + instance: The row's instance id. + result_id: The id of the result the row points at. + + Returns: + The record id. + """ + return hasher.hash_table(record_id_preimage(instance, result_id)) diff --git a/src/orcapod/protocols/core_protocols/datagrams.py b/src/orcapod/protocols/core_protocols/datagrams.py index 5173ee0f7..eb19f07ee 100644 --- a/src/orcapod/protocols/core_protocols/datagrams.py +++ b/src/orcapod/protocols/core_protocols/datagrams.py @@ -677,6 +677,22 @@ def source_info(self) -> dict[str, SourceInfoValue]: """ ... + def source_info_table(self) -> "pa.Table": + """ + Return the source-info tokens as a one-row table. + + One ``_source_`` column per data column, in the order of the data + columns, typed as a row's own source-info columns are. These are the + columns ``as_table(columns={"source": True})`` appends to the data + columns. The placeholder of a result that is gone (``EmptyData``) has no + data columns to read; it returns the tokens it carries, and a table with + no column when it carries none. + + Returns: + The one-row table of source-info columns. + """ + ... + def with_source_info( self, **source_info: SourceInfoValue, diff --git a/tests/test_core/test_empty_data.py b/tests/test_core/test_empty_data.py index 0f9e25ba0..892da88b2 100644 --- a/tests/test_core/test_empty_data.py +++ b/tests/test_core/test_empty_data.py @@ -5,6 +5,7 @@ import uuid +import pyarrow as pa import pytest from orcapod.core.datagrams import Data @@ -109,14 +110,25 @@ def test_identity_structure_raises(self): class TestEmptyDataSourceInfo: - def test_empty_source_info_none_by_default(self): + def test_no_tokens_by_default(self): ed = EmptyData() - assert ed.empty_source_info is None - - def test_empty_source_info_stored(self): - si = {"source_id": "abc", "record_id": None} - ed = EmptyData(empty_source_info=si) - assert ed.empty_source_info == si + assert ed.source_info() == {} + assert ed.source_info_table().num_columns == 0 + + def test_tokens_are_kept_in_the_order_given(self): + tokens = {"total": "f:h:v0::X::total", "count": "f:h:v0::X::count"} + ed = EmptyData(source_info=tokens) + assert ed.source_info() == tokens + table = ed.source_info_table() + assert table.column_names == ["_source_total", "_source_count"] + assert table.to_pylist() == [ + {"_source_total": "f:h:v0::X::total", "_source_count": "f:h:v0::X::count"} + ] + assert set(table.schema.types) == {pa.large_string()} + + def test_a_copy_keeps_the_tokens(self): + tokens = {"total": "f:h:v0::X::total", "count": None} + assert EmptyData(source_info=tokens).copy().source_info() == tokens class TestEmptyDataMetadata: diff --git a/tests/test_core/test_row_ids.py b/tests/test_core/test_row_ids.py new file mode 100644 index 000000000..41f4fdebd --- /dev/null +++ b/tests/test_core/test_row_ids.py @@ -0,0 +1,347 @@ +"""The three nested row ids and their preimages (ITL-1471). + +``core/row_ids.py`` is the one place the entry id, the instance id and the record id +are built. These tests state each preimage column by column and hash it by hand, so a +change of a column name, a type or the nesting fails here. + +The rows have three tags (two user tags in two orders, with two system tags) and three +data columns in two orders, each with its own source-info token. +""" + +from __future__ import annotations + +import uuid +from typing import Any + +import pyarrow as pa +import pytest + +from orcapod.contexts import get_default_context +from orcapod.core import row_ids +from orcapod.core.data_function import output_source_info +from orcapod.core.datagrams import Data, Tag +from orcapod.core.datagrams.tag_data import EmptyData +from orcapod.system_constants import constants + +HASHER = get_default_context().arrow_hasher + +SYSTEM_TAGS = { + f"{constants.SYSTEM_TAG_PREFIX}source_id::abc": "dict_v1:mice", + f"{constants.SYSTEM_TAG_PREFIX}record_id::abc": "row_0", +} +TAG_ORDERS = [("subject", "session"), ("session", "subject")] +DATA_ORDERS = [("weight", "length", "note"), ("note", "weight", "length")] +TAG_VALUES: dict[str, Any] = {"subject": "m1", "session": 3} +DATA_VALUES: dict[str, Any] = {"weight": 21.5, "length": 9, "note": "ok"} +TOKENS = {name: f"dict_v1:mice::row_0::{name}" for name in DATA_VALUES} + + +def _tag(order: tuple[str, ...] = TAG_ORDERS[0]) -> Tag: + return Tag({name: TAG_VALUES[name] for name in order}, system_tags=SYSTEM_TAGS) + + +def _data( + order: tuple[str, ...] = DATA_ORDERS[0], tokens: dict[str, str] | None = None +) -> Data: + tokens = TOKENS if tokens is None else tokens + return Data( + {name: DATA_VALUES[name] for name in order}, + source_info={name: tokens[name] for name in order}, + ) + + +def _binary(value: bytes) -> "pa.Array[Any]": + return pa.array([value], type=pa.large_binary()) + + +class TestEntryId: + def test_the_preimage_is_the_tags_the_system_tags_and_the_labelled_data_hash( + self, + ) -> None: + tag, data = _tag(), _data() + preimage = row_ids.entry_id_preimage(tag, data) + assert preimage.num_rows == 1 + assert preimage.column_names == [ + "subject", + "session", + *SYSTEM_TAGS, + "__input_data_hash", + ] + assert preimage.schema.field("__input_data_hash").type == pa.large_binary() + assert preimage.column("__input_data_hash").to_pylist() == [ + data.content_hash().to_prefixed_digest() + ] + # No token and no index column. + assert not [n for n in preimage.column_names if n.startswith("_source_")] + assert "__pipeline_recomputation_index" not in preimage.column_names + + def test_the_id_is_the_arrow_hash_of_the_preimage(self) -> None: + tag, data = _tag(), _data() + by_hand = tag.as_table(columns={"system_tags": True}).append_column( + "__input_data_hash", _binary(data.content_hash().to_prefixed_digest()) + ) + assert row_ids.entry_id(HASHER, tag, data) == HASHER.hash_table(by_hand) + + @pytest.mark.parametrize("tag_order", TAG_ORDERS) + @pytest.mark.parametrize("data_order", DATA_ORDERS) + def test_the_order_of_tags_and_data_columns_does_not_count( + self, tag_order: tuple[str, ...], data_order: tuple[str, ...] + ) -> None: + assert row_ids.entry_id( + HASHER, _tag(tag_order), _data(data_order) + ) == row_ids.entry_id(HASHER, _tag(), _data()) + + def test_a_token_is_no_part_of_it(self) -> None: + other = {name: f"dict_v1:other::row_9::{name}" for name in DATA_VALUES} + assert row_ids.entry_id( + HASHER, _tag(), _data(tokens=other) + ) == row_ids.entry_id(HASHER, _tag(), _data()) + + def test_tags_system_tags_and_data_each_count(self) -> None: + base = row_ids.entry_id(HASHER, _tag(), _data()) + other_tag = Tag({"subject": "m2", "session": 3}, system_tags=SYSTEM_TAGS) + other_system = Tag( + TAG_VALUES, + system_tags={**SYSTEM_TAGS, next(reversed(SYSTEM_TAGS)): "row_1"}, + ) + other_data = Data({**DATA_VALUES, "length": 10}, source_info=TOKENS) + ids = { + base, + row_ids.entry_id(HASHER, other_tag, _data()), + row_ids.entry_id(HASHER, other_system, _data()), + row_ids.entry_id(HASHER, _tag(), other_data), + } + assert len(ids) == 4 + + +class TestInstanceId: + def test_the_preimage_is_the_labelled_entry_id_then_the_tokens_in_name_order( + self, + ) -> None: + tag, data = _tag(), _data() + entry = row_ids.entry_id(HASHER, tag, data) + preimage = row_ids.instance_id_preimage(entry, data) + assert preimage.column_names == [ + "__pipeline_entry_id", + "_source_length", + "_source_note", + "_source_weight", + ] + assert preimage.schema.field("__pipeline_entry_id").type == pa.large_binary() + assert preimage.to_pylist() == [ + { + "__pipeline_entry_id": entry.to_prefixed_digest(), + "_source_length": TOKENS["length"], + "_source_note": TOKENS["note"], + "_source_weight": TOKENS["weight"], + } + ] + + def test_the_id_is_the_arrow_hash_of_the_preimage(self) -> None: + tag, data = _tag(), _data() + entry = row_ids.entry_id(HASHER, tag, data) + by_hand = pa.table( + { + "__pipeline_entry_id": _binary(entry.to_prefixed_digest()), + **{ + f"_source_{name}": pa.array([TOKENS[name]], pa.large_string()) + for name in sorted(TOKENS) + }, + } + ) + assert row_ids.instance_id(HASHER, tag, data) == HASHER.hash_table(by_hand) + + @pytest.mark.parametrize("tag_order", TAG_ORDERS) + @pytest.mark.parametrize("data_order", DATA_ORDERS) + def test_the_order_of_the_token_columns_does_not_count( + self, tag_order: tuple[str, ...], data_order: tuple[str, ...] + ) -> None: + assert row_ids.instance_id( + HASHER, _tag(tag_order), _data(data_order) + ) == row_ids.instance_id(HASHER, _tag(), _data()) + + @pytest.mark.parametrize("changed", sorted(TOKENS)) + def test_a_change_of_any_one_token_is_another_instance_of_the_same_entry( + self, changed: str + ) -> None: + other = {**TOKENS, changed: f"dict_v1:mice::row_7::{changed}"} + assert row_ids.entry_id( + HASHER, _tag(), _data(tokens=other) + ) == row_ids.entry_id(HASHER, _tag(), _data()) + assert row_ids.instance_id( + HASHER, _tag(), _data(tokens=other) + ) != row_ids.instance_id(HASHER, _tag(), _data()) + + def test_it_differs_from_the_entry_id(self) -> None: + tag, data = _tag(), _data() + assert row_ids.instance_id(HASHER, tag, data) != row_ids.entry_id( + HASHER, tag, data + ) + + +class TestRecordId: + def test_the_preimage_is_the_labelled_instance_id_and_the_result_id_bytes( + self, + ) -> None: + instance = row_ids.instance_id(HASHER, _tag(), _data()) + result_id = uuid.uuid4() + preimage = row_ids.record_id_preimage(instance, result_id) + assert preimage.column_names == ["__pipeline_instance_id", "__data_id"] + assert set(preimage.schema.types) == {pa.large_binary()} + assert preimage.to_pylist() == [ + { + "__pipeline_instance_id": instance.to_prefixed_digest(), + "__data_id": result_id.bytes, + } + ] + assert row_ids.record_id(HASHER, instance, result_id) == HASHER.hash_table( + preimage + ) + + def test_another_result_of_one_instance_is_another_record(self) -> None: + instance = row_ids.instance_id(HASHER, _tag(), _data()) + first, second = uuid.uuid4(), uuid.uuid4() + assert row_ids.record_id(HASHER, instance, first) != row_ids.record_id( + HASHER, instance, second + ) + assert row_ids.record_id(HASHER, instance, first) == row_ids.record_id( + HASHER, instance, first + ) + + def test_one_result_of_two_instances_is_two_records(self) -> None: + other = {name: f"dict_v1:other::row_9::{name}" for name in DATA_VALUES} + result_id = uuid.uuid4() + assert row_ids.record_id( + HASHER, row_ids.instance_id(HASHER, _tag(), _data()), result_id + ) != row_ids.record_id( + HASHER, row_ids.instance_id(HASHER, _tag(), _data(tokens=other)), result_id + ) + + def test_the_three_ids_carry_the_arrow_label(self) -> None: + tag, data = _tag(), _data() + instance = row_ids.instance_id(HASHER, tag, data) + for value in ( + row_ids.entry_id(HASHER, tag, data), + instance, + row_ids.record_id(HASHER, instance, uuid.uuid4()), + ): + assert value.to_prefixed_digest().startswith(b"arrow_v1:") + + +class TestPlaceholder: + """The instance id of an ``EmptyData`` placeholder, with and without tokens.""" + + URI = ("inc", "0" * 64, "v0", "python.function.v1") + + def _placeholder(self, columns: tuple[str, ...]) -> EmptyData: + return EmptyData( + cached_content_hash=_data().content_hash(), + source_info=output_source_info( + self.URI, row_ids.EPHEMERAL_RESULT_GONE, columns + ), + ) + + def test_the_entry_id_reads_only_the_hash_the_placeholder_keeps(self) -> None: + assert row_ids.entry_id( + HASHER, _tag(), self._placeholder(("y", "z")) + ) == row_ids.entry_id(HASHER, _tag(), _data()) + + def test_a_placeholder_with_no_token_gives_the_hash_of_the_entry_id_alone( + self, + ) -> None: + placeholder = EmptyData(cached_content_hash=_data().content_hash()) + entry = row_ids.entry_id(HASHER, _tag(), placeholder) + preimage = row_ids.instance_id_preimage(entry, placeholder) + assert preimage.column_names == ["__pipeline_entry_id"] + assert row_ids.instance_id(HASHER, _tag(), placeholder) == HASHER.hash_table( + pa.table({"__pipeline_entry_id": _binary(entry.to_prefixed_digest())}) + ) + + @pytest.mark.parametrize("columns", [("y", "z"), ("z", "y")]) + def test_a_placeholder_with_tokens_is_hashed_as_any_row_with_those_tokens( + self, columns: tuple[str, ...] + ) -> None: + placeholder = self._placeholder(columns) + entry = row_ids.entry_id(HASHER, _tag(), placeholder) + source = ":".join(self.URI) + by_hand = pa.table( + { + "__pipeline_entry_id": _binary(entry.to_prefixed_digest()), + "_source_y": pa.array( + [f"{source}::EPHEMERAL_RESULT_GONE::y"], pa.large_string() + ), + "_source_z": pa.array( + [f"{source}::EPHEMERAL_RESULT_GONE::z"], pa.large_string() + ), + } + ) + assert row_ids.instance_id_preimage(entry, placeholder).equals(by_hand) + assert row_ids.instance_id(HASHER, _tag(), placeholder) == HASHER.hash_table( + by_hand + ) + + def test_its_instance_id_is_not_the_one_of_the_result_that_is_gone(self) -> None: + real = Data( + DATA_VALUES, + source_info=output_source_info(self.URI, uuid.uuid4().hex, DATA_VALUES), + ) + gone = EmptyData( + cached_content_hash=real.content_hash(), + source_info=output_source_info( + self.URI, row_ids.EPHEMERAL_RESULT_GONE, DATA_VALUES + ), + ) + assert row_ids.entry_id(HASHER, _tag(), gone) == row_ids.entry_id( + HASHER, _tag(), real + ) + assert row_ids.instance_id(HASHER, _tag(), gone) != row_ids.instance_id( + HASHER, _tag(), real + ) + + +class TestSentinel: + """``EPHEMERAL_RESULT_GONE`` names no result and keeps the token grammar.""" + + def test_no_result_id_can_equal_it(self) -> None: + sentinel = row_ids.EPHEMERAL_RESULT_GONE + # A result id in a token is the hex of a UUID: 32 characters of 0-9a-f. + for result_id in (uuid.uuid4(), uuid.UUID(int=0), uuid.UUID(int=2**128 - 1)): + assert len(result_id.hex) == 32 + assert set(result_id.hex) <= set("0123456789abcdef") + assert len(sentinel) != 32 + assert not set(sentinel) <= set("0123456789abcdefABCDEF") + with pytest.raises(ValueError): + uuid.UUID(hex=sentinel) + with pytest.raises(ValueError): + uuid.UUID(sentinel) + + def test_it_holds_no_separator(self) -> None: + assert constants.BLOCK_SEPARATOR == "::" + assert "::" not in row_ids.EPHEMERAL_RESULT_GONE + assert ":" not in row_ids.EPHEMERAL_RESULT_GONE + + @pytest.mark.parametrize("column", ["y", "weight_g", "a:b"]) + def test_a_token_with_it_splits_at_its_first_and_last_separator( + self, column: str + ) -> None: + uri = ("inc", "ab" * 32, "v0", "python.function.v1") + token = output_source_info(uri, row_ids.EPHEMERAL_RESULT_GONE, [column])[column] + source, rest = token.split("::", 1) + record, last = rest.rsplit("::", 1) + assert (source, record, last) == ( + ":".join(uri), + row_ids.EPHEMERAL_RESULT_GONE, + column, + ) + assert token.count("::") == 2 + + def test_a_real_output_token_has_the_same_form_with_the_result_id(self) -> None: + uri = ("inc", "ab" * 32, "v0", "python.function.v1") + result_id = uuid.uuid4() + real = output_source_info(uri, result_id.hex, ["y", "z"]) + gone = output_source_info(uri, row_ids.EPHEMERAL_RESULT_GONE, ["y", "z"]) + assert list(real) == list(gone) == ["y", "z"] + for column in real: + assert real[column].replace(result_id.hex, "X") == gone[column].replace( + row_ids.EPHEMERAL_RESULT_GONE, "X" + ) From f5cdbc8a09359253964185814ea12d5f3e620965 Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" Date: Thu, 26 Nov 2026 01:14:21 -0800 Subject: [PATCH 003/142] feat(nodes)!: key rows by instance and record id; layouts pdb_v2, odb_v2, tdb_v2 (ITL-1471) A function node looks a row up by its instance id and keys it by its record id; the recomputation index and the query before every write are gone. Side effects and functions that take the invocation context are keyed by the entry id, the log column record_id_hash is entry_id, and PostRunPayload.record_id_hash is result_id. The operator cache stores the entry id and its insertion time beside its row key, outside the key. FunctionRun.entry_id is record_id. BREAKING CHANGE: stored pipeline tables, operator caches and side-effect logs move to new layouts; every invocation hash changes once; an operator cache on a SQLite database is refused when it is attached. Co-Authored-By: Claude Fable 5.2 --- .../exp05_hash_comparison.py | 2 +- scripts/hash_audit_example.py | 28 +- src/orcapod/core/function_pod.py | 28 +- src/orcapod/core/nodes/function_node.py | 545 +++++++-------- src/orcapod/core/nodes/operator_node.py | 65 +- src/orcapod/hooks.py | 9 +- src/orcapod/invocation.py | 9 +- src/orcapod/pipeline/provenance.py | 5 +- src/orcapod/side_effects.py | 70 +- src/orcapod/system_constants.py | 12 +- src/orcapod/types/provenance.py | 5 +- .../integration/test_provenance.py | 2 +- tests/test_arrays/test_array_v02_store.py | 2 +- .../data_tags/test_operator_node_storage.py | 18 +- .../data_tags/test_tag_order_identity.py | 8 +- .../function_pod/test_ephemeral_result.py | 108 +-- .../test_function_node_arrow_types.py | 2 +- .../test_function_node_caching.py | 89 +-- .../function_pod/test_function_pod_node.py | 19 +- .../test_node_content_hash_redundancy.py | 89 ++- .../function_pod/test_post_run_hooks.py | 8 +- .../nodes/test_function_node_empty_data.py | 2 +- .../nodes/test_function_node_fetch_joined.py | 37 +- .../nodes/test_function_node_get_cached.py | 26 +- .../operators/test_chained_aggregation.py | 4 +- .../side_effect_pod/test_side_effect_pod.py | 34 +- tests/test_core/test_order_invariance.py | 9 +- tests/test_data_function_types.py | 9 +- tests/test_databases/test_list_table_paths.py | 40 +- .../test_databases/test_unstorable_columns.py | 58 +- tests/test_hashing/test_hash_label_rule.py | 6 +- .../test_type_hash_registration.py | 2 +- .../test_hashing/test_wrong_hash_findings.py | 2 +- .../loaded_job/test_loaded_job_readback.py | 60 +- .../test_bind_narrower_source.py | 2 +- .../test_cross_session_miss_tags.py | 56 +- .../test_function_commit_dependencies.py | 19 +- .../test_pipeline/test_hash_step_combined.py | 14 +- .../test_pipeline/test_job_batched_commits.py | 18 +- .../test_pipeline/test_job_crash_recovery.py | 9 +- .../test_job_node_rows_after_run.py | 2 +- .../test_pipeline_record_metadata.py | 52 +- tests/test_pipeline/test_provenance.py | 8 +- tests/test_pipeline/test_provenance_review.py | 11 +- tests/test_pipeline/test_result_database.py | 6 +- tests/test_pipeline/test_row_ids_stored.py | 622 ++++++++++++++++++ tests/test_pipeline/test_rows_on_read.py | 21 +- .../test_pipeline/test_store_write_failure.py | 2 +- .../test_pipeline/test_stored_data_context.py | 28 +- .../test_tag_table_source_info.py | 58 +- .../test_zero_row_column_order.py | 2 +- 51 files changed, 1522 insertions(+), 820 deletions(-) create mode 100644 tests/test_pipeline/test_row_ids_stored.py 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/scripts/hash_audit_example.py b/scripts/hash_audit_example.py index 358120920..eea141a38 100644 --- a/scripts/hash_audit_example.py +++ b/scripts/hash_audit_example.py @@ -15,6 +15,7 @@ from orcapod.config import DEFAULT_CONFIG from orcapod.contexts import resolve_context +from orcapod.core import row_ids from orcapod.core.function_pod import function_pod from orcapod.core.nodes.function_node import FunctionJobNode from orcapod.core.operators.join import Join @@ -169,21 +170,20 @@ def grade(math: int, days: int) -> float: pipeline_database=db_for_node, ) - sub("Site 7 — compute_base_entry_id() — recomputation-index-free") - alice_base = node.compute_base_entry_id(alice_tag_j, alice_data_j) - bob_base = node.compute_base_entry_id(bob_tag_j, bob_data_j) - print(f" alice base_entry_id (hex) = {alice_base.hex()!r}") - print(f" bob base_entry_id (hex) = {bob_base.hex()!r}") - - sub("Site 8 — compute_pipeline_entry_id() — includes recomputation_index=0") - alice_pipe = node.compute_pipeline_entry_id( - alice_tag_j, alice_data_j, recomputation_index=0 - ) - bob_pipe = node.compute_pipeline_entry_id( - bob_tag_j, bob_data_j, recomputation_index=0 + hasher = node.data_context.arrow_hasher + sub("Site 7 — entry id — tags, system tags, input data hash") + alice_entry = row_ids.entry_id(hasher, alice_tag_j, alice_data_j) + bob_entry = row_ids.entry_id(hasher, bob_tag_j, bob_data_j) + print( + f" alice entry id (hex) = {alice_entry.to_prefixed_digest().hex()!r}" ) - print(f" alice pipeline_entry_id (hex) = {alice_pipe.hex()!r}") - print(f" bob pipeline_entry_id (hex) = {bob_pipe.hex()!r}") + print(f" bob entry id (hex) = {bob_entry.to_prefixed_digest().hex()!r}") + + sub("Site 8 — instance id — entry id, source-info tokens") + alice_instance = node.compute_instance_id(alice_tag_j, alice_data_j) + bob_instance = node.compute_instance_id(bob_tag_j, bob_data_j) + print(f" alice instance id (hex) = {alice_instance.hex()!r}") + print(f" bob instance id (hex) = {bob_instance.hex()!r}") sub("FunctionJobNode hashes") print(f" node.content_hash() = {node.content_hash()}") diff --git a/src/orcapod/core/function_pod.py b/src/orcapod/core/function_pod.py index 8a24c3b49..a2453472b 100644 --- a/src/orcapod/core/function_pod.py +++ b/src/orcapod/core/function_pod.py @@ -14,6 +14,7 @@ from orcapod import contexts from orcapod.channels import ReadableChannel, WritableChannel from orcapod.config import OrcapodConfig +import orcapod.core.row_ids as row_ids from orcapod.core.base import TraceableBase from orcapod.core.data_function import CachedDataFunction, PythonDataFunction from orcapod.core.datagrams import Data @@ -191,11 +192,13 @@ def _build_invocation_context( ) -> Any: """Build a per-row ``InvocationContext`` for ctx-aware pods. - Uses the same preimage as ``SideEffectPod._execute_side_effect_row`` and - ``FunctionJobNode._build_entry_id_preimage``: system-tag columns + - ``INPUT_DATA_HASH_COL`` (``large_binary``) + recomputation index 0. - ``NODE_CONTENT_HASH_COL`` is intentionally excluded — it is redundant, - fully determined by the table path (``pipeline_hash()``) plus system tags. + The record-level component is the row's entry id (``row_ids.entry_id``: + its tags, system tags and input data hash), the id a side-effect pod keys + its deliveries by. The row's source-info tokens are no part of it, so a + row that arrives again with other tokens has the same invocation hash + (ITL-1471). ``NODE_CONTENT_HASH_COL`` is intentionally excluded — it is + redundant, fully determined by the table path (``pipeline_hash()``) plus + system tags. Args: tag: The input tag for this row. @@ -205,22 +208,15 @@ def _build_invocation_context( Returns: An ``InvocationContext`` instance. """ - import pyarrow as pa - from orcapod.core.nodes.function_node import _build_record_id_preimage from orcapod.invocation import InvocationContext, InvocationHashConfig - from orcapod.side_effects import _SIDE_EFFECT_RECOMPUTATION_INDEX_COL - preimage = _build_record_id_preimage(tag, data).append_column( - _SIDE_EFFECT_RECOMPUTATION_INDEX_COL, - pa.array([0], type=pa.int32()), - ) - record_id_hash = self.data_context.arrow_hasher.hash_table(preimage) + entry_id = row_ids.entry_id(self.data_context.arrow_hasher, tag, data) return InvocationContext( pod_name=self.label, pipeline_run_id=run_id, _pipeline_hash_ch=self.pipeline_hash(), - _record_id_hash_ch=record_id_hash, + _entry_id_hash_ch=entry_id, _hash_config=InvocationHashConfig(), _track_completion=True, ) @@ -482,10 +478,10 @@ def _build_post_run_payload( Returns: A ``PostRunPayload`` ready to pass to registered hooks. """ - record_id = str(output_data.datagram_uuid) if output_data is not None else None + result_id = str(output_data.datagram_uuid) if output_data is not None else None invocation_context = self._build_invocation_context(tag, data, run_id=run_id) return PostRunPayload( - record_id_hash=record_id, + result_id=result_id, tag=tag, input=data, output=output_data, diff --git a/src/orcapod/core/nodes/function_node.py b/src/orcapod/core/nodes/function_node.py index 9a0353053..1b8d2dec5 100644 --- a/src/orcapod/core/nodes/function_node.py +++ b/src/orcapod/core/nodes/function_node.py @@ -68,7 +68,10 @@ ) from orcapod.core.tracker import DEFAULT_TRACKER_MANAGER from orcapod.core.nodes.staleness import RunHoldingNode +import orcapod.core.row_ids as row_ids +from orcapod.core.data_function import output_source_info from orcapod.core.datagrams.tag_data import Data, EmptyData, Tag +from orcapod.core.row_ids import INSTANCE_ID_COL, RECORD_ID_COL from orcapod.errors import ( EphemeralResultMissingError, InputValidationError, @@ -125,19 +128,6 @@ logger = logging.getLogger(__name__) -# Pipeline entry ID column name used when fetching records from the pipeline -# database. Always present in the table returned by _fetch_joined_records. -_PIPELINE_ENTRY_ID_COL = "__pipeline_entry_id" - -# Column name for the stable base entry ID (no recomputation index). -# Stores the per-logical-input identity; later tasks wire this into the -# Phase 1 filter and the in-memory cache key. -_PIPELINE_BASE_ENTRY_ID_COL = "__pipeline_base_entry_id" - -# Column storing the recomputation chain index (pa.int32). -# 0 for the first computation, N+1 for each miss-triggered recompute. -_PIPELINE_RECOMPUTATION_INDEX_COL = "__pipeline_recomputation_index" - PIPELINE_RUN_ID_COL = "__pipeline_run_id" PIPELINE_RECORDED_AT_COL = "__recorded_at" @@ -148,10 +138,12 @@ def _pipeline_meta_schema() -> pa.Schema: - """The bookkeeping columns of a function node's pipeline record (``pdb_v1``). + """The bookkeeping columns of a function node's pipeline record (``pdb_v2``). The record holds the tags, system tags and input source-info columns, then - these. One definition for the writer (``add_pipeline_record``) and for the + these. The row's key, its record id, is not among them: the database keeps it + and a read names it ``__pipeline_record_id``. The instance id is the plain + column a run looks a row up by (``core/row_ids.py``, ITL-1471). One definition for the writer (``add_pipeline_record``) and for the check of the pipeline database when it is attached (ITL-1162). """ return pa.schema( @@ -163,44 +155,12 @@ def _pipeline_meta_schema() -> pa.Schema: pa.field(constants.DATA_CONTEXT_COL, pa.large_string()), pa.field(f"{constants.META_PREFIX}computed", pa.bool_()), pa.field(constants.IS_EPHEMERAL_COL, pa.bool_()), - pa.field(_PIPELINE_BASE_ENTRY_ID_COL, pa.large_binary()), - pa.field(_PIPELINE_RECOMPUTATION_INDEX_COL, pa.int32()), + pa.field(INSTANCE_ID_COL, pa.large_binary()), *_PIPELINE_RECORDING_FIELDS, ] ) -def _build_record_id_preimage( - tag: "TagProtocol", - input_data: "DataProtocol", -) -> "pa.Table": - """Build the Arrow preimage table for record_id / base_entry_id computation. - - Combines the tag's system-tag columns with the binary input data hash into a - single-row Arrow table. ``NODE_CONTENT_HASH_COL`` is intentionally excluded — - it is redundant (fully determined by the table path + system tags). - - The input data hash enters with its label, ``b"