Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/core/src/v3/utils/ioSerialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,15 @@ interface ReplacerOptions {
}

function makeSafeReplacer(options?: ReplacerOptions) {
const seen = new WeakSet<any>();

return function replacer(key: string, value: any) {
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return "[Circular]";
}
seen.add(value);
}
// Check if the key should be filtered out
if (options?.filteredKeys?.includes(key)) {
return undefined;
Expand Down
27 changes: 27 additions & 0 deletions references/hello-world/src/trigger/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,30 @@ export const resourceMonitorTest = task({
};
},
});

export const circularReferenceTask = task({
id: "circular-reference",
run: async (payload: { message: string }, { ctx }) => {
logger.info("Hello, world from the circular reference task", { message: payload.message });

// Create an object
const user = {
name: "Alice",
details: {
age: 30,
email: "[email protected]",
},
};

// Create the circular reference
// @ts-expect-error - This is a circular reference
user.details.user = user;

// Now user.details.user points back to the user object itself
// This creates a circular reference that standard JSON can't handle

return {
user,
};
},
});