different-ai/openwork · critical

Connection lost

Error message

Connection lost

What it means

createReadySession probes the client with a bounded (3s) global.health() call before creating a session. If the health probe fails or times out, the transport is considered dead and it throws 'Connection lost' instead of attempting session.create against a broken connection. Diagnostic marks recorded via mark() (health:error, etc.) accompany the failure for debugging.

Source

Thrown at apps/app/src/react-app/domains/session/sync/actions-store.ts:381

      try {
        return await Promise.race([promise, timeoutPromise]);
      } finally {
        if (timeoutId) {
          clearTimeout(timeoutId);
        }
      }
    };

    try {
      mark("health:start");
      try {
        await withTimeout(c.global.health(), 3_000, "health");
        mark("health:ok");
      } catch (healthErr) {
        mark("health:error", {
          error: healthErr instanceof Error ? healthErr.message : safeStringify(healthErr),
        });
        throw new Error("Connection lost");
      }

      let rawResult: Awaited<ReturnType<typeof c.session.create>>;
      try {
        const directory = toSessionTransportDirectory(workspaceRoot) || undefined;
        mark("session:create:start");
        rawResult = await c.session.create({ directory });
        mark("session:create:ok");
      } catch (createErr) {
        mark("session:create:error", {
          error: createErr instanceof Error ? createErr.message : safeStringify(createErr),
        });
        throw createErr;
      }

      const session = unwrap(rawResult);
      if (initialPrompt) {
        saveSessionDraft(LOCAL_SESSION_DRAFT_SCOPE, id, session.id, {

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Check the server is running and reachable (health endpoint), then reconnect the client and retry session creation.
  2. Look at the recorded marks (health:error message) to see the underlying health failure cause.
  3. Increase the 3s timeout if your environment (remote/slow network) legitimately needs longer, or add automatic reconnect-before-create logic.
  4. Restart the app session to re-establish the transport if reconnect fails.

Example fix

// before
throw new Error("Connection lost");
// after
await reconnectClient(); // attempt re-establish
throw new Error(`Connection lost: ${healthErr instanceof Error ? healthErr.message : "health timeout"}`);
Defensive patterns

Strategy: retry

Validate before calling

try {
  await withTimeout(c.global.health(), 3_000, "health");
} catch {
  await reconnectClient(); // re-establish before attempting session creation
}
await createSessionInWorkspace(workspaceRoot);

Type guard

function isClientAlive(c: unknown): c is NonNullable<typeof c> {
  return typeof c === "object" && c !== null && "global" in c && typeof (c as { global?: { health?: unknown } }).global?.health === "function";
}

Try / catch

try {
  await createSessionInWorkspace(root);
} catch (e) {
  if (e instanceof Error && e.message === "Connection lost") {
    await reconnectClient();
    showToast("Connection dropped — reconnected, please retry");
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: c.global.health() throws or exceeds the 3-second withTimeout window — server process died, network dropped, websocket disconnected, or the server is overloaded and unresponsive at the moment of session creation.

Common situations: OpenWork server restarted or crashed while the UI stayed open; laptop slept/resumed invalidating the connection; firewall/network change; local server still booting when the user tried to create a task.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/a7d6dccdea1f3133. Report an issue: GitHub.