{"record":{"id":"47a6b56d87d35acd","repo":"different-ai/openwork","slug":"provider-name-needs-environment-variables-e","errorCode":null,"errorMessage":"`${provider.name} needs environment variables (${envEntries.map((entry) => entry.key).join(\", \")}) but the OpenWork server is not available.`","messagePattern":"`(.+?) needs environment variables \\((.+?)\\) but the OpenWork server is not available\\.`","errorType":"exception","errorClass":"CloudProviderNeedsServerError","httpStatus":null,"severity":"error","filePath":"apps/app/src/react-app/domains/connections/provider-auth/store.ts","lineNumber":1694,"sourceCode":"      });\n      const provider = await den.getOrgLlmProviderConnection(orgId, cloudProviderId);\n      const localProviderId = getCloudManagedProviderId(provider);\n      assertProviderAllowedByDesktopPolicy(localProviderId);\n      const existingImported = state.importedCloudProviders[cloudProviderId] ?? null;\n      const { envEntries, primaryApiKey } = resolveCloudProviderCredentials(provider);\n      const env = getCloudProviderEnv(provider.providerConfig);\n      if (!primaryApiKey && env.length > 0) {\n        throw new CloudProviderNeedsCredentialError(\n          `${provider.name} does not have a stored organization credential yet.`,\n        );\n      }\n\n      await assertCloudProviderImportSafe(provider);\n\n      if (envEntries.length > 0) {\n        const openworkClient = options.openworkServer.getSnapshot().openworkServerClient;\n        if (!openworkClient) {\n          throw new CloudProviderNeedsServerError(\n            `${provider.name} needs environment variables (${envEntries\n              .map((entry) => entry.key)\n              .join(\", \")}) but the OpenWork server is not available.`,\n          );\n        }\n        await openworkClient.upsertUserEnv(envEntries);\n      }\n      if (primaryApiKey) {\n        await c.auth.set({\n          providerID: localProviderId,\n          auth: { type: \"api\", key: primaryApiKey },\n        });\n        await mirrorOpenWorkModelsVoiceEnv(provider, primaryApiKey, envEntries);\n      }\n      if (existingImported?.providerId && existingImported.providerId !== localProviderId) {\n        try {\n          await removeProviderAuthCredentials(existingImported.providerId);\n        } catch (error) {","sourceCodeStart":1676,"sourceCodeEnd":1712,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/app/src/react-app/domains/connections/provider-auth/store.ts#L1676-L1712","documentation":"During cloud provider import, if the provider requires environment variables (envEntries) they must be written to the local OpenWork server via upsertUserEnv. When the OpenWork server client is unavailable the store throws CloudProviderNeedsServerError explaining which env vars are needed, and the import stops.","triggerScenarios":"Importing a cloud provider whose config declares required env vars while options.openworkServer.getSnapshot().openworkServerClient is null — e.g. app running without the local server, server not yet initialized, or in a browser-only context without the server.","commonSituations":"Cloud sync fired at startup before the server client connects; self-hosted setup where the OpenWork server is down; headless/test environments without the server wiring.","solutions":["Start/connect the OpenWork server before importing cloud providers.","Wait for the openworkServer snapshot to expose a client (poll or subscribe) before import.","Catch CloudProviderNeedsServerError and retry the import once the server is available.","If the provider does not actually need env vars, fix its providerConfig or org credential so envEntries is empty."],"exampleFix":"// before\nawait store.importCloudProvider(id); // throws CloudProviderNeedsServerError\n// after\nawait waitFor(() => openworkServer.getSnapshot().openworkServerClient, { timeoutMs: 15000 });\nawait store.importCloudProvider(id);","handlingStrategy":"retry","validationCode":"const client = openworkServer.getSnapshot().openworkServerClient;\nif (!client && getCloudProviderEnv(provider.providerConfig).length > 0) {\n  await waitForServerConnection({ timeoutMs: 15000 });\n}","typeGuard":"function canUpsertEnv(s: { openworkServerClient: unknown }): boolean {\n  return s.openworkServerClient != null;\n}","tryCatchPattern":"try {\n  await store.importCloudProvider(cloudProviderId);\n} catch (e) {\n  if (e instanceof CloudProviderNeedsServerError) {\n    await waitForServerConnection();\n    await store.importCloudProvider(cloudProviderId);\n  }\n}","preventionTips":["Wait for server readiness before bulk imports","Monitor server health and surface it in the UI before cloud operations","Avoid running provider syncs in contexts without the OpenWork server","Retry imports that fail solely due to server unavailability"],"tags":["cloud","server","env-vars"],"backgroundTag":"client-not-connected","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}