Skip to content

v2: experimental.policies not enforced for model selection or LLM execution #34971

Closed as not planned

Description

@GermainBergeron

Description

Summary:
experimental.policies statements are parsed and loaded into the v2 Policy service but are not enforced by the Provider.Service that powers model listing, model selection, and session execution.

Expected behavior:
Denied providers should be excluded from model listing and rejected at execution time, as documented:

A provider denied by policy is not available for model selection or model use, even if it has credentials or is otherwise configured correctly.

Root cause:
The v2 Catalog (packages/core/src/catalog.ts) correctly evaluates policies in its finalize step, but nothing in the active code path uses it. The v2 Catalog is only consumed by debug v2 today.

Workaround:
Use the older enabled_providers field:

{
  "enabled_providers": ["anthropic"]
}

Plugins

N/A

OpenCode version

1.17.13

Steps to reproduce

  1. Configure policies in opencode.json:
    {
      "experimental": {
        "policies": [
          { "effect": "deny", "action": "provider.use", "resource": "*" },
          { "effect": "allow", "action": "provider.use", "resource": "anthropic" }
        ]
      }
    }
  2. Run opencode models — all providers with credentials still appear, not just anthropic.
  3. Select a denied provider's model and send a prompt — it executes successfully.

Screenshot and/or share link

TUI
Image

Desktop app:

Image

Operating System

macOS 26.5.1

Terminal

iTerm2

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Jul 4, 2026
  2. changed the title [-]`experimental.policies` not enforced for model selection or LLM execution[/-] [+]v2: `experimental.policies` not enforced for model selection or LLM execution[/+] on Jul 4, 2026
  3. github-actions commented on Sep 3, 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.

  4. lucashervier commented on Oct 7, 2026

    @lucashervier

    Still reproducible on OpenCode 1.18.35.

    I have a project config with a custom provider and a deny-all/allow-one provider policy:

    {
      "model": "custom/gpt-5.6-terra",
      "provider": {
        "custom": {
          "npm": "@ai-sdk/openai",
          "name": "Custom Gateway",
          "options": {
            "baseURL": "http://localhost:xxxx/openai/v1"
          }
        }
      },
      "experimental": {
        "policies": [
          {
            "effect": "deny",
            "action": "provider.use",
            "resource": "*"
          },
          {
            "effect": "allow",
            "action": "provider.use",
            "resource": "custom"
          }
        ]
      }
    }

    opencode debug config confirms that the policy is loaded.
    However, this still succeeds:

    opencode run \
      --model 'opencode/muse-spark-1.3-contributor-free' \
      --print-logs \
      --log-level DEBUG \
      'Reply exactly: POLICY_BYPASS_TEST'

    Relevant log lines:
    providerID=opencode
    modelID=muse-spark-1.3-contributor-free
    llm.provider=opencode
    llm.model=muse-spark-1.3-contributor-free

    And the model successfully replies:
    POLICY_BYPASS_TEST

    So provider.use is still not being enforced for execution in 1.18.35.
    As a workaround, adding:

    "enabled_providers": ["custom"]
    

    does correctly prevent the opencode provider from being resolved/used. The same CLI command then fails with ProviderModelNotFoundError.

    Environment:

    • OpenCode 1.18.35
    • Ubuntu on WSL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

2.0coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions