Skip to content

Keep the async worker moving when one operation reads more than the reserve - #311

Draft
reeceyang wants to merge 2 commits into
batch-node-writesfrom
batch-oversized-op
Draft

reeceyang wants to merge 2 commits into
batch-node-writesfrom
batch-oversized-op

Conversation

@reeceyang

@reeceyang reeceyang commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Runs each async batch in a subtransaction with tighter limits, so an operation that reads more than the worker's 2 MiB reserve (a split of a full internal node reads every child) no longer overflows the transaction and stalls the queue for good. A cycle that runs out of room after other operations marks the row to stop before the operation, so the next cycle commits what came before it, and an operation too big for a cycle of its own is dead-lettered. The flush of pending node writes at the end of a cycle runs under the same limits, so a flush that runs out of room also cuts the cycle before its last operation. Splits also read children one at a time, because every read in flight counts when a limit trips, and parallel reads could overshoot the reserve by many nodes.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

🤖 Generated with Claude Code

@reeceyang
reeceyang force-pushed the batch-oversized-op branch 2 times, most recently from 3222918 to f445d3a Compare December 4, 2026 01:42
@pkg-pr-new

pkg-pr-new Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@convex-dev/aggregate@311

commit: 4c11d08

reeceyang and others added 2 commits December 4, 2026 12:04
Every write patches each node on its path to keep counts and sums current, so
a batch rewrote a tree's root once per operation. Hold node writes in the
batch's node cache and flush them when the batch ends, counting the held
writes against the transaction's headroom so the flush always fits.

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

A batch's last operation can read more than the 2 MiB headroom reserve (a
split of a full internal node reads every child), overflowing the transaction
limit or leaving no room to retire its row. The failed cycle rolled back and
retried unchanged, so the queue stalled for good.

The inner cycle now runs with transactionLimits that keep the reserve free in
the outer transaction. If it overflows after other operations ran, the row is
marked to stop before that operation, so the next cycle commits the prefix and
the operation then runs first. An operation that can't fit in a cycle of its
own is dead-lettered.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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