Skip to content

Commit 84558a9

Browse files
NiteshDhanpalclaude
andcommitted
fix(tracing): import TracingActivityName only after the in_activity() guard
The enum import sat above the in_activity() check, so it ran on every start_span -- including the pure-sync ACP path that never touches Temporal. That pulled the whole temporal activities module graph into workflow-less processes, made the docstring's "inside an activity" safety justification untrue for the path actually taken, and meant a broken import would silently return False (disabling dispatch discrimination) even on the sync path. Move it below the guard: sync never runs it, and inside an activity the graph is loaded so the lazy import stays safe. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4a8b7e3 commit 84558a9

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/agentex/lib/core/tracing/trace.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,21 @@ def _in_tracing_dispatch_activity() -> bool:
122122
try:
123123
from temporalio import activity
124124

125-
# Lazy import: TracingActivityName lives in the activities package whose
126-
# module graph imports back into this one (activities -> TracingService ->
127-
# AsyncTracer -> trace), so a top-level import would be circular. At call
128-
# time (inside an activity) that graph is fully loaded, so this is safe --
129-
# and it keeps the discriminator keyed on the enum, not on drifting string
130-
# literals. ``activity_type`` round-trips as the enum's str value, which a
131-
# str-Enum member compares equal to.
125+
if not activity.in_activity():
126+
return False
127+
# Import only AFTER the in_activity() guard: the pure-sync ACP path never
128+
# runs this, so it doesn't pull the temporal activities module graph
129+
# (activities -> TracingService -> AsyncTracer -> trace, also circular at
130+
# import time) into a process that never runs a workflow, and a broken
131+
# import can't silently disable the guard on that path. Inside an activity
132+
# the graph is fully loaded, so the lazy import is safe -- and it keeps the
133+
# discriminator keyed on the enum, not on drifting string literals.
134+
# ``activity_type`` round-trips as the enum's str value, which a str-Enum
135+
# member compares equal to.
132136
from agentex.lib.core.temporal.activities.adk.tracing_activities import (
133137
TracingActivityName,
134138
)
135139

136-
if not activity.in_activity():
137-
return False
138140
return activity.info().activity_type in (
139141
TracingActivityName.START_SPAN,
140142
TracingActivityName.END_SPAN,

0 commit comments

Comments
 (0)