@@ -150,9 +150,45 @@ echo "[pilotdeck-docker] Starting PilotDeck (gateway + UI server)..."
150150echo " [pilotdeck-docker] Config: $CONFIG_FILE "
151151echo " [pilotdeck-docker] UI will be available at http://0.0.0.0:${SERVER_PORT:- 3001} "
152152
153+ # ── Remove stale auth token so the bridge never uses a leftover value ──
154+ rm -f " $PILOT_HOME /server-token"
155+
153156# ── Start gateway + UI server via concurrently ────────────────────────
157+ # The bridge retries for PILOTDECK_BRIDGE_TIMEOUT ms (default 30s) which
158+ # may be too short on cold Docker starts. We first wait for the gateway
159+ # health endpoint before launching the bridge, eliminating the race.
154160cd /app
155161
156- exec npx concurrently --kill-others --names gateway,server \
157- " node dist/src/cli/pilotdeck.js server" \
158- " node --import tsx ui/server/index.js"
162+ GATEWAY_PORT=" ${PILOTDECK_GATEWAY_PORT:- 18789} "
163+ GATEWAY_HEALTH_URL=" http://127.0.0.1:${GATEWAY_PORT} /health"
164+ GATEWAY_READY_TIMEOUT=" ${PILOTDECK_GATEWAY_READY_TIMEOUT:- 120} "
165+
166+ wait_for_gateway () {
167+ echo " [pilotdeck-docker] Waiting for gateway to become ready (timeout=${GATEWAY_READY_TIMEOUT} s)..."
168+ local elapsed=0
169+ while [ " $elapsed " -lt " $GATEWAY_READY_TIMEOUT " ]; do
170+ if curl -sf " $GATEWAY_HEALTH_URL " > /dev/null 2>&1 ; then
171+ echo " [pilotdeck-docker] Gateway is ready (took ${elapsed} s)."
172+ return 0
173+ fi
174+ sleep 1
175+ elapsed=$(( elapsed + 1 ))
176+ done
177+ echo " [pilotdeck-docker] WARNING: Gateway did not become ready within ${GATEWAY_READY_TIMEOUT} s, starting bridge anyway." >&2
178+ return 0
179+ }
180+
181+ node dist/src/cli/pilotdeck.js server &
182+ GATEWAY_PID=$!
183+
184+ wait_for_gateway
185+
186+ node --import tsx ui/server/index.js &
187+ BRIDGE_PID=$!
188+
189+ # If either process exits, kill the other and propagate the exit code.
190+ wait -n $GATEWAY_PID $BRIDGE_PID 2> /dev/null
191+ EXIT_CODE=$?
192+ kill $GATEWAY_PID $BRIDGE_PID 2> /dev/null
193+ wait $GATEWAY_PID $BRIDGE_PID 2> /dev/null
194+ exit $EXIT_CODE
0 commit comments