Repository navigation
[Data] Add REVIEW.md code-review instructions for Ray Data subsystems - #67928
Conversation
Adds Claude Code Review instruction files (REVIEW.md) for python/ray/data and its major subsystems: execution, logical planning, physical planning, datasource v1 (marked deprecated, maintenance-only), datasource v2 (home for all new datasources), and the public datasource API. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Goutam <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces subsystem-specific REVIEW.md files across the python/ray/data/ directory to guide code reviewers on critical checks, such as data integrity, API stability, performance, and resource management. The review feedback suggests minor improvements to these guidelines, including fixing a typo ('detrimental'), rephrasing a sentence in the execution guidelines to avoid repetition, and correcting the grammar of a sentence in the logical planning guidelines.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Goutam <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Goutam <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Goutam <[email protected]>
| @@ -0,0 +1,38 @@ | |||
| # Review instructions: datasources (v2) | |||
|
|
|||
| Checks for changes under `python/ray/data/_internal/datasource_v2/` (listing, | |||
There was a problem hiding this comment.
These no longer exist.
There was a problem hiding this comment.
Fixed. The parenthetical now matches the real layout — interfaces/ (abstract classes, imports nothing else here), common/ (format-independent impls, imports only interfaces/), formats/<name>/. listing/, readers/, scanners/, chunkers/ and partitioners/ are gone, so the checks that referenced them are reworded around the interfaces instead. Also pointed the file at this directory's README.md as the thing to read first.
| - Readers and scanners stream blocks incrementally; chunkers (`chunkers/`) | ||
| produce batches near the target size, including the last/partial chunk and | ||
| empty-file cases. | ||
| - Partitioners (`partitioners/`) handle hive-style and unpartitioned layouts, |
There was a problem hiding this comment.
Partiotioning or partitioners?
There was a problem hiding this comment.
Both, and conflating them was the bug in that line. Split into two checks: FilePartitioner (how manifest rows get regrouped into read tasks) and partition columns (hive-style directory partitioning), with a note not to mix the two in one change. The hive-style/unpartitioned-layout and column-collision checks now sit under the latter.
|
|
||
| ## Always check | ||
|
|
||
| - Any `pyarrow.Table` deserialized from external input calls |
There was a problem hiding this comment.
Good catch. Rephrased so it doesn't depend on the mechanism: the invariant is that a read never unpickles untrusted bytes and a ray.data.arrow_pickled_object column from external input never reaches a block. It then says to check against whatever guard is in master — today the per-table raise_on_pickle_object_columns(table) call, and that enforcement is being centralized, so once #66402 lands the per-call check stops being the thing to look for. Made the matching edit in _internal/datasource/REVIEW.md so the two files don't contradict each other.
|
|
||
| ## What Important means here | ||
|
|
||
| Same as v1 datasources: data loss/corruption, remote code execution via |
There was a problem hiding this comment.
I think we shouldnt define important according to something we plan to deprecate and remove, no?
There was a problem hiding this comment.
Agreed — dropped the "Same as v1 datasources" deference. The section now defines Important from v2's own invariants: rows lost/duplicated/reordered (usually an over-eager pushdown), a block whose schema differs from the inferred schema, RCE or credential leaks, driver-side or per-file work that scales with file count, and one bad file failing a whole read.
| @@ -0,0 +1,38 @@ | |||
| # Review instructions: datasources (v2) | |||
There was a problem hiding this comment.
Some issues that keep coming up in DSv2 format PRs and would be worth checking here:
- Filter pushdown is conservative: a file, row group or stripe is skipped only when its metadata proves no row can match. Missing or unusable statistics mean it's read.
- A new pushdown never disables or weakens an existing one.
- A read that needs no stored column (count(), selecting only path or partition columns) still returns every row.
- A path listed twice is read twice.
- A bad file fails only its own read.
- Every block matches the planned schema. A file that can't be cast fails its own read with an error naming the file and column.
- Each scanner's docstring lists which pushdowns (column pruning, filter, limit) it implements and which it doesn't yet, and it never reports one its reader doesn't enforce. The file header should mention if it has column, filter, path, and/or limit pruning
- Read tasks are sized by peak decoded memory, not bytes on disk; a size that can't be known is None, not 0.
- An indexer that reads per-file metadata yields rows as it goes and stops at a pushed limit.
- Shared interfaces only use types every format has.
- A format moves to V2 behind use_datasource_v2, not a new per-format flag.
There was a problem hiding this comment.
Oh also,
12. Schedule as little on the driver as possible. Aim to schedule on listing or read tasks.
13. Try and push the predicate as far down as possible. Prefer to prune during listing.
There was a problem hiding this comment.
- Make sure the code and tests work for every possible version of the softwares we support.
There was a problem hiding this comment.
All 14 are in, grouped rather than appended as a flat list so the reviewer agent reads them as themes. Mapping:
Pushdowns — 1 (pruning is conservative; missing/partial/unusable stats mean the piece is read), 2 (a new pushdown never weakens an existing one; push_* returns a scanner still carrying everything previously pushed), 7 (a scanner never reports a pushdown its reader does not enforce; docstring and file header state which of column/filter/partition/limit it implements), 13 (push predicates as far down as possible, prefer pruning in the FileIndexer so the file is never opened), 3 (count() or selecting only __path/partition columns must not prune to nothing and yield zero rows).
Listing, partitioning, and task sizing — 4 (a path listed twice is read twice; deduping is a behavior change, not a cleanup), 9 (per-file-metadata indexers yield as they go and stop at a pushed limit), 8 (sized by peak decoded memory, not bytes on disk; unknown is None, not 0 — 0 reads as free to the partitioner and packs unbounded work into one task), 12 (schedule as little as possible on the driver; a driver-side open/stat/log replay scaling with file or partition count is Important).
Failure isolation and schema — 5 (a bad file fails only its own read), 6 (every block matches the inferred schema; a file that cannot be cast fails its own read with an error naming the file and the column, not a bare pyarrow cast error).
Structure and compatibility — 10 (shared interfaces use only types every format can supply; a signature needing a Parquet footer or row-group index belongs on the format), 11 (DataContext.use_datasource_v2, not a new per-format flag — with the caveat that a temporary per-format flag needs a stated removal plan, since a few in-flight ports use one), 14 (works on every supported version of the underlying library; gate on capability via inspect.signature/feature probe rather than a parsed version string, and make sure the test exercises the installed version instead of monkeypatching a version number).
Pushed in d6eff8d.
## Summary Adds `python/ray/data/tests/AGENTS.md`, short instructions that tell coding agents how to write Ray Data tests: shared cluster fixtures, `DataContext` fixtures, test data, parametrize, asserts and mocks, plus one before/after example. Recent agent-written Data PRs added 1.6× to 15× more test code than library code, much of it repeated setup: a Ray cluster per test, a hand-set `DataContext`, field-by-field asserts. It also adds one shared `datasource_v2` fixture to `tests/conftest.py`, which the instructions point to. It replaces three copies of the same fixture. ## Before - No agent instructions say how to structure a Data test. #67919 (open) adds rules on *which* tests to write, in `python/ray/data/.claude/rules/`, which only Claude Code reads. #67928 (open) adds review instructions with one line on shared fixtures. - Three copies of the V1/V2 reader fixture: `orc_reader_version` in `test_orc.py`, `use_datasource_v2` in `test_parquet.py`, and an autouse `datasource_v2` in `test_mcap.py`. ## After - `python/ray/data/tests/AGENTS.md` holds the instructions. Codex, Cursor and other agents read `AGENTS.md`; `python/ray/data/tests/.claude/CLAUDE.md` imports it for Claude Code, as `python/ray/data/` already does. The rules apply to new and changed tests, not to rewriting untouched ones. - One `datasource_v2` fixture in `tests/conftest.py`. `test_orc.py` and `test_parquet.py` take it by name, and `test_mcap.py` applies it to every test through `pytestmark`. Test ids (`[v1]`, `[v2]`) don't change. No library code changes. The fixture change is a refactor: each file collects the same tests as before. ## Subsystems None. Tests and agent instructions only. ## Questions for reviewers - @AarryaSaraf: this covers *how* to write tests, and your `test_rules.md` in #67919 covers *which* tests to write. The PRs that prompted this were written with Codex, which doesn't read `.claude/rules/`. Would you be OK moving your test rules into this `AGENTS.md`, here or in #67919, so every agent sees both? - @goutamvenkat-anyscale: the fixture line in #67928's `REVIEW.md` could link to this file. ## Additional information ### Not a duplicate #67919 and #67928 are the only open PRs with agent rules for Data tests. This PR covers what they don't: test structure and fixtures, in a file that agents other than Claude Code also read. ### Testing | Command | Result | |---|---| | pre-commit on the 6 changed files | Passed | | `pytest datasource/test_mcap.py` | 67 passed, 6 skipped. The collected test ids are identical to master's (73). | | `pytest datasource/test_parquet.py -k "v1 or v2"` (the tests that use the fixture) | 23 passed, 1 skipped | | `pytest datasource/test_orc.py` | 217 passed, 6 failed: all `test_read_orc_v2_partitioned_scan_optimizations`, which asserts the reader's source path ends in `python/ray/data/...`. That isn't true for the pip-installed Ray used locally, and the test doesn't use the renamed fixture. | Environment: Ray nightly (3eb9895) with this branch's `python/ray/data` and `python/ray/tests` linked over it, Python 3.12.10, pyarrow 23.0.1, pandas 2.3.3, pytest 7.4.4. Not checked yet: that Codex and Claude Code load the new file when run from the repository root. ### Note for open PRs #68235 adds a test that takes `use_datasource_v2`. If it merges after this PR, that test needs the one-word rename to `datasource_v2`. AI assistance (Claude Code) was used to draft the instructions, the fixture change and this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Abhishek Verma <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
- Fix the directory list: datasource_v2 is interfaces/, common/, formats/<name>/; listing/, readers/, scanners/, chunkers/ and partitioners/ no longer exist. - Define "Important" from v2's own invariants instead of deferring to the deprecated v1 file. - Separate FilePartitioner (regrouping manifest rows into read tasks) from hive-style partition columns, which the old wording conflated. - State the no-untrusted-unpickling invariant and note the enforcement is being centralized, so the guidance survives #66402. - Add the checks that keep coming up in DSv2 format PRs: conservative pruning, pushdowns not weakening each other, no-stored-column reads, scanner docstrings matching reader enforcement, duplicate paths read twice, per-file failure isolation, planned-schema conformance, sizing by peak decoded memory (None not 0), incremental indexing that honors a pushed limit, interfaces using only types every format has, use_datasource_v2 over per-format flags, driver-side work minimized, predicates pushed to listing, and version compatibility across supported library versions. Signed-off-by: Goutam <[email protected]>
iamjustinhsu
left a comment
There was a problem hiding this comment.
We can update as we go, so nothing blocking
| - The streaming executor control loop stays non-blocking: no `ray.get`, | ||
| `ray.wait(timeout=None)` on unfinished work, sleeps, or other blocking calls | ||
| on the scheduling path. | ||
| - `RefBundle` ownership is respected: `owns_blocks` is set correctly, and |
There was a problem hiding this comment.
You also probably want to check if there are dangling object refs, or circular references that could delay gc'ing objects
There was a problem hiding this comment.
Added, and your point is sharper than the existing bullet — destroy_if_owned() doesn't actually free anything. It just calls trace_deallocation for memory tracing; the blocks are reclaimed by Ray refcounting once no Python reference to the ObjectRef remains. So the executor can account a bundle as freed while it is still resident.
New check asks for: an ObjectRef/RefBundle captured in a closure, a retry or backpressure buffer, a stats/metrics dict, or an operator output queue being dropped (or the queue clear()ed) on the consume, cancel, and failure paths — not just the happy one. Cycles are called out as the same bug with a delay: a cycle through an operator, its bundles, or a captured self defers reclamation to the cyclic collector, so the leak presents as memory that frees "eventually" under GC pressure instead of at consume time, with a preference for breaking the cycle over leaning on gc.
Pushed in d57e32d.
| (projection, filter, limit) must not move an operator past one it does not | ||
| commute with (e.g. a filter past a map that creates the filtered column, or | ||
| a limit past an operator that changes row count). | ||
| - Rules are idempotent and terminate: re-applying the rule to its own output |
There was a problem hiding this comment.
Maybe also want to specify that confluence (two different optimization paths always lead to the same terminal state) is not guaranteed, but worth pointing out if new rules are added
There was a problem hiding this comment.
Done. Phrased so the reviewer agent doesn't go hunting for a proof it won't find: confluence is explicitly not guaranteed, and a missing confluence argument is not a reportable finding. What it should flag is a new or changed rule that makes ordering matter more — rewrites a pattern another rule also matches, can re-enable a rule that already ran, or only fires depending on whether some other rule ran first — naming the rule and the direction of the dependency.
One addition while grounding it: since Ruleset topologically sorts on Rule.dependencies() (and rejects cycles), with insertion order only breaking ties, the check now asks that a real ordering dependency be declared there rather than left implicit in list position. A rule whose correctness depends on ordering it hasn't declared is Important.
Pushed in d57e32d.
- execution: add a check for references outliving the bundle that owns them. destroy_if_owned() only records the deallocation for memory tracing; blocks are reclaimed by Ray refcounting once no Python reference to the ObjectRef remains, so a ref held in a closure, retry buffer, stats dict or operator output queue keeps the block resident after the executor accounts it freed. Call out reference cycles as the same bug deferred to the cyclic collector. - logical: state that confluence is not guaranteed, so a missing confluence proof is not a finding, but a new rule that makes ordering matter is worth naming -- and its dependency belongs in Rule.dependencies() so Ruleset can order it topologically instead of relying on insertion order. Signed-off-by: Goutam <[email protected]>
…plies them (#68532) ## Summary Import each Ray Data `REVIEW.md` from a `CLAUDE.md` in the same directory, so a local `/code-review` in Claude Code applies the review rules added in #67928, not only the hosted Code Review. ## Before The hosted Claude Code Review reads `REVIEW.md` natively. The local `/code-review` command doesn't: it looks only for `CLAUDE.md` and `CLAUDE.local.md` on the changed files' ancestor paths. `AGENTS.md` was applied only because `python/ray/data/.claude/CLAUDE.md` imports it. Seen on #67840: a local review listed the `REVIEW.md` files but never read them, and raised nothing from them. ## After - `python/ray/data/.claude/CLAUDE.md` imports `../REVIEW.md` alongside `../AGENTS.md`. - New `.claude/CLAUDE.md` files import `../REVIEW.md` in `_internal/execution`, `_internal/logical`, `_internal/planner`, `_internal/datasource`, `_internal/datasource_v2` and `datasource`. Rerunning the local review of #67840 with these imports, the reviewer read `python/ray/data/REVIEW.md` and `_internal/datasource_v2/REVIEW.md`, and raised a finding citing the `datasource_v2` rule on Arrow schemas in `interfaces/`. Side effects: - Interactive Claude Code sessions that work on files in these directories also load the matching `REVIEW.md` (26–120 lines each) as context. - The hosted review may now see the same rules twice, natively and through `CLAUDE.md`. The content is identical, so this shouldn't change its findings. No code or behavior change to Ray Data. ## Subsystems None at runtime. Agent/review configuration for all Ray Data subsystems. ## Testing - `pre-commit` hooks ran on commit and passed (trailing whitespace, end of file, links to master resolve). - Checked that each `@../REVIEW.md` import resolves to an existing file. - Manually reran `/code-review` on #67840 with the imports, as described above. ## Notes - Not a duplicate: `gh pr list --repo ray-project/ray --state open --search "REVIEW.md"` returns only #67840, which is unrelated; searches for "CLAUDE.md data" and "code-review data" found nothing that touches these files. - AI assistance (Claude Code) was used for this change and description; every line was human-reviewed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Goutam <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Adds Claude Code Review instruction files (
REVIEW.md) forpython/ray/data/and its major subsystems, so automated PR reviews apply Ray Data-specific severity calibration and checks.Before
Code Review runs on Ray Data PRs with only the default guidance plus
CLAUDE.md/AGENTS.mdproject context. There are no review-specific instructions: no Ray Data definition of what "Important" means, and team rules (e.g. "new datasources go indatasource_v2, v1 is deprecated") aren't checked.After
Reviews of changes under
python/ray/data/pick up directory-scoped instructions:python/ray/data/REVIEW.md— umbrella: severity calibration (data loss/corruption, API breakage, hangs/leaks, hot-path regressions, security = Important), API annotation/redirect rules,DataContextfor new knobs, lazy/streaming + zero-copy expectations._internal/execution/REVIEW.md— non-blocking scheduling loop,RefBundleownership, metrics/queue accounting, backpressure livelock, shutdown cleanup._internal/logical/REVIEW.md— optimizer rules must preserve semantics, be idempotent, and be wired to planner translation._internal/planner/REVIEW.md— complete logical→physical translation, option preservation, exchange row-count/schema invariants, checkpoint fingerprint stability._internal/datasource/REVIEW.md— marked deprecated/maintenance-only: a new datasource added here is flagged Important and routed to v2; plus security (raise_on_pickle_object_columns, no credentials in logs) and streaming/metadata checks._internal/datasource_v2/REVIEW.md— declared the home for all new datasources; pushdown correctness (conservative pruning, pushdowns not weakening each other, scanner docstrings matching what the reader enforces), listing/task-sizing (duplicate paths, peak decoded memory vs. bytes on disk, driver-side work), per-file failure isolation and planned-schema conformance, interface conformance, port-parity with v1, and version compatibility across supported library versions.datasource/REVIEW.md— public extension surface: subclass backward compatibility, stability annotations, safe defaults.No code or behavior changes — documentation/review-configuration only, so no data flow diagram.
Subsystems
All (review configuration spanning API, planning, execution, IO); no behavioral change to any.
Testing
Documentation-only change; no code paths to test.
pre-commit runpassed on all files (trailing-whitespace, end-of-file, link checks).Notes
gh pr list --state open --search ...) — no existing PR adds review instructions for Ray Data.🤖 Generated with Claude Code