Skip to content

diagnostics_channel: add BoundedChannel and scopes#61680

Open
Qard wants to merge 3 commits intonodejs:mainfrom
Qard:dc-windows
Open

diagnostics_channel: add BoundedChannel and scopes#61680
Qard wants to merge 3 commits intonodejs:mainfrom
Qard:dc-windows

Conversation

@Qard
Copy link
Member

@Qard Qard commented Feb 4, 2026

This adds BoundedChannel, adds a using syntax equivalent to runStores, and modifies the internals of TracingChannel to use these to avoid closures in several places.

Why BoundedChannel?

Reviewers asked why a new class is needed instead of just using the existing channel() or tracingChannel() APIs. Here's the motivation:

  • vs channel(): A bare Channel has no built-in concept of start/end lifecycle events or store binding for async context propagation. BoundedChannel combines two channels with a withScope() / run() API that ties start → store entry → user code → end → store exit into a single unit, which a raw channel can't express.

  • vs tracingChannel(): TracingChannel is designed for tracing operations with async continuations (it has 5 events: start, end, asyncStart, asyncEnd, error). BoundedChannel is a simpler, synchronous-only primitive with just start and end. It is also used internally by TracingChannel to implement its call window and continuation window, making the code cleaner and removing several closure allocations.

The name "Bounded" reflects that the scope is bounded by the using block — start fires when the scope begins, end fires when it is disposed.

Depends on #61674

cc @nodejs/diagnostics

@Qard Qard self-assigned this Feb 4, 2026
@Qard Qard added the diagnostics_channel Issues and PRs related to diagnostics channel label Feb 4, 2026
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/web-infra

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Feb 4, 2026
@Qard Qard added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 4, 2026
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Feb 4, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 4, 2026

Failed to start CI
   ⚠  No approving reviews found
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/21678728231

@Qard Qard force-pushed the dc-windows branch 7 times, most recently from c764f06 to 1018c57 Compare February 4, 2026 17:50
Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

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

Could you please expand on PR description on why this is needed? We have channels, tracingChannels and now windowChannel, it would be great to know for which kind of situations we need each one of them.

added: REPLACEME
-->

> Stability: 1 - Experimental
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> Stability: 1 - Experimental
> Stability: 1 - Experimental

Perhaps 1.1 Active Development instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

The particular change is inherited from #61674. Do you want that made there? What about the new APIs in diagnostics_channel? Same status?

@Qard
Copy link
Member Author

Qard commented Feb 4, 2026

WindowChannel is mainly just to enable using syntax scopes, but is exposed as there are possible use cases where one may want to emit events around a block/scope without the greater complexity of TracingChannel.

It's also replacing most of the internals of TracingChannel to make it more coherent since there seemed to be a lot of misunderstanding of how it worked. Now TracingChannel is just a WindowChannel around start + end, a WindowChannel around asyncStart + asyncEnd, and an error channel.

@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 98.42271% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.69%. Comparing base (06a8240) to head (bf59a1f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/diagnostics_channel.js 98.17% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #61680    +/-   ##
========================================
  Coverage   89.68%   89.69%            
========================================
  Files         676      677     +1     
  Lines      206578   206784   +206     
  Branches    39555    39588    +33     
========================================
+ Hits       185267   185470   +203     
- Misses      13446    13448     +2     
- Partials     7865     7866     +1     
Files with missing lines Coverage Δ
...nternal/async_local_storage/async_context_frame.js 100.00% <100.00%> (ø)
lib/internal/async_local_storage/async_hooks.js 98.03% <100.00%> (+0.08%) ⬆️
lib/internal/async_local_storage/run_scope.js 100.00% <100.00%> (ø)
lib/diagnostics_channel.js 98.88% <98.17%> (+0.38%) ⬆️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

});
```

#### `diagnostics_channel.windowChannel(nameOrChannels)`
Copy link
Member

Choose a reason for hiding this comment

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

This name window channel is confusing. It's not related to the specific window API in JavaScript. It reads to me that it is a version of tracing channel that enables using support. I feel terms like scope could be a more intuitive name.

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel "scope" is an equally problematic name in that it makes many think of lexical scope which is typically associated with closures, which is exactly what this is explicitly trying to not be. Naming is hard. 🤷🏻

I'm happy to pick a different name if you have a better idea for one, but I'm not convinced "scope" is much better. I had also considered "block" but that also has weird associations with "blocking" which is again misleading. 😐

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with BoundedChannel. Hopefully that is clear and unique enough naming.

Qard added 2 commits March 18, 2026 00:40
Adds support for using scope = storage.withScope(data) to do
the equivalent of a storage.run(data, fn) with using syntax.
This enables avoiding unnecessary closures.
@Qard Qard changed the title diagnostics_channel: add WindowChannel and scopes diagnostics_channel: add BoundedChannel and scopes Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics_channel Issues and PRs related to diagnostics channel lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants