From 77462ab93bcc7ec32641d85d35cf820683bf47e9 Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" Date: Sun, 29 Nov 2026 01:20:27 -0800 Subject: [PATCH 1/7] fix(pipeline): retain commutative input occurrences in structural hashes Part A of ITL-1590. Keep historical row layout and count occurrences in the three chains and capture keys. --- .zed/rules | 5 +- CLAUDE.md | 6 +- changelog.d/ITL-1590.md | 15 ++ docs/dev/design_issues/ITL-1559-TC1.md | 10 +- docs/dev/design_issues/ITL-1590-CS1.md | 18 ++ docs/reference/hashing.md | 17 +- src/orcapod/core/base.py | 37 ++- src/orcapod/core/identity_chains.py | 222 ++++++++++-------- src/orcapod/core/nodes/function_node.py | 1 + src/orcapod/core/nodes/operator_node.py | 17 +- src/orcapod/core/operators/batch.py | 5 +- src/orcapod/core/operators/group_by.py | 5 +- src/orcapod/core/operators/join.py | 22 +- src/orcapod/core/operators/merge_join.py | 3 +- .../core/operators/static_output_pod.py | 9 +- src/orcapod/core/operators/streaming_joins.py | 7 +- src/orcapod/core/streams/base.py | 37 ++- .../semantic_hashing/semantic_hasher.py | 12 +- src/orcapod/pipeline/base.py | 101 +++++++- src/orcapod/pipeline/graph.py | 3 + src/orcapod/pipeline/job.py | 4 + src/orcapod/pipeline/pod_invocation.py | 95 +++++++- src/orcapod/pipeline/provenance.py | 9 +- src/orcapod/pipeline/restrictions.py | 7 +- src/orcapod/protocols/core_protocols/pod.py | 8 +- src/orcapod/protocols/hashing_protocols.py | 23 +- src/orcapod/types/argument_groups.py | 26 ++ tests/test_channels/test_polling_source.py | 9 +- .../operators/test_async_sync_equivalence.py | 24 ++ tests/test_hashing/test_identity_chains.py | 162 ++++++++++--- tests/test_pipeline/test_deep_capture.py | 69 ++++++ 31 files changed, 748 insertions(+), 240 deletions(-) create mode 100644 changelog.d/ITL-1590.md create mode 100644 docs/dev/design_issues/ITL-1590-CS1.md create mode 100644 src/orcapod/types/argument_groups.py create mode 100644 tests/test_pipeline/test_deep_capture.py diff --git a/.zed/rules b/.zed/rules index a1858c50f..83e0d2caf 100644 --- a/.zed/rules +++ b/.zed/rules @@ -1318,7 +1318,10 @@ these preimages anywhere else. else: blocks) only for a module `import orcapod` never loads (networkx, deltalake, pyarrow.fs, pyarrow.dataset, git) and the optional extras (psycopg, ray, spiral); tests/test_utils/test_lazy_module_use.py checks it. -- Argument symmetry — operators return frozenset (commutative) or tuple (ordered). +- Argument symmetry — `structural_argument_symmetry(streams)` describes the occurrences + in a structural identity. A commutative `SymmetricGroup` sorts hashes and keeps repeats. + A tuple preserves argument order. `argument_symmetry(streams)` still supplies the legacy + content and row-layout digests (ITL-1590). - StaticOutputPod.process() → DynamicPodStream — wraps static_process() with staleness detection and automatic recomputation. - Source delegation — CSVSource, DictSource, etc. create an internal ArrowTableSource. diff --git a/CLAUDE.md b/CLAUDE.md index 33273dd7e..60f5884d0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1364,8 +1364,10 @@ and `as_table()` methods. `all_info=True` sets everything to True. `import orcapod` never loads (networkx, deltalake, `pyarrow.fs`, `pyarrow.dataset`, git) and for the optional extras (psycopg, ray, spiral). `tests/test_utils/test_lazy_module_use.py` checks it. -- **Argument symmetry** — each operator declares `argument_symmetry(streams)` returning - `frozenset` (commutative) or `tuple` (ordered). Determines how upstream hashes combine. +- **Argument symmetry** — `structural_argument_symmetry(streams)` describes the occurrences + in a structural identity. A commutative `SymmetricGroup` sorts hashes and keeps repeats. + A tuple preserves argument order. `argument_symmetry(streams)` still supplies the legacy + content and row-layout digests (ITL-1590). - **`StaticOutputPod.process()` → `DynamicPodStream`** — wraps `static_process()` output with timestamp-based staleness detection and automatic recomputation. - **Source delegation** — CSVSource, DictSource, etc. all create an internal diff --git a/changelog.d/ITL-1590.md b/changelog.d/ITL-1590.md new file mode 100644 index 000000000..ca626b6fd --- /dev/null +++ b/changelog.d/ITL-1590.md @@ -0,0 +1,15 @@ +### Breaking changes and migration + +- The pipeline hash now counts every input to a commutative operator. It changes + for a pipeline with a commutative step whose inputs include repeated or + content-equal streams. Stored table paths for that step and its downstream + steps move because those paths include the pipeline hash. + +### Fixed + +- The pipeline, source, and name chains retain every occurrence of an input + to a commutative step. Capture preserves the same multiplicity when compiling + the graph and handles deep pipelines without recursion. +- Capture refuses two invocations in one job when only their input repeat + counts distinguish them. The execution graph still uses legacy content + identity for its nodes and cannot run such a pair independently. diff --git a/docs/dev/design_issues/ITL-1559-TC1.md b/docs/dev/design_issues/ITL-1559-TC1.md index 0487c0700..431888922 100644 --- a/docs/dev/design_issues/ITL-1559-TC1.md +++ b/docs/dev/design_issues/ITL-1559-TC1.md @@ -10,9 +10,9 @@ It also cannot follow a slot through a rebind while identifying the same computa (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. +available even when no source is bound. The execution graph still uses +legacy content identity. ITL-1590 makes commutative structure +independent of source equality and retains every input occurrence. 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 @@ -21,8 +21,8 @@ symmetry to report the new chains. Schema-less polling sources report a node has 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. +three chains retain content-equal argument occurrences. The row-layout digest +still uses the legacy grouping. 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. diff --git a/docs/dev/design_issues/ITL-1590-CS1.md b/docs/dev/design_issues/ITL-1590-CS1.md new file mode 100644 index 000000000..da1043bea --- /dev/null +++ b/docs/dev/design_issues/ITL-1590-CS1.md @@ -0,0 +1,18 @@ +## Pipeline identity + +### CS1 — Commutative pipeline hashes lost equal input occurrences +**Status:** resolved +**Severity:** high +**Issue:** ITL-1590 + +Join's set of streams could collapse operands that compared equal by content. +The resulting pipeline hash depended on source equality and lost an argument. + +**Fix:** Carry every argument occurrence through the pipeline, source and name +chains. A commutative structural preimage sorts its input hashes and keeps repeats. +The capture registry keeps repeated occurrences and computes keys bottom-up, +reusing upstream keys across captures. Compilation preserves each recorded +operand. Execution maps still compare compiled nodes by legacy +content identity, which drops repeats, so a capture that differs from a recorded +one only in a repeat count is refused until the graph-key and content-identity +migrations (steps 3 and 5) land; those steps lift the refusal. diff --git a/docs/reference/hashing.md b/docs/reference/hashing.md index 1b268d1c2..14c742f14 100644 --- a/docs/reference/hashing.md +++ b/docs/reference/hashing.md @@ -315,9 +315,10 @@ upstream is hashed once per chain. hash combines the pipeline hash and the source chain. Reading either the source chain or the chain-based content hash raises `UnboundSourceError` while a 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. +`_chain_content_hash()` until the switch to `content_hash()`. Pipeline hashes now +include every commutative input occurrence (ITL-1590). Capture also counts occurrences +and refuses invocations that differ only by a repeat count while the execution graph +still uses legacy content identity. Stored table paths use the pipeline hash. The saved job format does not carry input symmetry yet. A loaded built-in with one input uses the saved pipeline hash and hashes that input's chains, even when its operator implementation is unavailable. An unavailable operator with multiple @@ -438,7 +439,7 @@ test session with `-p tests.test_hashing.hash_site_trace`. | `schema:` / `instance:` / `node:` path components | `core/nodes/function_node.py:FunctionNodeBase.node_identity_path`, `core/nodes/operator_node.py:OperatorNodeBase.node_identity_path`, `side_effects.py:SideEffectJobNode.attach_databases`, `core/sources/cached_source.py:CachedSource._unversioned_cache_path` | | implicit source-node slot names for streams with no source name | `core/nodes/source_node.py:slot_name_for` | | source system-tag column name (schema digest) | `utils/schema_utils.py:compute_schema_hash` | -| system-tag suffixes of `Join`, `MergeJoin`, `Batch`, `GroupBy` | `core/operators/join.py:Join._compute_system_tag_suffixes`, `core/operators/join.py:Join._predict_system_tag_schema`, `core/operators/join.py:Join.static_process`, `core/operators/merge_join.py:MergeJoin._system_tag_suffix`, `core/operators/batch.py:Batch.unary_output_schema`, `core/operators/batch.py:Batch.unary_static_process`, `core/operators/group_by.py:GroupBy.unary_output_schema`, `core/operators/group_by.py:GroupBy.unary_static_process` | +| system-tag suffixes of `Join`, `MergeJoin`, `Batch`, `GroupBy` | `core/base.py:row_layout_hash` (uses the historical structural digest), `core/operators/join.py:Join._compute_system_tag_suffixes`, `core/operators/join.py:Join._predict_system_tag_schema`, `core/operators/join.py:Join.static_process`, `core/operators/merge_join.py:MergeJoin._system_tag_suffix`, `core/operators/batch.py:Batch.unary_output_schema`, `core/operators/batch.py:Batch.unary_static_process`, `core/operators/group_by.py:GroupBy.unary_output_schema`, `core/operators/group_by.py:GroupBy.unary_static_process` | | a saved hash shown as a digest | `core/nodes/function_node.py:_bare_digest` | | source ids (`_v: