Repository navigation
fix(plugin): return a promise from MethodProgress - #2114
Conversation
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
left a comment
There was a problem hiding this comment.
[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
left a comment
There was a problem hiding this comment.
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.
|
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 The release notes have a new "Method progress type compatibility" section: Commit 465c620. |
|
Agreed on keeping The fast Process Commit 465c620. |
zerob13
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
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 Fixed in 1104c76. |
eric8810
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
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:568still declared it as returningvoid, and the authoring guide showedprogress({ phase: 'started' })withoutawait.The failure in #2082 is the observable consequence: a method that sends
startedand thensettledwithout awaiting either lets the two notices race, so a client can receivesettledfirst or losestartedwhen the reply closes the progress channel. #2083 fixed the fixture behind that failure. Its two reviews asked for this part separately:MethodProgressreturn type can be clarified separately."Change
npm/plugin.d.ts:MethodProgressreturnsPromise<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 aPromise<void>and keeps the calls that ignore it, and the four synchronous stubs passed toMethodHandlerandSessionMethodHandlerbecameasync () => {}.The guide's TypeScript examples are extracted and compiled by the SDK test, so the
awaitin 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 witherror 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.mjspasses all 22 tests,tsc -p runtime/plugins/workflow/tsconfig.jsonpasses, 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
MethodHandlerorSessionMethodHandlerdirectly and passes a synchronous stub as the progress callback fails to compile with TS2345 and needsasync () => {}.no-floating-promisesrule starts reportingprogress(...)calls it does not await.progress(...)without awaiting it still compiles undertsc --strict, so the guide, not the type, is what says when to await.Intentional breaking change
MethodProgressnow returnsPromise<void>, matching the callback the host already supplies. This is an intentional breaking change for code that calls the exportedMethodHandlerorSessionMethodHandlerdirectly: a synchronous callback such as() => {}fails with TS2345 and migrates toasync () => {}. Handlers registered throughmanagementMethods.registerorsessionMethods.registerkeep the same callback at runtime, and no host build is required. The migration and the callback's delivery and rejection behaviour are documented indocs/typescript-plugin-authoring.mdunder "Session tools and client methods", and recorded under "Method progress type compatibility" indocs/release/README.md.Fixes #2112