( ref: LargeValueRef, context?: LargeValueStoreContext )
| 202 | } |
| 203 | |
| 204 | export async function materializeLargeValueRef( |
| 205 | ref: LargeValueRef, |
| 206 | context?: LargeValueStoreContext |
| 207 | ): Promise<unknown> { |
| 208 | if (!context?.executionId) { |
| 209 | return undefined |
| 210 | } |
| 211 | |
| 212 | assertLargeValueRefAccess(ref, context) |
| 213 | assertInlineMaterializationSize(ref.size, context.maxBytes) |
| 214 | |
| 215 | if (!ref.key || !isValidLargeValueKey(ref)) { |
| 216 | return materializeLargeValueRefSync(ref, context) |
| 217 | } |
| 218 | |
| 219 | if (context.trackReference !== false) { |
| 220 | const { addLargeValueReference } = await import('@/lib/execution/payloads/large-value-metadata') |
| 221 | // Reference tracking is GC-critical: if it fails, fail the read rather than |
| 222 | // return a value whose reference was never recorded (it could later be |
| 223 | // garbage-collected out from under a live consumer). Read-only consumers |
| 224 | // that don't need a reference set trackReference: false to skip this. |
| 225 | await addLargeValueReference( |
| 226 | { |
| 227 | workspaceId: context.workspaceId, |
| 228 | workflowId: context.workflowId, |
| 229 | executionId: context.executionId, |
| 230 | source: 'execution_log', |
| 231 | }, |
| 232 | ref.key |
| 233 | ) |
| 234 | } |
| 235 | |
| 236 | try { |
| 237 | const cached = materializeLargeValueRefSync(ref, context) |
| 238 | if (cached !== undefined) { |
| 239 | return cached |
| 240 | } |
| 241 | |
| 242 | const value = await readLargeValueRefFromStorage(ref, { |
| 243 | workspaceId: context.workspaceId, |
| 244 | workflowId: context.workflowId, |
| 245 | executionId: context.executionId, |
| 246 | largeValueExecutionIds: context.largeValueExecutionIds, |
| 247 | largeValueKeys: context.largeValueKeys, |
| 248 | allowLargeValueWorkflowScope: context.allowLargeValueWorkflowScope, |
| 249 | userId: context.userId, |
| 250 | maxBytes: context.maxBytes ?? ref.size, |
| 251 | }) |
| 252 | if (value === undefined) { |
| 253 | return undefined |
| 254 | } |
| 255 | cacheLargeValue( |
| 256 | ref.id, |
| 257 | value, |
| 258 | ref.size, |
| 259 | { |
| 260 | ...context, |
| 261 | executionId: ref.executionId ?? context.executionId, |
no test coverage detected