{"record":{"id":"a7d6dccdea1f3133","repo":"different-ai/openwork","slug":"connection-lost","errorCode":null,"errorMessage":"Connection lost","messagePattern":"Connection lost","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"apps/app/src/react-app/domains/session/sync/actions-store.ts","lineNumber":381,"sourceCode":"      try {\n        return await Promise.race([promise, timeoutPromise]);\n      } finally {\n        if (timeoutId) {\n          clearTimeout(timeoutId);\n        }\n      }\n    };\n\n    try {\n      mark(\"health:start\");\n      try {\n        await withTimeout(c.global.health(), 3_000, \"health\");\n        mark(\"health:ok\");\n      } catch (healthErr) {\n        mark(\"health:error\", {\n          error: healthErr instanceof Error ? healthErr.message : safeStringify(healthErr),\n        });\n        throw new Error(\"Connection lost\");\n      }\n\n      let rawResult: Awaited<ReturnType<typeof c.session.create>>;\n      try {\n        const directory = toSessionTransportDirectory(workspaceRoot) || undefined;\n        mark(\"session:create:start\");\n        rawResult = await c.session.create({ directory });\n        mark(\"session:create:ok\");\n      } catch (createErr) {\n        mark(\"session:create:error\", {\n          error: createErr instanceof Error ? createErr.message : safeStringify(createErr),\n        });\n        throw createErr;\n      }\n\n      const session = unwrap(rawResult);\n      if (initialPrompt) {\n        saveSessionDraft(LOCAL_SESSION_DRAFT_SCOPE, id, session.id, {","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/react-app/domains/session/sync/actions-store.ts#L363-L399","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the server is running and reachable (health endpoint), then reconnect the client and retry session creation.","Look at the recorded marks (health:error message) to see the underlying health failure cause.","Increase the 3s timeout if your environment (remote/slow network) legitimately needs longer, or add automatic reconnect-before-create logic.","Restart the app session to re-establish the transport if reconnect fails."],"exampleFix":"// before\nthrow new Error(\"Connection lost\");\n// after\nawait reconnectClient(); // attempt re-establish\nthrow new Error(`Connection lost: ${healthErr instanceof Error ? healthErr.message : \"health timeout\"}`);","handlingStrategy":"retry","validationCode":"try {\n  await withTimeout(c.global.health(), 3_000, \"health\");\n} catch {\n  await reconnectClient(); // re-establish before attempting session creation\n}\nawait createSessionInWorkspace(workspaceRoot);","typeGuard":"function isClientAlive(c: unknown): c is NonNullable<typeof c> {\n  return typeof c === \"object\" && c !== null && \"global\" in c && typeof (c as { global?: { health?: unknown } }).global?.health === \"function\";\n}","tryCatchPattern":"try {\n  await createSessionInWorkspace(root);\n} catch (e) {\n  if (e instanceof Error && e.message === \"Connection lost\") {\n    await reconnectClient();\n    showToast(\"Connection dropped — reconnected, please retry\");\n    return;\n  }\n  throw e;\n}","preventionTips":["Check the recorded health marks (health:error) to identify the root cause before retrying.","Add automatic client reconnection on websocket close/idle so health probes rarely fire on a dead transport.","Tune the 3s health timeout for slow/remote environments.","Restart the OpenWork server if health failures persist — the process has likely died."],"tags":["network","timeout","health-check"],"backgroundTag":"connection-lost","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}