Skip to content

fix(plugin): return a promise from MethodProgress - #2114

Merged
yyhhyyyyyy merged 5 commits into
mainfrom
hui/method-progress-promise
Nov 23, 2026
Merged

yyhhyyyyyy merged 5 commits into
mainfrom
hui/method-progress-promise

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

progress(...) has been asynchronous since the runtime moved to rutis 0.23 (#1941, ADR 025 D4): the host hands the callback over and awaits it outside a synchronous call, so each call is a frame the host dispatches on its own task. npm/plugin.d.ts:568 still declared it as returning void, and the authoring guide showed progress({ phase: 'started' }) without await.

The failure 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. Its two reviews asked for this part separately:

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

Change

  • npm/plugin.d.ts: MethodProgress returns Promise<void>, so the declaration matches the call the runtime makes.
  • docs/typescript-plugin-authoring.md: the session method example awaits the call, and the text states the two cases that need an await, keeping several progress notices in order and having a notice queued before the method returns and the reply closes the channel.
  • runtime/plugin-sdk.test.mjs: the compiled example stores the progress result in a Promise<void> and keeps the calls that ignore it, and the four synchronous stubs passed to MethodHandler and SessionMethodHandler became async () => {}.

The guide's TypeScript examples are extracted and compiled by the SDK test, so the await in the example is type checked along with the rest.

Evidence

The first commit adds only the Promise<void> assertion to the compiled example. With the declared type unchanged it fails type checking with error TS2322: Type 'void' is not assignable to type 'Promise<void>' at that line; with the type change the same test passes.

The four stubs fail with error TS2345: Argument of type '() => void' is not assignable to parameter of type 'MethodProgress' until they return a promise, which is the change in the second and third commits.

node --test runtime/plugin-sdk.test.mjs runtime/light-ocr-helper.test.mjs runtime/light-ocr-row.test.mjs passes all 22 tests, tsc -p runtime/plugins/workflow/tsconfig.json passes, and the Node-backed flow that sends progress notices from a TypeScript Session method, transport_flow session_typescript::node_session_typescript_tools_methods_and_generation_lifetimes, passes.

Effect on code outside this repository

  • A unit test that calls a MethodHandler or SessionMethodHandler directly and passes a synchronous stub as the progress callback fails to compile with TS2345 and needs async () => {}.
  • A project that enables the typescript-eslint no-floating-promises rule starts reporting progress(...) calls it does not await.
  • A plugin that calls progress(...) without awaiting it still compiles under tsc --strict, so the guide, not the type, is what says when to await.

Intentional breaking change

MethodProgress now returns Promise<void>, matching the callback the host already supplies. This is an intentional breaking change for code that calls the exported MethodHandler or SessionMethodHandler directly: a synchronous callback such as () => {} fails with TS2345 and migrates to async () => {}. Handlers registered through managementMethods.register or sessionMethods.register keep the same callback at runtime, and no host build is required. The migration and the callback's delivery and rejection behaviour are documented in docs/typescript-plugin-authoring.md under "Session tools and client methods", and recorded under "Method progress type compatibility" in docs/release/README.md.

Fixes #2112

The compiled session method stores the progress result in a Promise<void>, which the packed declarations do not declare yet, so this commit fails type checking until the type lands.

Refs #2112.
The progress callback the host hands a method has been asynchronous since the runtime moved to rutis 0.23, so the declaration, the authoring example and the call shapes now say so. The guide states the two cases that need an await: keeping several progress notices in order, and having a notice queued before the reply closes the channel.

A plugin that ignores the result still compiles, and the compiled example keeps those calls.

Refs #2112.
Its synchronous callback raised TS2345 on its own, which satisfied the ts-expect-error directive that pins the missing sessionId. Returning a promise leaves that directive with the error it was written for.

Refs #2112.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P2] Keep synchronous progress callbacks valid for direct SDK callers, or document the intentional breaking change. The host really does supply an awaitable callback, but npm/plugin.d.ts:565–574 uses the same MethodProgress type for callers invoking the public handler types directly. Changing it to Promise<void> rejects previously valid synchronous callbacks; the SDK test changes four such stubs on this PR. Please separate the host-supplied contract from the direct-call input if both are supported, or explicitly record the breaking decision and migration. Also clarify at docs/typescript-plugin-authoring.md:647–653 that fulfillment is not a delivery acknowledgment: the host can drop notices, and detached calls need rejection handling. The Linux SDK and transport tests and the required CI gate passed on the reviewed integration.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I verified the shared Process/Session callback is asynchronous and the SDK suite and Node-backed Session method flow passed on the exact Linux job. I agree with keeping an honest Promise<void> for a host-supplied callback rather than widening it to void | Promise<void>; the latter would make callers handle a case the host does not produce. The PR description already has the right mock migration (async () => {}); put that in the consumer-facing guide or release notes, and explain that await orders the host's send attempts, not client delivery.

Nonblocking follow-up: the existing fast Process example.status fixture still fires started and settled without awaiting. It would benefit from the same before-reply ordering test as Session.

… change

The authoring guide now states that awaiting the callback orders the host's send attempts without acknowledging delivery, the cases where the host drops a notice, the rejection a detached call needs to handle, and the async mock for a handler called directly.

The release notes record the breaking change to MethodProgress: a direct caller that passes a synchronous callback is rejected with TS2345 and migrates to async () => {}. The runtime callback is unchanged.

Refs #2112.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Thanks. I took the second option: the breaking change is recorded rather than splitting the host contract from the direct-call input. The authoring guide states, under "Session tools and client methods", that awaiting the callback orders the host's send attempts and is not a delivery acknowledgment; the host drops progress a method does not declare, progress sent after it hands over the reply, and progress its connection cannot take, including after a disconnect, while the call itself still resolves. A detached progress(...) call returns a promise that can reject, so it needs .catch(...), and a unit test that calls MethodHandler or SessionMethodHandler directly passes async () => {}.

The release notes have a new "Method progress type compatibility" section: MethodProgress returns Promise<void>, a direct caller's synchronous callback fails with TS2345, and the migration is async () => {}. The runtime callback is unchanged, so no host build is required.

Commit 465c620.

@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Agreed on keeping Promise<void>. The mock migration is in docs/typescript-plugin-authoring.md, in the paragraph after the callback ordering text, and in the new "Method progress type compatibility" section of docs/release/README.md: a direct caller passes async () => {}, and a synchronous callback fails with TS2345. Both places state that await orders the host's send attempts, not client delivery, and that the host can drop a notice; the guide lists the cases and also says a detached call needs .catch(...).

The fast Process example.status fixture is not part of this PR. Awaiting its started and settled notices and adding a before-reply ordering test for Process, like the Session one, is left for a separate follow-up.

Commit 465c620.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The intentional source break and direct-call migration are now explicit in the guide and release notes. The guide distinguishes best-effort delivery from send ordering and addresses detached rejection handling. The exact integration passed the Linux SDK and Node-backed transport suites and the required gate. One non-blocking wording refinement: distinguish the App Server's progress allowance (a dropped notice can still fulfill) from the rutis transfer limit (which can reject).

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at head 465c620.

This is the other half of #2083, and it is the half that matters more: the fixture fix made one test deterministic, this makes the declaration and the guide tell authors the truth, so the next plugin does not reproduce it. MethodProgress returning Promise<void> matches what rutis 0.23 actually does — the host hands the callback over and awaits it outside a synchronous call, so each call is a frame dispatched on its own task — and the example now awaits.

The guide paragraph is the part I would have asked for and could not have written as well: it says awaiting orders the host's send attempts rather than acknowledging delivery to the client, then names the cases where progress is dropped while the call still resolves (undeclared progress, progress after the reply is handed over, a connection that cannot take it), and closes the trap a promise introduces — a detached call can reject, so attach .catch. The note that a unit test calling a handler directly must pass async () => {} is the detail that will otherwise cost someone an afternoon.

The release note is also the right addition: a declaration that changed shape is something an existing TypeScript plugin can feel.

Blocking: none.

Checks are green at this head. I read the guide delta, the plugin.d.ts change, the file list and the PR body; I did not read the SDK test change or the release note's text, and ran nothing.

Non-blocking: none.

The authoring guide and the release notes now state the two outcomes separately: the App Server's progress allowance is best effort, so a dropped notice leaves the call's reply intact, while a progress call whose encoded frame exceeds the rutis session's max_transfer fails with bad-value and rejects the promise. A closed bridge rejects a progress call as well, so the guide keeps the detached-call .catch(...) guidance.
@yyhhyyyyyy

Copy link
Copy Markdown
Collaborator Author

Thanks. Both places now separate the two outcomes. The guide says the App Server's progress allowance is best effort: a notice from a method that does not declare progress, one sent after the reply is handed over, or one its connection cannot take is dropped while the call still resolves (connection.rs, methods.rs). It then says the rutis transfer limit is not best effort: a call whose encoded frame exceeds the session's max_transfer fails with bad-value (rpc.rs), and the JS call's promise rejects (session.ts). The release note states the same distinction in one sentence.

Fixed in 1104c76.

@eric8810 eric8810 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at head 1104c76.

Approving, citing my review at 465c620d. The one commit since then is a documentation refinement, and it fixes a distinction the earlier text muddled: it separated the App Server's best-effort drops — progress a method does not declare, progress after the reply is handed over, progress a connection cannot take — from the limits rutis enforces, where an encoded frame over the session's max_transfer fails with bad-value and a call on a closed bridge fails too. That matters because the two have different owners and different consequences: the first is loss the call survives, the second is a rejection a detached call must .catch. Naming max_transfer and bad-value also gives an author something to look up rather than a paraphrase.

The .catch advice and the async () => {} note for handlers called directly are unchanged, so the practical guidance an author needs is the same; only its justification is now accurate. The release note line moves with it.

Blocking: none.

Checks are green at this head. I read the doc delta and the commit list; I did not re-read the declaration, the SDK test or the release note at this head, and ran nothing.

Non-blocking: none.

@zerob13 zerob13 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Rechecked the documentation-only follow-up. The guide and release notes now distinguish a best-effort App Server drop from a rutis transfer rejection, while retaining the direct-call migration. No runtime or declaration changes since my prior approval; the required checks are green.

@yyhhyyyyyy
yyhhyyyyyy merged commit d5dbed9 into main Nov 23, 2026
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.

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

3 participants