Context passing between client, workflows and activities using interceptors

I’ve seen some discussion on passing context between clients, workflows and activities, but no good end-to-end example. Our use-case is a multi-tenant app, where the tenant ID is determined on the client side, but needs to be available in almost all activities. So we’re thinking of using client/workflow/activity interceptors to pass the tenant ID using headers from client to the workflows and on to each activity.

I’ve got a working example of how this might look like here: samples-typescript/context-passing at context-passing · jhecking/samples-typescript · GitHub

One open question I have is regarding passing the context between the inbound and outbound workflow interceptors. Here is how I am currently doing it:

import {
  ActivityInput,
  WorkflowInterceptorsFactory,
  WorkflowInboundCallsInterceptor,
  WorkflowExecuteInput,
  WorkflowOutboundCallsInterceptor,
} from '@temporalio/workflow'
import { Payload } from '@temporalio/common'

let contextPayload: Payload

class WorkflowInboundContextInterceptor implements WorkflowInboundCallsInterceptor {
  async execute(input: WorkflowExecuteInput, next: any) {
    contextPayload = input.headers.context
    return next(input)
  }
}

class WorkflowOutboundContextInterceptor implements WorkflowOutboundCallsInterceptor {
  async scheduleActivity(input: ActivityInput, next: any) {
    input.headers.context = contextPayload
    return next(input)
  }
}

export const interceptors: WorkflowInterceptorsFactory = () => {
  return {
    inbound: [new WorkflowInboundContextInterceptor()],
    outbound: [new WorkflowOutboundContextInterceptor()],
  }
}

Since each workflow runs in a separate v8 isolate I think it should be safe to just store the context in a local variable? But with the introduction of the reuseV8Context option (enabled by default since v1.9 of the TypeScript SDK), I’m not sure if that is actually still true?

Is there some better way to pass the context between the interceptors or is this solution safe?