Skip to content

Fix opencode Unsloth provider selection - #6906

Merged
wasimysaid merged 13 commits into
unslothai:mainfrom
Imagineer99:fix/opencode-unsloth-provider-selection
Jul 8, 2026
Merged

wasimysaid merged 13 commits into
unslothai:mainfrom
Imagineer99:fix/opencode-unsloth-provider-selection

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

Summary

  • Ensure the session Unsloth provider is not disabled in opencode config.
  • Launch opencode with an explicit --model unsloth/<model> argument.
  • Add regressions for user config that disables unsloth and for the no-launch command/env output.

Root Cause

unsloth start opencode writes a session provider named unsloth, but opencode merges user config first. If the user-level config contains disabled_providers = ["unsloth"], the session provider exists but remains disabled, so the TUI can fall back to another configured provider/model such as Ollama Cloud.

Validation

  • python -m py_compile unsloth_cli/commands/start.py unsloth_cli/tests/test_start.py
  • git diff --check
  • Targeted Windows pytest: test_write_opencode_config_fresh, test_write_opencode_config_preserves_and_idempotent, test_connect_opencode_no_launch
  • Manual resolved-config check with installed opencode confirmed disabled_providers: [] enables the unsloth provider.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the opencode configuration and command-line execution to ensure that 'unsloth' is not disabled in the disabled_providers list and explicitly passes the --model flag. It also adds corresponding unit tests. Feedback is provided regarding a potential test failure on non-Windows platforms where single quotes wrapping the environment variable are not stripped, which causes a JSON decoding error.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread unsloth_cli/tests/test_start.py Resolved
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b2999759d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/tests/test_start.py Resolved
The session overlay wrote disabled_providers unconditionally and the inline
OPENCODE_CONFIG_CONTENT set disabled_providers to an empty list. Since that
inline layer outranks the user's global and project config and opencode
replaces the array rather than merging it, every provider the user had
disabled was silently re-enabled for the session. Only strip 'unsloth' from an
existing disable list, and drop disabled_providers from the inline config.

Also insert --model only on a bare launch: it is a global flag for the TUI, so
placing it before a passthrough subcommand (serve/run) breaks arg parsing; a
subcommand takes the model from the pinned config instead. Parse the printed
OPENCODE_CONFIG_CONTENT with shlex.split in the test so it round-trips under
POSIX shell quoting.
@danielhanchen

Copy link
Copy Markdown
Member

Pushed a small revision (19e16a4) on top of your branch:

  • Only strip unsloth from an existing disabled_providers list instead of writing it unconditionally, and drop disabled_providers: [] from the inline OPENCODE_CONFIG_CONTENT. That inline layer outranks the user's global and project config, and opencode replaces the array rather than merging it, so the previous version silently re-enabled every provider the user had disabled for the session.
  • Insert --model only on a bare launch. It is a global flag for the TUI, so placing it before a passthrough subcommand (serve/run) breaks arg parsing; a subcommand takes the model from the pinned config instead.
  • Parse the printed OPENCODE_CONFIG_CONTENT with shlex.split in the test so it round-trips under POSIX shell quoting. The previous .strip('"') left the single quotes that shlex.quote adds on Linux/macOS and raised JSONDecodeError; the sibling test is aligned too.

Verified with the full test_start.py suite (129 passed, 3 skipped) plus new regression tests for the disabled-providers preservation and the passthrough argv.

…h-provider-selection

# Conflicts:
#	unsloth_cli/commands/start.py
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 15ddbf7051

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/start.py Resolved
A fresh OPENCODE_CONFIG overlay omits disabled_providers, and opencode
replaces that array across config layers only when a higher layer sets the
key, so a user's global disabled_providers of ['unsloth', ...] survived the
merge and left the session provider disabled even though the overlay defines
provider.unsloth and pins the model.

Consult the user's global opencode config (XDG_CONFIG_HOME/opencode, or
%APPDATA%/opencode on Windows) when the overlay has no list of its own, and
when the effective list disables unsloth write it back to the overlay minus
unsloth. The provider loads while the user's other disabled providers stay
disabled. Best-effort read: a missing or unparseable global config is a
no-op.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d60f55439

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
…flag for TUI flags

Re-enabling a disabled unsloth provider now rides in the inline
OPENCODE_CONFIG_CONTENT layer instead of the session overlay. The overlay
sits below a project opencode.json, which could re-disable the provider; the
inline layer outranks both global and project configs and is recomputed each
run, so no-launch reruns never reuse a stale generated list. The effective
disabled list is read from the project config if the repo sets one, else the
global config, across config.json/opencode.json/opencode.jsonc (JSONC
tolerated), and written back minus unsloth only when unsloth is disabled.

Also keep the pinned --model when the opencode passthrough starts with a
top-level TUI flag such as --dir or --continue; only a real subcommand
(serve/run/...) takes the model from config, so a leading '-' now still gets
--model injected.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f43e072ae4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/tests/test_start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
opencode finds a project config by searching ancestor directories, not just
the cwd. Walk from the cwd up to the filesystem root and use the nearest
directory that sets disabled_providers, so running unsloth start opencode
from a subdirectory of a repo whose root config disables unsloth still gets
the inline override.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 714cc30d57

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Outdated
Comment on lines +1173 to +1174
for name in ("config.json", "opencode.json", "opencode.jsonc"):
data = _load_opencode_config(directory / name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scan .opencode configs for disabled providers

When a project keeps its OpenCode settings in the supported .opencode/opencode.json or .opencode/opencode.jsonc directory config, this helper never reads it, because it only checks files directly in each walked directory. In that setup, .opencode/opencode.json with disabled_providers: ["unsloth"] is still loaded by OpenCode and disables the provider, but the wrapper thinks nothing needs to be overridden and omits the inline disabled_providers fix.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid: opencode also reads .opencode/ config directories, which the scan does not cover. See the summary comment below.

Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
…el pin

Injecting --model whenever the passthrough started with a flag could place it
before a subcommand (e.g. opencode --print-logs serve), which opencode can
misparse. --model is unnecessary for any passthrough because the inline
OPENCODE_CONFIG_CONTENT pins the model in the highest-priority layer, so the
session model is forced without the flag. Restrict --model to the bare launch
and pass any other invocation through untouched.
@danielhanchen

Copy link
Copy Markdown
Member

On the disabled_providers handling: the recent review items (global config dirs, ancestor project walk, .opencode directories, OPENCODE_CONFIG_DIR, the --dir target, config.json/opencode.json/opencode.jsonc, JSONC comments, {env:...} variable substitution, and multi-file merge order) are each valid, and together they show that computing the effective disabled_providers this way means reimplementing opencode's full config resolution. That surface is large and keeps growing, so the read-and-rewrite approach is hard to make correct and keep correct.

A simpler and fully robust alternative sidesteps all of it: register the session provider under an id the user's disabled_providers cannot match (for example a session-scoped id like unsloth-studio) instead of unsloth, and pin the model to <that-id>/<model>. The displayed provider name stays "Unsloth Studio"; only the internal id changes. With that, there is no disabled list to read or override, so none of the config-resolution edge cases apply.

The current inline-layer override is in place and covers the common global and project cases, so this PR is not blocked. But given the growing edge-case list, switching to a session-unique provider id is likely the cleaner long-term fix. Happy to help wire that up if you want to go that route.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f06c808575

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
Selecting the Unsloth model reliably required the wrapper to re-enable a
user-disabled unsloth provider, which meant reconstructing OpenCode's full
disabled_providers resolution (global, OPENCODE_CONFIG overlay, project config
discovered via --dir or an ancestor walk, .opencode directories,
OPENCODE_CONFIG_DIR, config.json/opencode.json/opencode.jsonc precedence, and
{env:} variable substitution) and overriding it in the inline layer. That is
unbounded and cannot be kept correct.

Register the session provider under a dedicated id (unsloth-studio) instead. A
user's disabled_providers list would never target it, so the session model is
always selectable and the overlay no longer reads or writes disabled_providers
at all: the user's own disables, in whatever config layer, are left exactly as
they are. This removes the JSONC parser, the config-directory scan, and the
ancestor/global resolution helpers, and the tests that exercised them.
@danielhanchen

Copy link
Copy Markdown
Member

Switched the opencode integration to register the session provider under a dedicated id (unsloth-studio) instead of reading and rewriting the user's disabled_providers.

Why: making the model selectable when the user disabled the unsloth provider required reconstructing opencode's entire disabled_providers resolution (global config, the OPENCODE_CONFIG overlay, the project config selected by --dir or found by an ancestor walk, .opencode directories, OPENCODE_CONFIG_DIR, the config.json/opencode.json/opencode.jsonc precedence, and {env:} variable substitution) and overriding it in the inline layer. That surface is unbounded and each missed source silently left the provider disabled.

Registering under an id the user's disable list would never target sidesteps all of it: the session model is always selectable, and the overlay no longer touches disabled_providers in any layer, so the user's own disables are preserved exactly. This removes the JSONC parser, the config-directory scan, and the ancestor/global resolution helpers along with their tests (net -197 lines). The other agents (codex/factory/hermes/pi) keep the unsloth provider id since they have no equivalent disable mechanism.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b81e22235

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# user's disable list would never target, so the model is always selectable
# without the wrapper having to reconstruct (and override) OpenCode's full,
# multi-layer disabled_providers resolution.
_OPENCODE_PROVIDER = "unsloth-studio"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Account for enabled_providers allowlists

OpenCode's config docs say enabled_providers is an allowlist where only the listed provider IDs are enabled, and merged lower-priority config keys are preserved. With this new provider id, a user who already had enabled_providers: ["unsloth"] (which matched the previous session provider) will now keep that allowlist while the wrapper writes and pins unsloth-studio/...; OpenCode then filters out the session provider before the pinned model can load, so unsloth start opencode still falls back/fails for those configs. The fix needs to handle enabled_providers in the overlay as well, or keep using an ID that existing allowlists include.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 1e6c5de. Confirmed against opencode source that enabled_providers/disabled_providers filter config-defined providers too, a model pin does not bypass the gate, and both arrays are replaced (not merged) across layers. The inline OPENCODE_CONFIG_CONTENT overlay now sets enabled_providers to just the session provider and clears disabled_providers, which (being the highest-priority layer that replaces these arrays) guarantees the Studio model survives any user allowlist or denylist. It is session-only and never reads or edits the user's config files, so their persistent opencode config is untouched; only this session is scoped to the Studio provider.

Comment thread unsloth_cli/tests/test_start.py Resolved
Comment thread unsloth_cli/commands/start.py Resolved
opencode filters every provider, including a config-defined custom one, through
its enabled_providers allowlist and disabled_providers denylist, and pinning the
model does not bypass that gate (a filtered provider resolves to a not-found
error). The provider arrays are also replaced, not merged, across config layers.
So a user with an enabled_providers allowlist that omits the session provider
would still have the Studio model filtered out.

Set enabled_providers to just the session provider and clear disabled_providers
in the inline OPENCODE_CONFIG_CONTENT overlay (the highest-priority layer, which
replaces these arrays). This guarantees the Studio model loads regardless of the
user's provider filters, without reading or reconstructing their multi-layer
config. It is session-only: the overlay lives in the env for this launch and
never touches the user's config files, so their normal opencode is unchanged and
only this session is limited to the Studio provider.

Also drop the redundant --model on --no-launch so the printed command stays
append-safe for drivers that append a subcommand (the inline pin forces the
model), and parse both POSIX and PowerShell no-launch output in the opencode
tests so they are not shell-specific.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e6c5dec0b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1498 to +1502
inline_config: dict = {
"model": opencode_model,
"enabled_providers": [_OPENCODE_PROVIDER],
"disabled_providers": [],
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pin small_model under the provider allowlist

When a user or project already has small_model set to another provider (for example openai/gpt-4o-mini), this inline overlay now allowlists only _OPENCODE_PROVIDER but leaves that separate model setting intact. OpenCode documents small_model as a separate model used for lightweight tasks and enabled_providers as an allowlist, so those tasks can resolve a filtered provider and error even though the main model is pinned to Studio; include "small_model": opencode_model in the same overlay (or avoid the allowlist) so all model uses stay on the enabled provider.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 60ec64b: the inline overlay now also pins small_model to the session model. Since the session serves one model and is scoped to the Studio provider, that is the only valid target, so opencode's lightweight tasks stay on the enabled provider instead of resolving a filtered one. Still session-only; the user's config is untouched.

The session allowlists only the Studio provider, but opencode's separate
small_model (used for lightweight tasks) could still point at another provider
from the user or project config; under the allowlist that provider is filtered,
so the lightweight task would resolve a not-found error mid-session even with the
main model pinned. Pin small_model to the session model in the same inline
overlay so every model use stays on the enabled provider. The session serves one
model, so it is the only valid target, and this stays session-only like the rest
of the overlay.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 60ec64bd13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@wasimysaid
wasimysaid marked this pull request as ready for review July 8, 2026 09:22
@wasimysaid
wasimysaid merged commit 393d7e9 into unslothai:main Jul 8, 2026
23 of 43 checks passed
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

2 similar comments
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 393d7e9c2b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants