| # Wrapper that starts the Python research engine, but no-ops if a healthy | |
| # instance is already serving on the target port. The Replit workflow | |
| # manager occasionally double-starts the dev workflow after a restart; | |
| # without this guard the second instance dies on EADDRINUSE and the | |
| # workflow status flips to FAILED even though the engine is fine. | |
| set -euo pipefail | |
| PORT="${PORT:-8011}" | |
| HEALTH_URL="http://127.0.0.1:${PORT}/internal/healthz" | |
| if curl -fsS --max-time 2 "${HEALTH_URL}" >/dev/null 2>&1; then | |
| echo "research-engine: healthy instance already on :${PORT}, skipping start" >&2 | |
| # Block forever so the workflow stays in RUNNING; otherwise Replit | |
| # treats the immediate exit as a crash and restarts again. | |
| exec sleep infinity | |
| fi | |
| REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | |
| cd "${REPO_ROOT}/artifacts/research-engine" | |
| export TOOL_GRAPH_ENABLED="${TOOL_GRAPH_ENABLED:-1}" | |
| exec python3 -m app.server | |