-
Notifications
You must be signed in to change notification settings - Fork 158
Add support for custom class instance serialization #762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add support for custom class instance serialization #762
Conversation
🦋 Changeset detectedLatest commit: 3a3ac36 The changes in this PR will be included in the next version bump. This PR includes changesets to release 15 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🧪 E2E Test Results❌ Some tests failed Summary
❌ Failed Tests🌍 Community Worlds (21 failed)mongodb (1 failed):
redis (1 failed):
starter (18 failed):
turso (1 failed):
Details by Category✅ ▲ Vercel Production
✅ 💻 Local Development
✅ 📦 Local Production
✅ 🐘 Local Postgres
✅ 🪟 Windows
❌ 🌍 Community Worlds
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Will get to this by your morning tomorrow |
VaguelySerious
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM to merge, though some issues we should fix in follow-ups afterwards:
1: O11y
O11y code will fail when inspecting a run/step with this custom serialization. In the web UI, in the trace viewer sidebar panel, you get:
The console shows Error: Failed to hydrate data, which comes from web-shared server-actions when calling hydrateResourceIO from core/src/observability.ts.
In the CLI, it's a bit better, where for wf i steps -r wrun_01KF32121K0XCTS4JSCJQ5503V --withData, I get this nicer error: Error] Error: Class "class//example/workflows/10_single_stmt_control_flow.ts//Point" not found. Make sure the class is registered with registerSerializationClass.
For both, it'd be nice if we could follow-up with a PR that fixes these.
2: Run failure not showing error state
This is an issue that already exists and isn't due to this PR, but is made a lot clearer in this PR: if I fail to provide the right symbols, then I get an error in the console of the runtime that looks pretty good (Failed to queue message: WorkflowRuntimeError: Failed to serialize step arguments. Ensure you're passing serializable types [... some more info that's helpful ...]), BUT the run doesn't actually fail, it just gets stuck in "running".
I imagine a lot of runs stuck in "running" with no steps are down to something like this, since it applies to many serialization issues.
CC @pranaygp
If the queue call fails, we should update the Run to be in error state generally.
| * Note: We use Symbol.for() directly instead of importing WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE | ||
| * because the SWC plugin specifically looks for the `Symbol.for('workflow-serialize')` pattern | ||
| * in computed property names. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. I'm fine with the e2e test just covering one of the possible states, since we have compiler tests for the other two, but the comment needs updating
Signed-off-by: Peter Wielander <[email protected]>
…e objects" This reverts commit 94630a5.
|
@TooTallNate Sorry, I accidentally pushed to this branch. I reverted the pushed commit since I didn't want to force-push, just FYI. |

Added support for custom class instance serialization across workflow/step boundaries.
What changed?
@workflow/serdepackage withWORKFLOW_SERIALIZEandWORKFLOW_DESERIALIZEsymbolsHow to test?
The PR includes a new e2e test
customSerializationWorkflowthat demonstrates the feature:Run the e2e test to verify that class instances are properly serialized and deserialized.
Why make this change?
Previously, user-defined class instances couldn't be passed between workflows and steps without losing their prototype chain and methods. This change allows developers to define custom serialization/deserialization logic for their classes, enabling proper reconstruction of instances with their full functionality intact when crossing workflow/step boundaries.