Skip to content

typescript: MethodProgress returns a promise and the guide says when to await it #2112

Closed

Description

@yyhhyyyyyy

The TypeScript progress callback has been asynchronous since the runtime moved to rutis 0.23 (#1941, ADR 025 D4): a callback handed over by another plugin or the host is awaited outside a synchronous call, so each progress(...) is a frame the host dispatches on its own task. The public declaration and the authoring guide still describe a synchronous void call.

  • npm/plugin.d.ts:568 declares export type MethodProgress = <T>(data: T & CheckedData<T>) => void;.
  • docs/typescript-plugin-authoring.md:584 shows progress({ phase: 'started' }); without await.

The flake in #2082 is the observable consequence: a method that sends started and then settled without awaiting either lets the two notices race, so a client can receive settled first or lose started when the reply closes the progress channel. #2083 fixed the fixture behind that failure and left the type and the guide as the separate decision this issue takes.

Both reviews on #2083 asked for that part:

  • eric8810 (review 6016766788) asked for a guide sentence stating "that ordering across successive progress calls requires awaiting each one".
  • zerob13 (review 6016801609) wrote "The authoring example and MethodProgress return type can be clarified separately."

The change has three parts:

  1. npm/plugin.d.ts: MethodProgress returns Promise<void>, so the declaration matches the runtime the callback talks to.
  2. docs/typescript-plugin-authoring.md: the session method example awaits the call, and the text states the two cases that need it, keeping several progress notices in order and making sure a notice is queued before the method returns and the reply closes the channel.
  3. runtime/plugin-sdk.test.mjs: the compiled example asserts that progress(...) is a Promise<void> and keeps the calls that ignore the result, and the synchronous stubs passed to MethodHandler and SessionMethodHandler become async () => {}.

Effect on code outside this repository: a plugin that calls progress(...) without awaiting it still type-checks under tsc --strict, so the guide, not the type, has to say when to await. Code that stores the result in a Promise<void> fails with TS2322 today, and a unit test that passes a synchronous stub as the progress callback fails to compile with TS2345 after the change. A project that enables the typescript-eslint no-floating-promises rule starts reporting progress calls it does not await.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions