Skip to content

-refactor: activeHandlerContext to invocation context with authRef#16

Open
ka1ii wants to merge 5 commits into
wfe-service-bindfrom
wfe-sdk-authref
Open

-refactor: activeHandlerContext to invocation context with authRef#16
ka1ii wants to merge 5 commits into
wfe-service-bindfrom
wfe-sdk-authref

Conversation

@ka1ii

@ka1ii ka1ii commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Refactor activeHandlerContext to Invocation Context

The existing activeHandlerContext stores authToken and requestId for an given invocation in the handler runtime one-to-one. This presents two problems

Race condition when handler runtime dispatches multiple messages asynchronously

Scenario:

  • HandleTransactionMessages (msg1) arrives -> we store the authTokens + requestId for that invocation
  • msg1 makes an asynchronous external request
  • msg2 arrives -> we overwrite the existing activeHandlerContext with msg2's context
  • msg1 unblocks, and is now using msg2's context

AuthRef

AuthRef is per transaction while requestId and authToken are per invocation, meaning when we handle batch + parallel invocation modes, we would need a way to store the authref on a per transaction basis.

AsyncLocalStorage for storing handlerContext

AsyncLocalStorage lets us to safely store the activeHandlerContext within the confines of a callback, solving both of the problems that we currently have.

It also eliminates solutions that requires custom data structure inside of handler runtime.

@ka1ii ka1ii marked this pull request as ready for review April 13, 2026 14:00
@ka1ii ka1ii requested a review from a team as a code owner April 13, 2026 14:00
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.

1 participant