Skip to content

perf(engine): fold a correlated block's inner rows as they stream - #1341

Merged
ragnorc merged 7 commits into
ModernRelay:mainfrom
ragnorc:fix/1338-stream-correlated-fold
Nov 13, 2026
Merged

ragnorc merged 7 commits into
ModernRelay:mainfrom
ragnorc:fix/1338-stream-correlated-fold

Conversation

@ragnorc

@ragnorc ragnorc commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A correlated block on the per-row path (max($b.x) { $a knows $b … } > …, or any block whose inner reads the outer row) drained its whole inner output into a Vec, charging every batch to the query pool, and only then folded it. Its peak memory was the whole fan-out, so a large fan-out was refused with query_memory_bytes although the fold needs one batch at a time.

This change folds each inner batch into the SubqueryAggregate as the stream yields it and drops it, as the key-set path in the same file already does.

Closes #1338

Reproduction

New test engine_v2_memory::correlated_block_folds_inner_batches_as_they_stream_issue_1338: one hub with 16,384 neighbours, each with a 1 KiB payload (16 MiB of inner output), and the query

query hubs() {
    match {
        $a: Person { name: "hub" }
        max($b.payload) { $a knows $b  $a.name = $a.name } > ""
    }
    return { $a.name }
}

under a 12 MiB query pool. The test asserts that the plan uses the correlated strategy, so the block cannot move to the key-set or bulk path without the test noticing.

  • On main 2c4b2f12: ResourceLimitExceeded { resource: "query_memory_bytes", limit: 12582912, actual: 12587123 }. With a 24 MiB pool, main is still refused (actual: 25376187).
  • With this change: passes under 12 MiB and returns the hub. The pool is released afterwards (assert_released).

Verdict: reproduced as the issue describes.

Root cause

AntiJoinMaskExec::execute in crates/omnigraph/src/engine/operators/anti_join.rs called drain(inner.execute(..), &reservation). That held every inner batch under the reservation, and only then called absorb_inner_batches (subquery_aggregate.rs), which folded the batches one by one. Holding the batches was not needed: the fold is per batch and order-preserving.

Decisions

  • Fold while streaming, as the key-set path does (chosen). The batch order is unchanged, so min/max still keep the first signed zero and the results are the same. Each in-flight batch is not held under the reservation, the same as key_set_mask. The aggregate's per-row accumulators are now reserved before the inner stream starts instead of after it, so a pool too small for them refuses before the inner plan runs.
  • The FilledSlot guard lives until the inner stream ends. OuterReferenceExec takes the tagged outer batch when its stream is first polled, so the guard must cover the whole stream, as before.
  • absorb_inner_batches(&[RecordBatch]) became absorb_inner_batch(&RecordBatch). This was its only caller.
  • Alternative not taken: lower the block to DataFusion's AggregateExec, which also streams and spills. The issue notes that this waits on the float-semantics decision in query: correlated block aggregates fold row by row; decide their float semantics, then use DataFusion's grouped accumulators #1260.

Lance: not involved. The change is in the engine's operator, after Lance has produced the batches; no pending Lance change affects it.

Before and after

Pool main 2c4b2f12 this branch
12 MiB, 16,384 × 1 KiB inner rows refused (query_memory_bytes) 1 row
24 MiB, same refused (actual 25,376,187) 1 row
8 MiB, 4,096 × 4 KiB refused (actual 8,661,403) 1 row

With smaller pools, the refusals in this branch come from the inner expand and hydration (expand hop, hydrate_nodes), which hold their own working sets; they are not changed here.

