Skip to content

Commit e0c5ec8

Browse files
committed
fix: surface disconnect error instead of queue-closed when deferred already failed
When a client disconnects while a request is pending, disconnect() fails the deferred with PreviewAutomationClientDisconnectedError before shutting down the queue. If invoke()'s Queue.offer then observes the shutdown, it would previously return PreviewAutomationRequestQueueClosedError, masking the more specific disconnect error already recorded on the deferred. Use Deferred.poll to check whether the deferred was already completed before falling back to the queue-closed error, ensuring callers receive the correct PreviewAutomationClientDisconnectedError.
1 parent 472d593 commit e0c5ec8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

apps/server/src/mcp/PreviewAutomationBroker.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,11 @@ export const make = Effect.gen(function* PreviewAutomationBrokerMake() {
375375
timeoutMs,
376376
});
377377
if (!offered) {
378-
return yield* new PreviewAutomationRequestQueueClosedError(requestContext);
378+
const completed = yield* Deferred.poll(deferred);
379+
return yield* Option.match(completed, {
380+
onNone: () => Effect.fail(new PreviewAutomationRequestQueueClosedError(requestContext)),
381+
onSome: (effect) => effect as Effect.Effect<A, PreviewAutomationError>,
382+
});
379383
}
380384
const result = yield* Deferred.await(deferred).pipe(Effect.timeoutOption(timeoutMs));
381385
return yield* Option.match(result, {

0 commit comments

Comments
 (0)