[core] QuickJS terminal hook drain drops hook_disposed when a later same-token hook is also disposed before return

Open
#5,065 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@akasakariko is already working on this.

Since Oct 29, 2026.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
node.js, typescript

Research direction

Start by tracing the QuickJS completion drain and the hook event persistence path; the issue does not name files or tests. Reproduce with WORKFLOW_VM=quickjs using two disposed hooks with the same token in the final turn, then compare the persisted event order with the default Node VM. Done means the earlier hook_disposed is persisted before the later hook_created and the token conflict is avoided.

Written by the indexing model from the issue text.

Description

Describe the Bug

When running on the QuickJS engine (WORKFLOW_VM=quickjs), if a workflow disposes a hook and then creates and disposes another hook with the same token in the final turn before returning (for example, using block-scoped or function-scoped using hook = createHook({ token })), the runtime omits the hook_disposed event for the earlier hook while still writing hook_created for the second hook. As a result, the second hook's creation conflicts with the first hook on the same token at workflow completion instead of succeeding like on the default Node VM engine.

Steps to Reproduce
  1. Enable the QuickJS runtime (WORKFLOW_VM=quickjs).
  2. Run a workflow that registers a hook with token 'shared', suspends and resumes, disposes that hook, and then in the final turn declares using hook2 = createHook({ token: 'shared' }) (or calls hook2.dispose()) before returning.
  3. Inspect the run's persisted events: the first hook's hook_disposed event is skipped during the completion drain, and the second hook's hook_created event conflicts with the still-active token.
Expected Behavior

The first hook's hook_disposed event should still be persisted before the second hook's hook_created event whenever a later uncommitted hook with the same token is drained at workflow completion, even if that second hook was also disposed before the workflow returned.

Environment
  • @workflow/core: 5.2.3 (main commit 9d0f748)
  • Runtime: QuickJS (WORKFLOW_VM=quickjs)
  • Node.js: v24.22.1
Dominant language
TypeScript
Stars
2.5k
Forks
401
Avg merge
1d 21h
Merged PRs (30d)
201

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel/workflow

All issues in vercel/workflow

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.