diff --git a/docs/dev/specs/itl-1559-three-chain-hash.md b/docs/dev/specs/itl-1559-three-chain-hash.md new file mode 100644 index 000000000..c0538f43c --- /dev/null +++ b/docs/dev/specs/itl-1559-three-chain-hash.md @@ -0,0 +1,590 @@ +# Three-chain hash design for slot identity (ITL-1559) + +Design decisions recorded on 2026-11-28. Measurements in this document use `main` at +`c1040ffa` unless noted. Related work includes ITL-1442, ITL-1427, ITL-1470, ITL-1506, +ITL-1472, ITL-1553, ITL-1554, ITL-1560 and ITL-1590. + +## 1. Summary + +Every stream, invocation and node has three hashes. A node downstream of an unbound slot has +no usable content hash until the slot is bound. + +| Hash | Definition | Use | +|---|---|---| +| `pipeline_hash` | Schemas and steps, including each step's upstream structure | Stored paths and system-tag column names | +| `content_hash` | `H(pipeline_hash, source_chain)` | Stored row and side-effect log attribution, and record ids | +| `node_hash` | `H(pipeline_hash, name_chain)` | Graph keys, `job.nodes`, edges, restrictions, and execution bookkeeping | + +The switch replaces the existing node content hash values. Slot names never reach the +stored content hash. The node hash contains no source binding, survives a rebind, and +exists for an unbound slot. Two differently named slots can therefore feed separate +graph nodes that share stored rows. + +## 2. How the chains are computed + +### 2.1 Hash labels and implementation + +PR 633 puts the hashing and traversal in `src/orcapod/core/identity_chains.py`. +`IdentityChainsMixin` provides `source_chain()`, `name_chain()`, `node_hash()` and +the internal `_chain_content_hash()`. It is used by `StreamBase`, `SourceNodeBase` +and `PodInvocation`. `PodInvocation` also gains `pipeline_hash()`. +`IdentityWalk` visits upstreams and reuses per-element results. The `IdentityChains` +record in `protocols/hashing_protocols.py` stores the source and name chain results +as `sources` and `names` and defers evaluation of the structural hash when possible. +A walk for `name_chain()` or `node_hash()` can skip reading source bindings where +the structural order is available without them. + +Each digest uses SHA-256 over the semantic hasher's canonical tuple, with nested +hashes embedded with their labels. The labels are defined in `core/identity_chains.py`. + +| Digest | Label | Preimage | +|---|---|---| +| Name leaf | `slot_name_v1` | `("slot", name)` | +| Multi-input source chain | `source_chain_v1` | Ordered upstream source chains | +| Multi-input name chain | `name_chain_v1` | Ordered upstream name chains | +| Content hash at the switch | `content_hash_v1` | `(pipeline_hash, source_chain)` | +| Node hash | `node_hash_v1` | `(pipeline_hash, name_chain)` | + +### 2.2 Leaves and node labels + +A slot contributes its declared Arrow schema to `pipeline_hash`, its bound source's +identity to `source_chain`, and its slot name to `name_chain`. PR 633 uses the +source's existing identity digest as the source-chain leaf. The declared slot schema +and the source's own schema can differ, for example when a non-nullable source is bound +to a nullable slot. A change in source schema or key columns can then distinguish two +readings of one dataset. + +| Leaf | Pipeline structure | Source-chain contribution | +|---|---|---| +| Root source, including Arrow, in-memory, file and database sources | Arrow schema | Source id, source schema identity, and record-id key columns | +| `SpiralDBTableSource` | Arrow schema | Root identity with the `tags_as_data` mapping when given. Restrictions are outside the hashes | +| `PollingSource` | Arrow schema when known | Source id, implementation identity, sorted tag columns, and key columns. Its identity is provisional (ITL-1316) | +| `CachedSource` | Wrapped source's structure | Wrapped source's identity. Its cache address follows the source identity | +| Plain `DerivedSource` | Arrow schema | Derived source identity uses the origin node's `content_hash`. An unbound origin leaves the source chain absent | +| `DerivedSource` with `tags_as_data` | Arrow schema | Root identity with the sorted mapping. This form requires a `source_id` | +| `SourceProxy` | Saved pipeline hash | Saved source identity. A delegate must match the saved source and pipeline identities | +| Raw `ArrowTableStream` | Arrow schema | Legacy digest of the canonically ordered table, when available | +| Unbound slot | Declared Arrow schema | Absent | + +**DQ2.** Outside a slot, the plain stream's name-chain leaf is the source's label. +A follow-up issue will re-evaluate this rule. PR 633 currently uses `RootSource.source_name` +for an uncaptured root source and an anonymous term for a raw Arrow stream. Its +`slot_name_for()` helper also uses `source_name` for an implicit root slot. +The slot's name, once assigned, is the slot's leaf. + +A step's display label enters none of its chains. A step node has one label. Declaring the +same computation again with a label replaces the earlier label. A declaration that +omits a label preserves the most recently given label. For example, declaring the same +step as `r1`, then `r2`, then without a label leaves one node displayed as `r2`. +Slot names are separate from step labels. + +**BL16 (a).** In step 3, steps without labels that receive the same automatic name +are numbered in `node_hash` order. Add a sentence documenting that rule. + +An unbound slot and its downstream nodes have a name chain and a node hash. +`source_chain()` returns `None`. Asking for the combined content hash raises +`UnboundSourceError` naming the unbound slots. A run leaves those branches out. +The saved file can represent the absent current content hash as `null`. + +### 2.3 One walk and input order + +Compute the chains together in one graph walk. At a single-input node, both upstream +chains pass through unchanged. At a multi-input node, hash the upstream chains in the +order fixed by the pipeline hash. Keep every occurrence, including repeats. + +| Producer | Input order | +|---|---| +| Unary operators, function pods and side-effect pods | Pass through their one input. A function pod over several streams has a separate join node before it | +| Ordered operators, including `SemiJoin` and `MergeJoin` | Argument order | +| Commutative operators, including `Join` and `Rejoin` | Canonical structural order. Within a group of equal pipeline hashes, sort the source chains by their own values and the name chains by theirs | + +For nested symmetry, each group uses the rule for its own kind. PR 633 obtains the +grouping from `argument_symmetry` via `encode_input_symmetry()`, retains input +positions, and sorts structural keys in `_pool_group()` by the canonical JSON of +the nested pipeline hashes. Inside a structural tie the implementation sorts each +chain by its labelled hash value. In step 1 the old pipeline hash remains in use, +so a legacy set that collapses equal inputs makes the combined hashes undefined. +Step 2b replaces that dependency with the input list. + +Equal-pipeline-hash inputs occur on `main`. Two inputs of one schema can reach +`Join` or `Rejoin` when all their data columns are data-tags. A shared ordinary data +column causes both operators to refuse the pair. A shared data-tag acts as a join key. +`MergeJoin` uses the argument index in system-tag names. `Rejoin` retains the input +system-tag names. + +A node may contribute its own term to either chain. No node does so today. +`_identity_terms()` supplies those optional terms in PR 633. If supplied, the term +is hashed with the pooled value, including for a single input. Anything that +distinguishes nodes that can coexist in one graph must be represented in +`pipeline_hash` or `name_chain`. A term only in `source_chain` must behave like +a binding, with one value per node at a time and the freedom to change without re-keying +the graph. + +### 2.4 Step 1 limits in PR 633 + +- A name-only walk normally avoids reading source identities. Legacy commutative + symmetry can still require an input content digest. A cold polling source in + such a group, or a lazy input requiring a row build, can make the new accessors + fail in step 1. A raw Arrow leaf can return `node_hash()` from its schema and + anonymous name, and its source chain can reuse a previously memoized digest. +- A polling leaf or a cached polling leaf can use a pending-schema structural term + for `node_hash()` before its schema is known. This is an implementation exception + to the final formula. The combined content hash and downstream identities that need + its pipeline hash require the schema. Source-chain access reuses a warm source + digest and refuses to call the polling implementation to obtain a missing one. +- A loaded built-in operator with one input can use its saved pipeline hash and + pass through both chains even when the implementation is unavailable. An + unavailable operator with several inputs needs its input symmetry to reconstruct + the chains. The step 1 saved form does not carry that symmetry. Custom operators + also leave the new accessors undefined in step 1. +- Transparent wrappers and row builds representing an existing stream delegate to + the underlying stream for the chains. A plain stream and the job node compiled from + the same computation are intended to agree on structure and source chain, subject + to the capture and saved-form limits above (ITL-1470). +- The step 1 walk tracks bindings through wrappers, including stored-result + `DerivedSource` objects whose origin belongs to another job. A rebind in the + origin job refreshes dependent source chains. A live input to another job that + depends directly on a job slot is still refused. + +## 3. Pipeline hash changes and row ids + +### 3.1 Context-taking function pods (D29) + +Step 2a (PR 634) gives a function pod that takes the invocation context its own +pipeline hash. `FunctionPod.pipeline_identity_structure()` uses +`(self.data_function, self._ctx_arg_name)` when the name is set and the data +function alone otherwise. This distinguishes two operations with the same underlying +function URI and propagates to the downstream `schema:` path +component, system-tag names that embed the affected hashes, and invocation keys. +The prototype held no context-taking pod golden case. + +**D29 (a)** is a breaking change. An upgraded live job does not detect the prior +completion and result stores at their prior paths. A context-taking pod or an affected +downstream tap can deliver once more for previously processed inputs whose completion +or result was recorded there. The stored table format is unchanged. PR 634 also +scopes result cache paths by the context parameter via `context_result_path()`. +Its saved-job descriptor records +`result_record_path` for context-taking pods without changing the format marker. +Saved jobs can still read results at their recorded or legacy paths when those stores +are retained. This is separate from completion lookup by a live upgraded job. + +### 3.2 Commutative input lists and tied joins (D32) + +Step 2b computes a commutative operator's pipeline hash from the input **list**, +preserving multiplicity. It builds on the positioned inputs in PR 587 +(`pipeline/edges.py`, including `input_positions`). + +On the measured baseline, a commutative `argument_symmetry` returns a frozenset of +streams, which drops members equal by content. Two equal-pipeline-hash inputs can +therefore yield different pipeline hashes depending on whether the sources are equal +(ITL-1590). For the measured all-data-tag join, `Join(A, B)` and `Join(B, A)` +gave the same pipeline hash, while `Join(A, A)` and `Join(A, A')`, with `A'` an +equal object, gave another. With the input list, all four use the same structural +preimage with two occurrences of the input hash. The historical prototype pinned no +case with collapsed inputs. + +**D32 (a).** Step 2b owns tied-join correctness because it rewrites ordering within +an equal-pipeline-hash group. The original faults concerned custom system tags +separated from their input's ids, differences between three-input row channels and +sync tables, and inconsistent record-id nullability. PR 607 already pairs custom +system tags with their input ids in the tested standalone row-channel joins and +pins agreement for symmetric ties across sync tables, row channels and batch +channels. It also pins the existing per-mode behavior for ties with different field +declarations. Use that merged baseline in step 2b to retain the covered behavior +and close remaining differences, including any record-id nullability discrepancy +between yielded rows and tables. + +The developer approves the exact list of values that move before any golden value is +regenerated for step 2b. + +### 3.3 Row identifiers + +The node content hash is stored in `__node_content_hash` and enters the operator +cache's row key. A pipeline record id hashes the recording node's content hash, the +instance id and the result id (`core/row_ids.py`). The record id is the pipeline +table's key. An entry id hashes the row's user tags, system tags and input data hash. +An instance id hashes the entry id and the input's typed source-info token columns, +which PR 607 preserves through transport and storage. A changed system tag or +derived source token can therefore change an entry or instance id. + +### 3.4 Side-effect log attribution and completion + +**SL2 (a).** The side-effect log identifies the writing node solely by its +`content_hash`, in `__node_content_hash`. The log omits a node-hash column, keeping +slot names out of row storage. + +**SL3 (a).** Side-effect completion remains keyed by the delivered row's entry id. +With completion tracking, two sinks of one pod over one source deliver each row +once. Renaming a slot leaves the completion key unchanged and repeats no delivery. +PR 650 specifies the side-effect log layout. + +## 4. Worked examples + +Let `x` and `y` be slots with one declared schema, `A` and `B` be source +identities, and `f`, `g` and `h` be pods. + +| Graph | Chain and hash result | +|---|---| +| `x -> f -> g`, with `x` bound to `A` | All three nodes share the source leaf for `A` and name leaf for `x`. The pipeline hash distinguishes each step | +| Diamond `x -> (f, h) -> Rejoin` | The join hashes both occurrences of the source leaf for `A` and both occurrences of the name leaf for `x`, in the order of the branches' pipeline hashes | +| `x -> f -> g` and `y -> f -> g`, both bound to `A` | Each pair of corresponding steps has equal pipeline and content hashes but distinct node hashes. Each pair shares stored rows | +| Same branches, `x` bound to `A` and `y` bound to `B` | Each pair still shares a pipeline hash and table path. Their content hashes distinguish the rows. Their node hashes are the same as before | +| `Join(x, y)` with equal structural inputs, `x` bound to `B`, `y` to `A` | The pipeline hash includes two equal input hashes. If the source hashes sort as `A, B` and the name hashes as `x, y`, the source chain orders `y` first and the name chain orders `x` first. Swapping the two bindings yields the same pair of chains | +| `x -> f -> g`, then `job.bind(sources={"x": B})` | The node hashes, graph edges, restrictions and default table paths stay stable. Each downstream content hash incorporates `B`, and earlier rows keep the content hash under which they were written | +| `x -> f -> g` in an unbound blueprint | Node keys match the bound graph's node keys. The source chain and the live content hash are absent | + +## 5. Inventory + +Line numbers refer to `src/orcapod/` at `c1040ffa`. Section 3.4 records the +side-effect log decisions for PR 650. + +### 5.1 Graph keys move to `node_hash` + +| Place | What it does | +|---|---| +| `core/base.py:178`, `:189` | `__hash__` and `__eq__` of every stream, node and invocation: content hash and identity structure. Every node-keyed dict and set below goes through these | +| `pipeline/base.py:341`, `:344` | `_record_invocation`: the invocation's key and its upstream keys in `_hash_graph`, `_invocation_lut`, `_source_streams` | +| `pipeline/base.py:360` | `_remember_invocation` used to keep the smallest label for one key. Keep the most recently given label under the new rule | +| `pipeline/base.py:519`, `:522` | compile: leaves found and ordered by hash key | +| `pipeline/base.py:578` | compile: a node's upstream nodes looked up by the input's content hash | +| `pipeline/base.py:611` | compile: equal labels numbered in content hash order | +| `pipeline/base.py:622` to `:637`, `:656` to `:662` | `_persistent_node_map`, `_node_graph`, `_node_lut`, `_upstreams`, `_graph_edges`, all keyed by the hash key | +| `pipeline/base.py:667` | `_ordered_node_map`: ties broken by the key | +| `pipeline/base.py:727`, `:805`, `:809` | `to_invocations` and `from_invocations` rebuild the graph by content hash | +| `pipeline/dag.py:116` to `:121` | `OrcaDAG` keeps nodes as dict keys (`__hash__`); `networkx_backend.py` the same | +| `pipeline/job.py:192` to `:197`, `:255` to `:264`, `:548` to `:555` | `_sources_by_hash`, and the second index by the schema-based hash of `as_node()` | +| `pipeline/job.py:769` to `:846` | `as_pipeline`: maps job keys to blueprint keys, because the two differ today | +| `pipeline/job.py:953` to `:970` | `is_runnable`: walks `_hash_graph`, with a comment that the object graph breaks after `bind()` because `SourceJobNode.__hash__` changes | +| `pipeline/job.py:1305` to `:1368` | the run: the hash-keyed DAG, the excluded set and the execution DAG of node objects. Equal nodes collapse here (ITL-1442) | +| `pipeline/job.py:2006` to `:2149` | `load`: node map, predecessors and node graph by saved key | +| `pipeline/graph.py:174`, `:175`, `:293`, `:300` | save: nodes keyed by content hash, edges as pairs of those keys | +| `pipeline/graph.py:356` to `:652` | load: nodes and upstream map by saved key | +| `pipeline/sync_orchestrator.py:108`, `:109`, `:114` | `outputs`, `processed` and `held_streams` keyed by node | +| `pipeline/async_orchestrator.py:230` to `:274` | edge maps, output channels, edge readers, collectors, held rows keyed by node | +| `pipeline/node_run.py:276` to `:280` | `RunPlan.held`, `held_counts`, `held_rows` keyed by node | +| `core/nodes/source_node.py:1534`, `:2187` | implicit names for non-source leaves use the label and content hash. PR 613 refuses these leaves at capture | +| `core/nodes/function_node.py:2111`, `:2174`, `:2667`, `:4154`, `:4563`; `operator_node.py:1757`, `:2336`; `source_node.py:1366`, `:1406` | `node_hash` given to `on_node_start` and `on_node_end` (`protocols/observability_protocols.py:116`). The observer sees separate nodes even when they share a content hash | +| `pipeline/restrictions.py:213` | restrictions found per source content hash in the baseline. Under ITL-1472 they are kept per edge, keyed by node hash | + +Already keyed by `id()` and unaffected: staleness (`core/nodes/staleness.py:98`, `:113`), +the diagram (`pipeline/diagram.py:434`), provenance tracing (`pipeline/provenance.py`), +the run summary (`pipeline/run_summary.py:532`), the sync orchestrator's neighbour map +(`sync_orchestrator.py:102`). + +### 5.2 Storage uses `H(pipeline_hash, source_chain)` + +| Place | What it stores | +|---|---| +| `core/nodes/function_node.py:3271` | the record id's preimage (`row_ids.py:136`) | +| `core/nodes/function_node.py:3288` | `__node_content_hash` of a pipeline row | +| `core/nodes/function_node.py:2292`, `:3601`, `:3709` | reads that keep this node's rows in a shared table | +| `core/nodes/operator_node.py:1455` to `:1479` | `__node_content_hash` of an operator cache row, and through it the row key `_record_hash` | +| `core/nodes/operator_node.py:1398` | `_filter_by_content_hash` on every cache read | +| `core/nodes/function_node.py:670`, `operator_node.py:536` | the `instance:` path component of `table_scope="content_hash"` (not the default) | +| `core/sources/derived_source.py:292`, `:325` | a plain derived source's default id and identity, from the origin node | +| `pipeline/job.py:1376` | the run URI's snapshot hash, from the sink nodes | +| `pipeline/job.py:1686` to `:1705`, `:2029` to `:2121` | `run.node_job_content_hashes` in a saved job, by label | +| `pipeline/graph.py:226`; `function_node.py:1130`, `:1879`; `operator_node.py:790`, `:1137`, `:1189`, `:1300`; `loaded_side_effects.py:65`, `:209` | the `content_hash` of a saved node descriptor, and a loaded node returning it | + +Source registration, saved source descriptors, proxy matching and source cache paths +use the source identity that supplies the leaf of `source_chain` (baseline +`sources/base.py:461`, `source_proxy.py:125`, `cached_source.py:292`). Pod and row +hashes have their own preimages, including `pod_hash` (`function_pod.py:497` and +`hooks.py:66`), operator URIs (`static_output_pod.py:232`), and `data.content_hash()`. + +### 5.3 Structural consumers use `pipeline_hash` + +| Place | Use | +|---|---| +| `function_node.py:668`, `operator_node.py:534`, `side_effects.py:1203` | the `schema:` component of pipeline, operator cache and side-effect log paths | +| `join.py:215`, `:432`, `:485`, `:496`; `streaming_joins.py:691`, `:716`, `:1525`; `merge_join.py:348`; `batch.py:198`, `:232`; `group_by.py:555`, `:731`; `operator_node.py:2391` | canonical input order and system-tag column names | +| `side_effects.py:208`, `:989`, `:1288`, `:1543`; `function_pod.py:218` | `invocation_hash` combines the pipeline hash and entry id | +| `static_output_pod.py:991`, `:1924`; `semijoin.py:319`; `index.py:140`; `pick.py:151` | per-input caches and declared forms keyed by pipeline hash | +| `pipeline/provenance.py:447`, `:479`, `:516`, `:1198` | finding an input's system-tag columns | +| `pipeline/graph.py:227`, `pipeline/base.py:653`, `:680`; `sources/base.py:462`; `source_proxy.py:131` | saved and compared pipeline hashes | + +## 6. Source registration and shared storage + +**D31 (a).** PR 577 introduced an interim rule that refuses a second source object +with the same content hash in one job (`InconsistentSourceError`). Step 6 lifts both +two-slot refusals: + +| Binding in one job | Step 6 result | +|---|---| +| One source object on two differently named slots | Both slots are accepted | +| Two equal source objects on two differently named slots | Both slots are accepted. This is a step 6 acceptance test | +| Two source objects that would take the same slot name | They refer to one slot | + +A later direction is to check equivalence between source objects within a job according +to the source kind. That work is separate from this series. Equal source identities +rely on the source's contract to identify the same reading. The chains cannot establish +row equivalence by themselves. + +**DQ1.** Two nodes with equal `content_hash` share stored tables. The second writer +finds the first writer's rows and writes only missing rows. Apply this to pipeline +writes and operator-cache writes, including concurrent writers. Pipeline writes +need to check for an existing instance within the table and node content hash. +The record id includes a result id, so a record-id uniqueness check alone can miss +duplicates from concurrent computation. The operator cache key `_record_hash` +already covers the row. The exact synchronization mechanism remains open. + +Other slot and capture behavior from PRs 577, 608 and 613: + +- Different readings of one source id, such as different key columns, can occupy + distinctly named slots. Readings that would take the same slot name still refer + to one slot (ITL-1506). +- A recorded step retains its key after a rebind. Step 6 can remove the capture-after-bind + refusal. Removing the refusal for a prebuilt stream over the job's own slot also + depends on capture matching the slot correctly. The capture rule for prebuilt + streams remains open (ITL-1470 and ITL-1387). +- Foreign or standalone mutable slot objects, captured slot renames, and a slot + label that collides with a step label remain subject to the existing refusals. + A rename changes the name chain and would require an explicit graph operation. +- A captured leaf must be a source. Direct dependencies on mutable job slots + remain subject to the existing binding checks. General support for composite + bindings is separate work (ITL-1127). PR 633 already follows accepted bindings + through sources backed by another job's stored results. +- Capture and recompilation of a loaded job remain separate work (ITL-1560). + Step 4 prepares the graph with stable keys and ordered inputs. + +## 7. Golden entries + +A read-only prototype computed all 2,504 golden entries on the measured baseline, +then recomputed them with `H(pipeline_hash, source_chain)` for derived streams, nodes, +and invocations. It retained the existing leaf digests and pipeline hashes for that +comparison. It neither ran the generator nor edited the golden files. + +### 7.1 The prototype moved 104 entries + +| File | Entries | Class | Reason | +|---|---|---|---| +| `pipeline-02.json` (open revision, frozen at 0.4.0) | 25 | `content_hash` of a derived stream or job node | the definition is replaced | +| `provisional/pipeline.json` | 77 | the same, in cases that use a provisional operator | the same | +| `provisional/pipeline.json` | 2 | default source id of `node.as_source()` | it holds the origin node's content hash | + +`pipeline-02.json`, 25 entries, all `.content_hash`: +`column_selection.drop_data`, `column_selection.drop_tag`, `column_selection.select_data`, +`column_selection.select_tag`, `drop_nulls.data`, `drop_nulls.data_many`, +`drop_nulls.tag`, `drop_nulls_all.all`, `drop_nulls_all.method`, +`drop_nulls_job.node[present]`, `drop_nulls_job.node[ratio]`, +`drop_nulls_job.node[renamed]`, `job.node[adjust]`, `job.node[joined]`, +`join_key_nullability.join`, `join_key_nullability.semi_join_left_nullable`, +`join_key_nullability.semi_join_right_nullable`, `join_pod.join`, `join_pod.pod`, +`map_data`, `pod`, `semi_join`, `tag_and_data_columns.drop`, +`tag_and_data_columns.select`, `tag_and_data_columns.select_tag_and_data`. + +`provisional/pipeline.json`, 77 entries, all `.content_hash`: + +- `add_tags.every_type`, `add_tags.method`, `batch`, `filter.keyword`, `filter.terms`, + `filter.tree`, `group_by`, `group_by_nan_keys`, `group_by_nan_keys.data_tag_key`, + `index_pick.index`, `index_pick.pick`, `join_key_nullability.merge_join`, + `map_columns.drop_unmapped`, `map_columns.rename`, `merge_join`, `polars_filter`, + `polars_filter_expr.expr`, `polars_filter_expr.mixed` (18); +- `filter_job.node[adjust]`, `filter_job.node[joined]`, `filter_job.node[older]`, + `polars_filter_expr_job.node[adjust]`, `polars_filter_expr_job.node[joined]`, + `polars_filter_expr_job.node[older]` (6); +- `group_by_arrangement.{default,grouped_again,member_order_y}.{interleaved,reversed,tags_first}` (9); +- `rejoin.filtered_branch`, `rejoin.method`, `rejoin.pod_branch`, `rejoin.three`, + `rejoin.three_reordered`, `rejoin.two`, `rejoin.two_reordered` (7); +- `rejoin_arrangement.{job_async,job_sync,stream}.{data_tags,mixed,plain}.{interleaved,reversed,tags_first}` (27); +- `rejoin_job.node[X]` and `rejoin_job_async.node[X]` for `X` in `SelectDataColumns`, + `ages`, `ratio`, `rejoined`, `weights` (10). + +`provisional/pipeline.json`, 2 entries: `default_source_ids.as_source[function_node].source_id` +and `default_source_ids.as_source[operator_node].source_id`. + +After PR 609 two more move with them. These are the two `content_hash` entries it adds +for the plain derived sources, which use the origin node's content hash. + +Pairs that are equal today stay equal: `rejoin.two` and `rejoin.two_reordered`, +`rejoin.three` and `rejoin.three_reordered`, and the three arrangements of each +`group_by_arrangement` and `rejoin_arrangement` variant. + +### 7.2 Entries that stayed stable in the prototype + +| Class | Entries checked | +|---|---| +| Pipeline hashes (`*.pipeline_hash`) | 179 | +| System-tag column names (`*.system_tag_columns`) | 164 | +| Record id and source id values of rows (`_tag_record_id::*`, `_tag_source_id::*`) | 421 each | +| Row data hashes and tag hashes | 409 and 12 | +| Stored table paths (`*.table_paths`) and pipeline instance ids | 6 and 6 | +| Result-table keys (`*.input_data_hashes`) | 6 | +| Function uris, schema hashes, table hashes | 2, 38, 9 | +| Source ids of root sources (`schema-01.json`, `pipeline-02.json`) | 42 | +| Content hashes of root sources, raw streams and operators | 119 | +| Every entry of the `arrow`, `semantic`, `datagram`, `schema` and `torch` groups | all | + +Source-info tokens: no golden row sits below a default-named derived source, so no token +moves. Outside the golden files, a token that names such a source does move, with the +source id. + +Record ids and the operator cache's `_record_hash` move at the switch. The golden +files do not pin those keys. The pinned `_tag_record_id` values above are system tags. + +### 7.3 Other hard-coded values + +Nine test files outside the golden folder hold 64-hex literals, and 184 test files call +`content_hash()`. Each must be read when the definition changes (grep `tests/` and +`test-specification/` for 64-hex literals and run those files before reporting). + +### 7.4 Approval and freeze + +V1 hashes and stored layouts freeze with the 0.4.0 release on 2026-12-07, subject +to the repository's existing provisional identity rules. Step 5 requires the +developer's approval of the exact golden entries that move, each with an explanation. +Recompute the list on the final base after PR 609. The prototype moved 104 of 2,504 +entries, rising to 106 after the derived-source additions in PR 609. These counts +describe the prototype and do not substitute for the approval list. +PR 607 changed three `source_stream_builder.*.content_hash` pins in +`schema-01.json`, outside the prototype's move list. Use those updated values in +the baseline for the final comparison. + +**BL13 (a).** Add golden pins for data-tag identities after step 5 and before the +0.4.0 freeze. + +## 8. Implementation plan + +| Step | PR | What it changes | +|---|---|---| +| spec | 632 | This document | +| 1 | 633 | Compute `source_chain`, `name_chain` and `node_hash` alongside the old hashes. Graph and storage consumers continue to use the old values. Saved files are byte-identical | +| 2a | 634 | Give a context-taking function pod its own pipeline hash | +| 2b | To be written, on PR 587's work | Compute a commutative operator's pipeline hash from the input list, retaining equal inputs. Fix the tied-join faults in D32 | +| 3 | To be written | Key graph state, `job.nodes`, edges and restrictions by `node_hash`. Number steps with the same automatic name by node hash and document the rule | +| 4 | To be written | Write the new hashes into saved job files. Reuse the PR 645 acceptance test | +| 5, the switch | To be written, after PR 609 | Switch `content_hash` to `H(pipeline_hash, source_chain)` for storage and record ids, and refresh the content hash after binding. Requires approval of the exact list of golden entries that move | +| 6 | To be written | Lift both two-slot refusals. Equal-content nodes write if missing | + +The bind refresh follows the source chain at every depth, including in a loaded job +(ITL-1427). Using stable graph keys also addresses the slot that becomes unreachable +in the run graph after a bind (ITL-1204). The positioned inputs from PR 587 supply the +list in step 2b and take node-hash keys in step 3. They make restrictions per edge +possible. The edge registry and how a restricted view is represented in storage remain +part of ITL-1472. Step 4 addresses the saved-key collision for several slots bound to +one source (ITL-1554). + +## 9. Acceptance tests + +### 9.1 Hashes, ordering, and labels + +- Through the public APIs, compare a plain stream, its invocation and its job node. + Cover pipelines built before and inside capture, input column permutations, and + the sync and async paths. Use the ITL-1470 test from PR 579 where appropriate. +- Verify single-input pass-through and argument order for `SemiJoin` and + `MergeJoin`. Verify canonical structural order and repeat preservation in diamonds + and in two- and three-input commutative operators. Verify independent tie sorting + with the source and slot names ordered differently. +- For two all-data-tag inputs of equal pipeline hash, verify identical pipeline + hashes whether the two slots hold the same object, equal objects, or distinct + sources. Permuting the same two bindings gives the same chains, table, and + system-tag names and values. Cover custom system tags, three tied row-channel + inputs, and consistent record-id nullability across paths (D32). +- Verify that a plain pod and a context-taking pod over one source have different + pipeline hashes and graph keys. Verify the additional delivery after upgrading a + live job with a prior store, followed by normal completion lookup (D29). +- Verify that an unbound slot and its branch have node hashes, and that a request + for their live content hash names the unbound slots in its error. +- Declare one computation with `r1`, then `r2`, then without a label. Verify a single + node labelled `r2` in `job.nodes`, the run summary, and a saved and loaded job. + Reverse the two labels and expect `r1`. Check that the hashes are independent of + those labels. Verify automatic-name numbering in node-hash order (BL16). +- Check the new labels and hash sites against the hashing grammar and inventory. + Verify the byte-identical saved form in step 1. + +### 9.2 Binding, persistence, and shared tables + +- Run two separately named branches on one source object. Repeat the test with + **two equal objects on two differently named slots**. Each branch has distinct nodes + and edges, both hold all rows, and there is one stored pipeline entry per row and + one result per input. Check sync and async, the first run and a repeat, and a + branch with a caching operator. +- Unbind one slot and verify only the bound branch runs. Bind two sources to the + two slots, rebind to one and then back. Verify the node hashes stay stable, the + content hashes follow the binding at every depth, and old rows retain their + stored content hashes. +- Read one dataset with different key-column choices from differently named slots. + Save and load the two-slot cases, including one source in several slots feeding + one function pod (ITL-1554). Under otherwise identical `as_source()` settings, + equal-content nodes produce the same derived source id. +- Load a job with a source it cannot reconstruct, save it again, and verify the + source record is preserved (BL11, PR 645). Repeat this test for the step 4 writer. +- With completion tracking, run two sinks of one side-effect pod over the same + source. Verify one delivery per entry id and attribution by the writer's + `content_hash`. Rebuild with a renamed slot against the same store and verify + zero repeat deliveries (SL2 and SL3, PR 650). + +## 10. Alternatives considered + +- **Context-taking pods (D29).** Refusing two pods of the same URI in a graph or + adding the context argument to both auxiliary chains would distinguish those + operations. Step 2a puts the distinction in pipeline structure. +- **Pooling.** A flat list of leaves grows to one item per root-to-node path. + Twenty consecutive diamonds would give over a million entries. Hashing the + upstream values keeps each pooled result fixed-size while the pipeline hash fixes + the input structure. +- **Leaf hashes and labels.** Alternatives included omitting schema from the source + leaf and reusing the general `semantic_v1` label for the new hashes. Step 1 + reuses the source's identity preimage and gives the new digests distinct labels. +- **Unbound slots.** A placeholder content hash could reach storage. The live + content hash is absent until a source is bound. +- **Display labels and plain streams.** Putting step labels into the name chain + would make repeated declarations into separate nodes. Giving plain streams no + name chain would defer their node hash to capture. The decisions are recorded + in section 2.2. +- **Shared tables (DQ1).** Computing once and feeding both nodes can skip rows + when the nodes have different restrictions. That could be a later optimization + where the rows agree. Step 6 requires write-if-missing for shared storage. + +## 11. Open questions + +| Question | Decision or remaining work | +|---|---| +| Q1. Does a step's display label affect its node hash? | Decided in the first update (section 2.2). Labels stay out of the hashes. The most recent explicit label wins on one node. | +| Q2. What name-chain leaf does a plain stream use outside a job? | Decided by DQ2 for this rollout. Use the source label. A follow-up will re-evaluate that rule, and plain-stream equality outside graph keys remains open. PR 633's source-name behavior is documented in section 2.2. | +| Q3. How do two nodes with equal content hashes share storage? | Decided by DQ1. Pipeline and operator-cache writers write if missing. The synchronization mechanism remains open. | +| Q3 follow-up. Do two side-effect sinks of one pod over one source deliver each row once, including after a slot rename? | Decided for tracked completion by SL3 (a), using entry ids. The original proposal also asked about deduplication with `track_completion` disabled. That case remains open. | +| Which node identifier does a side-effect log row store? | Decided by SL2 (a). The log identifies the writer solely by `content_hash` in `__node_content_hash`. | +| Q4. What does a restricted chain's `as_source()` show without a membership table? | Still open. Options are all rows under the content hash, refusal with a pipeline filter as the remedy, or reapplying the restriction where the columns survive. The original recommendation was refusal. | +| Does step 4 read saved jobs from earlier development builds? | Still open. BL22 (a) settles the format marker, and BL11 (a) settles preserving a source record on re-save. The loader policy for earlier unreleased files remains open. | +| What is the final behavior for cold polling sources, unavailable multi-input operators and custom operators? | Still open beyond the step 1 limits in section 2.4. | +| How should PRs 587, 608 and 613 be integrated? | Still open. Step 2b uses PR 587's positioned inputs and step 3 re-keys its edges. The integration order for PRs 608 and 613 relative to the remaining steps is still open. | +| How should capture handle a prebuilt stream over the job's own slot? | Still open (ITL-1470 and ITL-1387). Section 6 records the dependency on matching the slot correctly. | + +## 12. Rebinding, saved jobs, and cost + +### 12.1 Rebinding and source attribution + +A bind invalidates the source-chain and content-hash results downstream of the +slot. The graph keeps the same node hashes and the pipeline and name terms stay +the same. At a commutative structural tie, the independently sorted chains cannot +recover which slot held which source. Store that association per slot in saved jobs +and any future membership table. + +The switch replaces the old hash values. Rows that are still at the same path with +an old `__node_content_hash` are outside the upgraded node's reads. The digest +labels distinguish the values. Any later membership table can use the node hash as +its key, reference entry or instance ids in the pipeline table, and record the +content hash under which membership was collected. + +### 12.2 Saved job files + +Step 4 keys saved nodes and edges by `node_hash` and saves the new hashes and +ordered inputs. A saved slot records its name and the identity of its bound source. +A loaded node retains the saved pipeline hash. Where the saved descriptor and +upstream nodes suffice to derive its chains, a loaded bound node can recompute the +live content hash after a rebind. If the source cannot be rebuilt, the node can read +its prior rows using the recorded content hash. Preserve the source record when +saving that job again (**BL11 (a)**, PR 645). + +**BL22 (a).** The saved-file marker names the format of the first release. Changes +before 0.4.0 is released keep that marker. A format change after the release changes +the marker and comes with an upgrade function or a permissive loader. + +### 12.3 Prototype cost + +A cold 50-node unary chain in the prototype used 394 calls to the semantic hasher +to compute both old hashes (1.6 ms). Computing the pipeline and both combined +hashes at every node used 297 calls (1.2 ms). A multi-input node adds pooling for +each auxiliary chain and a commutative group also sorts its inputs. The prototype +did not measure a cold join-heavy graph.