@@ -113,7 +113,7 @@ class Runtime(FileEditRuntimeMixin):
113113 config : OpenHandsConfig
114114 initial_env_vars : dict [str , str ]
115115 attach_to_existing : bool
116- status_callback : Callable [[str , str , str ], None ] | None
116+ status_callback : Callable [[str , RuntimeStatus , str ], None ] | None
117117 runtime_status : RuntimeStatus | None
118118 _runtime_initialized : bool = False
119119
@@ -124,7 +124,7 @@ def __init__(
124124 sid : str = 'default' ,
125125 plugins : list [PluginRequirement ] | None = None ,
126126 env_vars : dict [str , str ] | None = None ,
127- status_callback : Callable [[str , str , str ], None ] | None = None ,
127+ status_callback : Callable [[str , RuntimeStatus , str ], None ] | None = None ,
128128 attach_to_existing : bool = False ,
129129 headless_mode : bool = False ,
130130 user_id : str | None = None ,
@@ -207,16 +207,13 @@ def log(self, level: str, message: str) -> None:
207207 message = f'[runtime { self .sid } ] { message } '
208208 getattr (logger , level )(message , stacklevel = 2 )
209209
210- def set_runtime_status (self , runtime_status : RuntimeStatus ):
210+ def set_runtime_status (
211+ self , runtime_status : RuntimeStatus , msg : str = '' , level : str = 'info'
212+ ):
211213 """Sends a status message if the callback function was provided."""
212214 self .runtime_status = runtime_status
213215 if self .status_callback :
214- msg_id : str = runtime_status .value # type: ignore
215- self .status_callback ('info' , msg_id , runtime_status .message )
216-
217- def send_error_message (self , message_id : str , message : str ):
218- if self .status_callback :
219- self .status_callback ('error' , message_id , message )
216+ self .status_callback (level , runtime_status , msg )
220217
221218 # ====================================================================
222219
@@ -344,15 +341,13 @@ async def _handle_action(self, event: Action) -> None:
344341 else :
345342 observation = await call_sync_from_async (self .run_action , event )
346343 except Exception as e :
347- err_id = ''
348- if isinstance (e , httpx .NetworkError ) or isinstance (
349- e , AgentRuntimeDisconnectedError
350- ):
351- err_id = 'STATUS$ERROR_RUNTIME_DISCONNECTED'
344+ runtime_status = RuntimeStatus .ERROR
345+ if isinstance (e , (httpx .NetworkError , AgentRuntimeDisconnectedError )):
346+ runtime_status = RuntimeStatus .ERROR_RUNTIME_DISCONNECTED
352347 error_message = f'{ type (e ).__name__ } : { str (e )} '
353348 self .log ('error' , f'Unexpected error while running action: { error_message } ' )
354349 self .log ('error' , f'Problematic action: { str (event )} ' )
355- self .send_error_message ( err_id , error_message )
350+ self .set_runtime_status ( runtime_status , error_message )
356351 return
357352
358353 observation ._cause = event .id # type: ignore[attr-defined]
@@ -397,7 +392,7 @@ async def clone_or_init_repo(
397392
398393 if self .status_callback :
399394 self .status_callback (
400- 'info' , 'STATUS$ SETTING_UP_WORKSPACE' , 'Setting up workspace...'
395+ 'info' , RuntimeStatus . SETTING_UP_WORKSPACE , 'Setting up workspace...'
401396 )
402397
403398 dir_name = selected_repository .split ('/' )[- 1 ]
@@ -438,7 +433,7 @@ def maybe_run_setup_script(self):
438433
439434 if self .status_callback :
440435 self .status_callback (
441- 'info' , 'STATUS$ SETTING_UP_WORKSPACE' , 'Setting up workspace...'
436+ 'info' , RuntimeStatus . SETTING_UP_WORKSPACE , 'Setting up workspace...'
442437 )
443438
444439 # setup scripts time out after 10 minutes
@@ -470,7 +465,7 @@ def maybe_setup_git_hooks(self):
470465
471466 if self .status_callback :
472467 self .status_callback (
473- 'info' , 'STATUS$ SETTING_UP_GIT_HOOKS' , 'Setting up git hooks...'
468+ 'info' , RuntimeStatus . SETTING_UP_GIT_HOOKS , 'Setting up git hooks...'
474469 )
475470
476471 # Ensure the git hooks directory exists
0 commit comments