different-ai/openwork · error · Error

Failed to load connection details (${response.status}).

Error message

Failed to load connection details (${response.status}).

What it means

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.

Source

Thrown at ee/apps/den-web/app/(den)/dashboard/_components/background-agents-screen.tsx:321

    runtimeConfig,
  } = useDenFlow();

  async function loadConnectionDetails(workerId: string, workerName: string) {
    setConnectBusyWorkerId(workerId);
    setConnectError(null);

    try {
      const { response, payload } = await requestJson(
        `/v1/workers/${encodeURIComponent(workerId)}/tokens`,
        {
          method: "POST",
          body: JSON.stringify({ includeExpiringOpenworkUrl: true }),
        },
        12000,
      );

      if (!response.ok) {
        throw new Error(
          getErrorMessage(payload, `Failed to load connection details (${response.status}).`),
        );
      }

      const tokens = getWorkerTokens(payload);
      if (!tokens) {
        throw new Error("Connection details were missing from the worker response.");
      }

      const nextDetails: ConnectionDetails = {
        openworkUrl: tokens.openworkUrl,
        ownerToken: tokens.ownerToken,
        clientToken: tokens.clientToken,
        openworkAppConnectUrl: buildOpenworkAppConnectUrl(
          runtimeConfig.openworkAppConnectUrl,
          tokens.previewOpenworkUrl,
          tokens.clientToken,
          workerId,

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Check the status code: 401 → sign in again; 403 → request background-agent permissions; 404 → verify server supports workers and the sandbox exists.
  2. Retry after the sandbox finishes provisioning (the toggle flow usually waits for state).
  3. Confirm the Den server version includes worker connection endpoints.
  4. Increase the timeout or check server latency if 5xx/timeouts recur.

Example fix

// before
if (!response.ok) {
  throw new Error(getErrorMessage(payload, `Failed to load connection details (${response.status}).`));
}
// after
if (response.status === 404) {
  throw new Error("Worker not provisioned yet — start the sandbox first.");
}
if (!response.ok) {
  throw new Error(getErrorMessage(payload, `Failed to load connection details (${response.status}).`));
}
Defensive patterns

Strategy: retry

Validate before calling

// Ensure session is valid before loading details
const me = await fetch("/v1/me", { method: "GET" });
if (me.status === 401) { redirectToSignIn(); }

Type guard

function isConnectionDetails(v: unknown): v is { openworkUrl: string; ownerToken: string; clientToken: string } {
  const t = v as Record<string, unknown> | null;
  return !!t && typeof t.openworkUrl === "string" && typeof t.ownerToken === "string" && typeof t.clientToken === "string";
}

Try / catch

try {
  await loadConnectionDetails();
} catch (err) {
  const m = err instanceof Error ? err.message : "";
  if (m.includes("(404)")) showToast("Sandbox not ready — try again shortly.");
  else if (m.includes("(401)")) redirectToSignIn();
  else showToast(m || "Failed to load connection details");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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