44
55import logging
66import os
7- import threading
87from collections .abc import Callable
98from concurrent .futures import ThreadPoolExecutor
109from pathlib import Path
5150
5251_active : dict [str , Any ] = {}
5352_run_executor = ThreadPoolExecutor (max_workers = 4 , thread_name_prefix = "run-worker" )
54- _active_runs : set [str ] = set ()
55- _active_runs_lock = threading .Lock ()
5653
5754
5855def set_orchestrator_error (exc : Exception | None ) -> None :
@@ -248,15 +245,6 @@ def create_run(
248245 orchestrator : Orchestrator = Depends (get_orchestrator ),
249246) -> CreateRunResponse :
250247 """Create run + root node and launch orchestration asynchronously."""
251- _MAX_OBJECTIVE_LEN = 10000
252- objective = request .objective .strip ()
253- if not objective :
254- raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "objective must not be empty" )
255- if len (objective ) > _MAX_OBJECTIVE_LEN :
256- raise HTTPException (
257- status_code = status .HTTP_400_BAD_REQUEST ,
258- detail = f"objective exceeds maximum length ({ len (objective )} /{ _MAX_OBJECTIVE_LEN } )" ,
259- )
260248 if request .base_persona_id :
261249 registry = _load_persona_registry ()
262250 if not registry .has_profile (request .base_persona_id ):
@@ -266,19 +254,11 @@ def create_run(
266254 )
267255 try :
268256 created = orchestrator .create_run (
269- objective = objective ,
257+ objective = request . objective ,
270258 config = request .config ,
271259 base_persona_id = request .base_persona_id ,
272260 )
273261
274- with _active_runs_lock :
275- if created .run_id in _active_runs :
276- raise HTTPException (
277- status_code = status .HTTP_409_CONFLICT ,
278- detail = f"run { created .run_id } is already executing" ,
279- )
280- _active_runs .add (created .run_id )
281-
282262 def _run_background () -> None :
283263 try :
284264 orchestrator .run_existing (
@@ -287,25 +267,6 @@ def _run_background() -> None:
287267 )
288268 except Exception :
289269 _log .warning ("run_existing failed for run=%s" , created .run_id , exc_info = True )
290- repo = _active .get ("repository" )
291- stream = _active .get ("event_stream" )
292- if repo :
293- try :
294- repo .update_run_status (created .run_id , RunStatus .FAILED )
295- except Exception :
296- pass
297- if stream :
298- try :
299- stream .publish (DomainEvent (
300- event_id = f"evt_{ _default_id_factory ()} " , run_id = created .run_id ,
301- node_id = created .root_node_id , type = DomainEventType .RUN_FAILED ,
302- payload = {"status" : RunStatus .FAILED .value , "error" : "background_execution_failed" },
303- ))
304- except Exception :
305- pass
306- finally :
307- with _active_runs_lock :
308- _active_runs .discard (created .run_id )
309270
310271 _run_executor .submit (_run_background )
311272 except (LLMClientRuntimeError , DividerSchemaError , RuntimeError ) as exc :
@@ -546,22 +507,12 @@ def _evt(rtype, payload):
546507 }))
547508
548509 if target_status == NodeStatus .RUNNING :
549- with _active_runs_lock :
550- if run_id in _active_runs :
551- raise HTTPException (
552- status_code = status .HTTP_409_CONFLICT ,
553- detail = f"run { run_id } is already executing" ,
554- )
555- _active_runs .add (run_id )
556510
557511 def _resume_background () -> None :
558512 try :
559513 orchestrator .resume_from_node (run_id = run_id , node_id = node_id )
560514 except Exception :
561515 _log .warning ("resume_from_node failed for run=%s node=%s" , run_id , node_id , exc_info = True )
562- finally :
563- with _active_runs_lock :
564- _active_runs .discard (run_id )
565516
566517 _run_executor .submit (_resume_background )
567518
0 commit comments