paperclipai/paperclip · error · Error

Select an organization to test adapter environment

Error message

Select an organization to test adapter environment

What it means

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.

Source

Thrown at ui/src/components/AgentConfigForm.tsx:859

    if (isCreate) {
      const next = uiAdapter.buildAdapterConfig(val!);
      if (adapterConfigPatch) {
        Object.assign(next, adapterConfigPatch);
      }
      return omitUndefinedEntries(next);
    }
    const base = config as Record<string, unknown>;
    const next = { ...base, ...overlay.adapterConfig };
    if (adapterConfigPatch) {
      Object.assign(next, adapterConfigPatch);
    }
    return omitUndefinedEntries(next);
  }

  const testEnvironment = useMutation({
    mutationFn: async () => {
      if (!selectedCompanyId) {
        throw new Error("Select an organization to test adapter environment");
      }
      const flushedEnv = flushEnvironmentDraft();
      const adapterConfigPatch = flushedEnv ? { env: flushedEnv } : undefined;
      // Probe where a real run would actually execute: the agent's own
      // environment, else the instance default. Testing the host for an
      // agent that runs in the instance-default sandbox reports failures
      // (e.g. a CLI that only exists in the sandbox image) a real run would
      // never hit. The raw id is sent even for a local environment — the
      // server resolves the driver and probes the host in that case.
      //
      // Test can be clicked before the settings query settles (or after it
      // failed with retry:false), so when the agent relies on the instance
      // default, resolve the settings here rather than trusting the
      // render-time cache. A fetch that still fails FAILS the test with an
      // honest diagnostic — silently probing the host instead would report
      // the exact false command-not-found failure this resolution exists to
      // fix. Agents with their own environment never need the settings.
      let settings = instanceSettings;

View on GitHub (pinned to 01ad858492)

Solutions

  1. Select an organization in the company selector, then retry 'test environment'.
  2. Ensure the route/page initializes company selection (the company selection context) before rendering the test action.
  3. Disable the test button until selectedCompanyId is set to prevent the dead click.
  4. Check the companies API/health if the selector is empty because the company list failed to load.

Example fix

// before
<button onClick={() => testEnvironment.mutate()} disabled={testEnvironment.isPending}>Test</button>
// after
<button onClick={() => testEnvironment.mutate()} disabled={testEnvironment.isPending || !selectedCompanyId}>Test</button>
Defensive patterns

Strategy: validation

Validate before calling

const testEnvironment = useMutation({
  mutationFn: async () => {
    if (!selectedCompanyId) throw new Error("Select an organization to test adapter environment");
    // ...
  },
});
const canTest = Boolean(selectedCompanyId);

Type guard

const hasCompany = (id: string | null | undefined): id is string =>
  typeof id === "string" && id.length > 0;

Try / catch

try {
  await testEnvironment.mutateAsync();
} catch (e) {
  if (e instanceof Error && e.message === "Select an organization to test adapter environment") {
    setToast({ kind: "warning", message: "Choose an organization first, then test the environment." });
    return;
  }
  throw e;
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of paperclipai/paperclip@01ad858492 (2026-09-02). Data as JSON: /api/errors/6b1fba6e7733fdd5. Report an issue: GitHub.