Skip to content

[o11y] Add undefined to tailStream return types - #7436

Draft
fhanau wants to merge 1 commit into
mainfrom
felix/091826-tailstream
Draft

fhanau wants to merge 1 commit into
mainfrom
felix/091826-tailstream

Conversation

@fhanau

@fhanau fhanau commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Returning undefined indicates that tail events for the given worker event can be ignored, which is used to shut down the tail stream early as an optimization.

Comment thread types/defines/rpc.d.ts
scheduled?(controller: ScheduledController): void | Promise<void>;
tail?(events: TraceItem[]): void | Promise<void>;
tailStream?(event: TailStream.TailEvent<TailStream.Onset>): TailStream.TailEventHandlerType | Promise<TailStream.TailEventHandlerType>;
tailStream?(event: TailStream.TailEvent<TailStream.Onset>): TailStream.TailEventHandlerType | Promise<TailStream.TailEventHandlerType> | undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

async tailStream() { return undefined; } produces Promise<undefined>, which this signature still rejects because undefined is only outside the promise. The runtime explicitly awaits promises and treats a fulfilled undefined as the early-stop signal. Please also apply this same return contract to ExportedHandlerTailStreamHandler in src/workerd/api/global-scope.h and regenerate the snapshots; otherwise ordinary default-module tail workers remain unable to use the optimization.

Suggested change
tailStream?(event: TailStream.TailEvent<TailStream.Onset>): TailStream.TailEventHandlerType | Promise<TailStream.TailEventHandlerType> | undefined;
tailStream?(event: TailStream.TailEvent<TailStream.Onset>): TailStream.TailEventHandlerType | Promise<TailStream.TailEventHandlerType | undefined> | undefined;

@ask-bonk

ask-bonk Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

Adds undefined to the RPC tailStream return types.

  1. P1: The type still excludes promised undefined, and default-module handlers remain unchanged. Posted 1 inline suggestion.

github run

@fhanau
fhanau force-pushed the felix/091826-tailstream branch from dd26643 to 8a3cc98 Compare September 18, 2026 22:33
@github-actions

github-actions Bot commented Sep 18, 2026

Copy link
Copy Markdown

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

Returning undefined indicates that tail events for the given worker event can be
ignored, which is used to shut down the tail stream early as an optimization.
@fhanau
fhanau force-pushed the felix/091826-tailstream branch from 8a3cc98 to 889e8dd Compare September 19, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant