Skip to content

fix: add Node event-bus logging and awaitable worker.stop() - #540

Merged
kartikeya-27 merged 3 commits into
ByteVeda:masterfrom
stromanni:fix/node-emit-logging-stop-teardown
Jul 24, 2026
Merged

fix: add Node event-bus logging and awaitable worker.stop()#540
kartikeya-27 merged 3 commits into
ByteVeda:masterfrom
stromanni:fix/node-emit-logging-stop-teardown

Conversation

@stromanni

@stromanni stromanni commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #521 — the two Node robustness items from the SDK parity audit.

Event bus (sdks/node/src/events.ts)
Emitter.emit() isolated listener throws and async rejections but logged nothing, so a
misbehaving listener was invisible. Both paths now log.debug with the event name and the
error; isolation is unchanged.

Worker.stop() (sdks/node/src/worker.ts)
stop() fired resources.teardownWorker() fire-and-forget, returning before worker-scoped
resources were disposed — surprising in test teardown. It now returns Promise<void> that
resolves once teardown completes. Dispatch, the heartbeat, log consumers, native.stop() and
the worker.stopped emit all still run synchronously before the promise is returned, so callers
that ignore the result behave exactly as before. The promise never rejects; teardown failures are
logged. taskito run awaits it before exiting.

Tests

  • test/worker/emitter.test.ts — throwing listener logged and siblings still run, async
    rejection logged, no output when listeners behave.
  • test/resources/resources.test.tsawait worker.stop() observes a slow dispose as
    finished, with no polling.

Docs updated: Node worker API reference, workers guide, dependency-injection teardown section,
plus a CHANGELOG entry per fix.

Local run: biome check clean, targeted tests pass, full suite 422 passed. The 10 dashboard test
files fail in beforeAll on pnpm run build:dashboard (vite not installed in dashboard/) —
pre-existing environment gap, unrelated to these changes.

Summary by CodeRabbit

  • Bug Fixes
    • worker.stop() now returns a promise that completes after worker-scoped resources are disposed.
    • Shutdown remains safe when the promise is not awaited, while awaiting it enables reliable graceful teardown.
    • Event listener errors are now logged at debug level without interrupting other listeners or worker execution.
    • Listener failures are isolated for both synchronous throws and asynchronous rejections.
  • Documentation
    • Updated shutdown guidance and examples to explain and demonstrate awaiting worker.stop().

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@stromanni, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 944155f3-46cc-4eea-9970-817246334072

📥 Commits

Reviewing files that changed from the base of the PR and between 172cadb and bdd9a42.

📒 Files selected for processing (1)
  • docs/content/docs/shared/guides/core/workers.mdx
📝 Walkthrough

Walkthrough

Node worker shutdown now returns a promise that completes after worker-scoped resource disposal. Event listener throws and rejections are debug-logged while sibling listeners continue executing. Documentation, CLI shutdown handling, and tests were updated accordingly.

Changes

Node robustness updates

Layer / File(s) Summary
Awaitable worker shutdown
sdks/node/src/worker.ts, sdks/node/src/cli/commands/run.ts, sdks/node/test/resources/resources.test.ts, docs/content/docs/node/..., docs/content/docs/shared/..., CHANGELOG.md
worker.stop() returns a promise tied to worker-scoped disposal; CLI shutdown and documentation now await or describe the completion contract, with coverage for delayed disposal.
Event listener failure logging
sdks/node/src/events.ts, sdks/node/test/worker/emitter.test.ts
Synchronous listener throws and asynchronous rejections are logged at debug level without interrupting sibling listeners, with tests for failure and successful emission paths.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: pratyush618

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement both linked requirements: debug logging for listener failures and worker.stop() waiting for resource teardown.
Out of Scope Changes check ✅ Passed The docs, tests, changelog, and run-command update are all aligned with the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes: event-bus logging and making worker.stop() awaitable.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@stromanni stromanni changed the title fix: Node event-bus logging and awaitable worker.stop() fix: add Node event-bus logging and awaitable worker.stop() Jul 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/content/docs/shared/guides/core/workers.mdx`:
- Around line 478-479: Update the worker shutdown example to await the existing
worker.stop() call directly rather than invoking worker.stop() twice, preserving
the documented in-flight draining and resource teardown behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5ee18069-30d2-4cfd-9f53-09ca08f664af

📥 Commits

Reviewing files that changed from the base of the PR and between f447156 and 172cadb.

📒 Files selected for processing (9)
  • CHANGELOG.md
  • docs/content/docs/node/api-reference/worker.mdx
  • docs/content/docs/node/guides/resources/dependency-injection.mdx
  • docs/content/docs/shared/guides/core/workers.mdx
  • sdks/node/src/cli/commands/run.ts
  • sdks/node/src/events.ts
  • sdks/node/src/worker.ts
  • sdks/node/test/resources/resources.test.ts
  • sdks/node/test/worker/emitter.test.ts

Comment thread docs/content/docs/shared/guides/core/workers.mdx Outdated
@kartikeya-27
kartikeya-27 merged commit 35ec678 into ByteVeda:master Jul 24, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node robustness: silent event-bus emit and fire-and-forget stop teardown

2 participants