MCPcopy Index your code
hub / github.com/simstudioai/sim / externalizeExecutionData

Function externalizeExecutionData

apps/sim/lib/logs/execution/trace-store.ts:81–121  ·  view source on GitHub ↗
(
  executionData: Record<string, unknown>,
  context: TraceStoreWriteContext
)

Source from the content-addressed store, hash-verified

79 * cost-stripped) execution data is returned unchanged so the log is never lost.
80 */
81export async function externalizeExecutionData(
82 executionData: Record<string, unknown>,
83 context: TraceStoreWriteContext
84): Promise<Record<string, unknown>> {
85 const { workspaceId, workflowId, executionId, userId } = context
86 // workspaceId/workflowId build the storage key and can be null for
87 // deleted-workflow rows. userId is type-guaranteed by TraceStoreWriteContext;
88 // the falsy check is a defensive guard against an empty string. If any are
89 // missing the durable write can't succeed, so keep the data inline.
90 if (!workspaceId || !workflowId || !userId) return executionData
91
92 try {
93 const json = JSON.stringify(executionData)
94 const size = Buffer.byteLength(json, 'utf8')
95
96 // storeLargeValue persists to the execution bucket with a conforming key and
97 // registers owner + dependency closure (trace -> nested span large values),
98 // so GC keeps nested children alive while this run's log row exists.
99 const ref = await storeLargeValue(executionData, json, size, {
100 workspaceId,
101 workflowId,
102 executionId,
103 userId,
104 requireDurable: true,
105 })
106
107 const { preview: _preview, ...slimRef } = ref
108
109 const slim: Record<string, unknown> = { [TRACE_STORE_REF_KEY]: slimRef }
110 for (const key of INLINE_MARKER_KEYS) {
111 if (key in executionData) slim[key] = executionData[key]
112 }
113 return slim
114 } catch (error) {
115 logger.warn('Failed to externalize execution data; keeping inline', {
116 executionId,
117 error: toError(error).message,
118 })
119 return executionData
120 }
121}
122
123/**
124 * Resolves an `execution_data` row into its full form for reads. When the row

Callers 2

backfillTraceStorageFunction · 0.90

Calls 3

storeLargeValueFunction · 0.90
toErrorFunction · 0.90
warnMethod · 0.65

Tested by

no test coverage detected