[WIP] Fix S3 append_log quadratic re-upload of growing buffer#2597
Draft
PawelPeczek-Roboflow wants to merge 2 commits into
Draft
[WIP] Fix S3 append_log quadratic re-upload of growing buffer#2597PawelPeczek-Roboflow wants to merge 2 commits into
PawelPeczek-Roboflow wants to merge 2 commits into
Conversation
In append_log mode, buffer entries in memory and upload only on rotation or teardown (new _flush_buffer + __del__), instead of re-PUTting the entire accumulated buffer on every run(). Eliminates O(n^2) data transfer and matches the block's documented buffered behaviour. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚧 Work in progress — not ready for review
Draft PR from a batch addressing findings from an in-depth engineering review. Fixes review finding 46 (Medium, Performance).
The bug
In
append_logoutput mode,S3SinkBlockV1._append_to_bufferappended each entry toself._bufferand then, on everyrun(), rebuiltfull_content = "".join(self._buffer)andput_object-ed the whole accumulated buffer (inference/core/workflows/core_steps/sinks/s3/v1.py:358-371). Within one rotation window ofmax_entries_per_fileentries, entry k re-uploaded all k buffered entries, so total bytes uploaded ≈S * N*(N+1)/2— quadratic. It also contradicted the block's ownLONG_DESCRIPTION(lines 91-97: "data is buffered in memory and only uploaded to S3 when the limit is reached or the block is destroyed"), and the documented teardown flush had no implementation (there was no__del__). On rotation the old code also reset the buffer without uploading the completed object, silently dropping data.Root cause
The append path used the S3
put_objectcall as a per-run "validate credentials / surface errors immediately" mechanism, treating the accumulated buffer as the payload on every call. That makes cumulative upload volume grow as O(n²) per rotation window and diverges from the documented buffered semantics.Fix
inference/core/workflows/core_steps/sinks/s3/v1.pyonly:run()calls. A buffered run now returnserror_status=Falsewith a "N entries pending upload" message._flush_buffer()that uploads the current buffer as one complete object and, on success, clears the buffer / entry count / current key.max_entries_per_fileis reached, the completed object is flushed before a fresh key/buffer starts — fixing the previous silent data loss on rotation) and on teardown via a new__del__that flushes any remaining buffered entries (matching the documented behaviour).s3_client/bucket_name/content_typeon the instance so the buffer can be flushed at teardown.No
LONG_DESCRIPTIONchange was needed — the docs already described this buffered behaviour; the code now matches them.Verification
Standalone simulation of the buffer/rotation/flush accounting (S=10KB entries, N=1024):
S*N*(N+1)/2).Full runtime verification within the
inferencepackage deferred (WIP); the standalone repro reproduces the review's proven closed-form and the corrected behaviour.Scope
Focused change; one of a coordinated batch (one PR per finding).
🤖 Generated with Claude Code