{"record":{"id":"6b1fba6e7733fdd5","repo":"paperclipai/paperclip","slug":"select-an-organization-to-test-adapter-environment","errorCode":null,"errorMessage":"Select an organization to test adapter environment","messagePattern":"Select an organization to test adapter environment","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ui/src/components/AgentConfigForm.tsx","lineNumber":859,"sourceCode":"    if (isCreate) {\n      const next = uiAdapter.buildAdapterConfig(val!);\n      if (adapterConfigPatch) {\n        Object.assign(next, adapterConfigPatch);\n      }\n      return omitUndefinedEntries(next);\n    }\n    const base = config as Record<string, unknown>;\n    const next = { ...base, ...overlay.adapterConfig };\n    if (adapterConfigPatch) {\n      Object.assign(next, adapterConfigPatch);\n    }\n    return omitUndefinedEntries(next);\n  }\n\n  const testEnvironment = useMutation({\n    mutationFn: async () => {\n      if (!selectedCompanyId) {\n        throw new Error(\"Select an organization to test adapter environment\");\n      }\n      const flushedEnv = flushEnvironmentDraft();\n      const adapterConfigPatch = flushedEnv ? { env: flushedEnv } : undefined;\n      // Probe where a real run would actually execute: the agent's own\n      // environment, else the instance default. Testing the host for an\n      // agent that runs in the instance-default sandbox reports failures\n      // (e.g. a CLI that only exists in the sandbox image) a real run would\n      // never hit. The raw id is sent even for a local environment — the\n      // server resolves the driver and probes the host in that case.\n      //\n      // Test can be clicked before the settings query settles (or after it\n      // failed with retry:false), so when the agent relies on the instance\n      // default, resolve the settings here rather than trusting the\n      // render-time cache. A fetch that still fails FAILS the test with an\n      // honest diagnostic — silently probing the host instead would report\n      // the exact false command-not-found failure this resolution exists to\n      // fix. Agents with their own environment never need the settings.\n      let settings = instanceSettings;","sourceCodeStart":841,"sourceCodeEnd":877,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/ui/src/components/AgentConfigForm.tsx#L841-L877","documentation":"In AgentConfigForm, the 'test adapter environment' mutation (useMutation around line 800) requires an organization context: if selectedCompanyId is falsy it throws a plain Error before flushing the environment draft and probing the adapter. The mutation's error state surfaces this message so the user knows why the test did not run.","triggerScenarios":"Clicking 'test environment' in the agent config form while no company/organization is selected — e.g. the page loaded without a company in the selection context, or the company selector was cleared before testing.","commonSituations":"Deep-linking to an agent config page without choosing an organization first; the company context failing to load (API error) leaving selection empty; a user clearing the org dropdown and immediately pressing test.","solutions":["Select an organization in the company selector, then retry 'test environment'.","Ensure the route/page initializes company selection (the company selection context) before rendering the test action.","Disable the test button until selectedCompanyId is set to prevent the dead click.","Check the companies API/health if the selector is empty because the company list failed to load."],"exampleFix":"// before\n<button onClick={() => testEnvironment.mutate()} disabled={testEnvironment.isPending}>Test</button>\n// after\n<button onClick={() => testEnvironment.mutate()} disabled={testEnvironment.isPending || !selectedCompanyId}>Test</button>","handlingStrategy":"validation","validationCode":"const testEnvironment = useMutation({\n  mutationFn: async () => {\n    if (!selectedCompanyId) throw new Error(\"Select an organization to test adapter environment\");\n    // ...\n  },\n});\nconst canTest = Boolean(selectedCompanyId);","typeGuard":"const hasCompany = (id: string | null | undefined): id is string =>\n  typeof id === \"string\" && id.length > 0;","tryCatchPattern":"try {\n  await testEnvironment.mutateAsync();\n} catch (e) {\n  if (e instanceof Error && e.message === \"Select an organization to test adapter environment\") {\n    setToast({ kind: \"warning\", message: \"Choose an organization first, then test the environment.\" });\n    return;\n  }\n  throw e;\n}","preventionTips":["Disable the test button while selectedCompanyId is unset","Initialize company selection from route params/context on page load","Handle company-list load failures so the selector never silently renders empty","Guard other company-scoped mutations in the form the same way"],"tags":["ui","react","missing-selection","company-scope"],"backgroundTag":"missing-required-selection","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-02T18:44:00.616Z","contentChangedAt":"2026-09-02T18:44:00.616Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}