MCPcopy Create free account
hub / github.com/ShipSecAI/studio / unspill

Function unspill

worker/src/temporal/activities/run-component.activity.ts:226–280  ·  view source on GitHub ↗
(obj: Record<string, any>, contextLabel: string)

Source from the content-addressed store, hash-verified

224 const resolvedInputs = { ...inputs };
225
226 async function unspill(obj: Record<string, any>, contextLabel: string) {
227 for (const [key, value] of Object.entries(obj)) {
228 if (isSpilledDataMarker(value)) {
229 if (!globalStorage) {
230 console.warn(
231 `[Activity] ${contextLabel} '${key}' is spilled but no storage service is available`,
232 );
233 continue;
234 }
235
236 try {
237 let fullData: any;
238 if (spilledObjectsCache.has(value.storageRef)) {
239 fullData = spilledObjectsCache.get(value.storageRef);
240 } else {
241 const content = await globalStorage.downloadFile(value.storageRef);
242 fullData = JSON.parse(content.buffer.toString('utf8'));
243 spilledObjectsCache.set(value.storageRef, fullData);
244 }
245
246 const handle = (value as any).__spilled_handle__;
247 if (handle && handle !== '__self__') {
248 if (
249 fullData &&
250 typeof fullData === 'object' &&
251 Object.prototype.hasOwnProperty.call(fullData, handle)
252 ) {
253 obj[key] = fullData[handle];
254 } else {
255 console.warn(
256 `[Activity] Spilled handle '${handle}' not found in downloaded data for ${contextLabel.toLowerCase()} '${key}'`,
257 );
258 obj[key] = undefined;
259 warningsToReport.push({
260 target: key,
261 sourceRef: 'spilled-storage',
262 sourceHandle: String(handle),
263 });
264 }
265 } else {
266 obj[key] = fullData;
267 }
268 } catch (err) {
269 console.error(
270 `[Activity] Failed to resolve spilled ${contextLabel.toLowerCase()} '${key}':`,
271 err,
272 );
273 throw ApplicationFailure.retryable(
274 `Failed to resolve spilled ${contextLabel.toLowerCase()} '${key}': ${err instanceof Error ? err.message : String(err)}`,
275 'SpillResolutionError',
276 );
277 }
278 }
279 }
280 }
281
282 await unspill(resolvedParams, 'Parameter');
283 await unspill(resolvedInputs, 'Input');

Callers 1

runComponentActivityFunction · 0.85

Calls 9

isSpilledDataMarkerFunction · 0.90
warnMethod · 0.80
hasMethod · 0.80
parseMethod · 0.80
errorMethod · 0.80
getMethod · 0.65
downloadFileMethod · 0.65
pushMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected