Skip to content

Env vars used without consent + model_not_found causes infinite retry loop #14723

Closed as not planned

Description

@7shi

Description

Two distinct but related problems occur when OPENAI_API_KEY is set in the environment and an OpenAI model is selected via /models without running /connect.

1. Design concern — Implicit API key usage

At startup, packages/opencode/src/provider/provider.ts (lines 811–821) scans all environment variables and auto-registers any provider whose key is present, without user confirmation. When the OpenAI provider is registered this way, the background title-generation call in packages/opencode/src/session/summary.ts (summarizeMessage, lines 120–166) resolves gpt-5-nano within the user's own OpenAI provider via Provider.getSmallModel(). As a result, the request is sent directly to OpenAI using the user's API key, consuming their credits without explicit authorization.

Note: When a non-OpenAI provider is in use, title generation goes through OpenCode Zen's own servers by default, as documented in the official provider docs. The concern here is specific to the OpenAI case, where the user's own API key is used silently.

2. Bug — Infinite retry loop on model_not_found

When the selected model is inaccessible, OpenAI returns:

{"type": "error", "error": {"type": "invalid_request_error", "code": "model_not_found", "message": "The model 'gpt-5.3-codex' does not exist or you do not have access to it."}}

In packages/opencode/src/session/retry.ts (lines 92–98), the retryable() function contains an overly broad catch-all condition !!json.error, which matches any response with an error field — including permanent errors like model_not_found. The function returns a non-undefined value, causing packages/opencode/src/session/processor.ts to enter its retry path. The loop (while (true), line 49) has no maximum attempt cap, so the session retries indefinitely until the user manually aborts.

Plugins

No response

OpenCode version

1.2.10

Steps to reproduce

  1. Set a valid OPENAI_API_KEY in your shell environment.
  2. Launch OpenCode TUI.
  3. Select an OpenAI model (e.g., GPT-5.3 Codex) via /models without running /connect.
  4. Type a prompt and submit it.
  5. Observe that the session enters an infinite retry loop displaying "Provider Server Error".
  6. Check API usage; a gpt-5-nano request for session title generation has already fired against your OPENAI_API_KEY.

Screenshot and/or share link

Image

Operating System

Windows 11 (WSL2)

Terminal

Windows Terminal

Activity

  1. added
    bugSomething isn't working
    on Feb 22, 2026
  2. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Feb 22, 2026
  3. github-actions commented on Feb 22, 2026

    @github-actions
    Contributor

    This issue might be related to an existing issue. Please check:

  4. 7shi commented on Feb 22, 2026

    @7shi
    Author

    Thanks for the pointer. #12234 shares the same processor.ts while (true) loop, but the root cause and fix area are different:

    • There, StreamIdleTimeoutError is explicitly marked isRetryable: true in message-v2.ts, so retryable() works as intended. The problems are the lack of a max retry cap and the doom loop detection not firing for incomplete tool inputs.
    • Here, model_not_found is a permanent API-level rejection that is not explicitly marked retryable — it falls into the overly broad !!json.error catch-all in retry.ts lines 92–98 unintentionally. Fixing that issue would not touch this code path.

    So the two issues require different fixes: that issue needs a retry cap and better doom loop detection; this one needs retryable() to explicitly exclude invalid_request_error and similar permanent error types.

    Additionally, the implicit API key usage described here (Problem 1) is entirely unrelated and should be addressed independently.

  5. Cleroth commented on Mar 24, 2026

    @Cleroth

    Automatically loading the keys is fine, but I would really prefer having a way to remove them to provide a different key or OAuth. (In the desktop app at least).

    The desktop app also doesn't really make it clear whether the ChatGPT subscription is being used or not even after logging in, it just says OpenAI [Environment] so I'd assume not.

  6. assigned and unassigned on Apr 26, 2026
  7. removed
    bugSomething isn't working
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  8. github-actions commented on Jul 4, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions