diff --git a/.zed/rules b/.zed/rules index a1858c50f..33c256e2b 100644 --- a/.zed/rules +++ b/.zed/rules @@ -1293,9 +1293,10 @@ these preimages anywhere else. 1. Name-preserving — single-stream ops. Column name/value pass through unchanged. 2. Name-extending — multi-input ops. System tag column name gets - ::{pipeline_hash}:{canonical_position} appended. Commutative operators sort by - pipeline_hash and sort system tag values per row. MergeJoin is ordered (ITL-1281): the - position is the argument index and nothing is sorted. + ::{pipeline_hash}:{canonical_position} appended. Commutative operators sort by pipeline + hash. Join sorts each tied operand as a complete bundle when all tied inputs carry + only certified library provenance. Other ties use the historical per-path sort. + MergeJoin uses argument positions (ITL-1281). 3. Reducing — many→one ops (Batch, GroupBy). Data columns become list[T]; Batch makes every user tag list[T] and keeps it a tag, while GroupBy keeps its scalar keys and drops every other user tag (ITL-1070). No tag ever moves to the data group. Source-info columns become @@ -1318,7 +1319,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 — operators return SymmetricGroup (commutative) or tuple (ordered). + Preserve every occurrence in the pipeline hash and chains. Sort a commutative group by + upstream pipeline hash, and order tied members in each chain by that chain's own values. + The legacy content hash keeps its set preimage. - StaticOutputPod.process() → DynamicPodStream — wraps static_process() with staleness detection and automatic recomputation. - Source delegation — CSVSource, DictSource, etc. create an internal ArrowTableSource. @@ -1502,12 +1506,12 @@ data. The rules: building the source. This restriction is a stopgap pending ITL-1561. System-tag fields on a raw ArrowTableStream keep their metadata. DataFrameSource uses an explicit schema for custom system-tag nullability and validates the raw values, types and metadata before casting. - Join's sync and batch sort pairs source and record IDs within each printed - provenance path. The rebuilt ID field can hold nulls when any corresponding - input field can hold nulls or an input lacks that field. Custom tags keep their - input positions in these tables. Standalone row channels sort the custom tags - of a tied path with its IDs at every link. Join rows infer tied system-tag - fields from values. Non-tied system-tag fields keep their Arrow declarations. + Join sorts complete bundles by source and record IDs when tied operands carry only + certified library provenance (ITL-1590). Other ties keep the historical per-path + sorting and row inference. A shared system tag with incompatible normalized Arrow + types raises `InputValidationError` (ITL-1690). A job refuses two captures told apart + only by a commutative input’s repeat count (`Join()(a, b)` beside `Join()(a, b, b)`) + until node identity counts repeats (ITL-1559 steps 3, 5). A raw `ArrowTableStream` preserves the system-tag fields in its table and rows, including the Arrow Null type (ITL-1543). Streams, rows and record batches declare every `_source_*` token field nullable (ITL-1557). diff --git a/CLAUDE.md b/CLAUDE.md index 33273dd7e..585144099 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1326,8 +1326,9 @@ are defined in one module, `core/row_ids.py`; never build one of these preimages through unchanged. 2. **Name-extending** — multi-input ops (join, merge join). Each input's system tag column name gets `::{pipeline_hash}:{canonical_position}` appended. Commutative operators - canonically order inputs by `pipeline_hash` and sort system tag values per row. `MergeJoin` - is ordered (ITL-1281): the position is the argument index and nothing is sorted. + canonically order inputs by pipeline hash. Join sorts each tied operand as a complete + bundle when all tied inputs carry only certified library provenance. Other ties use + the historical per-path sort. `MergeJoin` uses argument positions (ITL-1281). 3. **Reducing** — many→one ops (`Batch`, `GroupBy`). Data columns become `list[T]`; `Batch` makes every user tag `list[T]` and keeps it a tag, while `GroupBy` keeps its scalar keys and drops every other user tag (ITL-1070). No tag ever moves to the data group. Source-info @@ -1365,7 +1366,9 @@ and `as_table()` methods. `all_info=True` sets everything to True. 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. + `SymmetricGroup` (commutative) or `tuple` (ordered). Each occurrence enters the pipeline + hash and both chains. A commutative group is sorted by upstream pipeline hash, and each + chain orders tied members by its own values. The legacy content hash keeps its set preimage. - **`StaticOutputPod.process()` → `DynamicPodStream`** — wraps `static_process()` output with timestamp-based staleness detection and automatic recomputation. - **Source delegation** — CSVSource, DictSource, etc. all create an internal @@ -1550,12 +1553,12 @@ data. The rules: building the source. This restriction is a stopgap pending ITL-1561. System-tag fields on a raw ArrowTableStream keep their metadata. DataFrameSource uses an explicit schema for custom system-tag nullability and validates the raw values, types and metadata before casting. - Join's sync and batch sort pairs source and record IDs within each printed - provenance path. The rebuilt ID field can hold nulls when any corresponding - input field can hold nulls or an input lacks that field. Custom tags keep their - input positions in these tables. Standalone row channels sort the custom tags - of a tied path with its IDs at every link. Join rows infer tied system-tag - fields from values. Non-tied system-tag fields keep their Arrow declarations. + Join sorts complete bundles by source and record IDs when tied operands carry only + certified library provenance (ITL-1590). Other ties keep the historical per-path + sorting and row inference. A shared system tag with incompatible normalized Arrow + types raises `InputValidationError` (ITL-1690). A job refuses two captures told apart + only by a commutative input’s repeat count (`Join()(a, b)` beside `Join()(a, b, b)`) + until node identity counts repeats (ITL-1559 steps 3, 5). A raw `ArrowTableStream` preserves the system-tag fields in its table and rows, including the Arrow Null type (ITL-1543). Streams, rows and record batches declare every `_source_*` token field nullable (ITL-1557). diff --git a/changelog.d/ITL-1590.md b/changelog.d/ITL-1590.md new file mode 100644 index 000000000..5a65989f5 --- /dev/null +++ b/changelog.d/ITL-1590.md @@ -0,0 +1,24 @@ +### Breaking changes and migration + +- A commutative operator's pipeline hash now counts every input occurrence. Rebuild jobs + with content-equal Join inputs to use the corrected pipeline identity. Custom operators + can declare interchangeable occurrences with `SymmetricGroup`, including nested groups. +- A tied Join refuses inputs whose shared custom system tag differs in type: when + Join inputs have one pipeline hash, a custom system tag they share must have one + Arrow type, or the Join raises `InputValidationError` naming the column and both + types, at graph build and on every execution path. Non-tied inputs are unchanged. + Accepted for 0.4.0; ITL-1690 revisits it. +- A job or pipeline refuses two captures that differ only in how many times an input of + a commutative operator is repeated, such as `Join()(a, b)` beside `Join()(a, b, b)`, + or `Join()(a, a)` beside `Join()(a, a, a)`. Such a pair used to run as one node, so one + read the other's rows. Build them in separate jobs. +- Joins of tied, multi-source operands now keep each branch's provenance together. For + branches `(0,a,z)` and `(0,b,c)`, the old `(0,a,c)` and `(0,b,z)` bundles become + `(0,a,z)` and `(0,b,c)`. Rows whose bundles change have new entry IDs. A fresh run + against a store written by the old implementation can add new pipeline records + alongside the old records at the same path. + +### Fixed + +- A repeated Join inside another Join, such as `Join()(Join()(a, a), b)`, records and + compiles with one pipeline hash and runs on the sync and the async path. diff --git a/docs/concepts/operators.md b/docs/concepts/operators.md index ac4d034b1..4911a11ce 100644 --- a/docs/concepts/operators.md +++ b/docs/concepts/operators.md @@ -103,6 +103,17 @@ order, so `Join()(a, b)` and `Join()(b, a)` have the same columns in the same or ordered operators such as `SemiJoin` and `MergeJoin` keep operand order; either way, address columns by name rather than by position. +When tied inputs carry only matching library provenance pairs, Join orders their +complete bundles by source and record IDs. Ties with custom system tags or raw +provenance names use the historical ordering for their execution path. A system +tag shared by tied inputs must have one Arrow type after normalizing layouts +such as `string` to `large_string`. Join raises `InputValidationError` if the +types differ (ITL-1690). + +A job or pipeline cannot yet hold two Joins that differ only in how many times an +input is repeated, such as `Join()(a, b)` and `Join()(a, b, b)`: capturing the +second raises `ValueError`. Build them in separate jobs. + ```python from orcapod.sources import DictSource from orcapod.operators import Join diff --git a/docs/dev/design_issues/ITL-1559-TC1.md b/docs/dev/design_issues/ITL-1559-TC1.md index 0487c0700..50681044a 100644 --- a/docs/dev/design_issues/ITL-1559-TC1.md +++ b/docs/dev/design_issues/ITL-1559-TC1.md @@ -11,8 +11,8 @@ It also cannot follow a slot through a rebind while identifying the same computa 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. +existing content hashes. Step 2b decouples commutative pipeline hashes from whether +input streams compare equal by content (ITL-1590). 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 @@ -20,9 +20,8 @@ and hashes that input's chains. An unavailable operator with multiple inputs nee 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. +**Fix:** The execution protocols require both combined identity accessors. +A commutative declaration retains all argument occurrences for the three chains. 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/dev/design_issues/ITL-1628-CJ1.md b/docs/dev/design_issues/ITL-1628-CJ1.md new file mode 100644 index 000000000..c3e04dfe0 --- /dev/null +++ b/docs/dev/design_issues/ITL-1628-CJ1.md @@ -0,0 +1,9 @@ +## `src/orcapod/core/operators/join.py` — tied inputs + +### CJ1 — Custom system tags could follow the wrong input +**Status:** open +**Severity:** high +**Issue:** ITL-1628 + +Sorting only the source and record IDs of structurally tied inputs left custom +system tags in the original argument positions. diff --git a/docs/dev/design_issues/ITL-1629-CJ2.md b/docs/dev/design_issues/ITL-1629-CJ2.md new file mode 100644 index 000000000..bfd82e3e3 --- /dev/null +++ b/docs/dev/design_issues/ITL-1629-CJ2.md @@ -0,0 +1,9 @@ +## `src/orcapod/core/operators/join.py` — tied inputs + +### CJ2 — Pairwise row joins diverged from tables on sparse system tags +**Status:** open +**Severity:** high +**Issue:** ITL-1629 + +A custom system tag missing from one tied operand could appear at different +positions on row channels and tables. diff --git a/docs/dev/design_issues/ITL-1631-CJ3.md b/docs/dev/design_issues/ITL-1631-CJ3.md new file mode 100644 index 000000000..5975712d4 --- /dev/null +++ b/docs/dev/design_issues/ITL-1631-CJ3.md @@ -0,0 +1,9 @@ +## `src/orcapod/core/operators/join.py` — tied inputs + +### CJ3 — Tied Join rows narrowed record ID declarations +**Status:** open +**Severity:** high +**Issue:** ITL-1631 + +Row channels and table iteration inferred tied record ID fields from individual +values, even when the table declared those fields nullable. diff --git a/docs/reference/hashing.md b/docs/reference/hashing.md index 1b268d1c2..569e87c5d 100644 --- a/docs/reference/hashing.md +++ b/docs/reference/hashing.md @@ -316,8 +316,7 @@ hash combines the pipeline hash and the source chain. Reading either the source 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. +the existing content hashes for graph keys and persistence. 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 @@ -336,11 +335,8 @@ 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. +raises an undefined-identity error. With a declared polling schema, a downstream Join +can compute its name chain and node hash without reading any source digest. A plain derived source, including one wrapped in a cache, reports an undefined source chain while a contributing slot of its origin is unbound. Chain accessors report an undefined @@ -426,6 +422,7 @@ test session with `-p tests.test_hashing.hash_site_trace`. | the `_content_hash` column | `core/streams/arrow_table_stream.py:ArrowTableStream._assemble_table..hashes`, `core/function_pod.py:FunctionPodStream.as_table..all_content_hashes`, `core/function_pod.py:FunctionPodStream.head..shown_content_hashes`, `core/function_pod.py:FunctionPodStream.head..`, `core/nodes/function_node.py:FunctionNodeBase.as_table..all_content_hashes`, `core/nodes/function_node.py:FunctionNodeBase._head_of_pairs..`, `side_effects.py:_table_of_rows` | | `__pf_var_function_signature_hash`, `__pf_var_function_content_hash` | `core/data_function.py:function_signature_hash`, `core/data_function.py:function_content_hash`, `core/data_function.py:PythonDataFunction.__init__` | | saved pipeline and job files | `pipeline/graph.py:Pipeline.save`, `pipeline/job.py:PipelineJob.save`, `pipeline/job.py:PipelineJob.as_pipeline`, `core/sources/base.py:RootSource._identity_config` | +| capture registry keys, serialized as graph vertices | `pipeline/pod_invocation.py:PodInvocation.capture_keys`, `pipeline/pod_invocation.py:PodInvocation.capture_keys..`, `pipeline/pod_invocation.py:PodInvocation.capture_keys..invocation_key`, `pipeline/pod_invocation.py:PodInvocation.capture_keys..invocation_key..resolve`, `pipeline/base.py:AbstractPipelineBase._remember_invocation` | | cached file hashes (in-memory writes compare validated hashes, SQLite and PostgreSQL read and write `b"sha256:" + 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`, `hashing/file_hashers.py:parse_stored_file_hash`, `hashing/file_hashers.py:serialize_storable_file_hash` | | `InvocationContext.invocation_hash` (`