Conversation
6 tasks
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
adenhertog
force-pushed
the
issue-331-reply
branch
from
October 4, 2026 00:18
dccf525 to
c61b020
Compare
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #331
Summary
Adds
ctx.reply(), which sends a reply straight to the queue that sent the message being handled. Every message from a bus that receives messages now carries a return address in a newreplyToattribute.Background
The request/reply guide (#330) had repliers publish the reply as an event and route it back through the sticky
workflowId. That fans the reply out to every subscriber, mixes up replies when several services ask the same service, needs a topic subscription, and drops replies sent from a workflow handler, because the handler swaps in its ownworkflowId. The maintainer's decisions on the issue: stamp a return address on every send and publish, allow any message as a reply, send replies point-to-point, and on Lambda use the source queue name when it's known.Problem
There was no reply primitive, no return address on messages, and no transport call that sends straight to a named queue.
Approach
prepareTransportOptionssetsreplyTototransport.endpointNameunless the bus is send-only (it has no queue that's read) or the endpoint name is empty. A caller can passreplyTo, orreplyTo: undefinedto leave it out. On Lambda the transport'sendpointNameis theSqsTransport'squeueName, which must already be the source queue for retries and dead-lettering. A transport without one stamps nothing, soreply()throwsReturnAddressMissing(documented in the Lambda page).HandlerContext.reply(message, attributes?): available in function handlers, class handlers, both workflow styles (WorkflowContext,workflowContext()) and incoming/handler middleware contexts. It inherits correlation and sticky attributes from the request'sTransportMessageas it arrived, not from the handling context, so a workflow replier sends the requester'sworkflowId. The workflow-replies-to-workflow test inbus-instance-reply.integration.tscovers both workflow styles. I checked it fails (2 tests) when the reply takes its sticky attributes from the handling context, which is howpublishbehaves.dispatchOutgoingwith a newOutgoingReplyContext(kind: 'reply', readonlydestination). It's buffered and flushed like any send, and dropped when the handler fails (tested).ReplyOutsideHandlingContext,ReturnAddressMissing(names the request and the reply),TransportReplyNotSupported, plusEndpointNotFoundfor the in-memory queue. All have ahelpfield.Transport.sendToAddress(endpointName, message, attributes, sendOptions)method, not aTransportSendOptionsfield. With a field, a transport that doesn't know about it, including any third-party one, would quietly ignore it and publish the reply to its topic, so the reply fans out again with no error. With a method, the bus can tell whether the transport supports replies and throwTransportReplyNotSupportedbefore anything is buffered. It also takes anyMessage, wheresend()is typed to commands andpublish()to events.EndpointNotFound.replyToproperty, so no header needs reserving.SendMessagetoresolveQueueUrl(config, endpointName)(same account and region), with the body shaped like the SNS envelope, soreadNextMessageand bus-sqs-lambda read it unchanged.replyTois a new SNS attribute and is reserved inassertSendOptions/toHeaderAttributeMap.transportTestsnow requiressendToAddress. It checks a direct send to the transport's own endpoint arrives through a custom handler with no topic, so it can only arrive point-to-point, with all its attributes includingreplyTo. It checks actx.reply()reaches the requester with its correlation and sticky attributes. The RabbitMQ and SQS integration tests also start requester, replier and bystander buses, and check that the bystander, which is subscribed to the reply type, doesn't receive the reply.request-reply.mdis rewritten aroundctx.reply(), with handler and workflow repliers in both styles and a return-address section. The fan-out caveats are gone, and the field-mapping section stays for repliers that can't usereply(). Also updated: message attributes, middleware, handling messages, the testing snippet, the custom transport page and snippet, and the SQS, RabbitMQ and Lambda pages.minor,MIGRATING.mdentries):HandlerContexthas a requiredreply,OutgoingContexthas areplykind,replyTois a reserved SQS header, andtransportTestsneedssendToAddress.Review follow-ups (latest commit):
returnAddress, which the bus stamps asreplyTo, falling back toendpointName. SQS returns the queue URL (fromqueueArn, or account + region +queueName), so cross-account and cross-region requesters work. The transport method is renamedsendToAddress(address, …)to match. SQS mapsQueueDoesNotExisttoEndpointNotFound. A bare queue name still resolves in the replier's own account and region.reply()now checks that the current handling context is this request (sameraw, still being handled) and that its handler's outbox is still open. New tests cover a kept context called while another message is handled, and a timer that fires after the handler resolved.defaultRecoverability()dead-lettersReturnAddressMissing,TransportReplyNotSupportedandEndpointNotFoundon the first failure (exported asALWAYS_UNRECOVERABLE).EndpointNotFound, dead-lettered; RabbitMQ: silently dropped). TheReplyOutsideHandlingContextandEndpointNotFoundhelp texts are corrected, and the docs nits are fixed.TestReplymust reach the bystander. They wait on events instead of sleeping.replyToon every message,replyToin received attributes, andOutgoingContext['message']widening toMessage.Rebased onto #328 (delayed delivery): delayed sends keep the
replyTostamped before they're stored, and the dispatcher sends it through unchanged (tested in core, and for RabbitMQ through a send-only transport like a scheduler's).ctx.reply()rejectsdeliverAfter/deliverAtwithDelayedReplyNotSupported(always unrecoverable): storing a reply would need a destination column in the Postgres and MongoDB outgoing-message stores, so delayed replies are left as a gap. Cross-region SQS replies go through a client for the queue's region.Things to look at:
ctx.reply()answers the message being handled. A workflow that answers in a later step can't use it, and the guide says so.🤖 Generated with Claude Code