diff --git a/.zed/rules b/.zed/rules index 67395d99a..4e48b9b1c 100644 --- a/.zed/rules +++ b/.zed/rules @@ -497,9 +497,9 @@ as a bare `pa.Table` (which the semantic hasher hashes as a value). ## Golden hash values -Hash values must stay identical across releases (developer, November 10, 2026). Not covered: -a provisional operator's identity and every hash downstream of it (ITL-1266, below). Every hash -Orcapod stores or embeds in a name is pinned in the golden folder of the current data context, +Frozen hash values must stay identical across releases (developer, November 10, 2026). +Provisional features and their downstream hashes are outside the freeze as described below. +Orcapod pins the hashes it stores or embeds in names in the golden folder of the current data context, `tests/test_hashing/golden/data//-NN.json`, and checked by `tests/test_hashing/golden/test_golden_hashes.py`. The mechanism is `docs/reference/golden-hashes.md` (developer, November 15, 2026, ITL-946). @@ -550,6 +550,16 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current The refusal sees a direct use only: a user class with a field of such a type embeds its identifier in an identity built once and cached, so golden items are split by `cases.provisional_types_of` (checked against every fixture class's identity record). +- `SideEffectPod` and its decorators (`@side_effect_pod`, `@sink_pod`, `@tap_pod`) are + provisional as a whole in 0.4.0 (developer, November 28, 2026, ITL-555). The pod's + identity, firing rule, `tdb` log layout and all hashes downstream are outside the freeze. + `core/provisional_pods.py` lists provisional pod kinds by issue. Building the pod or restoring + its node from a saved job or blueprint uses the shared `warn_provisional_use` helper. + Golden cases that do either declare `provisional=("SideEffectPod",)`. + A function pod configured with a context argument is also provisional in 0.4.0 (ITL-947): + its identity, firing rule, stored tables, and downstream hashes are outside the freeze. + Golden cases declare provisional=("FunctionPod with a context argument",). + Ordinary function pods retain their 0.4.0 freeze. - Provisional sources are outside the freeze too (developer, November 21, 2026, ITL-1314: "make polling source provisional"; ITL-1331: "Let's also make DerivedSource as provisional?", both forms): `orcapod.sources.PROVISIONAL_SOURCES` @@ -981,6 +991,10 @@ generation of hashing; rows of the current data context are the current entries. Operator cache — odb_v3 (OPERATOR_DB_SCHEMA_VERSION) Cached source — sdb_v2 (SOURCE_DB_SCHEMA_VERSION) +The tdb layout and the SideEffectPod identity are outside the 0.4.0 freeze while the +pod is provisional. The stored tables for a function pod that takes the invocation context +are also provisional and will be designed alongside the side-effect log (ITL-947). + - The layout version is the last component of a table path. Every layout marker started at v1 for the first release, 0.4.0 (developer, November 18, 2026, ITL-1259; 0.3.0 was withdrawn). The pipeline, side-effect log and operator cache layouts moved to v2 before that release, diff --git a/CLAUDE.md b/CLAUDE.md index 3b9ba4940..1a40b396e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -508,9 +508,9 @@ as a bare `pa.Table` (which the semantic hasher hashes as a value). ## Golden hash values -Hash values must stay identical across releases (developer, November 10, 2026). Not covered: -a provisional operator's identity and every hash downstream of it (ITL-1266, below). Every hash -Orcapod stores or embeds in a name is pinned in the golden folder of the current data context, +Frozen hash values must stay identical across releases (developer, November 10, 2026). +Provisional features and their downstream hashes are outside the freeze as described below. +Orcapod pins the hashes it stores or embeds in names in the golden folder of the current data context, `tests/test_hashing/golden/data//-NN.json`, and checked by `tests/test_hashing/golden/test_golden_hashes.py`. The mechanism is `docs/reference/golden-hashes.md` (developer, November 15, 2026, ITL-946). @@ -561,6 +561,16 @@ Orcapod stores or embeds in a name is pinned in the golden folder of the current The refusal sees a direct use only: a user class with a field of such a type embeds its identifier in an identity built once and cached, so golden items are split by `cases.provisional_types_of` (checked against every fixture class's identity record). +- `SideEffectPod` and its decorators (`@side_effect_pod`, `@sink_pod`, `@tap_pod`) are + provisional as a whole in 0.4.0 (developer, November 28, 2026, ITL-555). The pod's + identity, firing rule, `tdb` log layout and all hashes downstream are outside the freeze. + `core/provisional_pods.py` lists provisional pod kinds by issue. Building the pod or restoring + its node from a saved job or blueprint uses the shared `warn_provisional_use` helper. + Golden cases that do either declare `provisional=("SideEffectPod",)`. + A function pod configured with a context argument is also provisional in 0.4.0 (ITL-947): + its identity, firing rule, stored tables, and downstream hashes are outside the freeze. + Golden cases declare `provisional=("FunctionPod with a context argument",)`. + Ordinary function pods retain their 0.4.0 freeze. - Provisional sources are outside the freeze too (developer, November 21, 2026, ITL-1314: "make polling source provisional"; ITL-1331: "Let's also make DerivedSource as provisional?", both forms): `orcapod.sources.PROVISIONAL_SOURCES` @@ -1010,6 +1020,10 @@ current data context are the current entries. | Operator cache | `odb_v3` | `OPERATOR_DB_SCHEMA_VERSION` | | Cached source | `sdb_v2` | `SOURCE_DB_SCHEMA_VERSION` | +The `tdb` layout and the `SideEffectPod` identity are outside the 0.4.0 freeze while the +pod is provisional. The stored tables for a function pod that takes the invocation context +are also provisional and will be designed alongside the side-effect log (ITL-947). + - Every layout marker started at `v1` for the first release, 0.4.0 (developer, November 18, 2026, ITL-1259; 0.3.0 was withdrawn). The pipeline, side-effect log and operator cache layouts moved to `v2` before that release, with the three row ids (developer, November 25, diff --git a/changelog.d/ITL-555.md b/changelog.d/ITL-555.md new file mode 100644 index 000000000..42366ec7c --- /dev/null +++ b/changelog.d/ITL-555.md @@ -0,0 +1,18 @@ +### Changed + +- `SideEffectPod`, `@side_effect_pod`, `@sink_pod`, and `@tap_pod` are provisional in + 0.4.0. Building a side-effect pod or loading its node from a saved job or pipeline + issues one shared `ProvisionalHashWarning` per process. +- Function pods configured with `ctx_arg` are provisional in 0.4.0. They issue a + `ProvisionalHashWarning` once per process on construction or when loaded from a saved job + or blueprint. + +### Known limitations + +- A side-effect pod's identity, delivery rules, delivery log layout, and downstream hashes + are outside the 0.4.0 freeze. Stored tables at and below the pod may move and a delivery + may be repeated once after an upgrade. The follow-up design is tracked in ITL-947. +- A context-taking function pod's identity, firing rule, stored tables, and downstream hashes + are also outside the 0.4.0 freeze. Its table arrangement will be designed alongside the + side-effect pod's tables. Stored tables at and below the pod may move and a side effect may + be repeated once after an upgrade. diff --git a/docs/api/function-pods.md b/docs/api/function-pods.md index cde0c0485..731fba745 100644 --- a/docs/api/function-pods.md +++ b/docs/api/function-pods.md @@ -8,6 +8,18 @@ code. See site/README.md. Function pods wrap Python functions to transform individual data in a stream. +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + +!!! warning "Provisional" + In 0.4.0, function pods that take the invocation context (`ctx_arg`) are provisional. + Their identity, when they are called, and where their results are stored may change + in a later version. Stored tables at the pod and downstream may move, and a side + effect may be repeated once after an upgrade. + ::: orcapod.core.function_pod.FunctionPod ::: orcapod.core.function_pod.function_pod diff --git a/docs/api/index.md b/docs/api/index.md index 206afe787..710ed14ba 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -16,6 +16,12 @@ directly: | [`PipelineJob`](pipeline.md) | A pipeline bound to sources and a database; the object you run | | [`side_effect_pod`, `sink_pod`, `tap_pod`](function-pods.md) | Decorators for functions run for their side effects | +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + The table lists the public modules alongside the top-level `orcapod` namespace. Other modules support Orcapod internally or are covered in the concept pages. diff --git a/docs/concepts/arrays.md b/docs/concepts/arrays.md index 57f80ae2a..a08806d61 100644 --- a/docs/concepts/arrays.md +++ b/docs/concepts/arrays.md @@ -42,6 +42,18 @@ for tag, data in scale.pod(source): The v0.2 tables and rows stay on disk unchanged, readable with v0.2. A migration is planned after v0.3 (ITL-889). +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + +!!! warning "Provisional" + In 0.4.0, function pods that take the invocation context (`ctx_arg`) are provisional. + Their identity, when they are called, and where their results are stored may change + in a later version. Stored tables at the pod and downstream may move, and a side + effect may be repeated once after an upgrade. + ## Provisional value hashes The value hashes and stored identities of the library value types are provisional in v0.3: diff --git a/docs/concepts/function-pods.md b/docs/concepts/function-pods.md index 3a3531e23..d5c4f70e9 100644 --- a/docs/concepts/function-pods.md +++ b/docs/concepts/function-pods.md @@ -36,7 +36,7 @@ Key points: `OutputTypeError`): to keep the value, declare an output key with its type (a return annotation or `output_schema`), or return nothing. Such a pod is limited for now: in a job its rows fail, over data-tags and before an operator it - raises (ITL-1260); for a function run for its effect, use a `SideEffectPod`. An + raises (ITL-1260). For a function run for its effect, use a provisional `SideEffectPod`. An output that may be missing is not "no outputs": it is one output key typed `T | None`, and a returned `None` is stored as a null. @@ -1019,8 +1019,40 @@ re-run would fail at the same row. Both orchestrators handle these rows the same This is the contract for now. An opt-in mode that tolerates database failures may be added later. +### Functions that take the invocation context + +!!! warning "Provisional" + In 0.4.0, function pods that take the invocation context (`ctx_arg`) are provisional. + Their identity, when they are called, and where their results are stored may change + in a later version. Stored tables at the pod and downstream may move, and a side + effect may be repeated once after an upgrade. + +Set `ctx_arg` to the parameter that receives the invocation context. The parameter +is supplied by Orcapod and needs no input column. + +```python +from orcapod import InvocationContext, function_pod + +reports = [] + +@function_pod(output_keys="rounded_weight", ctx_arg="ctx") +def report_weight(weight: float, ctx: InvocationContext) -> int: + rounded = round(weight) + reports.append((ctx.invocation_hash, rounded)) # stands for sending a report + return rounded +``` + +See [Sharing function results between jobs](pipeline-job.md#sharing-function-results-between-jobs) for when a job +calls the function. + ### Side effects in a job: delivered by a run, never by a read +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + A `SideEffectPod` (or `side_effect_pod`, `sink_pod`, `tap_pod`) calls its function for every row for what the call does outside Orcapod (send an email, write a file) and passes the row on unchanged. In a job, side effects are delivered only by running: `job.run()`, or diff --git a/docs/concepts/notebooks.md b/docs/concepts/notebooks.md index 4a8f4e9c1..71485d4ce 100644 --- a/docs/concepts/notebooks.md +++ b/docs/concepts/notebooks.md @@ -245,6 +245,12 @@ nodes (sources, operators, function pods, side-effect pods) and the streams betw laid out left to right. Here is `job` as the last line of a cell, after its run, with the `rates` node selected: +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + ![The diagram of the tutorial job in JupyterLab: the sources sessions and units on the left, through column selections and a join into the function pod rates, then GroupBy, a selection and the function pod session_means on the right; the sources are marked bound and every other node current, the vertical and collapse checkboxes next to the zoom buttons are unticked, and the details panel of the selected node rates lists its tag and data columns, the node it reads from and the row counts of the last run](notebooks-diagram-light.png#gh-light-mode-only) ![The diagram of the tutorial job in JupyterLab's dark theme: the sources sessions and units on the left, through column selections and a join into the function pod rates, then GroupBy, a selection and the function pod session_means on the right; the sources are marked bound and every other node current, the vertical and collapse checkboxes next to the zoom buttons are unticked, and the details panel of the selected node rates lists its tag and data columns, the node it reads from and the row counts of the last run](notebooks-diagram-dark.png#gh-dark-mode-only) diff --git a/docs/concepts/pipeline-job.md b/docs/concepts/pipeline-job.md index 25871086b..f032dace6 100644 --- a/docs/concepts/pipeline-job.md +++ b/docs/concepts/pipeline-job.md @@ -200,6 +200,18 @@ A `CachedSource` is not a node of the job: its cache is kept in the cache databa the path it was created with, whatever job reads it, so two jobs given one `CachedSource` (or one cache database and path) share its cache. +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + +!!! warning "Provisional" + In 0.4.0, function pods that take the invocation context (`ctx_arg`) are provisional. + Their identity, when they are called, and where their results are stored may change + in a later version. Stored tables at the pod and downstream may move, and a side + effect may be repeated once after an upgrade. + Every run reads a function node's stored tables (its result table and its pipeline records) as they are when the node starts: results that another job, or another handle on the same database (a second `DeltaTableDatabase` over the same directory, another @@ -224,7 +236,8 @@ had loaded the old table keeps reading it (ITL-1413). Open a new database object replacing a table. A function that takes the invocation context (`ctx_arg`) can perform an external action. -Rows with equal input data reuse a stored result even when their tags differ. In an async +A job calls the function once per distinct input, even when rows have different tags. +This rule is provisional. In an async run, overlapping rows at one node give the first call time to store its result before checking for it again. Jobs that share a result database share stored results. A row can call the function again if the result was discarded or deleted. To perform an action for diff --git a/docs/concepts/sources.md b/docs/concepts/sources.md index 6da884ab0..bc402c153 100644 --- a/docs/concepts/sources.md +++ b/docs/concepts/sources.md @@ -1120,6 +1120,12 @@ IDs, and a `sink_pod` delivers it again. Because every key includes the hash of data, no result is ever paired with the wrong row; a function's stored result for that data is reused rather than recomputed. +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + Every source accepts `record_id_columns`, one or several key columns whose values name the row instead (`{"unit":"u1","time":1700000000}`), so the record ID follows the row. Both system tags must be stable: when you omit `source_id` an in-memory source is named after a diff --git a/docs/concepts/streams.md b/docs/concepts/streams.md index 60409af1d..986134c80 100644 --- a/docs/concepts/streams.md +++ b/docs/concepts/streams.md @@ -224,6 +224,12 @@ side-effect stream outside a job delivers its side effects again (its `head()` s a polling source polls again and a `SpiralDBTableSource` reads its whole table again. A view never asks its stream for more columns, because for those streams asking again is not a read. +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + What `run()` does on each kind of object: | Object | `run()` | diff --git a/docs/dev/design_issues/ITL-555-SE3.md b/docs/dev/design_issues/ITL-555-SE3.md new file mode 100644 index 000000000..b57d337ff --- /dev/null +++ b/docs/dev/design_issues/ITL-555-SE3.md @@ -0,0 +1,20 @@ +## `src/orcapod/side_effects.py` + +### SE3 — Side-effect pods need a provisional contract in 0.4.0 +**Status:** resolved +**Severity:** high +**Issue:** ITL-555 + +Freezing `SideEffectPod` in 0.4.0 would commit the release to its current identity, +delivery rules, and invocation log layout before the follow-up design is ready. + +**Fix:** The November 28, 2026 decision (SE1) keeps the entire pod and its decorators +provisional in 0.4.0. This covers its identity, firing rule, `tdb` layout, and downstream +hashes. Constructing the pod or restoring its node from a saved job or blueprint warns +once per process, and golden cases that do either must declare the pod. +The follow-up decision also makes function pods that take the invocation context +provisional (see ITL-947, SL4). + +ITL-947 tracks the design after 0.4.0: firing levels, one log row per arrival with its +delivery status, and coordination separate from the store that holds a lock from before +delivery until the outcome is recorded. diff --git a/docs/dev/design_issues/ITL-947-SL4.md b/docs/dev/design_issues/ITL-947-SL4.md new file mode 100644 index 000000000..c4a2a2f85 --- /dev/null +++ b/docs/dev/design_issues/ITL-947-SL4.md @@ -0,0 +1,14 @@ +## `src/orcapod/core/function_pod.py` — function pod identity + +### SL4 — Context-taking function pods need their own stored table arrangement +**Status:** open +**Severity:** high +**Issue:** ITL-947 + +Function pods configured with an invocation context can perform an external action. +Their current identity, firing rule, and result and pipeline storage should remain +provisional in 0.4.0, including every hash downstream. + +The November 29, 2026 decision applies the shared provisional pod warning to construction +and saved graph loading. Golden cases that depend on these pods must declare them. The +table arrangement is still to be designed alongside the side-effect pod's tables. diff --git a/docs/reference/data-function-types.md b/docs/reference/data-function-types.md index 815dc5e11..ff1e5b1a6 100644 --- a/docs/reference/data-function-types.md +++ b/docs/reference/data-function-types.md @@ -17,6 +17,12 @@ 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 ``, in that database, with no `/_result`. +!!! warning "Provisional" + In 0.4.0, function pods that take the invocation context (`ctx_arg`) are provisional. + Their identity, when they are called, and where their results are stored may change + in a later version. Stored tables at the pod and downstream may move, and a side + effect may be repeated once after an upgrade. + A job's default result path for a pod configured with `ctx_arg` is ```text diff --git a/docs/reference/golden-hashes.md b/docs/reference/golden-hashes.md index 8e26952ee..58500fbfa 100644 --- a/docs/reference/golden-hashes.md +++ b/docs/reference/golden-hashes.md @@ -24,7 +24,7 @@ wanted on purpose starts a new data context version. It never edits a released v entries that move, each explained. 0.4.0 freezes `v1`. See [Withdrawing a release](#withdrawing-a-release). -!!! note "Provisional operators, sources and library value types are outside the freeze" +!!! note "Provisional features are outside the freeze" A provisional operator (`orcapod.operators.PROVISIONAL_OPERATORS`; ITL-1266, ITL-1279) has an identity that no release freezes yet, and so have a provisional source (`orcapod.sources.PROVISIONAL_SOURCES`: `DerivedSource` in both forms, plain from @@ -38,6 +38,26 @@ wanted on purpose starts a new data context version. It never edits a released v the developer's approval of the exact list. So the promise on this page holds for a pipeline only when it contains none of them. See [Provisional files](#provisional-files). +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. Constructing the pod or loading a saved job or blueprint that + contains it issues one shared `ProvisionalHashWarning` per process. Golden cases + that use either route declare `provisional=("SideEffectPod",)`. + +!!! warning "Provisional" + In 0.4.0, function pods that take the invocation context (`ctx_arg`) are provisional. + Their identity, when they are called, and where their results are stored may change + in a later version. Stored tables at the pod and downstream may move, and a side + effect may be repeated once after an upgrade. + + Building the pod or loading a saved job or blueprint that contains it issues one + shared `ProvisionalHashWarning` per process. Golden cases declare + `provisional=("FunctionPod with a context argument",)`. + + Ordinary function pods retain their 0.4.0 freeze. + ## The pieces at a glance The mechanism has five layers. Each one is checked against the layer below it, and the last @@ -154,12 +174,12 @@ tests/test_hashing/golden/data/ ### Provisional files `tests/test_hashing/golden/data/v1/provisional/.json` holds the values of the cases -that depend on a provisional operator (ITL-1266, ITL-1279), a provisional source (ITL-1331) or -a provisional library value type (ITL-1324), one file per group and no counter: such a file is never frozen, and the generator -rewrites it in place. +that depend on a provisional operator (ITL-1266, ITL-1279), source (ITL-1331), pod (ITL-555), +or library value type (ITL-1324). There is one file per group and no counter. The generator +rewrites these files in place. -- **Which entries.** A case declares the provisional features it depends on, operators and - sources by class name and library value types by extension name: +- **Which entries.** A case declares the provisional features it depends on. It uses the + class name for an operator, source or pod and the extension name for a library value type: `@case("pipeline", "group_by", provisional=("GroupBy",))`, `@case("schema", "derived_source_tags_as_data", provisional=("DerivedSource",))`, `@case("datagram", "ndarray", provisional=("orcapod.numpy.ndarray",))`. The generator runs @@ -172,8 +192,9 @@ rewrites it in place. `static_process`), and when a stream it produced is hashed, read or previewed (`head`); a source when it is built and when its source id, content or pipeline hash or identity structure is read (a `DerivedSource` also when its rows are read or previewed, and when a - saved one is loaded, also over a job node it cannot rebuild); a library value type when it - is resolved. So an operator or source built before the case, at module level, is still + saved one is loaded, also over a job node it cannot rebuild); a pod when it is built, + applied or its identity structure is read; a library value type when it is resolved. + So an operator or source built before the case, at module level, is still recorded when the case reads its identity or applies it, and a step built in the case downstream of it reaches it while its own hash is computed. - **What the guard sees, and the convention that makes it enough.** The guard sees a diff --git a/docs/reference/hashing.md b/docs/reference/hashing.md index 157986c24..cca28e9c8 100644 --- a/docs/reference/hashing.md +++ b/docs/reference/hashing.md @@ -5,10 +5,8 @@ orcapod-python framework. For conceptual background on the two identity chains (`content_hash` and `pipeline_hash`), see [Identity & Hashing](../concepts/identity.md). Every hash listed here that Orcapod stores or embeds in a name is pinned as a golden value; how released values are protected is described in [Golden Hashes](golden-hashes.md). A -release freezes every golden value except those of the provisional operators -(`orcapod.operators.PROVISIONAL_OPERATORS`, such as `Filter` and `GroupBy`) and of every step downstream -of one: their identity may still change in a later release (see -[Provisional operators](../concepts/operators.md#provisional-operators)). +release freezes the golden values outside the [provisional files](golden-hashes.md#provisional-files). +The identities of provisional features and hashes downstream may change in a later release. --- @@ -1460,10 +1458,22 @@ November 26, 2026; to be reconsidered in ITL-1475). ## 4. Side-Effect Log Key & Invocation Hash -Side-effect pods (and `FunctionPod` instances with a `ctx_arg_name`) are keyed by the entry id -of §3 (site 7), computed by the same function. Pod-version scoping is handled at the delivery -log's table-path level via `pipeline_hash()` and `uri`, not at the preimage level — consistent -with how `FunctionJobNode` scopes its pipeline table in §3. +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + +!!! warning "Provisional" + In 0.4.0, function pods that take the invocation context (`ctx_arg`) are provisional. + Their identity, when they are called, and where their results are stored may change + in a later version. Stored tables at the pod and downstream may move, and a side + effect may be repeated once after an upgrade. + +Side-effect pods check delivery by the entry id of §3 (site 7). A function pod configured +with `ctx_arg` uses that same entry id for its invocation hash and its input data hash +for result reuse. The side-effect pod scopes its delivery log by `pipeline_hash()` and +`uri` in the table path, as a function job node scopes its pipeline table in §3. The `invocation_hash` string is composed from two `ContentHash` components and exposed to the pod function as an idempotency key via `InvocationContext.invocation_hash`. @@ -2026,9 +2036,9 @@ a null. A source whose table has such a column fails when it is constructed. A label names the algorithm that produced one hash. It does not say which generation of Orcapod's hashing a stored row belongs to. That is the **data context**: one key that changes whenever any existing hash value can change (the hashers, the identity definitions, the -record-id recipes, the libraries behind them). This does not cover a provisional operator: -its identity, and every hash downstream of one, can change in a later release under the same -key ([Provisional operators](../concepts/operators.md#provisional-operators)). Orcapod v0.3 +record-id recipes, the libraries behind them). Provisional features and their downstream +hashes can change in a later release under the same key +([Provisional files](golden-hashes.md#provisional-files)). Orcapod v0.3 writes `std:v1:default`; everything stored before v0.3 is the earlier generation, `std:v0.1:default`. The manifest of the current data context is `orcapod/contexts/data/v1.json`. It is frozen at the release of @@ -2048,7 +2058,7 @@ Every row Orcapod stores names its data context in the column `__data_context`: | Function result table | `rdb_v1`, after the revision of the data function type's record (`.../python.function.v1/rev1/rdb_v1`; see [Data function types](data-function-types.md)) | | Operator-node cache table | `odb_v3` | | Cached-source table | `sdb_v2` | -| Side-effect invocation log | `tdb_v2` | +| Side-effect invocation log | `tdb_v2` (provisional in 0.4.0) | The layout component is always the last component of a table's path, also when a `CachedSource` is given an explicit `cache_path`. The `sdb_v2` layout stores diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 5e2b218ae..c4eef9016 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -209,6 +209,12 @@ same (`Run of job '...': 1 row failed.`). ### `TypeError: ...() got an unexpected keyword argument 'ctx'` from a `sink_pod` +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + **Cause.** A function decorated with `@sink_pod`, `@tap_pod` or `@side_effect_pod` must accept the invocation context as a parameter named `ctx`. It is checked when the job runs, not when the function is decorated. This is a known defect. diff --git a/docs/tutorial/05-pipeline-job.md b/docs/tutorial/05-pipeline-job.md index 7be269bc2..b58b31e92 100644 --- a/docs/tutorial/05-pipeline-job.md +++ b/docs/tutorial/05-pipeline-job.md @@ -95,6 +95,15 @@ units have the same spike count and the same session duration. Orcapod stores a the function and the *values* of its inputs, so the second of those two units found its result already stored. +Use a provisional [`SideEffectPod`](../concepts/function-pods.md#side-effects-in-a-job-delivered-by-a-run-never-by-a-read) +when an action needs to run once per row instead. + +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + ## Nodes Each recorded step is a **node** of the job. `job.nodes` lists them by name: diff --git a/docs/tutorial/where-next.md b/docs/tutorial/where-next.md index d7e0a1e1b..ce91ff6c2 100644 --- a/docs/tutorial/where-next.md +++ b/docs/tutorial/where-next.md @@ -20,7 +20,13 @@ durations = sessions.select_data_columns(["duration_s"]) ## Side effects -**Side-effect pods** are steps that exist for their effect: send a notification, upload a +!!! warning "Provisional" + In 0.4.0, `SideEffectPod` and its decorators are provisional: the pod's identity, + when it delivers, and the layout of its delivery log may change in a later version. + Stored tables at the pod and downstream may move, and a delivery may be repeated once + after an upgrade. + +**Provisional side-effect pods** are steps that exist for their effect: send a notification, upload a file, write a row to another database. One kind is the **sink**, made with `@sink_pod`: it runs once for each row and remembers which rows it has already handled, so a re-run does not repeat the effect for them. A row counts as handled once its function has returned and that @@ -31,6 +37,8 @@ without them can make the sink handle them again, and so can a source whose name in-memory source without a `source_id` is named after its content, so adding a row renames it. For a sink, give the source both a `source_id` and key columns. +The first sink built in these examples emits `ProvisionalHashWarning` on stderr. + ```python from orcapod import InvocationContext, sink_pod diff --git a/src/orcapod/core/data_function.py b/src/orcapod/core/data_function.py index 2320ed01a..dce03fa3c 100644 --- a/src/orcapod/core/data_function.py +++ b/src/orcapod/core/data_function.py @@ -23,6 +23,7 @@ from orcapod.contexts.stored import require_same_data_context from orcapod.core.base import TraceableBase from orcapod.core.data_function_types import DataFunctionTypeDeclaration, StoredColumn +from orcapod.core.provisional_pods import CONTEXT_FUNCTION_POD, warn_provisional_pod from orcapod.core.datagrams import Datagram, Data from orcapod.hashing.semantic_hashing.builtin_handlers import ( DEFAULT_VALUE_REFUSALS, @@ -1597,6 +1598,7 @@ def __init__( self._result_database = result_database self._record_path_prefix = record_path_prefix if context_parameter is not None: + warn_provisional_pod(CONTEXT_FUNCTION_POD) record_path_prefix += ("side_effect_function",) self._cache = ResultCache( result_database=result_database, diff --git a/src/orcapod/core/function_pod.py b/src/orcapod/core/function_pod.py index 671514bbb..fd8910acb 100644 --- a/src/orcapod/core/function_pod.py +++ b/src/orcapod/core/function_pod.py @@ -30,6 +30,7 @@ data_tag_names, stream_data_tags, ) +from orcapod.core.provisional_pods import CONTEXT_FUNCTION_POD, warn_provisional_pod from orcapod.core.streams.base import ( ZERO_ROW_INPUT_COLUMNS, StreamBase, @@ -74,6 +75,7 @@ resolve_concurrency, ) from orcapod.utils import arrow_utils, schema_utils +from orcapod.utils.provisional import note_provisional_use from datetime import datetime, timezone @@ -149,6 +151,8 @@ def __init__( self.input_data_schema, data_function.output_data_schema, ) + if self._ctx_arg_name is not None: + warn_provisional_pod(CONTEXT_FUNCTION_POD) def computed_label(self) -> str | None: """Use the data function's canonical name as the default label.""" @@ -202,12 +206,14 @@ def pod_config(self) -> PodConfig: def identity_structure(self) -> Any: if self._ctx_arg_name is not None: + note_provisional_use(CONTEXT_FUNCTION_POD) return (self.data_function, self._ctx_arg_name) 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: + note_provisional_use(CONTEXT_FUNCTION_POD) return (self.data_function, self._ctx_arg_name) return self.data_function @@ -1000,6 +1006,8 @@ def process( Returns: A ``FunctionPodStream`` wrapping the computation. """ + if self._ctx_arg_name is not None: + note_provisional_use(CONTEXT_FUNCTION_POD) logger.debug("Invoking kernel %s on streams: %s", self, streams) input_stream = self.handle_input_streams(*streams) diff --git a/src/orcapod/core/nodes/function_node.py b/src/orcapod/core/nodes/function_node.py index b863cf5cd..5b108e94f 100644 --- a/src/orcapod/core/nodes/function_node.py +++ b/src/orcapod/core/nodes/function_node.py @@ -72,6 +72,7 @@ from orcapod.core.data_function import output_source_info from orcapod.core.datagrams.tag_data import Data, EmptyData, Tag from orcapod.core.row_ids import INSTANCE_ID_COL, RECORD_ID_COL +from orcapod.core.provisional_pods import CONTEXT_FUNCTION_POD, warn_provisional_pod from orcapod.errors import ( EphemeralResultMissingError, InputValidationError, @@ -1141,6 +1142,8 @@ def from_descriptor( node._load_status = LoadStatus.UNAVAILABLE node._node_type = descriptor["node_type"] + if node._node_type == "side_effect_function": + warn_provisional_pod(CONTEXT_FUNCTION_POD) return node @@ -1886,6 +1889,7 @@ def from_descriptor( # their pipeline paths, and new files also record their result path. pod_uri = node._stored_node_uri if node._node_type == "side_effect_function": + warn_provisional_pod(CONTEXT_FUNCTION_POD) pod_uri = ("side_effect_function",) + pod_uri node._stored_result_record_path = tuple( descriptor.get("result_record_path", pod_uri) diff --git a/src/orcapod/core/provisional_pods.py b/src/orcapod/core/provisional_pods.py new file mode 100644 index 000000000..479266c54 --- /dev/null +++ b/src/orcapod/core/provisional_pods.py @@ -0,0 +1,38 @@ +"""Provisional pod kinds and their shared construction warning.""" + +from collections.abc import Mapping +from types import MappingProxyType + +from orcapod.utils.provisional import warn_provisional_use + +CONTEXT_FUNCTION_POD = "FunctionPod with a context argument" + +PROVISIONAL_PODS: Mapping[str, str] = MappingProxyType( + {"SideEffectPod": "ITL-947", CONTEXT_FUNCTION_POD: "ITL-947"} +) +"""Provisional pod kinds mapped to the issues that decide their contracts.""" + + +def warn_provisional_pod(name: str | None) -> None: + """Record use of a provisional pod and warn once per kind per process. + + Args: + name: The provisional kind, or None for a pod outside the list. + """ + if name is None: + return + if name == CONTEXT_FUNCTION_POD: + message = ( + "A function pod with a context argument is provisional. Its identity, when it is " + "called, and where its results are stored may change in a later version. Stored " + "tables at this pod and downstream may move, and a side effect may be repeated " + "once after an upgrade." + ) + else: + message = ( + f"{name} is provisional. Its identity, when it delivers, and " + "the layout of its delivery log may change in a later version. Stored " + "tables at this pod and downstream may move, and a delivery may be " + "repeated once after an upgrade." + ) + warn_provisional_use(name, message) diff --git a/src/orcapod/errors.py b/src/orcapod/errors.py index a748add05..db2579acc 100644 --- a/src/orcapod/errors.py +++ b/src/orcapod/errors.py @@ -880,7 +880,7 @@ class OrcapodDatabaseContentWarning(UserWarning): class ProvisionalHashWarning(UserWarning): - """A value type or an operator was used whose identity is provisional. + """A feature was used whose identity is provisional. The library value types (``numpy.ndarray``, ``torch.Tensor``, pandas and polars ``DataFrame`` and ``Series``) are hashed and stored with formats that may still @@ -902,6 +902,13 @@ class ProvisionalHashWarning(UserWarning): with data context v1. The warning is issued once per source kind per process, when the source is constructed (also from a saved config). + A provisional side-effect pod (ITL-555) may change its identity, delivery rules, + and log layout in a later version. Stored tables at the pod and downstream may + move, and a delivery may be repeated once after an upgrade. Function pods configured + to take the invocation context (ITL-947) are also provisional, including their identity, + when they are called, and where their results are stored. Building a provisional pod or + loading a saved job or blueprint containing it warns once per pod kind per process. + To silence it, call ``warnings.filterwarnings("ignore", category=ProvisionalHashWarning)`` after importing Orcapod. Python's ``-W`` option and ``PYTHONWARNINGS`` cannot name this class: they are read before installed diff --git a/src/orcapod/pipeline/loaded_side_effects.py b/src/orcapod/pipeline/loaded_side_effects.py index 9e11b605d..ba6f3e83c 100644 --- a/src/orcapod/pipeline/loaded_side_effects.py +++ b/src/orcapod/pipeline/loaded_side_effects.py @@ -16,7 +16,12 @@ from typing_extensions import override from orcapod.core.nodes.function_node import run_job_node -from orcapod.side_effects import SideEffectJobNode, SideEffectNode +from orcapod.core.provisional_pods import warn_provisional_pod +from orcapod.side_effects import ( + SideEffectJobNode, + SideEffectNode, + SideEffectPod, +) if TYPE_CHECKING: from orcapod.channels import ReadableChannel, WritableChannel @@ -29,7 +34,6 @@ TagProtocol, ) from orcapod.protocols.observability_protocols import ExecutionObserverProtocol - from orcapod.side_effects import SideEffectPod from orcapod.types import ContentHash @@ -75,6 +79,7 @@ def __init__(self, descriptor: dict[str, Any]) -> None: self.orcapod_config: OrcapodConfig = OrcapodConfig.from_node_descriptor( descriptor ) + warn_provisional_pod(SideEffectPod.__name__) def cannot_deliver_error(label: str | None) -> RuntimeError: diff --git a/src/orcapod/side_effects.py b/src/orcapod/side_effects.py index c04b7f286..ea9df70b3 100644 --- a/src/orcapod/side_effects.py +++ b/src/orcapod/side_effects.py @@ -13,7 +13,7 @@ import datetime import logging from collections.abc import Callable, Collection, Iterator, Sequence -from typing import TYPE_CHECKING, Any, Literal, cast +from typing import TYPE_CHECKING, Any, ClassVar, Literal, cast import pyarrow as pa from typing_extensions import override @@ -37,6 +37,7 @@ ViewStatus, StreamView, ) +from orcapod.core.provisional_pods import warn_provisional_pod from orcapod.core.tracker import DEFAULT_TRACKER_MANAGER from orcapod.errors import ( OrcapodDatabaseError, @@ -64,6 +65,10 @@ from orcapod.types import ColumnConfig from orcapod.utils import arrow_utils from orcapod.utils.database_errors import flush_best_effort +from orcapod.utils.provisional import ( + note_provisional_use, + provisional_class_name, +) if TYPE_CHECKING: from orcapod.channels import ReadableChannel, WritableChannel @@ -83,7 +88,6 @@ # The invocation log's column holding the row's entry id, which is also its key. INVOCATION_LOG_ENTRY_ID_COL = "entry_id" - # --------------------------------------------------------------------------- # SideEffectPodConfig # --------------------------------------------------------------------------- @@ -581,6 +585,8 @@ def _write_invocation_row( class SideEffectPod(TraceableBase): """A pipeline node whose primary purpose is a side effect. + Provisional in 0.4.0: its identity, delivery rules and log layout may change. + Wraps a ``(data: T, ctx: InvocationContext) -> None`` callable. ``InvocationContext`` is always constructed and passed — it is part of the function contract. Callees that do not need it may ignore it (name @@ -608,6 +614,8 @@ class SideEffectPod(TraceableBase): data_context: Optional data context override. """ + PROVISIONAL: ClassVar[bool] = True + def __init__( self, fn: Callable, @@ -618,6 +626,7 @@ def __init__( data_context: Any = None, ctx_arg_name: str = "ctx", ) -> None: + warn_provisional_pod(provisional_class_name(type(self))) super().__init__(label=label, data_context=data_context) self._fn = fn self._name: str = ( @@ -646,7 +655,13 @@ def computed_label(self) -> str | None: """Use the callable's ``__name__`` as the default label.""" return getattr(self._fn, "__name__", None) + def _note_provisional_use(self) -> None: + provisional = provisional_class_name(type(self)) + if provisional is not None: + note_provisional_use(provisional) + def identity_structure(self) -> Any: + self._note_provisional_use() return ( self.uri, self._ctx_arg_name, @@ -708,6 +723,7 @@ def process( raise ValueError( f"SideEffectPod.process() expects exactly 1 stream; got {len(streams)}." ) + self._note_provisional_use() input_stream = streams[0] self.tracker_manager.record_side_effect_pod_invocation( self, input_stream, label=label diff --git a/src/orcapod/utils/provisional.py b/src/orcapod/utils/provisional.py index 2e1657250..09bb1ca75 100644 --- a/src/orcapod/utils/provisional.py +++ b/src/orcapod/utils/provisional.py @@ -1,9 +1,10 @@ """Uses of provisional features: the record of which ones a block of code used (ITL-1266). A provisional feature is one whose identity is not frozen with the current data context: a -provisional operator (``core/operators/provisional.py``) or a provisional source -(``core/sources/provisional.py``). Its hashes may change in a later -release, so the golden values that depend on it are kept outside the frozen golden files. +provisional operator (``core/operators/provisional.py``), a provisional source +(``core/sources/provisional.py``) or a provisional pod (``core/provisional_pods.py``). Its hashes +may change in a later release, so the golden values that depend on it are kept outside +the frozen golden files. Each provisional feature calls ``note_provisional_use`` with its name whenever it is used, before its once-per-process warning; ``recording_provisional_uses`` collects those names for a block of code. The golden hash tool runs each golden case inside one, so a case that @@ -65,7 +66,7 @@ def provisional_class_name(cls: type) -> str | None: """The provisional class ``cls`` is, or derives from. Args: - cls: A class that may set ``PROVISIONAL = True`` (an operator or a source). + cls: A class that may set ``PROVISIONAL = True`` (an operator, source or pod). Returns: The name of the nearest class in ``cls``'s method resolution order that sets diff --git a/tests/test_core/function_pod/test_function_pod_ctx_arg.py b/tests/test_core/function_pod/test_function_pod_ctx_arg.py index bb354f7d2..6bd8594f9 100644 --- a/tests/test_core/function_pod/test_function_pod_ctx_arg.py +++ b/tests/test_core/function_pod/test_function_pod_ctx_arg.py @@ -22,6 +22,10 @@ TRACKING_DB_SCHEMA_VERSION, ) +pytestmark = pytest.mark.filterwarnings( + "ignore:A function pod with a context argument is provisional:orcapod.errors.ProvisionalHashWarning" +) + def _make_stream(n: int = 3) -> ArrowTableStream: """Simple stream: tag=id (int), data=value (int).""" diff --git a/tests/test_core/function_pod/test_provisional_context_function.py b/tests/test_core/function_pod/test_provisional_context_function.py new file mode 100644 index 000000000..aa3cc5567 --- /dev/null +++ b/tests/test_core/function_pod/test_provisional_context_function.py @@ -0,0 +1,148 @@ +"""Only function pods configured to receive the invocation context are provisional.""" + +from __future__ import annotations + +import subprocess +import sys +import warnings +from collections.abc import Callable, Iterator +from pathlib import Path + +import pytest + +from orcapod import PipelineJob, function_pod, side_effect_function_pod +from orcapod.core.data_function import CachedDataFunction, PythonDataFunction +from orcapod.core.function_pod import FunctionPod +from orcapod.databases import DeltaTableDatabase +from orcapod.errors import ProvisionalHashWarning +from orcapod.invocation import InvocationContext +from orcapod.pipeline import Pipeline +from orcapod.sources import DictSource +from orcapod.utils.provisional import ( + recording_provisional_uses, + reset_provisional_use_warnings, +) + +NAME = "FunctionPod with a context argument" +WARNING = ( + "A function pod with a context argument is provisional. Its identity, when it is " + "called, and where its results are stored may change in a later version. Stored " + "tables at this pod and downstream may move, and a side effect may be repeated " + "once after an upgrade." +) + + +def _compute(x: int, ctx: InvocationContext) -> int: + """A function whose context can be supplied by the pod.""" + assert isinstance(ctx, InvocationContext) + return x + 1 + + +def _plain(x: int) -> int: + """A function without a context parameter.""" + return x + 1 + + +@pytest.fixture +def fresh_process() -> Iterator[None]: + reset_provisional_use_warnings() + yield + reset_provisional_use_warnings() + + +def _save(root: Path, *, contextual: bool) -> tuple[Path, Path]: + root.mkdir() + job = PipelineJob(name="example", database=DeltaTableDatabase(root / "store")) + pod = ( + FunctionPod.from_fn(_compute, output_keys="y", ctx_arg_name="ctx") + if contextual + else FunctionPod.from_fn(_plain, output_keys="y") + ) + with job: + _ = pod(DictSource([{"x": 1}], source_id="input"), label="step") + job_path, blueprint_path = root / "job.json", root / "blueprint.json" + job.save(job_path) + job.compiled_pipeline.save(blueprint_path) + return job_path, blueprint_path + + +@pytest.mark.filterwarnings( + "ignore:A function pod with a context argument is provisional:orcapod.errors.ProvisionalHashWarning" +) +@pytest.mark.usefixtures("fresh_process") +@pytest.mark.parametrize( + "first", + [ + "constructor", + "from_fn", + "decorator", + "legacy_decorator", + "data_function", + "job", + "blueprint", + ], +) +def test_context_function_routes_share_a_once_per_process_warning( + tmp_path: Path, first: str +) -> None: + job_path, blueprint_path = _save(tmp_path / "contextual", contextual=True) + data_function = PythonDataFunction(_compute, output_keys="y") + routes: dict[str, Callable[[], object]] = { + "constructor": lambda: FunctionPod( + data_function, # pyright: ignore[reportArgumentType] # PythonDataFunction works at runtime; its protocol typing is incomplete. + ctx_arg_name="ctx", + ), + "from_fn": lambda: FunctionPod.from_fn( + _compute, output_keys="y", ctx_arg_name="ctx" + ), + "decorator": lambda: function_pod(output_keys="y", ctx_arg="ctx")(_compute), + "legacy_decorator": lambda: side_effect_function_pod(_compute, output_keys="y"), + "data_function": lambda: CachedDataFunction( + data_function, # pyright: ignore[reportArgumentType] # PythonDataFunction works at runtime; its protocol typing is incomplete. + DeltaTableDatabase(tmp_path / "result"), + context_parameter="ctx", + ), + "job": lambda: PipelineJob.load(job_path), + "blueprint": lambda: Pipeline.load(blueprint_path), + } + reset_provisional_use_warnings() + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always", ProvisionalHashWarning) + with recording_provisional_uses() as used: + _ = routes[first]() + assert used == {NAME} + assert len(caught) == 1 + assert caught[0].filename == __file__ + for route in routes.values(): + with recording_provisional_uses() as used: + _ = route() + assert used == {NAME} + assert [str(w.message) for w in caught] == [WARNING] + + +@pytest.mark.usefixtures("fresh_process") +def test_ordinary_functions_and_saved_graphs_are_not_provisional( + tmp_path: Path, +) -> None: + with warnings.catch_warnings(): + warnings.simplefilter("error", ProvisionalHashWarning) + with recording_provisional_uses() as used: + _ = function_pod(output_keys="y")(_plain) + job_path, blueprint_path = _save(tmp_path / "plain", contextual=False) + _ = PipelineJob.load(job_path) + _ = Pipeline.load(blueprint_path) + assert used == set() + + +def test_importing_orcapod_does_not_warn() -> None: + result = subprocess.run( + [ + sys.executable, + "-c", + "import warnings; warnings.simplefilter('error'); import orcapod", + ], + capture_output=True, + text=True, + check=False, + ) + assert result.returncode == 0, result.stderr diff --git a/tests/test_core/operators/test_provisional_operators.py b/tests/test_core/operators/test_provisional_operators.py index 423a646df..c1ca93ef5 100644 --- a/tests/test_core/operators/test_provisional_operators.py +++ b/tests/test_core/operators/test_provisional_operators.py @@ -4,13 +4,15 @@ import inspect import warnings -from collections.abc import Iterator +from collections.abc import Callable, Iterator from typing import Any, ClassVar import pyarrow as pa import pytest import orcapod.operators as operators +import orcapod.side_effects as side_effects +from orcapod.core.function_pod import FunctionPod from orcapod.core.operators.base import UnaryOperator from orcapod.core.operators.provisional import ( PROVISIONAL_OPERATORS, @@ -19,10 +21,12 @@ warn_provisional_operator, ) from orcapod.core.operators.static_output_pod import StaticOutputOperatorPod +from orcapod.core.provisional_pods import PROVISIONAL_PODS from orcapod.errors import ProvisionalHashWarning +from orcapod.invocation import InvocationContext from orcapod.operators import PolarsFilter from orcapod.sources import ArrowTableSource -from orcapod.utils.provisional import recording_provisional_uses +from orcapod.utils.provisional import provisional_class_name, recording_provisional_uses # PolarsFilter is built here on purpose; the warning of every construction is tested in # test_polars_filter_warning.py (ITL-1296). @@ -114,6 +118,59 @@ def test_the_list_and_the_markers_agree() -> None: assert provisional_operator_name(cls) == expected, name +def test_the_pod_list_and_the_markers_agree() -> None: + marked = { + name + for name, cls in vars(side_effects).items() + if inspect.isclass(cls) and cls.__dict__.get("PROVISIONAL") is True + } + assert marked == {"SideEffectPod"} + assert dict(PROVISIONAL_PODS) == { + "SideEffectPod": "ITL-947", + "FunctionPod with a context argument": "ITL-947", + } + assert provisional_class_name(FunctionPod) is None + + +@pytest.mark.parametrize( + "first", + [ + side_effects.SideEffectPod, + side_effects.side_effect_pod, + side_effects.sink_pod, + side_effects.tap_pod, + ], +) +def test_side_effect_pod_warns_once_across_entry_routes( + first: Callable[[Callable[[InvocationContext, int], None]], object], +) -> None: + def deliver(_ctx: InvocationContext, _age: int) -> None: + pass + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always", ProvisionalHashWarning) + assert isinstance(first(deliver), side_effects.SideEffectPod) + assert len(caught) == 1 + assert caught[0].filename == __file__ + for decorator in ( + side_effects.side_effect_pod, + side_effects.sink_pod, + side_effects.tap_pod, + ): + assert isinstance(decorator(deliver), side_effects.SideEffectPod) + wrapped = decorator() + assert not isinstance(wrapped, side_effects.SideEffectPod) + assert isinstance(wrapped(deliver), side_effects.SideEffectPod) + _ = side_effects.SideEffectPod(deliver) + + assert _provisional_warnings(caught) == [ + "SideEffectPod is provisional. Its identity, when it delivers, and " + "the layout of its delivery log may change in a later version. Stored " + "tables at this pod and downstream may move, and a delivery may be " + "repeated once after an upgrade." + ] + + # The developer-approved list (2026-11-19, ITL-1279), each with the issue that decides # its identity or output. APPROVED = { diff --git a/tests/test_core/side_effect_function/test_side_effect_function_pod.py b/tests/test_core/side_effect_function/test_side_effect_function_pod.py index 0543c1ab7..8a8ecacad 100644 --- a/tests/test_core/side_effect_function/test_side_effect_function_pod.py +++ b/tests/test_core/side_effect_function/test_side_effect_function_pod.py @@ -7,6 +7,10 @@ from orcapod.core.streams import ArrowTableStream from orcapod.side_effects import InvocationContext +pytestmark = pytest.mark.filterwarnings( + "ignore:A function pod with a context argument is provisional:orcapod.errors.ProvisionalHashWarning" +) + def _make_stream(n: int = 3) -> ArrowTableStream: """Simple stream: tag=id (int), data=value (int).""" diff --git a/tests/test_hashing/golden/cases.py b/tests/test_hashing/golden/cases.py index 2dfe4277c..04967742a 100644 --- a/tests/test_hashing/golden/cases.py +++ b/tests/test_hashing/golden/cases.py @@ -113,13 +113,14 @@ def register(fn: CaseFn) -> CaseFn: def declarable_provisional_names() -> frozenset[str]: """The names a case may declare provisional: the provisional operators (ITL-1266), - ``DECLARABLE_PROVISIONAL_SOURCES`` (ITL-1331) and the provisional library value - types, by extension name (the ``provisional`` list of ``contexts/logical_types.json``; - ITL-1324). ``PollingSource`` is not declarable: a case that builds one is refused, - declared or not (ITL-1314).""" + ``DECLARABLE_PROVISIONAL_SOURCES`` (ITL-1331), provisional pods (ITL-555), and the + provisional library value types, by extension name (the ``provisional`` list of + ``contexts/logical_types.json``; ITL-1324). A case that builds a ``PollingSource`` is + refused regardless of its declaration (ITL-1314).""" import importlib.resources from orcapod.core.operators.provisional import PROVISIONAL_OPERATORS + from orcapod.core.provisional_pods import PROVISIONAL_PODS registration = json.loads( importlib.resources.files("orcapod.contexts") @@ -129,6 +130,7 @@ def declarable_provisional_names() -> frozenset[str]: return ( frozenset(PROVISIONAL_OPERATORS) | DECLARABLE_PROVISIONAL_SOURCES + | frozenset(PROVISIONAL_PODS) | frozenset(registration.get("provisional", [])) ) @@ -243,7 +245,8 @@ def compute_group_kinds( previewed. A provisional source is recorded when it is built or loaded and when its ``source_id``, hashes or identity structure is read (a ``DerivedSource`` also when its rows are read or previewed). So an operator or source built before the case (at module - level) is recorded too. A provisional library value type is recorded when it is + level) is recorded too. A provisional pod is recorded when it is built, applied or + its identity structure is read. A provisional library value type is recorded when it is resolved. A case that uses one it does not declare, or declares a name ``declarable_provisional_names`` does not hold (``PollingSource`` among them), is refused. The fixtures are registered first, outside every record, so registering one @@ -251,10 +254,10 @@ def compute_group_kinds( Limits: the guard sees a provisional object built or read inside the case, not one hidden behind a hash computed before the case. A stream, source or node downstream of - a provisional operator or source that was built and hashed, or computed, before the + a provisional operator, source or pod that was built and hashed, or computed, before the case returns its cached hash or kept result without reaching it, so it records nothing. The convention that makes the guard enough: every case builds its sources, - operators and jobs inside the case function, which + operators, side-effect pods and jobs inside the case function, which ``test_golden_store.test_cases_hold_no_prebuilt_pipeline_objects`` checks. A user class with a field of a provisional library type embeds that type's identifier in its identity, which is built once, at registration, and cached; a later use of the class records @@ -286,8 +289,7 @@ def compute_group_kinds( if unknown: raise ValueError( f"golden case {group}:{name} declares {unknown} provisional, but " - "they are not provisional (orcapod.operators.PROVISIONAL_OPERATORS, " - "or 'provisional' of contexts/logical_types.json)" + "they are not in declarable_provisional_names()" ) try: with _recording() as used: diff --git a/tests/test_hashing/golden/generate_golden_hashes.py b/tests/test_hashing/golden/generate_golden_hashes.py index 119a223ec..358ec0179 100644 --- a/tests/test_hashing/golden/generate_golden_hashes.py +++ b/tests/test_hashing/golden/generate_golden_hashes.py @@ -49,14 +49,15 @@ unreleased file and records that file again in the open revision (it refuses an entry a release lists), then ``--add`` writes the new value. -5. Provisional operators (``orcapod.operators.PROVISIONAL_OPERATORS``, ITL-1266) are outside - the freeze. A case that depends on one declares it (``@case(..., provisional=(...))``); +5. Provisional features are outside the freeze, including provisional operators (ITL-1266) + and ``SideEffectPod`` (ITL-555). A case that depends on one declares it + (``@case(..., provisional=(...))``); its entries go to ``/provisional/.json``, which the manifest lists in ``golden.provisional``, outside the history, so no release freezes them. Their values are checked like every other and change only with the developer's approval of the exact list (``--remove`` then ``--add``), without a new data context. ``--relocate`` moves pinned entries, values unchanged, to the kind of file their case declares: out of an - unreleased frozen file into the provisional file, or, when an operator leaves the group + unreleased frozen file into the provisional file, or, when a feature leaves the group before a release, into the open frozen file of its group. Never edit a golden file to make a failing test pass. If a test fails and you did not mean to diff --git a/tests/test_hashing/golden/test_golden_store.py b/tests/test_hashing/golden/test_golden_store.py index bf4a8a616..94b6893d9 100644 --- a/tests/test_hashing/golden/test_golden_store.py +++ b/tests/test_hashing/golden/test_golden_store.py @@ -20,6 +20,7 @@ from orcapod.contexts import get_default_context from orcapod.errors import ProvisionalHashWarning +from orcapod.invocation import InvocationContext from orcapod.operators import Batch, MergeJoin from tests.test_hashing.golden import cases, store from tests.test_hashing.golden.generate_golden_hashes import dump, main @@ -1100,6 +1101,117 @@ def test_a_case_using_an_undeclared_provisional_operator_is_refused( _ = cases.compute_group_kinds("semantic") +def test_a_case_using_a_sink_requires_a_provisional_declaration( + monkeypatch: pytest.MonkeyPatch, +) -> None: + from orcapod.side_effects import SideEffectPod, sink_pod + from orcapod.sources import DictSource + + def sink_case() -> dict[str, str]: + def deliver(_ctx: InvocationContext, _age: int) -> None: + pass + + sink = sink_pod(deliver) + assert isinstance(sink, SideEffectPod) + source = DictSource([{"age": 2}], source_id="sink_input") + downstream = sink(source).select_data_columns(["age"]) + return {"hash": downstream.pipeline_hash().to_string()} + + monkeypatch.setitem(cases._CASES, "pipeline", [("sink", sink_case, ())]) + with pytest.raises( + ValueError, match=re.escape("uses the provisional ['SideEffectPod']") + ): + _ = cases.compute_group_kinds("pipeline") + + monkeypatch.setitem( + cases._CASES, "pipeline", [("sink", sink_case, ("SideEffectPod",))] + ) + values, provisional = cases.compute_group_kinds("pipeline") + assert set(values) == provisional == {"sink.hash"} + + +@pytest.mark.parametrize("load_job", [True, False], ids=["job", "blueprint"]) +def test_a_case_loading_a_sink_requires_a_provisional_declaration( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path, load_job: bool +) -> None: + """A saved sink's hash is provisional even when the pod is built outside the case.""" + from orcapod import PipelineJob + from orcapod.databases import DeltaTableDatabase + from orcapod.pipeline import Pipeline + from orcapod.side_effects import SideEffectPod, sink_pod + from orcapod.sources import DictSource + + def deliver(ctx: InvocationContext, age: int) -> None: + """Accept a delivery.""" + del ctx, age + + source = DictSource([{"age": 2}], source_id="sink_input") + job = PipelineJob(name="sink_job", database=DeltaTableDatabase(tmp_path / "store")) + sink = sink_pod(deliver) + assert isinstance(sink, SideEffectPod) + with job: + _ = sink(source, label="sink") + _ = job.run() + graph = job if load_job else job.compiled_pipeline + path = tmp_path / "saved.json" + graph.save(path) + saved_hash = graph.nodes["sink"].pipeline_hash().to_string() + load = PipelineJob.load if load_job else Pipeline.load + + def load_case() -> dict[str, str]: + return {"hash": load(path).nodes["sink"].pipeline_hash().to_string()} + + monkeypatch.setitem(cases._CASES, "pipeline", [("sink", load_case, ())]) + with pytest.raises( + ValueError, match=re.escape("uses the provisional ['SideEffectPod']") + ): + _ = cases.compute_group_kinds("pipeline") + + monkeypatch.setitem( + cases._CASES, "pipeline", [("sink", load_case, ("SideEffectPod",))] + ) + values, provisional = cases.compute_group_kinds("pipeline") + assert values == {"sink.hash": saved_hash} + assert provisional == {"sink.hash"} + + +@pytest.mark.filterwarnings( + "ignore:A function pod with a context argument is provisional:orcapod.errors.ProvisionalHashWarning" +) +@pytest.mark.parametrize("declare", [False, True]) +def test_a_case_using_a_context_function_requires_a_provisional_declaration( + monkeypatch: pytest.MonkeyPatch, declare: bool +) -> None: + from orcapod import function_pod + from orcapod.operators import SelectDataColumns + from orcapod.sources import DictSource + + def context_case() -> dict[str, str]: + @function_pod(output_keys="next_age", ctx_arg="ctx") + def next_age(age: int, ctx: InvocationContext) -> int: + assert isinstance(ctx, InvocationContext) + return age + 1 + + source = DictSource([{"age": 2}], source_id="context_input") + downstream = SelectDataColumns(columns=["next_age"])(next_age.pod(source)) + return {"hash": downstream.pipeline_hash().to_string()} + + name = "FunctionPod with a context argument" + monkeypatch.setitem( + cases._CASES, + "pipeline", + [("context_function", context_case, (name,) if declare else ())], + ) + if declare: + _, provisional = cases.compute_group_kinds("pipeline") + assert provisional == {"context_function.hash"} + else: + with pytest.raises( + ValueError, match=re.escape(f"uses the provisional {[name]}") + ): + _ = cases.compute_group_kinds("pipeline") + + def _prebuilt_inputs() -> tuple[Any, Any]: """Two inputs with two tags and two data columns, colliding on ``age``.""" from orcapod.sources import ArrowTableSource diff --git a/tests/test_pipeline/loaded_job/test_loaded_side_effect_nodes.py b/tests/test_pipeline/loaded_job/test_loaded_side_effect_nodes.py index 7e37b03d3..4ba1c37ab 100644 --- a/tests/test_pipeline/loaded_job/test_loaded_side_effect_nodes.py +++ b/tests/test_pipeline/loaded_job/test_loaded_side_effect_nodes.py @@ -13,6 +13,7 @@ import json import logging import pathlib +import warnings from collections.abc import Callable from typing import Any @@ -20,12 +21,15 @@ from orcapod import PipelineJob, function_pod from orcapod.databases import DeltaTableDatabase +from orcapod.errors import ProvisionalHashWarning +from orcapod.invocation import InvocationContext from orcapod.pipeline import Pipeline from orcapod.pipeline.async_orchestrator import AsyncPipelineOrchestrator from orcapod.pipeline.observer import NoOpObserver from orcapod.side_effects import SideEffectPod, SideEffectPodConfig from orcapod.sources import DictSource from orcapod.streams import ViewStatus +from orcapod.utils.provisional import reset_provisional_use_warnings ROWS = 3 SIDE_EFFECT_NODES = ("delivered", "tail") @@ -123,6 +127,37 @@ def test_a_loaded_job_lists_its_side_effect_nodes( assert loaded.nodes[label].label == label +@pytest.mark.parametrize("load_job_first", [True, False]) +def test_loading_side_effect_nodes_shares_the_pod_construction_warning( + saved: tuple[PipelineJob, list[int], pathlib.Path], load_job_first: bool +) -> None: + """Either loader warns once, shared by further loads and live construction.""" + job, _, job_path = saved + blueprint_path = job_path.with_name("blueprint.json") + job.compiled_pipeline.save(blueprint_path) + routes = [(PipelineJob.load, job_path), (Pipeline.load, blueprint_path)] + if not load_job_first: + routes.reverse() + + def deliver(_ctx: InvocationContext, _x: int) -> None: + """Accept a delivery.""" + + reset_provisional_use_warnings() + try: + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter("always", ProvisionalHashWarning) + for load, path in routes: + _ = load(path) + assert len(caught) == 1 + _ = SideEffectPod(deliver) + assert len(caught) == 1 + assert caught[0].category is ProvisionalHashWarning + assert str(caught[0].message).startswith("SideEffectPod is provisional.") + assert caught[0].filename == __file__ + finally: + reset_provisional_use_warnings() + + def test_a_restored_side_effect_node_has_its_saved_identity_and_position( saved: tuple[PipelineJob, list[int], pathlib.Path], ) -> None: diff --git a/tests/test_pipeline/test_function_pod_concurrency.py b/tests/test_pipeline/test_function_pod_concurrency.py index 5390ae66b..ad9e291b4 100644 --- a/tests/test_pipeline/test_function_pod_concurrency.py +++ b/tests/test_pipeline/test_function_pod_concurrency.py @@ -33,6 +33,10 @@ PodConfig, ) +pytestmark = pytest.mark.filterwarnings( + "ignore:A function pod with a context argument is provisional:orcapod.errors.ProvisionalHashWarning" +) + if TYPE_CHECKING: from collections.abc import Iterator from pathlib import Path