Skip to content

Failed to apply migration 00_use_single_api_key_and_url: Error: Migration failed #468

Closed
@yshngg

Description

@yshngg
Contributor

Issue Description

When I run oco, I encounter the following error:

$ oco
Applying migration 00_use_single_api_key_and_url

└─ Failed to apply migration 00_use_single_api_key_and_url: Error: Migration failed, set AI provider first. Run "oco config set OCO_AI_PROVIDER=<provider>", where <provider> is one of: ollama, openai, anthropic, gemini, azure, test, flowise, groq, mistral, mlx, deepseek

Configuration File

$ cat ~/.opencommit
OCO_AI_PROVIDER=deepseek
OCO_MODEL=deepseek-reasoner
OCO_API_URL=https://api.deepseek.com
OCO_API_KEY=sk-xxx
OCO_TOKENS_MAX_INPUT=40960
OCO_TOKENS_MAX_OUTPUT=4096
OCO_DESCRIPTION=false
OCO_EMOJI=true
OCO_LANGUAGE=en
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=$msg
OCO_PROMPT_MODULE=conventional-commit
OCO_ONE_LINE_COMMIT=true
OCO_TEST_MOCK_TYPE=commit-message
OCO_OMIT_SCOPE=false
OCO_GITPUSH=true
OCO_WHY=false

System Information

$ uname -a
Linux DESKTOP-ITA59KV 6.6.84.1-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Tue Apr  1 19:37:06 UTC 2025 x86_64 GNU/Linux

Any help would be appreciated. 🙏

Activity

di-sukharev

di-sukharev commented on Apr 30, 2025

@di-sukharev
Owner

hi, did you try to update to latest version npm i -g opencommit@latest? but anyway i think the fastest and cleanest way is to delete opencommit from your global node_modules and install it again. be careful, Node.js installs global packages in different versions, e.g. if you ever switched node version (via nvm or else) then opencommit can be in multiple folders, like node/21.0.1/node_modules/opencommit and node/19.0.1/node_modules/opencommit, i suggest you remove every one of them and install again with npm i -g opencommit@latest

yshngg

yshngg commented on Apr 30, 2025

@yshngg
ContributorAuthor

be careful, Node.js installs global packages in different versions, e.g. if you ever switched node version (via nvm or else) then opencommit can be in multiple folders, like node/21.0.1/node_modules/opencommit and node/19.0.1/node_modules/opencommit

Hi @di-sukharev , thanks for the quick response!

I suspect the issue may be caused by: I initially installed opencommit via Bun but encountered shebang execution errors. Subsequently, I installed it through Node.js, resulting in multiple installations across different locations.

I will later reinstall opencommit to confirm this hypothesis.

yshngg

yshngg commented on Apr 30, 2025

@yshngg
ContributorAuthor

Unfortunately, I still encountered the error:

Applying migration 00_use_single_api_key_and_url

└  Failed to apply migration 00_use_single_api_key_and_url: Error: Migration failed, set AI provider first. Run "oco config set OCO_AI_PROVIDER=<provider>", where <provider> is one of: ollama, openai, anthropic, gemini, azure, test, flowise, groq, mistral, mlx, deepseek

Steps I Performed:

1. Uninstalled bun
rm -rf ~/.bun
2. Uninstalled oco/opencommit
npm uninstall -g opencommit
3. Reinstalled opencommit
npm install -g opencommit
4. Attempted to run opencommit
$ oco
Applying migration 00_use_single_api_key_and_url

└  Failed to apply migration 00_use_single_api_key_and_url: Error: Migration failed, set AI provider first. Run "oco config set OCO_AI_PROVIDER=<provider>", where <provider> is one of: ollama, openai, anthropic, gemini, azure, test, flowise, groq, mistral, mlx, deepseek
5. Additional environment information
$ which oco
/run/user/1000/fnm_multishells/376781_1746015561650/bin/oco
$ which opencommit
/run/user/1000/fnm_multishells/376781_1746015561650/bin/opencommit

$ npm -v
11.3.0
$ node -v
v22.15.0
di-sukharev

di-sukharev commented on Apr 30, 2025

@di-sukharev
Owner

okay, could you confirm there are no opencommits installed in different node versions? it should be in Users/<you>/.nvm/versions/node/<version>/<here>

wjx0912

wjx0912 commented on Jun 4, 2025

@wjx0912

i have the same problem, .opencommit:

