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
- Use edit/update mode for the existing entry instead of add
- Pick a unique key name not present in the list
- 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
- Check the existing list before choosing an add key
- Refresh the env list cache before add operations
- Use edit mode for existing keys
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
- keyError (i18n validation message returned by validateKey)
- Agent context diagnostics timeout must be between 1 ms and 3
- Invalid cloud provider sync response.
- Invalid cloud provider sync status.
- Invalid cloud provider sync status response.
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/3b2895e28a39810f.
Report an issue: GitHub.