Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,11 @@ Every pipeline element has two parallel hashes:
sources that differ only in how they name their rows are two sources, with one pipeline
hash and one source id (developer, November 16, 2026, ITL-1154). Row content enters only where a source puts it into its own
identity: the default source_id of the in-memory sources
(<source kind>:<algorithm label>:<hex> of the table hash, used when none is given) and the elements of a ListSource. A downstream stream or node hashes its
(<source kind>:<algorithm label>:<hex> of the table hash, used when none is given; the rows
in the order given, or sorted by the key columns with hash_in_key_order=True, ITL-1272). A
ListSource has no rule of its own (developer, November 21, 2026, ITL-1272): its elements
and tag function enter only through that default and its output schema (their types), and
with a given source_id it is an address like every other source (the review of every source's identity is ITL-1311). A downstream stream or node hashes its
pod's identity plus its upstreams' content hashes; a function pod's identity is its uri,
not its body. The uri holds the hash of the output schema, a set of named, typed outputs
in no order (developer, November 17, 2026, ITL-1244): reordering output_keys changes it
Expand Down Expand Up @@ -1187,7 +1191,11 @@ data. The rules:
delta_table, sqlite_table, postgresql_table, db_table, spiraldb_table,
polling_source, cached), or names the operation that derives the source
(tags_as_data). A default built from a hash is <kind>:<algorithm label>:<hex>, built
only by core/sources/source_ids.hash_source_id; one built from where the data lives is
only by core/sources/source_ids.hash_source_id (an in-memory source hashes its table as
given; hash_in_key_order=True, refused without key columns or with a source_id, hashes
it sorted by the key columns in key order, arrow_utils.key_row_order, an Arrow sort after
the keys are validated, rows presented as given; developer, November 21, 2026, ITL-1272);
one built from where the data lives is
<kind>:<location>, built only by location_source_id: csv:<path as passed>,
delta_table:<path or URI as passed>, sqlite_table:<db path as passed>:main.<table>,
postgresql_table:<host>:<port>/<database>.<schema>.<table> (the server the connection
Expand Down
12 changes: 10 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,11 @@ Every pipeline element has two parallel hashes:
sources that differ only in how they name their rows are two sources, with one pipeline
hash and one source id (developer, November 16, 2026, ITL-1154). Row content enters only where a source puts it into its own
identity: the default `source_id` of the in-memory sources
(`<source kind>:<algorithm label>:<hex>` of the table hash, used when none is given) and the elements of a `ListSource`. A downstream stream or node hashes its
(`<source kind>:<algorithm label>:<hex>` of the table hash, used when none is given; the rows
in the order given, or sorted by the key columns with `hash_in_key_order=True`, ITL-1272). A
`ListSource` has no rule of its own (developer, November 21, 2026, ITL-1272): its elements
and tag function enter only through that default and its output schema (their types), and
with a given `source_id` it is an address like every other source (the review of every source's identity is ITL-1311). A downstream stream or node hashes its
pod's identity plus its upstreams' content hashes; a function pod's identity is its uri,
not its body. The uri holds the hash of the output schema, a set of named, typed outputs
in no order (developer, November 17, 2026, ITL-1244): reordering `output_keys` changes it
Expand Down Expand Up @@ -1231,7 +1235,11 @@ data. The rules:
`delta_table`, `sqlite_table`, `postgresql_table`, `db_table`, `spiraldb_table`,
`polling_source`, `cached`), or names the operation that derives the source
(`tags_as_data`). A default built from a hash is `<kind>:<algorithm label>:<hex>`, built
only by `core/sources/source_ids.hash_source_id`; one built from where the data lives is
only by `core/sources/source_ids.hash_source_id` (an in-memory source hashes its table as
given; `hash_in_key_order=True`, refused without key columns or with a `source_id`, hashes
it sorted by the key columns in key order, `arrow_utils.key_row_order`, an Arrow sort after
the keys are validated, rows presented as given; developer, November 21, 2026, ITL-1272);
one built from where the data lives is
`<kind>:<location>`, built only by `location_source_id`: `csv:<path as passed>`,
`delta_table:<path or URI as passed>`, `sqlite_table:<db path as passed>:main.<table>`,
`postgresql_table:<host>:<port>/<database>.<schema>.<table>` (the server the connection
Expand Down
24 changes: 24 additions & 0 deletions changelog.d/ITL-1272.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Breaking changes and migration

- `ListSource` has the identity of every other root source: class name, output schema,
`source_id` and key columns (ITL-1272). Its elements and its tag function enter its
content hash only through its default `source_id` (the hash of its table), so a
`ListSource` given a `source_id` is an address like any other source: changing or
reordering its elements no longer changes its content hash while its output schema stays
the same (the schema is part of the identity, so elements of another type, or tags of
another type, still change it), and two `ListSource`s with
the same elements but different `source_id`s no longer share one. Every `ListSource`'s
content hash changed, and with it the identity of every node over one. A review of
every built-in source's identity is ITL-1311.
- `ListSource` no longer takes `tag_function_hash_mode`: the tag function's identity has
no role left. Remove the argument. It was never written to a saved job.

### Added

- `hash_in_key_order` (keyword-only, default `False`) on `ArrowTableSource`,
`DictSource`, `DataFrameSource` and `ListSource` (ITL-1272): a source with key columns
(`record_id_columns`) and no `source_id` hashes its table, for its default source id,
with the rows sorted by the key columns in the order given, so the same rows in any
order give one default source id and one content hash. The rows are presented in the
order given. Refused without key columns and with a `source_id`. Without it, nothing
changes: the table is hashed as given.
51 changes: 50 additions & 1 deletion docs/concepts/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,55 @@ order or content can vary between runs, pass an explicit, stable `source_id` **a
key columns that are unique per row; this avoids both the duplicate entries and the repeated
deliveries.

An in-memory source with key columns and no `source_id` can instead hash its rows in key
order: pass `hash_in_key_order=True` (`ArrowTableSource`, `DictSource`, `DataFrameSource`,
`ListSource`; ITL-1272). The table is hashed sorted by the key columns, in the order you list
them, so the same rows in any order give one default `source_id` and one content hash; the
rows are still presented in the order you gave. It is off by default, because the order you
gave may matter to you. It is refused without key columns (there is no key order) and with a
`source_id`: the table hash is still computed then, but it does not determine a given
`source_id` and enters no identity, so the argument would change nothing. The order of the key
columns is part of the content hash either way; it changes the default `source_id` only when
the two orders sort the table differently.

```python
from orcapod.sources import DictSource

rows = [
{"subject": "s1", "trial": 1, "weight": 20.5, "count": 3},
{"subject": "s1", "trial": 2, "weight": 22.25, "count": 1},
{"subject": "s2", "trial": 1, "weight": 19.0, "count": 4},
]
orders = (rows, rows[::-1], [rows[1], rows[2], rows[0]])
keyed = [
DictSource(order, tag_columns=["subject", "trial"],
record_id_columns=["subject", "trial"], hash_in_key_order=True)
for order in orders
]
print(len({s.source_id for s in keyed}), len({s.content_hash() for s in keyed}))
# 1 1
print(keyed[1].as_table().column("weight").to_pylist())
# [19.0, 22.25, 20.5]
other_key_order = DictSource(rows, tag_columns=["subject", "trial"],
record_id_columns=["trial", "subject"],
hash_in_key_order=True)
print(other_key_order.source_id == keyed[0].source_id)
# False
as_given = [
DictSource(order, tag_columns=["subject", "trial"],
record_id_columns=["subject", "trial"])
for order in orders
]
print(len({s.source_id for s in as_given}))
# 3
```

A source given a `source_id` is an address: its content hash is built from its class, schema,
`source_id` and key columns, never from its rows, so changing the rows changes it only when the
schema changes (a column of another type). This holds for `ListSource` too (developer,
November 21, 2026, ITL-1272): its elements and its tag function enter its identity only through
its default `source_id` and its output schema.

These columns are hidden by default. You can reveal them using `ColumnConfig`:

```python
Expand Down Expand Up @@ -842,7 +891,7 @@ print(table.column_names)
```

Pass `source_id` to give the source a readable name in these provenance tokens. Without it,
Orcapod derives an id from the source's content hash.
Orcapod derives an id from a hash of the source's table, as described above.

## Code example

Expand Down
28 changes: 28 additions & 0 deletions docs/dev/design_issues/ITL-1272-S3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## `src/orcapod/core/sources/`

### S3 — The default source id of a keyed in-memory source followed the order of its rows, and `ListSource` had an identity of its own
**Status:** resolved
**Severity:** medium
**Issue:** ITL-1272 (related: ITL-1227, ITL-1311)

An in-memory source given no `source_id` takes a default built from the Arrow hash of its
whole table (`SourceStreamBuilder.build`), and that hash includes the order of the rows. A
source with key columns (`record_id_columns`) names its rows by their keys and its reload
compares them without order, yet the same rows in another order gave another default source
id and content hash, with no way to ask otherwise. Separately, `ListSource` had an identity
of its own (class, name, its elements in order, a hash of its tag function chosen by
`tag_function_hash_mode`, key columns): unlike every other source its content hash followed
its elements under a given `source_id` and did not depend on that `source_id` at all (two
`ListSource`s with the same elements and different names shared a content hash).

**Fix:** developer decisions, November 21, 2026 (replacing an earlier "always sort"
decision of November 19). `hash_in_key_order=True`, a keyword of the four in-memory sources
and of `SourceStreamBuilder.build`, hashes the table sorted by the key columns in key order
(`arrow_utils.key_row_order`, an Arrow `sort_indices` then `take`), after the keys are
validated; it is refused without key columns and with a `source_id`, and the rows are
presented as given. The default stays the table as given, since the order may be deliberate.
`ListSource` takes `RootSource`'s identity (class name, output schema, `source_id`, key
columns); `tag_function_hash_mode` and the tag-function hash are removed. Three golden
values moved, each a `ListSource`'s own content hash (developer approval, November 21, 2026).
Tests: `tests/test_core/sources/test_keyed_default_source_id.py`. A review of every
built-in source's identity is ITL-1311.
86 changes: 86 additions & 0 deletions docs/dev/scripts/itl_1272/golden_diff_against_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""Compare every golden entry with a base revision (ITL-1272).

Run from the repository root: ``uv run python docs/dev/scripts/itl_1272/golden_diff_against_main.py [REV]``
(default ``origin/main``). Entries are compared by ``<group>:<name>`` across all golden
files, so an entry that the generator wrote into another file of its group counts as the
same entry. It asserts the change the developer approved on 2026-11-21: exactly three
``ListSource`` content hashes move, nothing is removed, and every new entry belongs to the
``schema:hash_in_key_order`` case; every other entry is byte-identical.
"""

import json
import pathlib
import subprocess
import sys

ROOT = pathlib.Path("tests/test_hashing/golden/data/v1")
REV = sys.argv[1] if len(sys.argv) > 1 else "origin/main"
APPROVED_MOVES = {
"schema:key_policy_identity.list.key.content_hash": (
"semantic_v1:b868793e9bc08672bbef6b629818bb812baad7ed1d9701d7245617ea3df97486",
"semantic_v1:6fe5579e74653616d575c5274fc0a72b4bccc1c46e56a837bdef0f709404df61",
),
"schema:key_policy_identity.list.position.content_hash": (
"semantic_v1:80f5d87ceac2469c2a4c411c3b36a3735885df1c036ffec49c60d0a5e18cb757",
"semantic_v1:e2660b0b39a19ac9a65b45ab888a1864f5c510aa18f66e0a5a99db956e11218a",
),
"pipeline:default_source_ids.list.content_hash": (
"semantic_v1:dbaf6ac70a35ec6928af0f8b53e222de18b69337d8985324218c6c05c16abf29",
"semantic_v1:9d892efaf950490f157554b14c2f32c8194dcb92e6fa21d29e6f86b0d3e64801",
),
}
NEW_CASE = "schema:hash_in_key_order."


def git(*args: str) -> str:
return subprocess.run(
["git", *args], capture_output=True, text=True, check=True
).stdout


def group(name: str) -> str:
stem = pathlib.PurePosixPath(name).name.removesuffix(".json")
return stem.split("-")[0]


def entries(rev: str | None) -> dict[str, object]:
if rev is None:
files = [p.relative_to(ROOT).as_posix() for p in ROOT.rglob("*.json")]
else:
files = [
pathlib.PurePosixPath(f).relative_to(ROOT.as_posix()).as_posix()
for f in git("ls-tree", "-r", "--name-only", rev, f"{ROOT}/").split()
]
out: dict[str, object] = {}
for f in sorted(files):
text = (
(ROOT / f).read_text() if rev is None else git("show", f"{rev}:{ROOT}/{f}")
)
for key, value in json.loads(text).items():
name = f"{group(f)}:{key}"
assert name not in out, f"{name} pinned twice"
out[name] = value
return out


old, new = entries(REV), entries(None)
removed = sorted(set(old) - set(new))
added = sorted(set(new) - set(old))
common = set(old) & set(new)
changed = sorted(k for k in common if old[k] != new[k])
print(f"base {REV} = {git('rev-parse', '--short', REV).strip()}")
print(
f"entries on base: {len(old)}; on the branch: {len(new)}; changed: {len(changed)}; "
f"removed: {len(removed)}; added: {len(added)}; byte-identical: {len(common) - len(changed)}"
)
for k in changed:
print(f" changed {k}: {old[k]} -> {new[k]}")
for k in added:
print(f" added {k}")
assert changed == sorted(APPROVED_MOVES), changed
assert all((old[k], new[k]) == APPROVED_MOVES[k] for k in changed)
assert removed == [], removed
assert all(k.startswith(NEW_CASE) for k in added), added
print(
"OK: exactly the approved moves, no removal, additions only in schema:hash_in_key_order"
)
Loading
Loading