Skip to content

feat(pipeline): a job node keeps a large output on local disk, read memory-mapped (ITL-1464) - #566

Closed
eywalker wants to merge 42 commits into
mainfrom
eywalker/itl-1464-node-rows
Closed

eywalker wants to merge 42 commits into
mainfrom
eywalker/itl-1464-node-rows

Conversation

@eywalker

@eywalker eywalker commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Draft, for ITL-1464: a job node no longer holds a large output in process memory. Stacked on #562 (transport) and #559 (the row spool); their commits are included here until they merge.

What this does

An operator job node kept its run's rows as one Arrow table in process memory, for as long as the job lives. Its kept rows now go through RowSpool (#559): in memory up to 64 MiB (KEPT_ROWS_MEMORY_BYTES), beyond that in a private temporary file, read back memory-mapped.

The node keeps the same ArrowTableStream over the same schema and values (only the arrays' chunking differs), so every read keeps its code path and meaning: as_table(), iteration, head(), a successor's read, the content hash. Sync: the same rows in the same order. No hash, identity, stored layout or golden value moves.

A public promise changes (approved by the coordinator for the developer's review, design decision N1): "a job node holds its current run's rows in memory" becomes "a job node shows its current run's rows; a large run is read from a private temporary file". The file is in the system's temporary directory, in a directory of the process, never part of a stored path or hash, deleted when the node lets its run go or the process ends.

A table a user holds stays valid: the mapping lives as long as a table that refers to it, after clear_cache(), after the node and the job are collected, after the file is deleted, and at interpreter shutdown (each tested).

Measured (synthetic 13-column table; "own memory" is the peak physical footprint, what the system charges the process; resident memory also counts mapped file pages, which the system drops when it needs them)

Job Rows Own memory before (#562) after Resident before after
map_data, async 1 million 4.36 GiB 0.89 GiB 4.75 GiB 4.65 GiB
map_data, async 200,000 0.60 GiB 1.61 GiB 1.58 GiB
drop_nulls, async 200,000 0.69 GiB 1.79 GiB 1.72 GiB

So a chain of row-by-row operators on the async path is now close to flat in rows: 0.60 GiB at 200,000 rows, 0.89 GiB at 1 million (the growth is the set of keys the source remembers, about 0.3 KiB per row).

What this does not bound, measured, not hidden:

Job Rows Own memory after
group_by, async 200,000 2.0 GiB
drop_nulls, group_by, map_data, function pod, async 200,000 2.15 GiB
the same 1 million 9.5 GiB
map_data, sync 200,000 1.13 GiB

GroupBy computes over its whole input with every source-info token (4.2 KiB per row here), and the sync path reads a source as one tokenized table. Those are the tokens (design T1) and grouping on a key index, not transport.

Tests

tests/test_core/operators/test_row_chunks.py (added to #562's): spilled chunks build the row list's table (data-tags and tag-only); a table read from spilled rows outlives what wrote it; an async job node over spilled rows reads as one in memory (rows as sets, content hash) for map_data, group_by, drop_nulls then batch, and its table survives clear_cache() and the job; a table held at interpreter shutdown reads and leaves no file; kept_table returns a small table as it is and a large one with the same schema and values; a sync job node over spilled rows equals one in memory exactly (table, order, schema, content hash, rows, head).

Run locally: tests/test_pipeline, tests/test_core/operators, tests/test_core/streams, tests/test_core/test_row_spool.py (17,301 passed, one process), ruff check, ruff format --check, basedpyright (0 errors), golden --check (no value moved).

The row reference for views

An operator job node offers current_run_row_count() and read_current_run(start, length, columns=..., all_info=...): exactly as_table(...).slice(start, length) of the current run, None without one, touching only the pages read when the run is on disk (sort_by_tags and content_hash read every row). Built on ArrowTableStream.num_rows and read_rows. Test: test_a_job_nodes_current_run_is_read_a_page_at_a_time (sync and async, in memory and on disk, four column configurations, before a run and after clear_cache()).

Function and side-effect job nodes

Their rows go through RowSpool too (core/held_rows.py): full chunks of 8,192 pairs become Arrow data, and a pair is built again when read. A row is kept that way only when the pair built again is the pair that was held in every view (types, Python values, schemas, ids, meta, source info); any other row (a user class instance, an array, a subclass) stays the object it is. The rows handed downstream are untouched; a sync run still hands its successors the row list, so sync peaks are not bounded by this. An async run over stored results still reads them all at once.

The holder alone, 200,000 two-column rows: own memory 0.93 GiB as pairs, 0.28 GiB as chunks. A small async job (60,000 rows, in-memory store, whole process): function pod 1.27 to 1.00 GiB; side-effect pod 0.82 to 1.00 GiB, worse. One run each, on a loaded machine. A likely cause, not verified: an in-memory source keeps the pairs it yields, so a node that passes the same pairs on saves nothing by holding a second form of them. Not measured at 1 million rows.

Reading a chunked row builds it again, so a function node's reads of many rows are slower than reads of kept pairs.

Review findings and their tests

Finding (independent review of 612f21c) Fix Test
A kept exception or cancellation pinned spill files every spool is closed where it was made, on any error and on cancellation test_a_job_that_fills_the_disk_leaves_no_file_while_its_error_is_kept, test_a_cancelled_node_leaves_no_file_while_its_cancellation_is_kept, test_a_barrier_that_fails_leaves_no_file_of_either_input
A seal retry gave duplicate rows #562's round 2 fix, merged here test_a_job_never_succeeds_with_rows_twice_after_a_failed_allocation
Spill errors were deferred and pairs accumulated a failed spill raises at once, nothing more is kept test_rows_that_cannot_be_written_are_all_let_go
The changelog did not name a barrier's input named

Function and side-effect nodes: tests/test_core/test_held_rows.py.

Not in this step

The row reference on function and side-effect nodes; operator nodes running async_execute_batches over record-batch channels (#565's joins).

Mentions ITL-1464.

🤖 Generated with Claude Code

eywalker and others added 22 commits November 25, 2026 00:56
…one (ITL-1464)

A SpiralDBTableSource read whose table holds no source-info column and no
content hash built one token per row and data column, then dropped them. On
2.2 million rows of 13 columns that was 9.3 GiB of Arrow memory for a 282 MiB
table. The read now builds them only when its result shows or hashes them.

Adds the memory diagnosis (docs/dev/specs/itl-1464-memory-diagnosis.md) and
the scripts it was measured with.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…isk (ITL-1464)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…L-1464)

An async job kept every row three times as (Tag, Data) pairs: in the
orchestrator's result collectors (never read by a job), in each operator job
node's output list, and in each barrier operator's gathered input, plus the
pairs an ArrowTableStream caches while a barrier sends its result. Rows are
now kept as Arrow tables of at most 8,192 rows (RowChunks), which build
exactly the table the row list built.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…TL-1464)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…464 material

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…464 material

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…lts says (ITL-1464)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…nd slices without copying (ITL-1464)

A forked child neither waits for a lock of its parent's threads nor touches its parent's
files; a failed spill leaves the spool as it was; an unlocked or partly removed directory is
swept. table() and slice() give rows through their mappings and outlive the spool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…a time across threads (ITL-1464)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hunk's error to the read (ITL-1464)

Review of PR 562: rows_once took the unkept path for any ArrowTableStream
subclass or shadowed iter_data, and a full chunk that cannot make one table
raised while a barrier was still collecting, leaving the other input's reader
behind and raising where main returned no rows for an empty other input.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…emory-mapped (ITL-1464)

An operator job node kept its run's rows as one Arrow table in process
memory. Its kept rows now go through the row spool: in memory up to 64 MiB,
beyond that in a private temporary file read back memory-mapped, on the
async path chunk by chunk as rows arrive and on the sync path when the
result is kept. The stream a node keeps is the same ArrowTableStream over the
same values; a table read from it stays valid after the node, the job and
the file are gone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

…464)

current_run_row_count() and read_current_run(start, length, columns) on an
operator job node, over ArrowTableStream.num_rows and read_rows: the row
reference a view needs, equal to as_table(...).slice(start, length).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…leaves no reader behind (ITL-1464)

Review of PR 562, round 2: a chunk that failed part way was built again and its
rows given twice; the first row's keys were read as it arrived; after a failed
chunk the pairs accumulated; a failing barrier left its sibling's reader alive.
A failure is now permanent, a want of memory ends the run at once, a row is read
only when its chunk is built, and the barriers end every reader on any error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.60956% with 12 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/orcapod/core/row_spool.py 96.93% 9 Missing ⚠️
src/orcapod/core/nodes/operator_node.py 90.00% 2 Missing ⚠️
src/orcapod/core/operators/static_output_pod.py 99.22% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/orcapod/core/operators/base.py 93.27% <100.00%> (-0.06%) ⬇️
src/orcapod/core/operators/batch.py 100.00% <100.00%> (ø)
src/orcapod/core/sources/spiraldb_table_source.py 98.10% <100.00%> (+0.29%) ⬆️
src/orcapod/core/sources/stream_builder.py 98.87% <100.00%> (+<0.01%) ⬆️
src/orcapod/core/streams/arrow_table_stream.py 97.15% <100.00%> (+0.22%) ⬆️
src/orcapod/pipeline/async_orchestrator.py 97.66% <100.00%> (-0.65%) ⬇️
src/orcapod/pipeline/job.py 96.75% <ø> (ø)
src/orcapod/core/operators/static_output_pod.py 95.96% <99.22%> (+0.59%) ⬆️
src/orcapod/core/nodes/operator_node.py 95.67% <90.00%> (-0.17%) ⬇️
src/orcapod/core/row_spool.py 96.93% <96.93%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

eywalker and others added 2 commits November 25, 2026 02:43
Merges the PR 562 round 2 fixes. Review of PR 566: the collectors relied on
finalization, so a kept exception pinned the files written before it. Every
spool is now closed where it was made, on any error and on cancellation; a
failed spill raises at once and nothing more is kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a spool (ITL-1464)

Full chunks of a node's rows become Arrow data, on local disk when large, and a
pair is built again when read. Only a row that reads back as exactly the pair
that was held is kept that way; every other row stays the pair it is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eywalker and others added 16 commits November 25, 2026 05:01
… rows in a spool (ITL-1464)"

This reverts commit 1fc3ebb.
…ements (ITL-1464)

The design states that the cache root must be on disk, bounds the pairs of
one join match, qualifies the SQLite primary-key trust, counts small results
kept in memory and narrows the preview's side-effect promise. The measurement
steps each use their own emptied result location, and setup runs under the
memory guard. One test runs an operator over the source in a job, sync and
async, in two tag orders.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The design names how a database-backed node read keeps the emitted order,
runs a PolarsFilter per batch only for a predicate known to be row-wise,
corrects the 1:1 join bound for inputs that share no key and fixes the
arrival order of the bound's tests. The job test over the source covers the
named columns as data, data-tags and tags, two table layouts and row
multiplicity on the async path; the measurement scripts get docstrings.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…omputation-without' into eywalker/itl-1464-async-transport
A node's reference names the stored row the run emitted (base entry id and
recomputation index), the stated bound excludes steps that need their whole
input, and async results are compared with sync row for row with
multiplicity.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…omputation-without' into eywalker/itl-1464-async-transport
The cache is read only from closed segments and waiting rows, a preview
continues one open read, the join index counts its per-key counts, and a
whole-input step counts its output and conversion buffers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…omputation-without' into eywalker/itl-1464-async-transport
…ITL-1464)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…omputation-without' into eywalker/itl-1464-async-transport
@eywalker

eywalker commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Closing as part of the ITL-1464 draft group. The async-route work continues as ITL-1347 stage 5 (ITL-1845). The SpiralDB read work landed in #687 and #679, and continues in #683.

Posted by a Claude Code agent on behalf of @eywalker.

@eywalker eywalker closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant