{"record":{"id":"e7581c5935fb3e34","repo":"different-ai/openwork","slug":"failed-to-load-connection-details-response-stat","errorCode":null,"errorMessage":"Failed to load connection details (${response.status}).","messagePattern":"Failed to load connection details \\((.+?)\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/background-agents-screen.tsx","lineNumber":321,"sourceCode":"    runtimeConfig,\n  } = useDenFlow();\n\n  async function loadConnectionDetails(workerId: string, workerName: string) {\n    setConnectBusyWorkerId(workerId);\n    setConnectError(null);\n\n    try {\n      const { response, payload } = await requestJson(\n        `/v1/workers/${encodeURIComponent(workerId)}/tokens`,\n        {\n          method: \"POST\",\n          body: JSON.stringify({ includeExpiringOpenworkUrl: true }),\n        },\n        12000,\n      );\n\n      if (!response.ok) {\n        throw new Error(\n          getErrorMessage(payload, `Failed to load connection details (${response.status}).`),\n        );\n      }\n\n      const tokens = getWorkerTokens(payload);\n      if (!tokens) {\n        throw new Error(\"Connection details were missing from the worker response.\");\n      }\n\n      const nextDetails: ConnectionDetails = {\n        openworkUrl: tokens.openworkUrl,\n        ownerToken: tokens.ownerToken,\n        clientToken: tokens.clientToken,\n        openworkAppConnectUrl: buildOpenworkAppConnectUrl(\n          runtimeConfig.openworkAppConnectUrl,\n          tokens.previewOpenworkUrl,\n          tokens.clientToken,\n          workerId,","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/background-agents-screen.tsx#L303-L339","documentation":"loadConnectionDetails in the background-agents screen POSTs to fetch worker connection details (including an expiring OpenWork URL) with a 12s timeout. If response.ok is false, this error is thrown with the server message or the status fallback. It means the worker/connections endpoint rejected the request.","triggerScenarios":"The connection-details endpoint returns 401 (expired session), 403 (no access to the worker/sandbox), 404 (worker not provisioned or feature absent on this server), or 5xx; the 12-second timeout elapses producing a non-ok path.","commonSituations":"Sandbox not yet provisioned when the user toggles it on; user lacks org permissions for background agents; self-hosted Den server lacking the worker endpoints; slow backend exceeding the 12s timeout.","solutions":["Check the status code: 401 → sign in again; 403 → request background-agent permissions; 404 → verify server supports workers and the sandbox exists.","Retry after the sandbox finishes provisioning (the toggle flow usually waits for state).","Confirm the Den server version includes worker connection endpoints.","Increase the timeout or check server latency if 5xx/timeouts recur."],"exampleFix":"// before\nif (!response.ok) {\n  throw new Error(getErrorMessage(payload, `Failed to load connection details (${response.status}).`));\n}\n// after\nif (response.status === 404) {\n  throw new Error(\"Worker not provisioned yet — start the sandbox first.\");\n}\nif (!response.ok) {\n  throw new Error(getErrorMessage(payload, `Failed to load connection details (${response.status}).`));\n}","handlingStrategy":"retry","validationCode":"// Ensure session is valid before loading details\nconst me = await fetch(\"/v1/me\", { method: \"GET\" });\nif (me.status === 401) { redirectToSignIn(); }","typeGuard":"function isConnectionDetails(v: unknown): v is { openworkUrl: string; ownerToken: string; clientToken: string } {\n  const t = v as Record<string, unknown> | null;\n  return !!t && typeof t.openworkUrl === \"string\" && typeof t.ownerToken === \"string\" && typeof t.clientToken === \"string\";\n}","tryCatchPattern":"try {\n  await loadConnectionDetails();\n} catch (err) {\n  const m = err instanceof Error ? err.message : \"\";\n  if (m.includes(\"(404)\")) showToast(\"Sandbox not ready — try again shortly.\");\n  else if (m.includes(\"(401)\")) redirectToSignIn();\n  else showToast(m || \"Failed to load connection details\");\n}","preventionTips":["Wait for sandbox provisioning to complete before requesting connection details.","Add retry with backoff for transient 5xx and timeouts (12s budget is tight).","Verify the Den server supports worker endpoints before showing the toggle.","Keep the expiring-URL request flag in sync with server capability."],"tags":["network","http-error","background-agents"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}