Skip to content

fix: automatic batching can exceed max_bytes - #123

Merged
quettabit merged 1 commit into
mainfrom
qb/107
Sep 10, 2026
Merged

quettabit merged 1 commit into
mainfrom
qb/107

Conversation

@quettabit

Copy link
Copy Markdown
Member

closes #107

@quettabit
quettabit requested a review from a team as a code owner September 10, 2026 22:21
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown

Greptile Summary

This PR prevents automatic batches from exceeding max_bytes by checking a record’s metered size before adding it.

  • Flushes a producer’s pending batch before accepting a record that would exceed the configured byte limit.
  • Carries an overflowing record into the next asynchronous batch rather than overfilling the current batch.
  • Adds coverage for exact-limit and pre-overflow batching behavior.

Confidence Score: 5/5

The PR appears safe to merge, with no outstanding findings.

The byte-limit checks preserve oversized single-record behavior while preventing multi-record batches from exceeding max_bytes. The previous concurrency-ordering thread was resolved after quettabit clarified that concurrent submit() calls have no ordering guarantee.

Important Files Changed

Filename Overview
src/s2_sdk/_batching.py Adds pre-insertion byte-limit checks and carries overflowing records into the next generated batch.
src/s2_sdk/_producer.py Flushes a non-empty accumulator before a submitted record would exceed the configured byte limit.
tests/test_batching.py Verifies batching at the exact byte limit and flushing before an overflow.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Receive record] --> B{Accumulator empty?}
    B -->|Yes| D[Add record]
    B -->|No| C{Would exceed max_bytes?}
    C -->|Yes| E[Flush current batch]
    C -->|No| D
    E --> D
    D --> F{Batch full or next record would overflow?}
    F -->|Yes| G[Yield or submit batch]
    F -->|No| A
Loading

Reviews (2): Last reviewed commit: "initial commit" | Re-trigger Greptile

Comment thread src/s2_sdk/_producer.py
@quettabit
quettabit merged commit 3508dd2 into main Sep 10, 2026
6 checks passed
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.

[Detail Bug] Producer drops records and becomes unusable when a batch exceeds the 1MiB server limit

1 participant