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
6 changes: 5 additions & 1 deletion .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,7 @@ generation of hashing; rows of the current data context are the current entries.
with the three row ids (developer, November 25, 2026, ITL-1471; below, "Row ids"). A change to the common bookkeeping columns of a table kind
moves its layout version, so the table gets a new path. Never add, rename or retype a stored
column without it.
- A function result table is at
- A plain function's result table is at
<function>/<output schema hash>/v<function major>/python.function.v1/rev1/rdb_v1, three
components with three owners (docs/reference/data-function-types.md):
- python.function.v1, the data function type and its MAJOR (what a function means and how it
Expand All @@ -1004,6 +1004,10 @@ generation of hashing; rows of the current data context are the current entries.
- Pipeline tables carry no revision (.../python.function.v1/schema:<pipeline hash>/pdb_v2). A
saved job names the type and major only (data_function_type_id); the revision comes from
the installed library's declaration (declaration_for(type id)).
- Context-taking result tables start with side_effect_function. They group the output
schema hash, function major and ctx:<parameter> in one component to preserve the
path depth available to callers (ITL-1559). Live jobs can repeat actions recorded
at the previous paths. Saved jobs can read their original results.
- A data function type's declaration (PYTHON_FUNCTION, beside its class in core/data_function.py;
the classes in core/data_function_types.py, a leaf module) is the
source of truth: type name, major, revision, identity recipe, run rules, and its record
Expand Down
6 changes: 5 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ current data context are the current entries.
2026, ITL-1471; below, "Row ids"). A change to the common
bookkeeping columns of a table kind moves its layout version, so the table gets a new path.
Never add, rename or retype a stored column without it.
- A function result table is at
- A plain function's result table is at
`<function>/<output schema hash>/v<function major>/python.function.v1/rev1/rdb_v1`, three
components with three owners (`docs/reference/data-function-types.md`):
- `python.function.v1`, the data function type and its MAJOR (what a function means and how
Expand All @@ -1035,6 +1035,10 @@ current data context are the current entries.
- Pipeline tables carry no revision (`.../python.function.v1/schema:<pipeline hash>/pdb_v2`).
A saved job names the type and major only (`data_function_type_id`); the revision comes
from the installed library's declaration (`declaration_for(type id)`).
- Context-taking result tables start with `side_effect_function`. They group the
output schema hash, function major and `ctx:<parameter>` in one component to
preserve the path depth available to callers (ITL-1559). Live jobs can repeat
actions recorded at the previous paths. Saved jobs can read their original results.
- A data function type's declaration (`PYTHON_FUNCTION`, beside its class in
`core/data_function.py`; the classes in `core/data_function_types.py`, a leaf module) is
the source of truth: type name, major, revision, identity recipe, run rules, and its record
Expand Down
23 changes: 23 additions & 0 deletions changelog.d/ITL-1559.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### Breaking changes and migration

- Function pods that receive an invocation context now include the configured parameter
name in their pipeline hash. Their pipeline tables and downstream tables that use the
affected hashes have new `schema:<P>` paths, and downstream system-tag column names
that incorporate those hashes change. The public idempotency key
`InvocationContext.invocation_hash` also changes for the affected function pods
and for downstream side-effect nodes whose pipeline hashes change. Tables written
by earlier development versions remain at their old paths. There is no migration
for these unreleased layouts.
Result tables for context-taking function pods include `ctx:<parameter>` in
their paths. Decorator caches also move context-taking results into the
`side_effect_function` namespace. Upgraded live jobs use the new completion
and result paths, so they can repeat actions recorded at the previous paths.
Retain the original stores if saved jobs need to read their results. Use a
separate store for upgraded runs after confirming that repeat deliveries for
previously processed inputs are acceptable.
(ITL-1559)

### Fixed

- Loading a saved job restores context-taking function nodes, their stored results,
and their downstream dependencies. (ITL-1559)
17 changes: 17 additions & 0 deletions docs/dev/design_issues/ITL-1559-CXP1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## `src/orcapod/core/function_pod.py` — function pod identity

### CXP1 — Function pod pipeline identity omitted the invocation context parameter
**Status:** resolved
**Severity:** high
**Issue:** ITL-1559