OCO_AI_PROVIDER=deepseek
OCO_MODEL=deepseek-reasoner
OCO_API_URL=https://api.deepseek.com
OCO_API_KEY=sk-e45f64c6a25c437*********
OCO_TOKENS_MAX_INPUT=40960
OCO_TOKENS_MAX_OUTPUT=4096
OCO_DESCRIPTION=false
OCO_EMOJI=true
OCO_LANGUAGE=zh_CN
OCO_MESSAGE_TEMPLATE_PLACEHOLDER=$msg
OCO_PROMPT_MODULE=conventional-commit
OCO_ONE_LINE_COMMIT=false
OCO_TEST_MOCK_TYPE=commit-message
OCO_OMIT_SCOPE=false
OCO_GITPUSH=false
OCO_WHY=false

wjx0912

wjx0912 commented on Jun 4, 2025

@wjx0912

i create a file: %userprofile%/.opencommit_migrations

[
  "00_use_single_api_key_and_url",
  "01_remove_obsolete_config_keys_from_global_file",
  "02_set_missing_default_values"
]

the oco work normal

di-sukharev

di-sukharev commented on Jun 8, 2025

@di-sukharev
Owner

a weird issue, please close if all ok now

Vincentqyw

Vincentqyw commented on Jun 21, 2025

@Vincentqyw

i create a file: %userprofile%/.opencommit_migrations

[
  "00_use_single_api_key_and_url",
  "01_remove_obsolete_config_keys_from_global_file",
  "02_set_missing_default_values"
]

the oco work normal

Same issue. This works!

reopened this on Jun 23, 2025
yshngg

yshngg commented on Jun 23, 2025

@yshngg
ContributorAuthor

The migration feature was implemented to ensure backward compatibility, but found a small gap in coverage. The migration script at src/migrations/00_use_single_api_key_and_url.ts doesn't exhaustively handle all providers from the OCO_AI_PROVIDER_ENUM defined in src/commands/config.ts.

if (aiProvider === OCO_AI_PROVIDER_ENUM.OLLAMA) {
apiKey = config['OCO_OLLAMA_API_KEY'];
apiUrl = config['OCO_OLLAMA_API_URL'];
} else if (aiProvider === OCO_AI_PROVIDER_ENUM.ANTHROPIC) {
apiKey = config['OCO_ANTHROPIC_API_KEY'];
apiUrl = config['OCO_ANTHROPIC_BASE_PATH'];
} else if (aiProvider === OCO_AI_PROVIDER_ENUM.OPENAI) {
apiKey = config['OCO_OPENAI_API_KEY'];
apiUrl = config['OCO_OPENAI_BASE_PATH'];
} else if (aiProvider === OCO_AI_PROVIDER_ENUM.AZURE) {
apiKey = config['OCO_AZURE_API_KEY'];
apiUrl = config['OCO_AZURE_ENDPOINT'];
} else if (aiProvider === OCO_AI_PROVIDER_ENUM.GEMINI) {
apiKey = config['OCO_GEMINI_API_KEY'];
apiUrl = config['OCO_GEMINI_BASE_PATH'];
} else if (aiProvider === OCO_AI_PROVIDER_ENUM.FLOWISE) {
apiKey = config['OCO_FLOWISE_API_KEY'];
apiUrl = config['OCO_FLOWISE_ENDPOINT'];
} else {
throw new Error(
`Migration failed, set AI provider first. Run "oco config set OCO_AI_PROVIDER=<provider>", where <provider> is one of: ${Object.values(
OCO_AI_PROVIDER_ENUM
).join(', ')}`
);
}

export enum OCO_AI_PROVIDER_ENUM {
OLLAMA = 'ollama',
OPENAI = 'openai',
ANTHROPIC = 'anthropic',
GEMINI = 'gemini',
AZURE = 'azure',
TEST = 'test',
FLOWISE = 'flowise',
GROQ = 'groq',
MISTRAL = 'mistral',
MLX = 'mlx',
DEEPSEEK = 'deepseek',
OPENROUTER = 'openrouter'
}

This causes errors like "Failed to apply migration 00_use_single_api_key_and_url..." when users try to use providers that aren't handled in the migration code.

yshngg

yshngg commented on Jun 23, 2025

@yshngg
ContributorAuthor

Hi @di-sukharev , I'm willing to contribute to solving this issue but I'm confused 🤔 about which option to choose.

Here are potential solutions I could consider:

  1. Skip unhandled providers in migration00
  2. Add all providers to migration00
  3. Remove migration code entirely

Could you share your thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @wjx0912@Vincentqyw@di-sukharev@yshngg

      Issue actions

        Failed to apply migration 00_use_single_api_key_and_url: Error: Migration failed · Issue #468 · di-sukharev/opencommit