Skip to content

Conversation

@steve-the-edwards
Copy link
Contributor

Add the runtime's CoroutineContext to the WorkflowSession info and then also forward the CoroutineDispatcher through the ConfigSnapshot that is used by the WorkflowRuntimeTracer. This can help us get definitive logging about the dispatcher being used in the runtime.

@steve-the-edwards steve-the-edwards force-pushed the sedwards/add-dispatcher-tracking branch from d17b4e0 to ee8b977 Compare October 14, 2025 18:15
@steve-the-edwards steve-the-edwards marked this pull request as ready for review November 11, 2025 16:02
@steve-the-edwards steve-the-edwards force-pushed the sedwards/add-dispatcher-tracking branch from ee8b977 to 9c18611 Compare November 11, 2025 16:02
public abstract fun getParent ()Lcom/squareup/workflow1/WorkflowInterceptor$WorkflowSession;
public abstract fun getRenderKey ()Ljava/lang/String;
public abstract fun getRuntimeConfig ()Ljava/util/Set;
public abstract fun getRuntimeContext ()Lkotlin/coroutines/CoroutineContext;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change for anyone implementing WorkflowInterceptor. I don't know if that's a concern....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New method is fine, no?

if (config.isEmpty()) {
append("Base, ")
}
append("Dispatch: ${runtimeDispatch?.toString()?.take(6)}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't always work. e.g. see the documentation from https://github.com/Kotlin/kotlinx.coroutines/blob/5d4954b17ac18c572e22a9a6e7bb4e4368ec568c/kotlinx-coroutines-core/common/src/MainCoroutineDispatcher.kt#L45 :

    /**
     * Returns a name of this main dispatcher for debugging purposes. This implementation returns
     * `Dispatchers.Main` or `Dispatchers.Main.immediate` if it is the same as the corresponding
     * reference in [Dispatchers] or a short class-name representation with address otherwise.
     */
    override fun toString(): String = toStringInternalImpl() ?: "$classSimpleName@$hexAddress"

The IO dispatcher - https://github.com/Kotlin/kotlinx.coroutines/blob/5d4954b17ac18c572e22a9a6e7bb4e4368ec568c/kotlinx-coroutines-core/native/src/Dispatchers.kt#L44 - is similar

Maybe you should drop the Dispatchers. from the beginning of the string if it exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to

append("Dispatch: ${runtimeDispatch?.toString()?.substringAfter("Dispatchers.")?.take(8)}")

substringAfter returns original string by default if does not contain the substring.

@steve-the-edwards steve-the-edwards force-pushed the sedwards/add-dispatcher-tracking branch from 9c18611 to d6a2382 Compare November 13, 2025 16:08
@steve-the-edwards steve-the-edwards force-pushed the sedwards/add-dispatcher-tracking branch from d6a2382 to 80b2d5d Compare November 14, 2025 17:15
@steve-the-edwards steve-the-edwards changed the base branch from main to sedwards/update-snapshot-timeout November 14, 2025 17:16
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.

3 participants