Tests and checks

  • Added cases/issue_1338_correlated_block_folds_inner_batches.gqt (changed in review): 16 MiB of inner rows under a 12 MiB query_memory_bytes, refused on 2c4b2f12 and answered here.
  • Added the _issue_1338 Rust test in tests/integration/engine_v2_memory.rs, the owner of pool acceptance tests, for what GQT cannot assert: the run releases every reservation it took.
  • fold_inner is the one inner-stream loop of both strategies (changed in review); absorb_inner_batch is removed. Its group closure is named group_of, because the chokepoint guard reads a call named tags( as Lance's native-ref Dataset::tags() (changed in review).
  • cargo fmt --all --check and cargo dev-clippy: pass.
  • Engine integration binary (tests/integration), run with CI's RUST_MIN_STACK=16777216: 665 passed, 0 failed, 9 ignored.
  • Engine unit tests: 637 passed, 1 failed. The failure is db::upgrade::tests::interrupted::unreadable_legacy_object_asks_for_a_rerun, which makes a file unreadable with mode 000; this box runs as root, so the file stays readable. It is in code this change does not touch.
  • docs/dev/execution.md (the AntiJoin row) and a changelog.d performance note are updated.

Risks and what was not verified

Workflow run: run-wf-reproduce-modernrelay-omnigraph-issue-20261110T1142Z-e43d0f
Response run: run-wf-respond-modernrelay-omnigraph-pr-20261112T1012Z-4bf986
Response run: run-wf-respond-modernrelay-omnigraph-pr-20261112T1712Z-71dbf1
Response run: run-wf-respond-modernrelay-omnigraph-pr-20261112T2007Z-4a902a
Response run: run-wf-respond-modernrelay-omnigraph-pr-20261113T0112Z-4da4e0

The per-row path of a correlated block drained its whole inner output
into a Vec, charging every batch to the query pool, before folding it.
Fold each inner batch into the SubqueryAggregate as the stream yields
it, as the key-set path already does, so the block's peak is one batch.

Closes ModernRelay#1338

@ragnorc ragnorc left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of #1341 at e9f733cb

Why. A correlated block on the per-row path, such as max($b.x) { $a knows $b $a.name = $a.name } > "", kept its whole inner output in memory before it folded it. A hub with a large fan-out was refused with query_memory_bytes, although the fold needs only one batch at a time (#1338).

What. The operator now folds each inner batch into SubqueryAggregate when the stream yields it, and then drops the batch. The key-set path in the same file already works this way.

How. AntiJoinMaskExec replaces drain(...) plus absorb_inner_batches(&[RecordBatch]) with a while let loop over the inner stream and absorb_inner_batch(&RecordBatch) (anti_join.rs:372-394, subquery_aggregate.rs:455). The per-row accumulators are now reserved before the inner plan runs (anti_join.rs:363-366).

Impact. The block's peak memory goes from "all inner rows" to "one inner batch plus one accumulator per outer row". Results do not change. No API, format or setting changes.

Recommendation: the code change is correct and I have no blocking finding in it. I ask for one addition before merge: a .gqt regression case (R1 below). The repository rule asks for it, and the reason the PR gives for leaving it out is not correct.

Correctness (checked by reading the code and by running tests)

  • Fold order. The batches arrive in the same order as before, and absorb folds rows in that order. min/max therefore still keep the first signed zero. The extremum is an owned ScalarValue (subquery_aggregate.rs:126), so dropping a batch does not leave a reference into its buffers.
  • Slot guard. OuterReferenceExec takes the tagged batch on its first poll (anti_join.rs:130). The guard is created after slot.fill and is dropped only after the stream ends. On an error, the inner stream is dropped inside the async block before the guard is dropped. This is the same order as before.
  • Accounting. The tagged outer batch is still held under the reservation. An inner batch in flight is not charged to this operator. The key-set path does the same, and docs/dev/execution.md now says so for both strategies. The input_rows metric is kept.
  • Earlier refusal. The accumulators are now reserved before the inner plan runs. A pool that is too small for them now refuses before any inner I/O. This is better than before.
  • The whole class. I looked for other "drain everything, then fold one batch at a time" paths in the engine. The remaining drain callers are drain_one (the outer side, which must be one batch to tag it), sort.rs (a full sort with no fetch needs all its input), and validate.rs (a write must judge all rows before it continues). None of them folds per batch. This PR closes the only case of this defect.

Required before merge

R1. Add a .gqt regression case. GQT can select the pool. The test comment (engine_v2_memory.rs:2192) and the PR body say "GQT cannot select the pool". That is not correct: set query_memory_bytes = N; is a request setting that applies to read queries, and the corpus already uses it (cases/query_memory_bytes_sizes_the_pool.gqt, cases/v2/rrf_narrow_limit_memory.gqt). The seed generator can build the hub (repeat, literal and key columns), and --- expect plan can pin anti join $a: correlated. AGENTS.md asks for the cheapest tier that catches the defect, and here the defect shows as an error. I wrote this case and ran it in a temporary copy of the tree:

# issue: 1338
# red_on: 2c4b2f12: the correlated block drains its 16 MiB inner output under the pool and is refused with query_memory_bytes.
# notes: A correlated block on the per-row path folds each inner batch as it streams: 16,384
# notes: neighbours with a 1 KiB payload (16 MiB of inner rows) run under a 12 MiB query pool.
# notes: The conjunct that reads the outer row keeps the block off the key-set path, and max
# notes: keeps it off the bulk row count.

--- runner
timeout_ms: 10000
environments:
  - target: omnigraph-engine
    storage: local-filesystem

--- schema
node Person {
    name: String @key
    payload: String
}
edge Knows: Person -> Person

--- seed generate: v1 seed: 0
tables:
  - kind: node
    name: Person
    rows: 16385
    commits: 9
    batch_rows: 2048
    columns:
      name: {kind: key, prefix: p, width: 5}
      payload: {kind: repeat, text: x, count: 1024}
  - kind: edge
    name: Knows
    rows: 16384
    commits: 8
    batch_rows: 2048
    start: 1
    from: {kind: literal, value: p00000}
    to: {kind: key, prefix: p, width: 5}
    columns: {}

--- query
set engine = v2;
set query_memory_bytes = 12582912;
query hubs() {
    match {
        $a: Person { name: "p00000" }
        max($b.payload) { $a knows $b  $a.name = $a.name } > ""
    }
    return { $a.name }
}

--- expect unordered
{"a.name": "p00000"}

--- expect shape
a.name: String

--- expect plan
anti join $a: correlated

As crates/omnigraph-gqt/cases/issue_1338_correlated_block_folds_inner_batches.gqt:

  • With the engine files of main 2c4b2f12: fails at step 1 with resource limit exceeded for query_memory_bytes: actual 12682022, limit 12582912 (2.99 s). This is the predicted reason.
  • At e9f733cb: passes (3.31 s, inside the 10 s case budget, so it can stay in the ordinary corpus).

Keep the Rust _issue_1338 test as well. Its assert_released probe is a mechanism assertion that GQT cannot make. Change its comment to give that reason. The older comment at engine_v2_memory.rs:463 makes the same claim about pool selection; its second reason (the collector's reservation owner) is still valid.

Optional suggestions

O1. One owner for "fold the inner stream, never hold it". After this change, the two strategies contain the same loop: take a batch, record input_rows, skip an empty batch, find a tag per row, evaluate the argument, absorb (anti_join.rs:376-392 and anti_join.rs:438-458). Only the tag source is different: the correlated path reads the tag column, and the key-set path maps the row's key to a group. One function, for example fold_inner(stream, &mut aggregate, tags: impl Fn(&RecordBatch) -> Result<UInt32Array>, arg, params, reservation) in subquery_aggregate.rs, would make "the inner stream is folded, not held" true by construction for both strategies and for any future one. absorb_inner_batch and the key-set loop would then share their empty-batch and length checks. If five more strategies of this kind were added, each would otherwise copy the loop and could reintroduce a drain. The cost is one closure parameter. This is not needed for correctness.

O2. Accumulator heap is not counted (this PR did not cause it). reservation.entries::<ValueAccumulator>(num_rows) (anti_join.rs:365) charges only the size of the enum. A min/max over a String keeps an owned value per outer row, on the heap and not charged. In this test that is one 1 KiB string. With many outer rows and long text, it can be large. Now that the inner batches are not held, this is the largest part of the fold state that the pool does not count. A follow-up could charge the extremum's size when it is replaced. This applies to both strategies.

O3. Remaining bound. The outer side is still drained into one batch (drain_one, anti_join.rs:319) and tagged, so peak memory is the outer rows, the accumulators, one inner batch and the inner operators' own working sets. The PR's table shows this: at smaller pools, expand hop and hydrate_nodes refuse first. That is correct and outside this PR's scope. I mention it only so that nobody reads "streams" as "bounded by one batch".

Liability

  • Removed: a Vec<RecordBatch> that grew with fan-out, and its per-batch charges. The fold now matches the key-set path, so the two strategies share one memory model.
  • Added: no new state, API, invariant or setting. The source lines are about even (+45/-37 in the two engine files). The only new obligation is the guard lifetime, and the PR's comment states it.
  • Alternative (lower to DataFusion AggregateExec). That would give streaming and spilling from the substrate (invariant 1). Waiting for #1260's float-semantics decision is reasonable. This change does not make that move harder.
  • Other open PRs. #1316 does not touch anti_join.rs or subquery_aggregate.rs. #1275 and #1282 also add tests at the end of engine_v2_memory.rs, so expect a small textual conflict there. Lance is not involved: the change is after the scan, on DataFusion record batch streams.

Validation

All runs are local, in a clean detached worktree at e9f733cb, unless stated otherwise.

What Commit Command Result
New Rust test, before engine files of 2c4b2f12, test from e9f733cb cargo test --workspace --exclude omnigraph-gqt --exclude omnigraph-gqt-served --exclude omnigraph-dst --locked --features omnigraph-engine/failpoints,omnigraph-cluster/failpoints -p omnigraph-engine --test integration -- engine_v2_memory::correlated_block_folds fails after the plan assertion (correlated) passes: ResourceLimitExceeded { resource: "query_memory_bytes", limit: 12582912, actual: 12587283 }
New Rust test, after e9f733cb same passes
engine_v2_memory:: module e9f733cb same, filter engine_v2_memory::, RUST_MIN_STACK=16777216 32 passed
Engine integration, related filters e9f733cb test binary with filters anti_join, block, correlat, negation 1, 8, 3 and 5 passed; 0 failed
GQT probe (R1), before / after 2c4b2f12 engine files / e9f733cb cargo test -p omnigraph-gqt --locked --test gq_logic_tests -- issue_1338 fails for the predicted reason / passes
Complete GQT corpus with the probe e9f733cb gq_logic_tests with no filter 468 passed, 0 failed
CI e9f733cb all checks 28 pass, 4 skipped, 0 fail

Limits. I did not run Clippy, rustfmt or the engine unit tests locally; CI ran them on this exact commit and they pass. I did not measure peak memory directly. As in the PR, admission under a pool smaller than the inner output is the evidence. I made no performance claims. I removed all temporary edits, and I pushed nothing to this branch.

…p for both strategies

A GQT case runs a correlated block whose 16 MiB of inner rows exceed its
12 MiB query pool: holding the inner output was refused with
query_memory_bytes, and the streaming fold answers the row. The Rust test
stays for the reservation release that GQT cannot assert, and its comment
and an older one no longer claim GQT cannot select the pool.

fold_inner is now the one loop that folds an inner stream batch by batch
for the correlated and key-set strategies, which differ only in how a row
finds its group, so no strategy can hold its inner output again.
@ragnorc

ragnorc commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Addressed at b49e232a. The commit before it merges main, which brings in #1347's KeyGroups in key_set_mask; the merge had no conflicts.

R1. Added your case unchanged as crates/omnigraph-gqt/cases/issue_1338_correlated_block_folds_inner_batches.gqt. It passes at this head in 6.6 s, inside its 10 s budget. Your red run on 2c4b2f12 stands as the before. I fixed both comments in engine_v2_memory.rs:

  • the _issue_1338 test now names the .gqt case and gives its own reason to exist: GQT cannot assert that the run releases every reservation it took;
  • the older comment at line 463 now keeps only the reason that still holds (the collector's reservation owner).

O1. Done. fold_inner in anti_join.rs is now the one loop over an inner stream: take a batch, record input_rows, skip an empty one, take each row's group, evaluate the argument, absorb. The correlated path passes its tag column (tag_array), and the key-set path passes its KeyGroups probe. absorb_inner_batch is removed. Folding the stream instead of holding it is now true by construction for both strategies and any later one.

O2 and O3 are outside this PR's scope, as you note. The accumulator heap of a text min/max and the drained outer side remain as described. Neither is changed here.

Checked locally on 1.97.1: fmt, cargo dev-clippy, and the lib and integration tests filtered to engine_v2_memory::, anti_join, report::, subquery_aggregate, block, correlat, negation and key_groups (all passed). cargo test -p omnigraph-gqt --test gq_logic_tests -- issue_1338 passes. I did not run the full GQT corpus locally; CI does.

@ragnorc ragnorc left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of #1341 at b49e232a (delta since e9f733cb)

Why. A correlated block on the per-row path kept its whole inner output in memory before it folded it, so a hub with a large fan-out was refused with query_memory_bytes (#1338). My first review (at e9f733cb) found the fold change correct and asked for a .gqt regression (R1). It also suggested one owner for the inner loop (O1).

What changed since e9f733cb. Two commits. 96c7ccf8 merges main with no conflict: its remerge diff is empty. b49e232a does three things:

  • It adds the R1 case as crates/omnigraph-gqt/cases/issue_1338_correlated_block_folds_inner_batches.gqt. The file is byte-identical to the probe in my first review.
  • It corrects the two test comments in engine_v2_memory.rs.
  • It adds fold_inner (anti_join.rs:450-474), the one loop over an inner stream for both strategies, and removes absorb_inner_batch.

Impact. Results and memory model are unchanged from e9f733cb. The new function makes "fold the inner stream, never hold it" true by construction for both strategies.

Recommendation: one blocking item, B1. CI is red at this head because of this commit, and the fix is a rename. The design and the R1 follow-up are correct.

Required before merge

B1. fold_inner's closure parameter tags trips the graph-write chokepoint guard. forbidden_apis::graph_visible_write_chokepoints_are_registered fails in Test Workspace and in Storage Upgrade Compatibility, so CI Gate fails too:

engine/operators/anti_join.rs `.tags(`: observed 1, no registered protocol

The cause is the call tags(&batch) at anti_join.rs:464. The guard's structural scanner (CallInventory::visit_expr_call, forbidden_apis.rs:1765) records every function call by its final path identifier. It cannot tell a local closure from Lance's native-ref Dataset::tags(). The .tags( primitive key is the bare identifier tags, from primitive_inventory_key. So the closure call counts as a native-ref access in a file that has no registered protocol.

Rename the parameter, for example group_of, and its mention in the doc comment above. Do not register anti_join.rs in the chokepoint registry. That would record a durable-effect protocol for code that has none, and it would hide a real .tags( call if one were added to this file later. The local let tags = … and aggregate.absorb(&tags, …) do not trip the guard (a binding, and a method call named absorb).

I checked this fix in my worktree. At b49e232a the guard fails locally with the same message. With only the parameter renamed to group_of (three lines in anti_join.rs), the whole forbidden_apis binary passes: 44 passed, 0 failed. I restored the file afterwards.

Also note that nextest stopped at the first failure in Test Workspace (3140/5316 tests run), so CI has no evidence for the remaining 2,176 workspace tests at this head. The rerun after the rename will provide it.

Delta correctness (code inspection and local tests)

  • Same fold, both paths. fold_inner keeps the order of the old loops: take a batch, record input_rows, skip an empty batch, find each row's group, evaluate the argument in the inner scope, absorb. The correlated path used to skip an empty batch inside absorb_inner_batch before it read the tag column. It now skips it in fold_inner before it calls the closure. Same behavior, and an empty batch with no tag column still does not fail.
  • Errors. The two manifest_internal errors for a missing or non-UInt32 tag column keep their text. They now go through external once, in tag_array, as the other inner errors already did.
  • tag_array clones. .cloned() on the downcast UInt32Array copies the array's Arcs, not its values. This is cheap, and it lets one closure type (FnMut(&RecordBatch) -> DfResult<UInt32Array>) serve both strategies. The key-set closure already built an owned array.
  • Slot guard. The FilledSlot guard is still created after slot.fill and dropped after fold_inner returns, so the inner stream still ends before the tagged batch is released.
  • Docs. docs/dev/execution.md (the AntiJoin row) already describes both strategies as folding each batch without holding it. Nothing in docs/ or the skill names the removed absorb_inner_batch.

Optional

O1 (new). The guard's false positive is a general hazard, not only this rename. Any local function or closure named after a durable primitive (tags, commit, restore, and the rest of DURABLE_PRIMITIVES) in a scanned file will trip the guard. A rename is the right fix here. If this happens again, the guard could skip calls whose path is a single segment bound by a closure or function parameter in scope. That costs a scope walk in a test file and is not needed now.

Earlier O2 (the uncounted heap of a text min/max accumulator) and O3 (the drained outer side) stay out of scope, as the author said.

Liability

  • Removed: two copies of the inner loop and absorb_inner_batch. The two engine files go +69/−56: the shared loop costs a few lines more than two copies, and the doc comment explains it. A third strategy now gets streaming by calling fold_inner, not by copying the loop.
  • Added: one closure parameter and tag_array. No new state, API, setting or invariant.
  • Other open PRs. git merge-tree against main fd58fd33 is clean. #1345 (which changes key_groups.rs) merges cleanly with this head. #1316 and #1334 conflict with it only on use lines in subquery_aggregate.rs (IRExpr moves to the test module here, and they rename query::ast to query::value). Both already conflict with main in crates/omnigraph-gqt/README.md.
  • Lance is not involved: the change is after the scan, on DataFusion record batch streams.

Validation

All local runs are in a clean detached worktree at b49e232a, debug, the cargo dev-test feature set, RUST_MIN_STACK=16777216, rustc 1.97.1.

What Commit Command Result
Chokepoint guard, as pushed b49e232a cargo dev-test -p omnigraph-engine --test forbidden_apis -- graph_visible_write_chokepoints_are_registered fails: engine/operators/anti_join.rs .tags(: observed 1, no registered protocol (same as CI)
forbidden_apis, with B1's rename b49e232a + rename of the tags parameter cargo dev-test -p omnigraph-engine --test forbidden_apis 44 passed, 0 failed
GQT regression, before b49e232a with anti_join.rs and subquery_aggregate.rs of main ad41b299 (the merge parent) cargo test -p omnigraph-gqt --locked --test gq_logic_tests -- issue_1338 fails at step 1: resource limit exceeded for query_memory_bytes: actual 12682022, limit 12582912. This is the predicted reason, now against current main
GQT regression, after b49e232a same passes (2.35 s, inside the 10 s budget)
Engine integration, related filters b49e232a engine integration binary with filters engine_v2_memory::, block, correlat, negation, anti_join 32, 8, 3, 5 and 1 passed; 0 failed
CI, complete GQT corpus b49e232a GQ Logic Tests 472 passed, issue_1338 in 3.43 s
CI, other checks b49e232a all checks 25 pass, 4 skipped, 3 fail (Test Workspace, Storage Upgrade Compatibility, CI Gate, all from B1). Clippy, rustfmt and DST pass. The in-source subquery_aggregate (5), key_groups (2) and report (19) unit tests passed before nextest stopped

Limits. I did not run the full workspace graph locally. The 2,176 workspace tests that CI did not reach at this head are not verified by me either; the rerun after B1 will cover them. I did not run Clippy or rustfmt locally; CI ran them on this exact commit and they pass. The Rust _issue_1338 test's before/after proof is from my first review (it is unchanged except its comment); at this head it passes inside the engine_v2_memory:: run above. I made no performance claims. I removed all temporary edits, and I pushed nothing to this branch.

The chokepoint guard records every call by its final path identifier, so
the closure call tags(&batch) counted as Lance's native-ref .tags( in a
file with no registered protocol, failing
forbidden_apis::graph_visible_write_chokepoints_are_registered.
@ragnorc

ragnorc commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Reply to the review of b49e232a. I pushed 4acd86bf to the same branch. It has two commits: 37b514a3 is the fix, and 4acd86bf merges main at 2bfb3f35. That merge brings in README changes only and had no conflicts.

B1: valid, fixed in 37b514a3. fold_inner's closure parameter is now named group_of, and its doc comment says the same. The change is three lines in anti_join.rs. I did not register anti_join.rs in the chokepoint registry, for the reason you gave.

  • Before, at b49e232a: cargo dev-nextest -E 'binary(forbidden_apis)' gave 43 passed and 1 failed. The failure was graph_visible_write_chokepoints_are_registered, with engine/operators/anti_join.rs .tags(: observed 1, no registered protocol, the same as CI run 43160347708.
  • After, at 4acd86bf: the same command gives 44 passed and 0 failed.

O1: declined for now. I agree with you that a rename is the right fix here. This is the first time a local name has tripped the guard. A scope-aware skip would add a scope walk to the guard's scanner, and that walk could also hide a real call. If the same false positive appears again, it will be worth doing.

Earlier O2 and O3 stay out of scope, as before.

Checks on 4acd86bf (debug, the cargo dev-* feature set, RUST_MIN_STACK=16777216):

  • forbidden_apis: 44 passed.
  • Engine tests filtered to engine_v2_memory::, correlat, anti_join, negation, key_groups, subquery_aggregate and block: 63 passed, 0 failed.
  • cargo fmt --all --check and cargo dev-clippy: pass.
  • CI: 28 passed and 4 skipped (run 43201399567), including Test Workspace, Storage Upgrade Compatibility and CI Gate. GitHub reports the pull request as mergeable.

@ragnorc ragnorc left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of #1341 at 4acd86bf (delta since b49e232a)

Why. My review at b49e232a found one blocking item, B1: the closure parameter tags in fold_inner tripped the graph-write chokepoint guard, so CI failed. The streaming fold itself and the R1 GQT case were correct.

What changed since b49e232a. Two commits.

  • 37b514a3 renames the closure parameter tags to group_of (anti_join.rs:447, :456, :464). This is the rename B1 asked for, three lines, and nothing else.
  • 4acd86bf merges main 2bfb3f35. It brings only README.md changes from main. Its remerge diff is empty, so the merge resolved nothing by hand.

Impact. No change to behavior, results or the memory model since b49e232a. anti_join.rs is not in the chokepoint registry, which is correct: the file has no durable effect, and a real .tags( call added there later will still fail the guard.

Recommendation: ready to merge. B1 is resolved, and CI at this head is green. No blocking findings. No new optional findings.

B1: resolved

  • The guard counts calls by their final path identifier (CallInventory::visit_expr_call, forbidden_apis.rs:1765; key from primitive_inventory_key, forbidden_apis.rs:1875). After the rename, the only call through the closure is group_of(&batch), which is not a durable primitive. The local binding let tags = … is not a call, so it does not count.
  • The doc comment above fold_inner names group_of, so the comment and the code agree.
  • The fix is at the right layer. It removes the false match. It does not add a registry entry that would claim a durable-effect protocol for this file.

O1 (declined in the reply): accepted. O1 was optional. The reason holds: a scope-aware skip adds a walk to the guard's scanner, and a wrong skip could hide a real call. This is the first false positive of its kind, so a rename is the cheaper fix until it recurs.

Liability

The delta adds nothing: no state, API, setting or registry entry. It removes the only CI failure. The PR as a whole keeps the assessment from my earlier review: one shared inner loop (fold_inner) in place of two copies, so a third strategy gets streaming by calling it, not by copying it.

Other open PRs

  • git merge-tree of this head with #1345: clean.
  • #1316 and #1334: conflict only in crates/omnigraph-gqt/README.md and the use lines of subquery_aggregate.rs, as at b49e232a.
  • #1362 (new since my last review): conflicts only at the end of crates/omnigraph/tests/integration/engine_v2_memory.rs, where both PRs append tests. Keep both tests when the second one merges.

Validation

Local runs are in a clean detached worktree at 4acd86bf, debug build, RUST_MIN_STACK=16777216.

What Commit Command Result
Chokepoint guard, before the rename 4acd86bf with anti_join.rs of b49e232a cargo dev-test -p omnigraph-engine --test forbidden_apis -- graph_visible_write_chokepoints_are_registered fails: engine/operators/anti_join.rs .tags(: observed 1, no registered protocol (the B1 reason)
Chokepoint guard, after 4acd86bf same passes
forbidden_apis, whole binary 4acd86bf cargo dev-test -p omnigraph-engine --test forbidden_apis 44 passed, 0 failed
GQT regression for #1338 4acd86bf cargo test -p omnigraph-gqt --locked --test gq_logic_tests -- issue_1338 passes (3.41 s, inside the 10 s budget)
CI, all checks 4acd86bf GitHub Actions 28 passed, 4 skipped, 0 failed. Test Workspace, Storage Upgrade Compatibility and CI Gate now pass, so the 2,176 workspace tests that CI did not reach at b49e232a ran at this head

Regression proof. The delta fixes a source guard, not query behavior, so GQT cannot express it. The guard test is the cheapest owner, and it is already in the tree. I put back the b49e232a version of anti_join.rs (only the three renamed lines differ), and the guard failed for the predicted reason. With the head's file it passed. I restored the file; git status is clean.

Limits. I did not run the full workspace suite locally; CI covers it at this head. The before/after proof for the streaming fold (the issue_1338 GQT case and the Rust memory test) is in my earlier reviews; this delta does not touch that code path except the rename. I made no performance claims. I removed all temporary edits, and I pushed nothing to this branch.

@ragnorc

ragnorc commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Reply to the delta review of 4acd86bf (review 5873132563). No new commit: the review has no blocking or optional items. The head stays 4acd86bf.

B1: fixed, as the review confirms. Nothing more to do.

O1: closed. The review accepts the reason it was declined. No change.

Merge state. main has moved to 1715b88a (#1365) since the review. git merge-tree of 4acd86bf with 1715b88a is clean, so I did not merge it in. With #1362 at 1a701abe, the only conflict is one hunk at the end of crates/omnigraph/tests/integration/engine_v2_memory.rs, where both pull requests add tests, as the review says. Whichever merges second keeps both tests. With #1345 at 498a3858 the merge is clean.

No code changed, so I ran no gates. CI on 4acd86bf is unchanged: every check passed, with the 4 tag and release jobs skipped. GitHub reports the pull request as mergeable.

@ragnorc

ragnorc commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Merged main into this branch to clear the conflict. I pushed 942aa0c4, one merge commit that merges main at bbabbd7d. There is no other code change. After that, 5313732f (21:24Z) merged main at 568180af on top of it. The pull request now merges cleanly with main at 7747bd3b.

Conflict. There was one conflict, at the end of crates/omnigraph/tests/integration/engine_v2_memory.rs. This branch and #1362 each add one test at that place. I kept both tests as they were: correlated_block_folds_inner_batches_as_they_stream_issue_1338 and a_query_that_fits_a_budget_fits_every_larger_budget_issue_1361. docs/dev/execution.md merged without a conflict, because #1362 changes a different section of it.

Checks at 942aa0c4, run locally.

  • cargo fmt --all --check: passed.
  • cargo dev-nextest on the engine tests for memory, correlated blocks, anti joins and block aggregates: 65 passed, 0 failed. Both tests above pass.
  • cargo test -p omnigraph-gqt --test gq_logic_tests issue_1338: 1 passed.
  • cargo dev-clippy: passed.

CI. At 5313732f, CI passed: 27 passed, 4 skipped (run 43309969887). At 942aa0c4, Test Workspace failed twice, both times in a_query_that_fits_a_budget_fits_every_larger_budget_issue_1361 (run 43301999483, attempts 1 and 2). That failure comes from main, not from this branch:

  • The test is flaky on main alone. I ran it 210 times on main at 568180af, with none of this branch's code. It failed 2 times: "5 MiB is refused although 4 MiB fits" and "4 MiB is refused although 3 MiB fits". Each refusal was in graph take output.
  • Another pull request failed on the same test at 20:45Z (run 43301358856, "5 MiB is refused although 4 MiB fits").
  • This branch changes only AntiJoinMaskExec, which runs only for a correlated block. The test's query (return { max($e.payload) as last }) has no block.

I did not change the test. The flake belongs to #1361.

The review findings do not change. B1 and O1 stay as in my earlier replies.

@ragnorc ragnorc left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of #1341 at 5313732f (delta since 4acd86bf)

Why. My review at 4acd86bf (review 5873132563) found no blocking and no optional items. Since then the head moved to 942aa0c4, and then to 5313732f while I reviewed. This review checks only that delta.

What changed since 4acd86bf. Two merge commits and no other change. 942aa0c4 merges main at bbabbd7d (#1365, #1184, #1364, #1362). 5313732f merges main at 568180aff (#1346). The PR's own diff against its merge base is the same, line for line. Only the position of the new test in engine_v2_memory.rs and one context line in docs/dev/execution.md moved.

The merge resolved one conflict by hand, at the end of crates/omnigraph/tests/integration/engine_v2_memory.rs. Both this PR and #1362 append a test there. The resolution keeps both tests: correlated_block_folds_inner_batches_as_they_stream_issue_1338, then #1362's a_query_that_fits_a_budget_fits_every_larger_budget_issue_1361. That is the outcome my last review asked for. git show --remerge-diff shows no other hand edit in 942aa0c4, and none at all in 5313732f. #1362 and #1346 also edit other rows of docs/dev/execution.md; this PR's AntiJoin row applies beside them unchanged.

#1346 changes FilterExec, which can run inside a correlated block's inner plan (the issue_1338 query has one inner filter). It changes how one batch is filtered, not how batches stream. So the fold still sees each inner batch once and in order. The issue_1338 Rust test passes at 5313732f.

Impact. No change to behavior, results or the memory model since 4acd86bf.

Recommendation: ready to merge. No blocking findings. No new optional findings. CI at this head is green. At 942aa0c4 one test failed in CI. It is intermittent on main and not caused by this PR (see below).

CI: issue_1361 failed at 942aa0c4, not caused by this PR

I agree with the reply on this flake, and I checked it on my own:

  • The failing query ($p $e:knows $q, return { max($e.payload) }) has no correlated block, so it never runs AntiJoinMaskExec. SubqueryAggregate is used only from anti_join.rs. Those two files are all the source this PR changes.
  • At 942aa0c4 the refusal was at 5 MiB, in graph take output (cannot reserve 358966 bytes: 4928521 bytes are reserved, query limit is 5242880 bytes), the same place as the failure in #1367's run 43301358856.
  • Locally it passed 6 of 6 times at 942aa0c4 and 5 of 5 at 5313732f. It passed in CI at 5313732f.

#1361 is closed, but its regression test still fails sometimes on main. That needs its own follow-up, not a change in this PR.

Other open PRs

5313732f merges cleanly with current main 7747bd3b (#1348). I also ran git merge-tree of 942aa0c4 with main 568180aff and with the head of each of the 37 other open PRs. Then I compared each result with the same PR merged into main.

  • The only conflicts this PR adds are in #1316 and #1334 (drafts): the use lines of subquery_aggregate.rs, the same as at 4acd86bf. Their crates/omnigraph-gqt/README.md conflict is with main too.
  • #1175 (draft) conflicts with this head in engine_v2_memory.rs, but it conflicts with main in that file as well, and in 34 others. So this PR adds no new work for it.

Validation

Local runs are in a clean detached worktree, debug build, RUST_MIN_STACK=16777216.

What Commit Command Result
Both tests at the hand-resolved spot, plus #1362's unit test 942aa0c4 cargo dev-nextest -E 'package(omnigraph-engine) & (test(issue_1338) | test(issue_1361))' 3 passed, 6 runs of 6
All of engine_v2_memory 942aa0c4 cargo dev-nextest -E 'package(omnigraph-engine) & binary(integration) & test(/^engine_v2_memory::/)' 33 passed, 0 failed
Same tests, after #1346 5313732f same two commands 3 passed, 5 runs of 5; engine_v2_memory 34 passed, 0 failed
PR diff unchanged 4acd86bf, 942aa0c4, 5313732f diff of git diff $(git merge-base <c> origin/main) <c> only index lines, the moved hunk and one context line differ
CI, all checks 5313732f GitHub Actions (CI 43309969887, GQ Logic Tests 43309969575, DST 43309969293) 27 passed, 4 skipped, 0 failed, including Test Workspace with issue_1361, and GQ Logic Tests with the issue_1338 GQT case
CI, all checks 942aa0c4 GitHub Actions 26 passed, 4 skipped, Test Workspace and CI Gate failed on issue_1361 only. GQ Logic Tests (with the issue_1338 GQT case), DST, clippy and the S3 and Azure jobs passed

Regression proof. This delta is a merge with no change to the PR's code. So there is no new fix to prove. The before/after proof for the streaming fold (the issue_1338 GQT case and the Rust memory test, red on 2c4b2f12, green on the PR) is in my earlier reviews and still applies.

Limits. I did not run the full workspace suite or the GQT corpus locally; CI ran them. I did not find the cause of the issue_1361 flake; I only showed that this PR's code is not on its path. I made no performance claims. I made no edits in the worktree, and I pushed nothing to this branch.

@ragnorc
ragnorc added this pull request to the merge queue Nov 12, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 12, 2026
@ragnorc

ragnorc commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Reply to the delta review of 5313732f (review 5882454437). I agree with it, and I made no change. The head stays 5313732f.

The review has no blocking items and no optional items, so there is nothing to fix. I checked the parts that could have changed since it was written:

The issue_1361 flake now has its own issue: #1370. This pull request does not change the code on that test's path, so it stays out of scope here, as the review says.

For a maintainer: nothing to decide. The review recommends merge.

@ragnorc
ragnorc added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ModernRelay:main with commit 380d0bb Nov 13, 2026
36 checks passed
ragnorc added a commit to ragnorc/omnigraph that referenced this pull request Nov 16, 2026
Merges main 9fb5b48..4f7c207 (17 commits; old merge base 9fb5b48).

Carried into edition-3 code:
- ModernRelay#1341 (fold a correlated block's inner rows as they stream): anti_join.rs
  takes main's streaming fold_inner on both strategies and keeps the
  branch's comparison against the outer row (reads_outer_row,
  keep_mask_against, keep_rows_against) in each; issue_1338 GQT case and
  the engine_v2_memory test respelled in edition 3.
- ModernRelay#1389 (sort merge reservation): engine fix merged as is; its three GQT
  cases respelled (property braces to `where`).
- ModernRelay#1406 (widen an edge @card): RelaxCardinality beside the branch's
  ChangeFullTextAnalysis and ChangeVectorDistance; schema_apply test
  queries respelled; skill and schema reference keep both lists.
- ModernRelay#1398, ModernRelay#1410 (gqt --check, closed diagnostic set): main's parser taken
  whole, the branch's changes re-applied (same as reference, the parse
  refusal as a step under `expect error:`, a section's called reads);
  diagnostic rules, process.rs and grammar/v1.txt say `same as
  reference`; four tests/invalid fixtures respelled.
- ModernRelay#1416 (bench over a shallow clone): the _served workloads and scenarios
  deleted as main did; served tests keep the edition-3 write spelling;
  the catalog identity fixture regenerated.

Other main commits touch no query-language code and merge unchanged.
The DST cost golden matches the merged tree; its moved lines are ModernRelay#1390's.
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.

performance: fold a correlated block's inner rows as they stream instead of holding its whole inner output

1 participant