From 99ab2e13a2f1b2b0884bca62da3c6af3e489a229 Mon Sep 17 00:00:00 2001 From: huihui Date: Mon, 23 Nov 2026 17:05:39 +0800 Subject: [PATCH 1/5] test(runtime): pin the progress callback's promise result The compiled session method stores the progress result in a Promise, which the packed declarations do not declare yet, so this commit fails type checking until the type lands. Refs #2112. --- runtime/plugin-sdk.test.mjs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/plugin-sdk.test.mjs b/runtime/plugin-sdk.test.mjs index 9b3b70d566..6544e01511 100644 --- a/runtime/plugin-sdk.test.mjs +++ b/runtime/plugin-sdk.test.mjs @@ -93,7 +93,8 @@ void management.register('fixture', [], typedHandler); void methods.register('fixture', [], async () => initialReply); void management.register('fixture', [], async () => configuredReply); void methods.register('fixture', [], async (call, cancelled, progress) => { - progress(configured); + const sent: Promise = progress(configured); + await sent; progress(entry); progress({}); // @ts-expect-error progress carries data, not callbacks. From 2c0a473be3795f06f9aa40857be14e1c02c54d6c Mon Sep 17 00:00:00 2001 From: huihui Date: Mon, 23 Nov 2026 17:06:23 +0800 Subject: [PATCH 2/5] types(plugin): return a promise from MethodProgress 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. --- docs/typescript-plugin-authoring.md | 8 ++++++-- npm/plugin.d.ts | 2 +- runtime/plugin-sdk.test.mjs | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/typescript-plugin-authoring.md b/docs/typescript-plugin-authoring.md index 7c3c25b55c..71339c0088 100644 --- a/docs/typescript-plugin-authoring.md +++ b/docs/typescript-plugin-authoring.md @@ -581,7 +581,7 @@ export const sessionExample = definePlugin({ 'session.example', [{ name: 'session.example.echo', mutating: false, interruption: 'report', progress: true }], async (call, _cancelled, progress) => { - progress({ phase: 'started' }); + await progress({ phase: 'started' }); return { kind: 'value', value: call.params }; }, ); @@ -646,7 +646,11 @@ under the `hello`, `daemon`, `agent` or `approval` roots; an `apply` that awaits fails its part. The registration lasts until the part unloads, and `session.methods` lists the methods registered at that call. `call` is asynchronous and receives an opaque runtime `callId`, the method and original params containing `sessionId` and -optional `branchId`; it also receives cancellation and a per-call progress callback. +optional `branchId`; it also receives cancellation and a per-call progress callback. The callback +returns a promise, and awaiting it is what keeps your notices in order: each call is a frame the host +runs on its own task, so two calls without a wait between them can arrive in either order. Await it +as well when a notice has to be queued before the method returns, because the reply closes the +progress channel and drops a send that has not run yet. Return `{kind: 'value', value}`, return a failure as data, `{code, message}`, or rethrow the service error you received. An omitted value becomes JSON null. Rpc maps a failure to the wire error: `code` becomes `appError`, with JSON-RPC code -32602 for `invalid_params` and diff --git a/npm/plugin.d.ts b/npm/plugin.d.ts index df3457e9bd..5920d13eb1 100644 --- a/npm/plugin.d.ts +++ b/npm/plugin.d.ts @@ -565,7 +565,7 @@ export type MethodReply = { kind: 'value'; value?: T } | Me export type CheckedData = T extends BridgeJsonValue | undefined ? T : T extends ((...args: never[]) => unknown) | (abstract new (...args: never[]) => unknown) ? never : T extends object ? keyof T extends never ? never : { [K in keyof T]: CheckedData } : never; -export type MethodProgress = (data: T & CheckedData) => void; +export type MethodProgress = (data: T & CheckedData) => Promise; export type SessionMethodDeclaration = MethodDeclaration; export type SessionMethodReply = MethodReply; /** How a registered management namespace serves one call. */ diff --git a/runtime/plugin-sdk.test.mjs b/runtime/plugin-sdk.test.mjs index 6544e01511..88f68c437b 100644 --- a/runtime/plugin-sdk.test.mjs +++ b/runtime/plugin-sdk.test.mjs @@ -121,7 +121,7 @@ void management.register('fixture', [], async () => ({ kind: 'other', value: con const declarations: MethodDeclaration[] = [{ name: 'example.status', mutating: false, interruption: 'report', progress: false }]; void management.register('example', declarations, handler); -void handler({ callId: 'call', method: 'example.status', params: [1, true] }, Promise.resolve(), () => {}); +void handler({ callId: 'call', method: 'example.status', params: [1, true] }, Promise.resolve(), async () => {}); // @ts-expect-error a declaration states its interruption and progress. void management.register('example', [{ name: 'example.status', mutating: false }], handler); const at = { sessionId: 'session', branchId: 'main' }; @@ -241,11 +241,11 @@ void execute({ }, Promise.resolve()); void methods.register('session.example', [{ name: 'session.example.echo', mutating: false, interruption: 'drain', progress: true }], sessionHandler); void sessionHandler({ callId: 'call', method: 'session.example.echo', params: { sessionId: 'session' } }, - Promise.resolve(), () => {}); + Promise.resolve(), async () => {}); // @ts-expect-error a Session method call names its Session. void sessionHandler({ callId: 'call', method: 'session.example.echo', params: {} }, Promise.resolve(), () => {}); void handler({ callId: 'call', method: 'example.status', params: [1, true], - origin: { connectionId: 'connection' } }, Promise.resolve(), () => {}); + origin: { connectionId: 'connection' } }, Promise.resolve(), async () => {}); const notificationOrigin: MethodDeclaration = { name: 'example.status', mutating: false, interruption: 'report', progress: false, notifications: ['example.changed'] }; void notificationOrigin; From 1bcddda7958ee252fde8a8b298e611d7a3faf3bf Mon Sep 17 00:00:00 2001 From: huihui Date: Mon, 23 Nov 2026 17:35:28 +0800 Subject: [PATCH 3/5] test(runtime): make the Session method stub asynchronous 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. --- runtime/plugin-sdk.test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/plugin-sdk.test.mjs b/runtime/plugin-sdk.test.mjs index 88f68c437b..8c9303a163 100644 --- a/runtime/plugin-sdk.test.mjs +++ b/runtime/plugin-sdk.test.mjs @@ -243,7 +243,7 @@ void methods.register('session.example', [{ name: 'session.example.echo', mutati void sessionHandler({ callId: 'call', method: 'session.example.echo', params: { sessionId: 'session' } }, Promise.resolve(), async () => {}); // @ts-expect-error a Session method call names its Session. -void sessionHandler({ callId: 'call', method: 'session.example.echo', params: {} }, Promise.resolve(), () => {}); +void sessionHandler({ callId: 'call', method: 'session.example.echo', params: {} }, Promise.resolve(), async () => {}); void handler({ callId: 'call', method: 'example.status', params: [1, true], origin: { connectionId: 'connection' } }, Promise.resolve(), async () => {}); const notificationOrigin: MethodDeclaration = { name: 'example.status', mutating: false, From 465c620d205d0ac8422324322113d66129efbb96 Mon Sep 17 00:00:00 2001 From: huihui Date: Mon, 23 Nov 2026 18:31:44 +0800 Subject: [PATCH 4/5] docs(plugin): record the progress callback's promise and its breaking 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. --- docs/release/README.md | 16 ++++++++++++++++ docs/typescript-plugin-authoring.md | 11 +++++++++++ 2 files changed, 27 insertions(+) diff --git a/docs/release/README.md b/docs/release/README.md index 882bcc1f92..dcf837196f 100644 --- a/docs/release/README.md +++ b/docs/release/README.md @@ -97,6 +97,22 @@ The JSON fields remain `name`, `systemPrompt` and rely on the removed reply type's rejection of unknown fields. There is no App Server protocol, event or persistence-format change. +## Method progress type compatibility + +The progress callback a `dimcode/plugin` method handler receives returns +`Promise`; its declaration was `() => void`. The host already supplies an +asynchronous callback, so `await progress(...)` and `progress(...).catch(...)` +now type-check, and no host build is required. The change breaks code that calls +an exported `MethodHandler` or `SessionMethodHandler` directly: a synchronous +argument such as `() => {}`, as a unit-test mock uses, fails with TS2345. Pass +`async () => {}` instead. Handlers registered through +`managementMethods.register` or `sessionMethods.register` receive the same +callback at runtime. Awaiting it orders the host's send attempts and does not +acknowledge client delivery; the host can drop a notice. The +[authoring guide](../typescript-plugin-authoring.md#session-tools-and-client-methods) +states the callback's delivery and rejection behaviour. There is no App Server +protocol, event or persistence-format change. + ## File access Under `read-only` and `workspace-write`, a file tool read (`read`, `grep` or `glob`) whose diff --git a/docs/typescript-plugin-authoring.md b/docs/typescript-plugin-authoring.md index 71339c0088..0ec1fcd659 100644 --- a/docs/typescript-plugin-authoring.md +++ b/docs/typescript-plugin-authoring.md @@ -651,6 +651,17 @@ returns a promise, and awaiting it is what keeps your notices in order: each cal runs on its own task, so two calls without a wait between them can arrive in either order. Await it as well when a notice has to be queued before the method returns, because the reply closes the progress channel and drops a send that has not run yet. + +Awaiting that promise orders the host's send attempts; it does not acknowledge +delivery to the client. 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 +progress call you do not await returns a promise that can reject, for example +when the data exceeds the channel limit or the bridge is closed, so attach +`.catch(...)` to a detached call. A unit test that calls a `MethodHandler` or +`SessionMethodHandler` directly must pass `async () => {}` as the progress +callback; the type requires a promise. + Return `{kind: 'value', value}`, return a failure as data, `{code, message}`, or rethrow the service error you received. An omitted value becomes JSON null. Rpc maps a failure to the wire error: `code` becomes `appError`, with JSON-RPC code -32602 for `invalid_params` and From 1104c7649ef8bb84c759d5dbdef836e42403be82 Mon Sep 17 00:00:00 2001 From: huihui Date: Mon, 23 Nov 2026 19:16:08 +0800 Subject: [PATCH 5/5] docs(plugin): distinguish dropped progress from a rejected transfer 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. --- docs/release/README.md | 4 +++- docs/typescript-plugin-authoring.md | 17 +++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/release/README.md b/docs/release/README.md index dcf837196f..e81c03e4d8 100644 --- a/docs/release/README.md +++ b/docs/release/README.md @@ -108,7 +108,9 @@ argument such as `() => {}`, as a unit-test mock uses, fails with TS2345. Pass `async () => {}` instead. Handlers registered through `managementMethods.register` or `sessionMethods.register` receive the same callback at runtime. Awaiting it orders the host's send attempts and does not -acknowledge client delivery; the host can drop a notice. The +acknowledge client delivery; the App Server's progress allowance can drop a +notice while the call still resolves, whereas a frame over the rutis session's +transfer limit fails the call and rejects the promise. The [authoring guide](../typescript-plugin-authoring.md#session-tools-and-client-methods) states the callback's delivery and rejection behaviour. There is no App Server protocol, event or persistence-format change. diff --git a/docs/typescript-plugin-authoring.md b/docs/typescript-plugin-authoring.md index 0ec1fcd659..0d1cf4d84d 100644 --- a/docs/typescript-plugin-authoring.md +++ b/docs/typescript-plugin-authoring.md @@ -653,14 +653,15 @@ as well when a notice has to be queued before the method returns, because the re progress channel and drops a send that has not run yet. Awaiting that promise orders the host's send attempts; it does not acknowledge -delivery to the client. 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 -progress call you do not await returns a promise that can reject, for example -when the data exceeds the channel limit or the bridge is closed, so attach -`.catch(...)` to a detached call. A unit test that calls a `MethodHandler` or -`SessionMethodHandler` directly must pass `async () => {}` as the progress -callback; the type requires a promise. +delivery to the client. The App Server's progress allowance is best effort: it +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. The rutis transfer limit is not: a call +whose encoded frame exceeds the session's `max_transfer` fails with +`bad-value`, and a call on a closed bridge fails too, so a progress call you do +not await can reject. Attach `.catch(...)` to a detached call. A unit test that +calls a `MethodHandler` or `SessionMethodHandler` directly must pass +`async () => {}` as the progress callback; the type requires a promise. Return `{kind: 'value', value}`, return a failure as data, `{code, message}`, or rethrow the service error you received. An omitted value becomes JSON null. Rpc maps a failure to