Skip to content

Self-improving AI Employees for everyone

fix: start Temporal server before worker, worker retry on connect

trohitga1782473fdf8
diff --git a/scripts/dev.js b/scripts/dev.js
index 0ec30b18..d76bfa86 100644
--- a/scripts/dev.js
+++ b/scripts/dev.js
@@ -87,7 +87,10 @@ async function main() {
}
services.push(isDaemonMode ? 'npm:python:daemon' : 'npm:python:start');
if (!skipWhatsApp) services.push('npm:whatsapp:api');
- if (config.temporalEnabled) services.push('npm:temporal:worker');
+ if (config.temporalEnabled) {
+ services.push('npm:temporal:start');
+ services.push('npm:temporal:worker');
+ }
// Ready-detection patterns for each service
const readyPatterns = [
diff --git a/scripts/start.js b/scripts/start.js
index cdbe3b94..38b2681c 100755
--- a/scripts/start.js
+++ b/scripts/start.js
@@ -60,7 +60,10 @@ async function main() {
services.push(`"node ${resolve(ROOT, 'scripts', 'serve-client.js').replace(/\\/g, '/')}"`);
services.push((isWindows || isWSL) ? 'npm:python:start' : 'npm:python:daemon');
if (!skipWhatsApp) services.push('npm:whatsapp:api');
- if (config.temporalEnabled) services.push('npm:temporal:worker');
+ if (config.temporalEnabled) {
+ services.push('npm:temporal:start');
+ services.push('npm:temporal:worker');
+ }
// Ready-detection patterns for each service
const readyPatterns = [
@@ -113,7 +116,10 @@ async function main() {
const serviceNames = ['client', 'server'];
if (!skipWhatsApp) serviceNames.push('whatsapp');
- if (config.temporalEnabled) serviceNames.push('temporal');
+ if (config.temporalEnabled) {
+ serviceNames.push('temporal-server');
+ serviceNames.push('temporal-worker');
+ }
const proc = spawn('npx', [
'concurrently', '--kill-others',
diff --git a/server/services/temporal/worker.py b/server/services/temporal/worker.py
index 25d4e3ec..b20e7e0f 100644
--- a/server/services/temporal/worker.py
+++ b/server/services/temporal/worker.py
@@ -180,7 +180,23 @@ async def run_standalone_worker(
# Use custom runtime with heartbeating disabled to avoid warning on older servers
runtime = create_runtime()
- client = await Client.connect(server_address, namespace=namespace, runtime=runtime)
+
+ # Connect with retries (server may still be starting)
+ client = None
+ for attempt in range(1, 6):
+ try:
+ logger.info(f"Connecting to Temporal server (attempt {attempt}/5)")
+ client = await Client.connect(server_address, namespace=namespace, runtime=runtime)
+ logger.info("Connected to Temporal server")
+ break
+ except Exception as e:
+ logger.warning(f"Temporal connection attempt {attempt}/5 failed: {e}")
+ if attempt < 5:
+ await asyncio.sleep(3.0)
+
+ if client is None:
+ logger.error(f"Could not connect to Temporal server at {server_address} after 5 attempts")
+ return
# Create shared session and activities
session = await create_shared_session(pool_size)