Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2b55e4b
feat(async): hand record batches through the async batch region (ITL-…
eywalker Dec 2, 2026
d8e9f28
feat(channels): check the token-shape rule on every sent record batch…
eywalker Dec 2, 2026
5b20d3b
docs(hashing): list the batch forms' observer node-hash sites (ITL-1845)
eywalker Dec 2, 2026
1083fae
test: compare function nodes order-free; isolate the fork-hook test (…
eywalker Dec 2, 2026
5a55c90
docs(spec): stage 5a differential result (ITL-1845)
eywalker Dec 2, 2026
c664210
fix(async): region sources keep main's collected output and route (IT…
eywalker Dec 2, 2026
d78a9bb
fix(async): region outputs end only after their node's work; honour s…
eywalker Dec 2, 2026
0a41c04
test(differential): the wide fixture crosses a source record batch (I…
eywalker Dec 2, 2026
701b5c6
test(differential): the wide fixture splits at the source batch size …
eywalker Dec 2, 2026
4e48084
test(async): a source subclass replacing one reader keeps main's rout…
eywalker Dec 2, 2026
73e5c68
docs(spec): stage 5a differential on the fixed head (ITL-1845)
eywalker Dec 2, 2026
72da51d
fix(async): decide a source's route at admission; collect an empty wh…
eywalker Dec 3, 2026
dc2a0c9
Merge remote-tracking branch 'origin/main' into eywalker/itl-1845-itl…
eywalker Dec 3, 2026
92c2b21
fix(async): close unsent snapshot streams before the end hook; bound …
eywalker Dec 3, 2026
99adc19
test(compat): compare a shared result store's computed/reused split a…
eywalker Dec 3, 2026
71131c8
fix(async): admit an own-reader source only when one class defines it…
eywalker Dec 3, 2026
c10ec18
fix(async): a buffer size below 1 makes the region's reader queues un…
eywalker Dec 3, 2026
2eadfe0
Merge remote-tracking branch 'origin/main' into eywalker/itl-1845-itl…
eywalker Dec 3, 2026
ece7e0c
fix(async_orchestrator): leave a source that cannot answer on the row…
eywalker Dec 3, 2026
708a053
fix(async_orchestrator): own admitted snapshot streams until the sour…
eywalker Dec 3, 2026
5f0dcee
fix(spiraldb): refuse a pinned snapshot's batches as the source's fir…
eywalker Dec 3, 2026
06ae9cb
chore: merge main into async batch transport
eywalker Dec 3, 2026
57bf204
fix(sources): validate projected snapshots before scanning
eywalker Dec 3, 2026
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
33 changes: 29 additions & 4 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1242,9 +1242,9 @@ these preimages anywhere else.
The type rule is the pure function
`schema_utils.token_layers_fit`; `token_shape_violations` lists the violating columns and
`token_shape_error` words the `InputValidationError`, which names the token column, the
data column and both types. Never loosen it. NOT covered: a record batch sent into an
`OutputChannel` (the channels are not wired into nodes; the stream `result()` builds is
checked; the follow-up is ITL-1526), and a `Data` built by hand outside a stream. The null check reads the
data column and both types. Never loosen it. A record batch sent into an
`OutputChannel` is checked by the same rule, per batch, after its token types are settled
(ITL-1845, in part ITL-1526). NOT covered: a `Data` built by hand outside a stream. The null check reads the
validity of EVERY list level of a list-typed token column (`schema_utils.null_list_level`:
the null count of each level's arrays, no value), and the error says at which level (0 is the
token itself). A typed zero-row table and a plain string token are unaffected. No
Expand Down Expand Up @@ -1621,7 +1621,7 @@ data. The rules:
datagrams' Arrow tables (as_table()), never from as_dict() values, and take the data
context from those datagrams (data_context_key). Add new async operators to
tests/test_core/operators/test_async_sync_equivalence.py.
- Record-batch channels (ITL-1347, ITL-1362; not wired into nodes or orchestrators yet):
- Record-batch channels (ITL-1347, ITL-1362; wired into the async batch region, ITL-1845):
InputChannel (core/streams/record_batch_input.py) and OutputChannel
(core/record_batch_channels.py) carry a stream's rows as Arrow record batches; operators see
them only through the protocols RecordBatchInput / RecordBatchOutput of
Expand All @@ -1647,6 +1647,31 @@ data. The rules:
Batch with a size has its own form, grouping rows by arrival. A new operator whose output
rows each come from one input row declares ROW_BY_ROW; write no other per-operator batch
code.
The async orchestrator's batch region (stage 5a, ITL-1845; _batch_region): bound snapshot
source job nodes (the StreamBase default async_iter_data, or a source that answers
snapshot_batch_streams(), a required SourceProtocol member every source kind and wrapper
answers for itself: never probe it) and library unary operator job nodes whose one input is
a region node with declared Arrow types send record batches (async_execute_batches of
SourceNodeBase and OperatorJobNode, with main's hook placement, LOG, REPLAY, zero-row keep
and failure handling). Every other node (joins, function, side-effect, held, polling) keeps
the row form and gets rows from the boundary adapter _rows_from_batches, batch by batch,
which turns an UpstreamFailedError into a normal row-channel close. A region producer that
fails calls output.fail(error), so its readers raise at the failure point and a region LOG
node never stores a partial result; failure selection skips UpstreamFailedError. An output
channel and its readers share one BatchStreams (static_output_pod.py): the description is
derived once per channel, never per batch; read it when wiring, inside
shared_zero_row_memo().
A source with its own async_iter_data joins only where its batches are read exactly as
snapshot_batch_streams gives them, asked once when the region is decided, before it is
wired (SourceJobNode.region_snapshot_batches; the streams are what it sends), and only
when one class defines both its async_iter_data and its snapshot_batch_streams; None
keeps it on main's row route, its own reader; never read it whole in place of that reader. Every region
output holds its end (OutputChannel(hold_end=True)) until its node's work after the last
batch (kept output, LOG store, modified time, end hook) returned; the orchestrator then
calls release_end(), so a failure there reaches readers as UpstreamFailedError, never
as a normal end. A region node that sent no row is collected as the sync route collects
it (rows_on_read([], node)). A source keeps the whole batches of a narrowed whole read
only when the run collects results (keep_whole).
- A Python declaration with a `float32` or `float16` dict key or set element raises
`NarrowFloatKeyError` (ITL-1591, D16, D25 and D41). Narrowing can turn two distinct
keys or elements into one stored value and lose an entry. The check in
Expand Down
33 changes: 29 additions & 4 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1271,9 +1271,9 @@ are defined in one module, `core/row_ids.py`; never build one of these preimages
The type rule is the pure function
`schema_utils.token_layers_fit`; `token_shape_violations` lists the violating columns and
`token_shape_error` words the `InputValidationError`, which names the token column, the
data column and both types. Never loosen it. NOT covered: a record batch sent into an
`OutputChannel` (the channels are not wired into nodes; the stream `result()` builds is
checked; the follow-up is ITL-1526), and a `Data` built by hand outside a stream. The null check reads the
data column and both types. Never loosen it. A record batch sent into an
`OutputChannel` is checked by the same rule, per batch, after its token types are settled
(ITL-1845, in part ITL-1526). NOT covered: a `Data` built by hand outside a stream. The null check reads the
validity of EVERY list level of a list-typed token column (`schema_utils.null_list_level`:
the null count of each level's arrays, no value), and the error says at which level (0 is the
token itself). A typed zero-row table and a plain string token are unaffected. No
Expand Down Expand Up @@ -1666,7 +1666,7 @@ data. The rules:
datagrams' Arrow tables (`as_table()`), never from `as_dict()` values, and take the data
context from those datagrams (`data_context_key`). Add new async operators to
`tests/test_core/operators/test_async_sync_equivalence.py`.
- Record-batch channels (ITL-1347, ITL-1362; not wired into nodes or orchestrators yet):
- Record-batch channels (ITL-1347, ITL-1362; wired into the async batch region, ITL-1845):
`InputChannel` (`core/streams/record_batch_input.py`) and `OutputChannel`
(`core/record_batch_channels.py`) carry a stream's rows as Arrow record batches; operators
see them only through the protocols `RecordBatchInput` / `RecordBatchOutput` of
Expand All @@ -1692,6 +1692,31 @@ data. The rules:
input (`to_stream()`); `Batch` with a size has its own form, grouping rows by arrival. A new
operator whose output rows each come from one input row declares `ROW_BY_ROW`; write no
other per-operator batch code.
The async orchestrator's batch region (stage 5a, ITL-1845; `_batch_region`): bound
snapshot source job nodes (the `StreamBase` default `async_iter_data`, or a source that
answers `snapshot_batch_streams()`, a required `SourceProtocol` member every source kind
and wrapper answers for itself: never probe it) and library unary operator job nodes whose
one input is a region node with declared Arrow types send record batches
(`async_execute_batches` of `SourceNodeBase` and `OperatorJobNode`, with `main`'s hook
placement, `LOG`, `REPLAY`, zero-row keep and failure handling). Every other node (joins,
function, side-effect, held, polling) keeps the row form and gets rows from the boundary
adapter `_rows_from_batches`, batch by batch, which turns an `UpstreamFailedError` into a
normal row-channel close. A region producer that fails calls `output.fail(error)`, so its
readers raise at the failure point and a region `LOG` node never stores a partial
result; failure selection skips `UpstreamFailedError`. An output channel and its readers
share one `BatchStreams` (`static_output_pod.py`): the description is derived once per
channel, never per batch; read it when wiring, inside `shared_zero_row_memo()`.
A source with its own `async_iter_data` joins only where its batches are read exactly as
`snapshot_batch_streams` gives them, asked once when the region is decided, before it is
wired (`SourceJobNode.region_snapshot_batches`; the streams are what it sends), and only
when one class defines both its `async_iter_data` and its `snapshot_batch_streams`; `None`
keeps it on main's row route, its own reader; never read it whole in place of that reader. Every region
output holds its end (`OutputChannel(hold_end=True)`) until its node's work after the last
batch (kept output, `LOG` store, modified time, end hook) returned; the orchestrator then
calls `release_end()`, so a failure there reaches readers as `UpstreamFailedError`, never
as a normal end. A region node that sent no row is collected as the sync route collects
it (`rows_on_read([], node)`). A source keeps the whole batches of a narrowed whole read
only when the run collects results (`keep_whole`).
- A Python declaration with a `float32` or `float16` dict key or set element raises
`NarrowFloatKeyError` (ITL-1591, D16, D25 and D41). Narrowing can turn two distinct
keys or elements into one stored value and lose an entry. The check in
Expand Down
25 changes: 25 additions & 0 deletions changelog.d/ITL-1845.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
### Breaking changes and migration

- A class that implements `SourceProtocol` itself (not a subclass of an Orcapod source)
now needs a `snapshot_batch_streams()` method. Return `None` when the source has no
per-batch snapshot read: an async job then reads the source as before, through its own
`async_iter_data` when it has one (row by row), otherwise whole.

### Changed

- An async job (`job.run(orchestrator=AsyncPipelineOrchestrator())`, `run_async()`) now
passes Arrow record batches, not rows, from a source over a snapshot (an in-memory
source, a keyed SpiralDB table) through the single-input operators that follow it
(selects, drops, renames, `DropNulls`, `Filter`, `AddTags`, `TagBy`, `Pick`, `Index`,
`Batch`, `GroupBy`). Rows are built only where a function or side-effect node, a join or
a held node reads them, one record batch at a time, so a function node still starts on
the first rows while the source is being read. Every node shows the same rows, types and
hashes as before, and as the sync run. Observer events: each node's start still comes
before its own row events and its end after them, ends stay in dependency order, and a
function node's rows start in arrival order. Where an upstream node's end event falls
among a downstream node's row events depends on record batches, backpressure and
scheduling: with an in-memory source, every upstream end can come before the first
downstream row event. A function node's rows complete in an order scheduling decides,
as before.
- An `OutputChannel` checks the source-info token shape rule on every record batch sent
into it.
71 changes: 71 additions & 0 deletions docs/dev/scripts/itl_1347/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
unit and counted by a second function pod, with ``Batch``, ``MergeJoin``, ``SemiJoin``,
``PolarsFilter``, ``AddTags``, ``DropNulls``, ``MapData`` and ``Rejoin`` beside it, and a
side effect at the end. Every operator of the stage-5 classification appears once.
- ``wide``: stage 5a's batch region (ITL-1845): the spike table twice, more than one
source record batch with the stock dataset, through several unary operators (not
every kind: the public job tests of the batch region cover every unary operator).
"""

from __future__ import annotations
Expand Down Expand Up @@ -166,7 +169,75 @@ def report_fn(n_bins: int, ctx: InvocationContext) -> None:
return job


# How many times the wide fixture repeats the spike table: the stock dataset has
# about 37,000 spikes, so two copies (about 73,000 rows) are more than one source
# record batch (``SOURCE_BATCH_ROWS``, 65,536 rows).
WIDE_COPIES = 2


def wide_table(data_dir: Path) -> pa.Table:
"""The spike table ``WIDE_COPIES`` times, each copy told apart by a ``copy`` tag
(0, 1, ...), copies in order, each in the spike table's order, in one chunk: the
source splits it at its own batch size (65,536 rows), not at the copies."""
spikes = spikes_table(data_dir)
copies = [
spikes.append_column(
pa.field("copy", pa.int64(), nullable=False),
pa.array([copy] * spikes.num_rows, pa.int64()),
)
for copy in range(WIDE_COPIES)
]
return pa.concat_tables(copies).combine_chunks()


def build_wide(data_dir: Path, database: Any) -> Any:
"""Stage 5a's batch region (ITL-1845): the spike table twice (``wide_table``),
above 65,536 rows with the stock dataset so the in-memory source sends several
record batches, through several unary operators (not every kind; the public job
tests of the batch region cover every one), two chained, then a select and a
function node on several branches."""
from orcapod import PipelineJob, function_pod
from orcapod.sources import ArrowTableSource

spikes = ArrowTableSource(
wide_table(data_dir),
tag_columns=["copy", "subject_id", "session", "probe", "unit", "spike"],
tag_only_columns=True,
source_id="spikes",
)

@function_pod(output_keys="bin")
def time_bin(time_s: float) -> int:
return int(time_s // 10.0)

job = PipelineJob(name="itl1347_wide", database=database)
with job:
timed = spikes.select_data_columns(["time_s"], label="timed")
time_bin.pod(timed, label="binned")
early = spikes.filter(probe="imec0", label="probe0").select_data_columns(
["time_s"], label="probe0_time"
)
time_bin.pod(early, label="probe0_binned")
fours = spikes.batch(batch_size=4, label="fours")
firsts = fours.index("time_s", 0, label="first_of_four")
time_bin.pod(
firsts.select_data_columns(["time_s"], label="first_time"),
label="first_binned",
)
spikes.batch(label="all_spikes")
spikes.group_by(
["copy", "subject_id", "session", "probe", "unit"], label="per_unit"
)
spikes.map_data({"time_s": "t"}, label="renamed").add_tags(
study="itl1347", label="tagged"
).drop_nulls(label="no_nulls")
spikes.tag_by("time_s", label="time_tagged")
spikes.drop_columns(["spike"], label="no_spike_index")
return job


FIXTURES: dict[str, Callable[[Path, Any], Any]] = {
"tutorial": build_tutorial,
"spikes": build_spikes,
"wide": build_wide,
}
Loading
Loading