different-ai/openwork · error

settings.environment.validation_duplicate

settings.environment.validation_duplicate

Error message

t("settings.environment.validation_duplicate")

What it means

When adding an environment variable, the mutation checks the cached env items (React Query cache for environmentUserEnvQueryKey) for a duplicate key and throws the localized "settings.environment.validation_duplicate" error if one already exists, preventing a conflicting upsert in "add" mode.

Source

Thrown at apps/app/src/react-app/domains/settings/pages/environment-variable-provider.tsx:155

  const { mutate: modifyAsync, isPending: isModifying, reset: resetModify, error: modifyError } = useMutation({
    mutationFn: async (nextEditor: EnvironmentEditorDraft) => {
      if (!client) {
        throw new Error(t("app.unknown_error"));
      }

      const keyError = validateKey(nextEditor.key);

      if (keyError) {
        throw new Error(keyError);
      }

      const key = nextEditor.key.trim();
      const existingItems = queryClient.getQueryData<{ items: EnvironmentVariableItem[] }>(
        environmentUserEnvQueryKey(runtimeKey),
      )?.items;

      if (nextEditor.mode === "add" && existingItems?.some((item) => item.key === key)) {
        throw new Error(t("settings.environment.validation_duplicate"));
      }

      return client.upsertUserEnv([{ key, value: nextEditor.value }]);
    },
    onSuccess: async () => {
      markChangesPending();

      await queryClient.invalidateQueries({
        queryKey: environmentUserEnvQueryKey(runtimeKey),
      });
    },
  }); 

  const { mutate: removeAsync, isPending: isRemoving, reset: resetRemove, error: removeError } = useMutation({
    mutationFn: async (key: string) => {
      if (!client) {
        throw new Error(t("app.unknown_error"));
      }

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Use edit/update mode for the existing entry instead of add
  2. Pick a unique key name not present in the list
  3. Refresh the environment variable list so the cache reflects current server state, then retry

Example fix

// before
mode: "add", key: "DEBUG"
// after (key exists)
mode: "edit", key: "DEBUG", value: newValue
Defensive patterns

Strategy: validation

Validate before calling

const items = queryClient.getQueryData<{ items: EnvironmentVariableItem[] }>(
  environmentUserEnvQueryKey(runtimeKey),
)?.items ?? [];
if (mode === "add" && items.some(i => i.key === key.trim())) {
  showDuplicateError();
  return;
}
modifyAsync(draft);

Try / catch

try {
  modifyAsync(draft);
} catch (e) {
  if (e.message.includes("validation_duplicate")) highlightExistingRow(draft.key);
  else throw e;
}

Prevention

When it happens

Trigger: modifyAsync with mode === "add" and a key that already exists in the current environment variable list for this runtime.

Common situations: Trying to add a variable like "PATH" or "NODE_ENV" that already exists; stale list vs. cache mismatch confusion; re-submitting a form after a previous successful add.

Related errors


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