@@ -250,6 +250,23 @@ def _patched_object_to_json(obj, **kwargs):
250250 runner .trial_dependencies = trial_deps
251251 runner ._parameter_groups = exp_cfg .get_parameter_groups ()
252252 runner ._metric_names = [m .name for m in opt_cfg .metrics ]
253+ # Seed runner.trial_registry from the experiment so that dependency
254+ # resolution (matching_group / nearest / best / by_index) and API
255+ # history views can see inherited trials (bootstrap runs and resumes).
256+ # Registry entries for dispatched trials get overwritten each callback.
257+ from ax .core .base_trial import TrialStatus as _TS_SEED
258+ _seeded = 0
259+ for _tidx , _trial in client ._experiment .trials .items ():
260+ _case_path = (_trial .run_metadata .get ("case_path" ) if _trial .run_metadata else None ) \
261+ or (_trial .run_metadata .get ("job" , {}).get ("case_path" ) if _trial .run_metadata else None )
262+ runner .trial_registry [_tidx ] = {
263+ "case_path" : _case_path ,
264+ "status" : _trial .status .name ,
265+ "parameters" : _trial .arm .parameters if _trial .arm else {},
266+ }
267+ _seeded += 1
268+ if _seeded :
269+ log .info ("Seeded runner trial_registry with %d inherited trial(s)" , _seeded )
253270 runner ._trial_timeout = orch_cfg .trial_timeout
254271 runner ._baseline_execution_time = None # set after baseline completes
255272 # Enable streaming data attachment during poll_trial (for early stopping)
@@ -929,10 +946,18 @@ def main():
929946
930947 if args .config_builder :
931948 from .api_server import app as _app , _state as _srv_state
932- import uvicorn
949+ import uvicorn , socket
933950 _srv_state .standalone = True
934951 host = "127.0.0.1"
935952 port = 8098
953+ with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
954+ try :
955+ s .bind ((host , port ))
956+ except OSError :
957+ s .bind ((host , 0 ))
958+ new_port = s .getsockname ()[1 ]
959+ print (f"Port { port } in use, using { new_port } instead" )
960+ port = new_port
936961 print (f"Config Builder running at http://{ host } :{ port } /config-builder" )
937962 uvicorn .run (_app , host = host , port = port , log_level = "warning" )
938963 return
0 commit comments