diff --git a/changelog.d/ITL-1559.md b/changelog.d/ITL-1559.md index 20903c136..49d50a6d5 100644 --- a/changelog.d/ITL-1559.md +++ b/changelog.d/ITL-1559.md @@ -17,7 +17,22 @@ previously processed inputs are acceptable. (ITL-1559) +### Added + +- Streams, recorded invocations, and job nodes expose `source_chain()`, `name_chain()`, and `node_hash()`. The node hash identifies a computation by its structure and input slot names, so it is available on an unbound pipeline. A polling source can report its node hash before its first batch supplies the schema. Existing pipeline and content hashes keep their values. + +- A job loaded without an operator implementation still exposes its saved hashes. A loaded built-in with one input can also report the new chains from its saved structure and its input's chains. Operators whose input symmetry is unavailable report an error for the new chains. + ### Fixed - Loading a saved job restores context-taking function nodes, their stored results, and their downstream dependencies. (ITL-1559) + +- Source chains follow rebindings inside composite input bindings. Name chains can be read without fetching a polling source's rows, and downstream identities that need its missing schema report that they are undefined. Nested commutative groups use the pipeline hash's canonical input order. +- Identity accessors reuse a memoized raw Arrow stream's legacy digest and report an undefined identity when they would have to materialize a lazy upstream or hash Arrow rows. Plain derived sources, including cached bindings, report no source chain while an origin slot is unbound. +- Polling source chain reads reuse a memoized legacy content hash from the polling source, a cache at any level of wrapping, or a bound job slot. A plain `DerivedSource` can use that digest without calling the polling implementation. A cold polling identity remains undefined. +- Custom operators report an undefined identity for the new accessors without calling their argument symmetry method. + +### Known limitations + +- The new combined hashes raise an error when a commutative group drops content-equal inputs from its argument symmetry (ITL-1590). The legacy pipeline and content hashes remain available. diff --git a/docs/dev/design_issues/ITL-1559-TC1.md b/docs/dev/design_issues/ITL-1559-TC1.md new file mode 100644 index 000000000..f411df6b8 --- /dev/null +++ b/docs/dev/design_issues/ITL-1559-TC1.md @@ -0,0 +1,37 @@ +## Pipeline identity + +### TC1 — Graph identity and source binding share one key +**Status:** in progress +**Severity:** high +**Issue:** ITL-1559 + +A graph key derived from bound data cannot distinguish two slots bound to one source. +It also cannot follow a slot through a rebind while identifying the same computation +(ITL-1442, ITL-1427). + +Step 1 computes separate structure, source and name chains. The new node hash is +available even when no source is bound. The graph and persistence still use their +existing hashes. ITL-1590 tracks the remaining structural dependency on source equality +when a commutative operator receives equal-structure inputs. + +The step 1 follow-up serializes binding and chain reads. Saved jobs retain the +existing file format. An unavailable built-in with one input uses its saved structure +and that input's chains. An unavailable operator with multiple inputs needs its input +symmetry to report the new chains. Schema-less polling sources report a node hash +before their first batch, including when wrapped in a cache. + +**Fix:** The execution protocols require both combined identity accessors. The +combined hashes raise when the legacy commutative grouping drops content-equal +arguments, including in downstream nodes. Recovering the lost order remains ITL-1590. +Source chains follow rebindings inside composite bindings and source wrappers. +Downstream chain reads never poll for a missing schema. Mixed nested input groups +use the pipeline hash's canonical ordering. +Polling source chain reads reuse a memoized legacy content hash or report that the +identity is undefined if the implementation's callback would have to run. +The polling digest can come from the polling source, any enclosing cache, or a bound +job slot. A plain derived source can resolve its origin using that digest. A warm +Arrow stream can reuse its legacy digest. The new accessors refuse to build lazy +upstream rows or hash cold raw Arrow rows. Custom operators report that the new +identities are undefined in this step without calling their symmetry method. +Plain derived source chains, including cached bindings, are absent while an origin +slot is unbound. diff --git a/docs/reference/hashing.md b/docs/reference/hashing.md index b99d06705..9a3929ab6 100644 --- a/docs/reference/hashing.md +++ b/docs/reference/hashing.md @@ -71,7 +71,7 @@ The container cell keeps its element count prefix, so it is self-contained and d depend on the cell boundary. `tests/test_hashing/test_hash_grammar.py` fails if any of these stops holding. -The labels of v0.3: +Hash labels: | Label | Names | Defined in | |---|---|---| @@ -93,6 +93,11 @@ The labels of v0.3: | `batch_v1` | the folded source id and record id of `Batch` (site 6b) | `BATCH_FOLD_LABEL`, `core/operators/batch.py` | | `group_v1` | the folded source id and record id of `GroupBy` (site 6b), and the merged source-info token of a data-tag group key | `GROUP_BY_FOLD_LABEL`, `core/operators/group_by.py` | | `join_v1` | the merged source-info token of a key that is a data-tag on several inputs of a `Join` (site 6b) | `JOIN_FOLD_LABEL`, `core/operators/join.py` | +| `slot_name_v1` | SHA-256 of the canonical tuple `("slot", name)` | `SLOT_NAME_HASH_LABEL`, `core/identity_chains.py` | +| `source_chain_v1` | SHA-256 of the canonical tuple of upstream source chains, with any local contribution | `SOURCE_CHAIN_HASH_LABEL`, `core/identity_chains.py` | +| `name_chain_v1` | SHA-256 of the canonical tuple of upstream name chains, with any local contribution | `NAME_CHAIN_HASH_LABEL`, `core/identity_chains.py` | +| `content_hash_v1` | SHA-256 of the canonical tuple of the pipeline hash and source chain | `CONTENT_HASH_LABEL`, `core/identity_chains.py` | +| `node_hash_v1` | SHA-256 of the canonical tuple of the pipeline hash and name chain | `NODE_HASH_LABEL`, `core/identity_chains.py` | | `sha256` | the file content hash: SHA-256 of the file's bytes | `SHA256_ALGORITHM`, `hashing/hash_utils.py` | Where a hash appears, and in which form: @@ -291,6 +296,54 @@ reusable as its data changes: a default in-memory source id is the hash of the w key order with `hash_in_key_order=True`), and a position moves when rows are inserted or reordered. +## Structure, source and name chains + +A stream, invocation or job node carries three chains. `pipeline_hash()` describes the +structure. `source_chain()` starts at each slot with the bound source's own content hash. +`name_chain()` starts with the slot's name. A raw stream outside a slot contributes +an anonymous name term. Display labels do not participate. A single-input step passes both chains +through unchanged unless the step contributes a term of its own. Ordered groups pool +inputs in argument order. Commutative groups use the pipeline hash's canonical order, +including when a group contains other groups. Within a tie the source and name chains +each sort their own values. Repeated inputs contribute at every position. + +`node_hash()` combines the pipeline hash and the name chain. The chain-based content +hash combines the pipeline hash and the source chain and is undefined while any +contributing slot is unbound. The chain-based content hash is available internally as +`_chain_content_hash()` until the switch to `content_hash()`. Orcapod continues to use +the existing hashes for graph keys and persistence. ITL-1590 tracks cases where the +existing pipeline hash depends on source equality within a commutative input tie. +The saved job format does not carry input symmetry yet. A loaded built-in with one +input uses the saved pipeline hash and passes through that input's chains, even when +its operator implementation is unavailable. An unavailable operator with multiple +inputs needs its input symmetry and reports an undefined identity for either chain +or combined hash. +Custom operators also report an undefined identity for all four new accessors in +step 1. Legacy hashing can still call their argument symmetry method. +The legacy pipeline and content hashes are available from the descriptor. + +A polling source, including one wrapped in a cache, can report its source chain, +name chain, and node hash before it knows its schema. The node hash combines a +pending polling-source structure term with the name chain without polling. Once a batch +supplies the schema, the node hash combines the pipeline hash with the same name +chain. The chain-based content hash requires the schema. Downstream identities that +need the pipeline hash report that it is undefined until the schema is known. +Polling source chain reads use the memoized legacy content hash when available, +including when only the wrapped polling source has memoized it. +If computing that hash would call the polling implementation, the identity read +raises an undefined-identity error. This includes `name_chain()` and +`node_hash()` on a `Join` over a cold polling stream, even with a declared +schema. The legacy symmetry check uses the inputs' content digests to form a +set. The step 1 accessors report an undefined identity when that check needs +the polling implementation. + +A plain derived source, including one wrapped in a cache, has no source chain while +a contributing slot of its origin is unbound. Chain accessors report an undefined +identity when they would have to build a lazy upstream from rows or hash a raw +Arrow stream's rows. A raw Arrow stream can report its node hash from its schema +and anonymous name. Once the raw stream has memoized its legacy content hash, +the new chains can reuse that digest. + ## Hash site inventory Every place Orcapod produces a digest, and every place it reads one, with its class @@ -316,6 +369,7 @@ test session with `-p tests.test_hashing.hash_site_trace`. | Location | What is hashed | Algorithm / label | Used as | Call sites | |---|---|---|---|---| | structure hasher | a Python value as a tagged JSON tree | SHA-256 of canonical JSON, `semantic_v1` | every `content_hash()` / `pipeline_hash()`, type and function hash; the names built on schema hashes | `hashing/semantic_hashing/semantic_hasher.py:SemanticAwarePythonHasher._hash_to_content_hash` | +| three-chain hashes | a slot name, a pool of upstream chains, or the pipeline hash paired with one chain | SHA-256 of canonical JSON, with the corresponding chain or combined-hash label | into a hash for chain pooling and combining, or returned by an identity accessor | `core/identity_chains.py:_hash`, `core/identity_chains.py:_pool`, `core/identity_chains.py:IdentityChainsMixin._identity_hash`, `core/identity_chains.py:IdentityChainsMixin._compute_identity_chains..`, `core/identity_chains.py:IdentityChainsMixin._chain_content_hash`, `core/identity_chains.py:IdentityChainsMixin.node_hash`, `core/sources/polling_source.py:PollingSource._identity_node_pipeline_hash` | | Arrow hasher | a table after the semantic visitor | starfix, `arrow_v1` (a table Orcapod built: float rule on); `hash_table_strict`: `arrow_strict_v1` (a pyarrow table given as a value: every bit counts); `hash_table_ordered`: `arrow_ordered_v1` (a library value's digest: every bit counts); `hash_schema`: `arrow_schema_v1` | row data hashes, entry ids, row keys, default source ids, table values; every schema in an identity | `hashing/arrow_hashers.py:StarfixArrowHasher.hash_table`, `hashing/arrow_hashers.py:StarfixArrowHasher.hash_table_strict`, `hashing/arrow_hashers.py:StarfixArrowHasher.hash_table_ordered`, `hashing/arrow_hashers.py:StarfixArrowHasher.hash_schema`, `hashing/arrow_hashers.py:StarfixArrowHasher._digest`, `hashing/starfix_digest.py:_digest_table`, `hashing/starfix_digest.py:digest_schema` | | file hasher | a file's bytes | SHA-256 of the bytes, label `sha256`. Hashers, cache writes, and data context loading reject other algorithms. Direct cache lookups for other labels miss (ITL-1155). Custom file hasher results are verified against SHA-256 of the file bytes. | `File` value hash | `hashing/hash_utils.py:hash_file`, `hashing/semantic_hashing/builtin_handlers.py:FileHandler.handle`, `hashing/file_hashers.py:verified_file_hash`, `hashing/file_hashers.py:canonical_file_hash`, `hashing/file_hashers.py:_validated_file_digest`, `hashing/hash_cachers.py:InMemoryHashCacher.put`, `hashing/hash_cachers.py:SqliteHashCacher.get`, `hashing/hash_cachers.py:SqliteHashCacher.put`, `hashing/postgres_hash_cacher.py:PostgresHashCacher.get`, `hashing/postgres_hash_cacher.py:PostgresHashCacher.put` | | directory hasher | a directory tree | Merkle tree of SHA-256 entries, `directory_v1`; file leaves taken with their label. The handler verifies custom directory hashes against the library Merkle procedure. | `Directory` value hash | `hashing/directory_hashers.py:BasicDirectoryHasher.hash_directory`, `hashing/directory_hashers.py:_hash_dir`, `hashing/semantic_hashing/builtin_handlers.py:DirectoryHandler.handle`, `hashing/directory_hashers.py:verified_directory_hash`, `hashing/directory_hashers.py:canonical_directory_hash` | @@ -340,7 +394,7 @@ test session with `-p tests.test_hashing.hash_site_trace`. | Location | Hash consumed | Into | Form | Call sites | |---|---|---|---|---| -| nested hash in a structure | any nested hash: types, schemas, upstream streams, value hashes | the enclosing structure hash | `{"__type__": "hash", "label": ..., "digest": ...}` | `hashing/semantic_hashing/semantic_hasher.py:_nested_hash` | +| nested hash in a structure | any nested hash: types, schemas, upstream streams, value hashes | the enclosing structure hash | `{"__type__": "hash", "label": ..., "digest": ...}` | `hashing/semantic_hashing/semantic_hasher.py:nested_hash` | | schema identity | the `arrow_schema_v1` hashes of a source's or slot's Arrow tag and data schemas, or of a function's output Arrow schema | a source's content and pipeline identity, system-tag column names, the function `uri` | the `ContentHash` objects, nested | `utils/schema_utils.py:arrow_schema_identity`, `utils/schema_utils.py:compute_schema_hash`, `core/data_function.py:DataFunctionBase.output_data_schema_hash` | | union and generic alias arguments | argument type hashes, sorted by digest, then label (ordering only) | the type hash, via the nested form | as above | `hashing/semantic_hashing/builtin_handlers.py:_sorted_hashes`, `hashing/semantic_hashing/builtin_handlers.py:_sorted_hashes..` | | logical-type cell, scalar and container | a value-hashed cell's value hash | the Arrow table hash | `::