Skip to content

Commit 591b132

Browse files
rustyconoverclaude
andcommitted
BufferedFinalizeState: emit one batch per produce() tick
OutputCollector enforces "one data batch per call" — emitting a list in a loop tripped the assertion at scale (any input that yielded >1 output batch would crash mid-stream). Switch to limit=1 in state_log_scan and emit exactly one batch per produce() call; the framework loops the ticks until out.finish() fires on EOS. Drops the unused _FINALIZE_PREFETCH constant from worker.py. Repro before this fix: SELECT count(*) FROM buffer_input((SELECT range FROM range(100000))) — RuntimeError "Only one data batch may be emitted per call". After: returns 100000. All 27 buffered_table integration tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 98e9c33 commit 591b132

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

‎vgi/protocol.py‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,6 @@ def produce(self, out: OutputCollector, ctx: CallContext) -> None:
12261226
# and avoid a circular dependency on vgi.worker.
12271227
from vgi.table_in_out_function import pack_int_cursor, unpack_int_cursor
12281228
from vgi.worker import (
1229-
_FINALIZE_PREFETCH,
12301229
_build_bound_storage_from_fields,
12311230
_decode_ipc_batch,
12321231
)
@@ -1235,15 +1234,18 @@ def produce(self, out: OutputCollector, ctx: CallContext) -> None:
12351234
self.execution_id, self.attach_opaque_data, ctx,
12361235
)
12371236
last_id = unpack_int_cursor(self.cursor)
1237+
# OutputCollector enforces one data batch per produce() tick, so
1238+
# we read exactly one row per call. Framework loops the ticks
1239+
# until out.finish() is called on EOS.
12381240
rows = storage.state_log_scan(
1239-
self.ns, self.key, after_id=last_id, limit=_FINALIZE_PREFETCH,
1241+
self.ns, self.key, after_id=last_id, limit=1,
12401242
)
12411243
if not rows:
12421244
out.finish()
12431245
return
1244-
for _log_id, value in rows:
1245-
out.emit(_decode_ipc_batch(value))
1246-
self.cursor = pack_int_cursor(rows[-1][0])
1246+
log_id, value = rows[0]
1247+
out.emit(_decode_ipc_batch(value))
1248+
self.cursor = pack_int_cursor(log_id)
12471249

12481250

12491251
# Type alias for the union of all stream state variants produced by init().

‎vgi/worker.py‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,6 @@ def clear_execution(self, shard_key: str, execution_id: bytes) -> None:
449449
_BUFFERED_TABLE_INIT_KEY = -1
450450

451451

452-
# Cursor-based finalize stream constants. ``BufferedFinalizeState.produce()``
453-
# uses these to drain the next page of a state_log per tick. Single tunable
454-
# value across all functions; if profiling shows it's wrong, lift to a
455-
# per-function Meta override.
456-
_FINALIZE_PREFETCH = 8
457-
458452
# Streaming-shape FINALIZE phase materializes the user's
459453
# ``finalize() -> list[batch]`` return into a single state_log keyed
460454
# by this constant. One streaming finalize per execution; one key.

0 commit comments

Comments
 (0)