Skip to content

fix(event-buffer): re-compact the event with preserveUserFileBase64: false#4579

Merged
icecrasher321 merged 2 commits into
stagingfrom
fix/event-buffer-compaction
May 13, 2026
Merged

fix(event-buffer): re-compact the event with preserveUserFileBase64: false#4579
icecrasher321 merged 2 commits into
stagingfrom
fix/event-buffer-compaction

Conversation

@icecrasher321
Copy link
Copy Markdown
Collaborator

Summary

When preserveUserFileBase64 is on and the event still exceeds the threshold, re-compact the event with preserveUserFileBase64: false. This drops inline base64 (clients can lazily fetch it via sim.files.readBase64) while keeping file metadata and the rest of the event intact, so the stream keeps flowing.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…d, re-compact the event with preserveUserFileBase64: false
@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 13, 2026 4:11am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 13, 2026

PR Summary

Medium Risk
Changes execution event compaction behavior when preserveUserFileBase64 is enabled, which can affect SSE/replay payload contents and client expectations in streaming scenarios. Logic is localized but touches a critical path for event delivery under size limits.

Overview
Prevents SSE/replay execution events from failing the LARGE_VALUE_THRESHOLD_BYTES cap when preserveUserFileBase64 is requested by re-compacting oversized payloads with preserveUserFileBase64: false, stripping inline base64 while keeping existing LargeValueRefs intact.

Adds a warning log when this fallback triggers, and still throws if the event remains too large after the second compaction.

Reviewed by Cursor Bugbot for commit f0d2431. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 13, 2026

Greptile Summary

This PR adds a two-pass compaction fallback in compactEventForBuffer: when preserveUserFileBase64 is enabled and the first-pass result still exceeds LARGE_VALUE_THRESHOLD_BYTES, it re-compacts the already-compacted payload with preserveUserFileBase64: false, stripping inline base64 while preserving existing LargeValueRef objects and all other metadata.

  • Fallback recompaction: The second compactExecutionPayload call targets compactedData (not event.data), so LargeValueRef objects from the first pass pass through unchanged via the isLargeValueRef early-return — no duplicate storage objects are created.
  • Observability: A logger.warn with execution ID, event type, and byte counts is emitted whenever the fallback path fires.
  • Error path preserved: If stripping base64 still leaves the payload over the threshold, the existing throw fires, keeping the hard failure contract intact.

Confidence Score: 5/5

Safe to merge — the fallback path is well-scoped, correctly avoids duplicate storage writes, and preserves the hard-failure contract for payloads that remain oversized after base64 stripping.

The change is a focused, defensive fallback that only activates when preserveUserFileBase64 is explicitly set and the compacted payload is still over the size cap. Recompacting the already-compacted result rather than raw event.data is the correct approach, and the existing isLargeValueRef early-return in compactValue guarantees no duplicate storage objects. The final error-throw path remains intact.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/lib/execution/event-buffer.ts Adds a two-pass size-reduction fallback: strips UserFile base64 inline when the first compaction pass still exceeds the threshold; correctly recompacts compactedData (not raw event.data) and adds logger.warn for observability.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[compactEventForBuffer] --> B{event has data?}
    B -- No --> C[return event unchanged]
    B -- Yes --> D[compactExecutionPayload\npass 1: preserveUserFileBase64=ctx.value]
    D --> E[trimFinalBlockLogsForEventData]
    E --> F[getJsonSize]
    F --> G{preserveUserFileBase64 &&\nsize > THRESHOLD?}
    G -- No --> H{size > THRESHOLD?}
    G -- Yes --> I[compactExecutionPayload\npass 2: preserveUserFileBase64=false\nInput: already-compacted data]
    I --> J[trimFinalBlockLogsForEventData]
    J --> K[getJsonSize]
    K --> L[logger.warn with byte counts]
    L --> H
    H -- No --> M[return event with compacted data]
    H -- Yes --> N[throw Error: still too large]
Loading

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

Comment thread apps/sim/lib/execution/event-buffer.ts Outdated
Comment thread apps/sim/lib/execution/event-buffer.ts
@icecrasher321
Copy link
Copy Markdown
Collaborator Author

@greptile

@icecrasher321
Copy link
Copy Markdown
Collaborator Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit f0d2431. Configure here.

@icecrasher321 icecrasher321 merged commit bdf9ffc into staging May 13, 2026
10 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/event-buffer-compaction branch May 13, 2026 06:20
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