Skip to content

fix(sdks/ts): don't crash on Node watch-mode messages#4284

Open
princed wants to merge 2 commits into
hatchet-dev:mainfrom
CarbonHQ:fix-heartbeat-worker-watch-mode-messages
Open

fix(sdks/ts): don't crash on Node watch-mode messages#4284
princed wants to merge 2 commits into
hatchet-dev:mainfrom
CarbonHQ:fix-heartbeat-worker-watch-mode-messages

Conversation

@princed

@princed princed commented Jun 26, 2026

Copy link
Copy Markdown

Description

Fixes a Node watch-mode compatibility issue in the TypeScript SDK heartbeat worker. Newer Node worker reload/watch behaviour can emit internal worker-thread messages such as watch:require and watch:import through the normal message event, see nodejs/node#62368.

The heartbeat controller previously assumed every worker message was a heartbeat log message and dynamically dispatched this.logger[message.type](message.message), which can fail for those internal messages.

For internal I used a much simpler fix via yarn patch, please let me know if that's something you prefer instead, happy to update the PR.

diff --git a/clients/dispatcher/heartbeat/heartbeat-controller.js b/clients/dispatcher/heartbeat/heartbeat-controller.js
index 246cb771d0beeb1d5ecaffb0c28bd5ebfb145c9e..32e9b0f6a4eff21649f27888d6374289a2727c3e 100644
--- a/clients/dispatcher/heartbeat/heartbeat-controller.js
+++ b/clients/dispatcher/heartbeat/heartbeat-controller.js
@@ -45,7 +45,7 @@ class Heartbeat {
                     },
                 });
                 this.heartbeatWorker.on('message', (message) => {
-                    this.logger[message.type](message.message);
+                    this.logger[message.type]?.(message.message);
                 });
             }
         });

Similar problem was also encounter in other projects, e.g. https://redirect.github.com/pinojs/thread-stream/pull/213

Type of change

  • Bug fix (non-breaking change which fixes an issue)

What's Changed

  • Added zod schema for heartbeat messages
  • Added runtime guard based on the schema

Checklist

Changes have been:

  • Tested (unit tests and manually)
  • Linted and formatted
  • Documented (where applicable)
  • Added to CHANGELOG (where applicable) -- see Keep a Changelog

Testing

  • Tested with AI-generated units test that were subsequently deleted to comply with the AI policy
  • Manually using yarn link in an affected project.

🤖 AI Disclosure
  • I acknowledge that an LLM was used in the creation of this Pull Request, in accordance with Hatchet's AI_POLICY.md.
  • Details: AI-generated test were deleted to comply with the policy

@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

@princed is attempting to deploy a commit to the Hatchet Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the sdk-ts Related to the Typescript SDK label Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sdk-ts Related to the Typescript SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant