MCPcopy Index your code
hub / github.com/AutoForgeAI/autoforge / _run_initializer

Method _run_initializer

parallel_orchestrator.py:1045–1118  ·  view source on GitHub ↗

Run initializer agent as blocking subprocess. Returns True if initialization succeeded (features were created).

(self)

Source from the content-addressed store, hash-verified

1043 return True, f"Started testing agent for features [{batch_str}]"
1044
1045 async def _run_initializer(self) -> bool:
1046 """Run initializer agent as blocking subprocess.
1047
1048 Returns True if initialization succeeded (features were created).
1049 """
1050 debug_log.section("INITIALIZER PHASE")
1051 debug_log.log("INIT", "Starting initializer subprocess",
1052 project_dir=str(self.project_dir))
1053
1054 cmd = [
1055 sys.executable, "-u",
1056 str(AUTOFORGE_ROOT / "autonomous_agent_demo.py"),
1057 "--project-dir", str(self.project_dir),
1058 "--agent-type", "initializer",
1059 "--max-iterations", "1",
1060 ]
1061 if self.model:
1062 cmd.extend(["--model", self.model])
1063
1064 print("Running initializer agent...", flush=True)
1065
1066 # CREATE_NO_WINDOW on Windows prevents console window pop-ups
1067 # stdin=DEVNULL prevents blocking on stdin reads
1068 # encoding="utf-8" and errors="replace" fix Windows CP1252 issues
1069 popen_kwargs: dict[str, Any] = {
1070 "stdin": subprocess.DEVNULL,
1071 "stdout": subprocess.PIPE,
1072 "stderr": subprocess.STDOUT,
1073 "text": True,
1074 "encoding": "utf-8",
1075 "errors": "replace",
1076 "cwd": str(AUTOFORGE_ROOT),
1077 "env": {**os.environ, "PYTHONUNBUFFERED": "1"},
1078 }
1079 if sys.platform == "win32":
1080 popen_kwargs["creationflags"] = subprocess.CREATE_NO_WINDOW
1081
1082 proc = subprocess.Popen(cmd, **popen_kwargs)
1083
1084 debug_log.log("INIT", "Initializer subprocess started", pid=proc.pid)
1085
1086 # Stream output with timeout
1087 loop = asyncio.get_running_loop()
1088 try:
1089 async def stream_output():
1090 while True:
1091 line = await loop.run_in_executor(None, proc.stdout.readline)
1092 if not line:
1093 break
1094 print(line.rstrip(), flush=True)
1095 if self.on_output is not None:
1096 self.on_output(0, line.rstrip()) # Use 0 as feature_id for initializer
1097 proc.wait()
1098
1099 await asyncio.wait_for(stream_output(), timeout=INITIALIZER_TIMEOUT)
1100
1101 except asyncio.TimeoutError:
1102 print(f"ERROR: Initializer timed out after {INITIALIZER_TIMEOUT // 60} minutes", flush=True)

Callers 1

run_loopMethod · 0.95

Calls 3

kill_process_treeFunction · 0.90
sectionMethod · 0.80
logMethod · 0.80

Tested by

no test coverage detected