A plain function pod and a context-taking pod with the same underlying data function URI
had the same pipeline identity. Under the three-chain design they would become one graph
node over the same slot, even though one receives an invocation context.

**Fix:** Include the context parameter in the pipeline identity when configured, giving the
pod and its downstream steps distinct pipeline hashes. Plain pods retain the data function's
pipeline identity. Result tables for context-taking pods also include the parameter
name in their paths. An upgraded live job uses the new paths and can deliver again
for an input handled before this change. A saved job restores its context-taking
function nodes and reads their results from the original paths.
17 changes: 15 additions & 2 deletions docs/reference/data-function-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,21 @@ A function stores each result in its result table, at
For a job given a separate result database (`PipelineJob(..., result_database=...)`), the
path starts at `<function>`, in that database, with no `<job>/_result`.

The first four components after `_result` are the function's uri. The last three each
have one owner:
A job's default result path for a pod configured with `ctx_arg` is

```text
<job>/_result/side_effect_function/<function>/<output schema hash>:v<function major>:ctx:<parameter>/python.function.v1/rev1/rdb_v1
```

With an explicit result database, the path starts at `side_effect_function` in that
database. Standalone pod and decorator caches also use this path relative to
their configured databases. Context-taking paths combine the schema hash,
function major, and context parameter in one component to preserve the store
depth available to callers. Saved jobs record the result path through the type
component.

For a plain pod the first four components after `_result` are the function's uri. The
last three components of both paths each have one owner:

| Component | What it controls | Owner | In a hash |
|---|---|---|---|
Expand Down
10 changes: 7 additions & 3 deletions docs/reference/hashing.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ The table below shows what each class returns from `identity_structure()`.
| `Data` | Data columns only (raw Arrow table) | Source info columns (`_source_*`) excluded — they are provenance metadata, not data content |
| `EmptyData` | Raises `EmptyDataAccessError` | `content_hash()` is overridden to return a stored `cached_content_hash` directly |
| `DataFunctionBase` | `self.uri` — `(canonical_function_name, output_schema_hash, major_version, data_function_type_id)` | `output_schema_hash` is site 11; see §5 |
| `FunctionPod` | `self.data_function` (bare object) when no ctx arg; `(self.data_function, self._ctx_arg_name)` when ctx arg present | `ctx_arg_name` is included when present so a ctx-aware pod has a distinct `content_hash` from a plain pod using the same data function |
| `FunctionPod` | `self.data_function` when no context argument is configured, otherwise `(self.data_function, self._ctx_arg_name)` | Both identities include the name of the parameter that receives the invocation context when configured |
| `FallThroughPod` (`pod(stream)` over data-tags) | `(plain_pod, ("fall_through_tags", sorted names))` | The data-tags that fall through are a set: sorted by name, so the order of the input's tag columns never moves the pod's hashes or its node's table paths (ITL-1246). The pod's config and a saved job's `fall_through_tags` list them sorted too |
| `ArrowTableStream` | `(producer, argument_symmetry(upstreams))` | With no producer (a raw stream), or a producer that is not a `PipelineElementProtocol`: `(class_name, identity table in canonical row order, sorted tag columns)`, plus `("data_tags", sorted names)` when it has any. See "The identity of a raw stream" below |
| `RootSource` (`ArrowTableSource`, `ListSource` and every other root source without its own rule) | `(source_id, (hash_schema(tag), hash_schema(data)), record ID key tuple)`, the Arrow schemas of its rows (ITL-640) | `source_id` is `<kind>_v<N>:<name>`, the name being the explicit user-supplied value; when not provided it defaults to `<kind part>:<algorithm label>:<hex>` of the Arrow hash of the raw table (site 4). The class name is not part of it (ITL-1425): the kind part names the kind and implementation version, and the kind enters a datum's identity there only. `PollingSource` is `(source_id, impl.identity(), sorted tag columns, record ID key tuple)` (provisional, ITL-1316). The record ID key tuple lists the columns used to identify rows, in key order (`record_id_columns`, or a database or SpiralDB table's primary key), `()` for the position: two sources that differ only in how they name their rows are two sources (developer decision, November 16, 2026, ITL-1154). Data-inclusive base case of the Merkle chain. A `ListSource` has no rule of its own (developer, November 21, 2026, ITL-1272): its elements and tags enter its identity only through its default source id and its Arrow schema (their types), and with a given `source_id` it is an address like every other source (other elements of the same types leave its content hash unchanged); it used to hold its elements and a hash of its tag function (and took `tag_function_hash_mode`), and with a given `source_id` its content hash did not depend on that id at all. A review of every built-in source's identity is ITL-1311 |
Expand Down Expand Up @@ -728,13 +728,17 @@ The pipeline hash uses the same `SemanticAwarePythonHasher` with the **`pipeline
| `DerivedSource` | `(hash_schema(tag), hash_schema(data))` | Acts as a new root in the pipeline Merkle chain; the Arrow types are its origin's (its typed zero-row table), so they do not change when rows are stored |
| `SourceNode`, `SourceJobNode` | `(hash_schema(tag), hash_schema(data))` of the slot's Arrow schemas | A slot made from a stream holds that stream's Arrow types; a slot declared with Python types holds the converter's (one Arrow type per Python type) |
| `DataFunctionBase` | `self.uri` (same as `identity_structure()`) | Function identity is already schema-only |
| `FunctionPod` | `self.data_function` **only** (excludes `ctx_arg_name`) | A ctx-aware pod and a plain pod over the same data function share the same `pipeline_hash` value, but have different `uri` values (`ctx_arg_name` is set → `"side_effect_function"` is prepended to the URI) and therefore write to **different** DB table paths |
| `FunctionPod` | `self.data_function` when no context argument is configured, otherwise `(self.data_function, self._ctx_arg_name)` | A context-taking pod has its own pipeline hash. Changing the configured context parameter name changes that hash even when the data function URI is the same |
| `FallThroughPod` | `(plain_pod, ("fall_through_tags", sorted names))` | As its content identity: the data-tags are a set of names (ITL-1246) |
| `ArrowTableStream` | `(producer, argument_symmetry(upstreams pipeline hashes))` | `pipeline_resolver` routes upstreams through `pipeline_hash()`. Falls back to the Arrow schema identity of the table it holds when producer is absent or not a `PipelineElementProtocol`. |
| Operators | `(operator_class_name, argument_symmetry(upstream pipeline hashes))` | Same structure as content identity but using pipeline hashes of upstreams |
| `SideEffectPodStream` | `(pod, argument_symmetry(upstreams))` | Same as `identity_structure()` |

> **Note:** `FunctionPod.ctx_arg_name` IS included in `content_hash()` (via `identity_structure()`). It is excluded only from `pipeline_identity_structure()`. A ctx-aware pod receives a system-injected `InvocationContext` argument — a deliberate deviation from the pure data-in / data-out contract — so it is kept distinct from a plain pod at every level: different `content_hash`, different `uri` (prefix `"side_effect_function"`), and different DB table path. The shared `pipeline_hash` value has no practical effect on scoping once the `uri` differs.
A context-taking `FunctionPod` receives a system-injected `InvocationContext` and adds the
`"side_effect_function"` prefix to its pod URI. The pipeline hash also distinguishes it
from a plain pod with the same underlying data function URI. The difference propagates
downstream to the `schema:<P>` component of stored paths and to system-tag column names
that incorporate the affected pipeline hashes.

---

Expand Down
14 changes: 9 additions & 5 deletions src/orcapod/core/cached_function_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
data_context_field,
require_storable,
)
from orcapod.core.result_cache import ResultCache, pod_timestamp_type
from orcapod.core.result_cache import (
ResultCache,
context_result_path,
pod_timestamp_type,
)
from orcapod.hooks import InvocationStatus
from orcapod.protocols.core_protocols import (
FunctionPodProtocol,
Expand All @@ -43,9 +47,9 @@
class CachedFunctionPod(WrappedFunctionPod):
"""Pod-level caching wrapper that intercepts ``process_data()``.

Caches at the ``process_data(tag, data)`` level using only the
**input data content hash** as the cache key — the output of a
data function depends solely on the data, not the tag.
Caches at the ``process_data(tag, data)`` level using the input data
content hash. Pods that take an invocation context use a result table
scoped by the configured context parameter.

Tag-level provenance tracking (tag + system tags + data hash) is
handled separately by ``FunctionNode.add_pipeline_record``.
Expand All @@ -67,7 +71,7 @@ def __init__(
super().__init__(function_pod, **kwargs)
self._cache = ResultCache(
result_database=result_database,
record_path=self.uri, # no prefix; db is pre-scoped
record_path=context_result_path(self.uri, self.ctx_arg_name),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
revision=function_pod.data_function.declaration.revision_component,
auto_flush=auto_flush,
# A pod that takes the invocation context performs an external action.
Expand Down
21 changes: 16 additions & 5 deletions src/orcapod/core/data_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
default_value_refused,
hash_default_value,
)
from orcapod.core.result_cache import ResultCache
from orcapod.core.result_cache import ResultCache, context_result_path
from orcapod.errors import (
NoOutputsDeclaredError,
OutputContainerTypeError,
Expand Down Expand Up @@ -1589,16 +1589,23 @@ def __init__(
data_function: DataFunctionProtocol,
result_database: ArrowDatabaseProtocol,
record_path_prefix: tuple[str, ...] = (),
*,
context_parameter: str | None = None,
**kwargs,
) -> None:
super().__init__(data_function, **kwargs)
self._result_database = result_database
self._record_path_prefix = record_path_prefix
if context_parameter is not None:
record_path_prefix += ("side_effect_function",)
self._cache = ResultCache(
result_database=result_database,
record_path=record_path_prefix + self.uri,
record_path=context_result_path(
record_path_prefix + self.uri, context_parameter
),
revision=self.declaration.revision_component,
auto_flush=True,
delivers_side_effects=context_parameter is not None,
# The first uri component is the function's name; no hash before it.
name_path=record_path_prefix + self.uri[:1],
)
Expand Down Expand Up @@ -1644,9 +1651,9 @@ def call(

``**kwargs`` are forwarded to the wrapped data function's ``call``
so that auto-provided arguments (e.g. ``InvocationContext``) reach
the underlying function. They are intentionally excluded from the
cache key — such arguments are deterministic per row and pod, so the
same input data always produces the same output.
the underlying function. The configured context parameter, when present,
selects a separate result table. Lookup within a table uses the input
data hash.

Raises:
InputValidationError: If ``data`` is of another data context than this
Expand All @@ -1665,6 +1672,8 @@ def call(
if output_data is not None:
module_logger.info(f"Cache hit for {data}!")
return output_data
else:
self._cache.check_before_side_effect(self.data_context_key)
output_data = self._data_function.call(data, logger=logger, **kwargs)
if output_data is not None:
if not skip_cache_insert:
Expand Down Expand Up @@ -1708,6 +1717,8 @@ async def async_call(
if output_data is not None:
module_logger.info(f"Cache hit for {data}!")
return output_data
else:
self._cache.check_before_side_effect(self.data_context_key)
output_data = await self._data_function.async_call(
data, logger=logger, **kwargs
)
Expand Down
7 changes: 7 additions & 0 deletions src/orcapod/core/function_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ def identity_structure(self) -> Any:
return self.data_function

def pipeline_identity_structure(self) -> Any:
"""Include the parameter that receives the invocation context, when set."""
if self._ctx_arg_name is not None:
return (self.data_function, self._ctx_arg_name)
return self.data_function

def _build_invocation_context(
Expand Down Expand Up @@ -1918,6 +1921,8 @@ def function_pod(
function_name: Name of the function pod; defaults to ``func.__name__``.
version: Version string for the data function.
label: Optional label for tracking.
ctx_arg: Name of the invocation context parameter. The pod uses this
name for injection and the decorator cache uses it to scope results.
result_database: Optional database for data-level caching
(wraps the data function in ``CachedDataFunction``).
pod_cache_database: Optional database for pod-level caching
Expand All @@ -1934,6 +1939,7 @@ def function_pod(
"""

def decorator(func: Callable) -> CallableWithPodProtocol:
"""Build the pod and give its decorator cache the same context parameter."""
if func.__name__ == "<lambda>":
raise ValueError("Lambda functions cannot be used with function_pod")

Expand All @@ -1952,6 +1958,7 @@ def decorator(func: Callable) -> CallableWithPodProtocol:
data_function = CachedDataFunction(
data_function,
result_database=result_database,
context_parameter=ctx_arg,
)

# Create a simple typed function pod
Expand Down
Loading
Loading