@@ -309,20 +309,30 @@ async function compactEventForBuffer(
309309
310310 // SSE/replay events are size-bounded by LARGE_VALUE_THRESHOLD_BYTES. When a
311311 // payload that preserved UserFile base64 (e.g., for chat/streaming) exceeds
312- // the cap, drop the inline base64 so consumers can lazily re-hydrate via
313- // sim.files.readBase64. This preserves the file metadata and keeps the
314- // event flowing instead of stalling the stream.
312+ // the cap, recompact the already-compacted result with base64 stripped so
313+ // consumers can lazily re-hydrate via sim.files.readBase64. Recompacting the
314+ // *compacted* value (not the raw event.data) lets existing LargeValueRefs
315+ // pass through unchanged and avoids minting fresh storage objects for the
316+ // same large fields.
315317 if (
316318 context . preserveUserFileBase64 &&
317319 eventDataSize !== null &&
318320 eventDataSize > LARGE_VALUE_THRESHOLD_BYTES
319321 ) {
320- compactedData = await compactExecutionPayload ( event . data , {
322+ const oversizedBytes = eventDataSize
323+ compactedData = await compactExecutionPayload ( compactedData , {
321324 ...baseOptions ,
322325 preserveUserFileBase64 : false ,
323326 } )
324327 eventData = trimFinalBlockLogsForEventData ( compactedData )
325328 eventDataSize = getJsonSize ( eventData )
329+ logger . warn ( 'Stripped inline UserFile base64 from execution event to fit size limit' , {
330+ executionId : baseOptions . executionId ,
331+ eventType : 'type' in event ? event . type : undefined ,
332+ thresholdBytes : LARGE_VALUE_THRESHOLD_BYTES ,
333+ originalBytes : oversizedBytes ,
334+ strippedBytes : eventDataSize ,
335+ } )
326336 }
327337
328338 if ( eventDataSize !== null && eventDataSize > LARGE_VALUE_THRESHOLD_BYTES ) {
0 commit comments