@@ -527,13 +527,19 @@ def create(
527527
528528 # If the input is a callable, create an event chain.
529529 elif isinstance (value , Callable ):
530- result = call_event_fn (value , args_spec , key = key )
531- if isinstance (result , Var ):
532- # Recursively call this function if the lambda returned an EventChain Var.
533- return cls .create (
534- value = result , args_spec = args_spec , key = key , ** event_chain_kwargs
535- )
536- events = [* result ]
530+ # Check if this is a decentralized event handler
531+ if is_decentralized_event_handler (value ):
532+ wrapped_fn = wrap_decentralized_handler (value )
533+ # Create an event spec directly
534+ events = [wrapped_fn ()]
535+ else :
536+ result = call_event_fn (value , args_spec , key = key )
537+ if isinstance (result , Var ):
538+ # Recursively call this function if the lambda returned an EventChain Var.
539+ return cls .create (
540+ value = result , args_spec = args_spec , key = key , ** event_chain_kwargs
541+ )
542+ events = [* result ]
537543
538544 # Otherwise, raise an error.
539545 else :
@@ -1330,13 +1336,14 @@ def call_event_handler(
13301336 # Handle partial application of EventSpec args
13311337 return event_callback .add_args (* event_spec_args )
13321338
1333- check_fn_match_arg_spec (
1334- event_callback .fn ,
1335- event_spec ,
1336- key ,
1337- bool (event_callback .state_full_name ),
1338- event_callback .fn .__qualname__ ,
1339- )
1339+ if not is_decentralized_event_handler (event_callback .fn ):
1340+ check_fn_match_arg_spec (
1341+ event_callback .fn ,
1342+ event_spec ,
1343+ key ,
1344+ bool (event_callback .state_full_name ),
1345+ event_callback .fn .__qualname__ ,
1346+ )
13401347
13411348 all_acceptable_specs = (
13421349 [event_spec ] if not isinstance (event_spec , Sequence ) else event_spec
@@ -1642,6 +1649,10 @@ def wrapper(*args, **kwargs):
16421649 wrapper .__doc__ = fn .__doc__
16431650 wrapper .__module__ = fn .__module__
16441651
1652+ # Preserve the decentralized event marker
1653+ if hasattr (fn , DECENTRALIZED_EVENT_MARKER ):
1654+ setattr (wrapper , DECENTRALIZED_EVENT_MARKER , True )
1655+
16451656 return wrapper
16461657
16471658
@@ -1679,8 +1690,9 @@ def call_event_fn(
16791690 # Call the wrapped function with the parsed arguments
16801691 return [wrapped_fn (* parsed_args )]
16811692
1682- # Check that fn signature matches arg_spec
1683- check_fn_match_arg_spec (fn , arg_spec , key = key )
1693+ # Check that fn signature matches arg_spec (skip for decentralized event handlers)
1694+ if not is_decentralized_event_handler (fn ):
1695+ check_fn_match_arg_spec (fn , arg_spec , key = key )
16841696
16851697 parsed_args = parse_args_spec (arg_spec )
16861698
0 commit comments