Skip to content

feat: detect installed coding agent CLIs in Studio settings - #6909

Merged
danielhanchen merged 23 commits into
unslothai:mainfrom
ErenAta16:add-coding-agent-detection
Jul 8, 2026
Merged

danielhanchen merged 23 commits into
unslothai:mainfrom
ErenAta16:add-coding-agent-detection

Conversation

@ErenAta16

Copy link
Copy Markdown
Contributor

The API-keys panel only ever showed the "claude" flavor of the unsloth start command, so anyone using Codex, OpenCode, OpenClaw, Hermes, or Pi had to manually rewrite the copied command by hand.

Add a backend check that looks for each agent's CLI binary on PATH (shutil.which, mirroring the pattern already used elsewhere in studio/backend/utils) and expose it as GET /api/settings/coding-agents. The API-keys panel now renders a picker for all six supported agents, marks the ones it finds installed, and defaults to one of those instead of always falling back to claude.

Includes unit tests for the detection helper.

The API-keys panel only ever showed the "claude" flavor of the
`unsloth start` command, so anyone using Codex, OpenCode, OpenClaw,
Hermes, or Pi had to manually rewrite the copied command by hand.

Add a backend check that looks for each agent's CLI binary on PATH
(shutil.which, mirroring the pattern already used elsewhere in
studio/backend/utils) and expose it as GET /api/settings/coding-agents.
The API-keys panel now renders a picker for all six supported agents,
marks the ones it finds installed, and defaults to one of those instead
of always falling back to claude.

Includes unit tests for the detection helper.
@ErenAta16
ErenAta16 requested a review from danielhanchen as a code owner July 6, 2026 15:05

@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 introduces dynamic detection of installed coding-agent CLIs (such as Claude, Codex, OpenClaw, etc.) on the system's PATH, allowing the frontend to default to an immediately runnable command in the API-keys settings panel. It adds a backend detection utility, a settings API endpoint, corresponding unit tests, and updates the frontend UsageExamples component to display and select the detected agents. The review feedback is highly constructive and identifies three key improvements: defensively catching exceptions during PATH detection to avoid API failures, using an immutable tuple instead of a mutable list for the Pydantic model's default field to prevent side effects, and fixing a race condition in the React component that could override a user's manual agent selection before the asynchronous detection promise resolves.

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 studio/backend/utils/coding_agents.py Resolved
Comment thread studio/backend/routes/settings.py Resolved
ErenAta16 added 2 commits July 6, 2026 18:10
Three fixes from PR review:

- detect_installed_coding_agents now treats a PATH lookup failure as
  "not installed" instead of letting it bubble up and break the
  settings endpoint; added a regression test for it.
- CodingAgentsResponse.agents is now typed as an immutable tuple
  instead of a list built from one, matching CODING_AGENTS itself.
- Fixed a race in the API-keys panel: picking an agent while the
  installed-CLI check is still in flight could get silently overwritten
  once that check resolved. A ref now tracks whether the user has made
  a manual choice, so the auto-detected default only applies before
  that happens.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 1f65a15ede

ℹ️ 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".

@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: eff559e9e4

ℹ️ 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".

// already made -- including one made while this request was in
// flight, which a value comparison against "claude" alone would miss.
if (!agentPickedByUserRef.current && info.detected.length > 0) {
setAgent(info.detected[0]);

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 Avoid defaulting to Codex for non-GGUF models

When Claude is not on PATH but Codex is, this picks codex unconditionally. I checked unsloth_cli/commands/start.py:1378, and the Codex subcommand preflights _require_gguf_for_codex(...) before launch, which exits for transformers-backed models; so with any non-GGUF model loaded the copied unsloth start codex command fails even though the panel says it uses the loaded model and marks Codex as installed. Please gate the auto-default on the current model being GGUF, or leave a compatible agent selected.

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.

Good catch, this is reachable: the codex start path preflights _require_gguf_for_codex and exits for transformers-backed models. The component already reads the GGUF signal (activeGgufVariant), so the auto-default can skip codex unless a GGUF model is loaded. In the detection effect, read the live value with useChatRuntimeStore.getState().activeGgufVariant inside the .then() (so it need not go in the deps), then pick info.detected.find((a) => a !== "codex" || isGguf) instead of detected[0], leaving the default untouched when no compatible agent is detected.

.then((info) => {
if (cancelled) return;
setAvailableAgents(info.agents);
setDetectedAgents(info.detected);

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 Avoid using the server PATH as the client install state

In remote/tunnel sessions, info.detected comes from /api/settings/coding-agents, whose backend implementation checks shutil.which(...) on the Studio server, but the copied command is meant to be run wherever the user launches the agent. When the browser is on a different machine from the backend, this marks and defaults based on the remote server's CLIs rather than the user's local CLIs, so it can select a command the user cannot run (or miss one they can); disable detection/defaulting for remote bases or make the scope explicit.

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.

Agreed: for remote/tunnel bases info.detected reflects the Studio server's PATH, not the client's. Suggest gating the auto-default (and the "detected" marking) on the base being loopback. agent-command.ts already has isLoopbackHost; export it and skip detection-driven defaulting when the resolved base host is not loopback, so a remote server's CLIs do not drive the local command.

- codex refuses to launch against a non-GGUF (transformers-backed) model
  (unsloth_cli's _require_gguf_for_codex), so auto-defaulting to it produced
  a copy-pasteable command that fails immediately whenever the loaded model
  isn't GGUF. Add useActiveModelIsGguf() (looks up the active checkpoint in
  the chat runtime store) and a correction effect that steers the auto-pick
  away from codex unless the loaded model qualifies, without ever touching a
  choice the user made by hand.
- Detection runs via shutil.which on the Studio backend host, which isn't
  the same machine as the browser in a tunnel/remote session. Reword the
  'installed'/'detected' copy to say so explicitly when the tunnel URL is
  in use, instead of implying the check ran on the viewer's own device.
Replaces the previous approach with the exact shape discussed on the PR:

- Export isLoopbackHost/normalizeHost from agent-command.ts. The detection
  endpoint runs shutil.which on the Studio backend, which only describes the
  browser's own machine when the base this panel targets resolves to
  loopback. For a LAN or tunnel/remote base, gate the whole thing off --
  don't mark anything as "detected" and don't let it drive the default --
  instead of just relabeling the copy.
- Drop the separate GGUF-correction effect and useActiveModelIsGguf hook.
  Read useChatRuntimeStore.getState().activeGgufVariant inline inside the
  existing detection effect's .then() (so it doesn't need to sit in the
  effect's deps), and pick the first detected agent that isn't codex unless
  the loaded model is GGUF, leaving the existing default untouched when no
  compatible agent is detected.

Verified both branches (loopback vs LAN/tunnel base, gguf vs non-gguf,
manual pick preserved, no-compatible-agent fallback) with a standalone
port of the .then() logic.

@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: 383e79fe36

ℹ️ 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 +530 to +531
const fallback = detectedAgents.find((id) => id !== "codex");
if (fallback) setAgent(fallback);

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 Fall back from Codex when no other agent is detected

When a non-GGUF model is loaded and the backend detects only codex, the initial detection effect sets agent to codex, but this correction only updates the selection if it can find another detected agent. Fresh evidence: the newly added fallback path has no default/else branch, so fallback is undefined in the Codex-only PATH case and the copied unsloth start codex command still exits in _require_gguf_for_codex; fall back to a compatible default such as claude whenever Codex is auto-picked for a non-GGUF model.

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.

Resolved in c3ee707: the detection effect now picks info.detected.find((a) => a !== "codex" || isGguf), so in the Codex-only + non-GGUF case no compatible agent is found and the selection stays on the claude default instead of a codex command that would exit in _require_gguf_for_codex.

Comment on lines +510 to +511
if (!agentPickedByUserRef.current && info.detected.length > 0) {
setAgent(info.detected[0]);

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 Avoid auto-selecting server-detected agents for tunnels

In tunnel/remote sessions, info.detected reflects the Studio backend's PATH, not the machine where the browser user will paste this command. Fresh evidence: the updated UI now labels these as server-side detections, but this effect still auto-selects info.detected[0] without checking whether the displayed base is loopback, so a backend-only install can make the copied command default to a binary the user cannot run locally; keep the default/manual selection unless the detection scope matches the command's execution host.

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.

Resolved in c3ee707: the effect now early-returns unless the panel's base resolves to loopback (isLoopbackHost/normalizeHost, now exported from agent-command.ts), so a LAN/tunnel/remote base no longer marks anything detected or drives the default; those cases keep the manual/claude default.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Jul 7, 2026
@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: c3ee707462

ℹ️ 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".

// targets is loopback; for a LAN/tunnel/remote base the server's
// installed CLIs describe a different machine, so don't mark
// anything as detected or let it drive the default.
if (!isLoopbackBase) return;

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 Clear stale detected agents when leaving loopback

When the panel switches from a loopback base to a tunnel/LAN base (for example after the Cloudflare URL arrives, or when the user toggles Secure HTTPS back on), this branch returns without clearing the previous detectedAgents. Any agents detected while the base was local remain marked as installed and keep driving the detected hint even though the command now targets a remote/tunnel URL, which this guard is specifically trying to avoid.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 00e4d77 — the effect now clears detectedAgents (and skips the fetch entirely) as soon as the base is no longer loopback, so a stale local-detection result can't keep marking agents as installed once the panel is pointed at a remote/tunnel base.

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.

Good catch. The non-loopback branch early-returns without clearing a prior detection, so agents found while the base was loopback keep driving the hint after the Cloudflare URL arrives or Secure HTTPS is toggled. Clear the state in that branch before returning (setDetectedAgents([]), and reset the auto-picked agent back to the default if it was set by detection) so stale loopback detections do not persist once the base is remote/tunnel.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Clear the state in that branch before returning (setDetectedAgents([ ])...)

return () => {
cancelled = true;
};
}, [isLoopbackBase]);

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 Recompute Codex selection when model type changes

If Codex is auto-selected while a GGUF is loaded (for example Codex is the only detected CLI), then the user switches to a transformers-backed model while this settings panel remains mounted, this effect does not rerun because it only depends on isLoopbackBase. The copied command can therefore stay as unsloth start codex even though the adjacent comment notes Codex rejects non-GGUF models, so the auto-selected command becomes one the user cannot run successfully.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 00e4d77 — added a separate, network-free effect keyed on the live activeGgufVariant: if codex was auto-picked while a GGUF model was loaded and the user then switches to a transformers-backed model with the panel still mounted, it steers away from codex (never touching a manual pick). Good catch, this was a real gap in the simplified version.

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.

Right, the effect only depends on isLoopbackBase, so switching from a GGUF to a transformers model while the panel stays mounted leaves an auto-picked codex selected. Track the loaded model's GGUF-ness as reactive state (for example useChatRuntimeStore((s) => s.activeGgufVariant)) and include it in this effect's deps, or re-add a small corrective effect keyed on it, so the selection re-steers away from codex when the model becomes non-GGUF.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Track the loaded model's GGUF-ness as reactive state (activeGgufVariant) ... re-add a small corrective effect

Comment on lines +37 to +38
if (cachedInfo) {
return cachedInfo;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3 Badge Refresh cached agent detection after installs

Because the installed-agent result is cached for the lifetime of the frontend module, a user who installs Codex/OpenCode/etc. after opening Settings (or reopens the API tab without a full page reload) keeps seeing the old detected list and the old default command even though a fresh /api/settings/coding-agents call would now find the binary on PATH. This detection is inherently environment state rather than a persisted setting, so it should be revalidated when the panel opens or provide a refresh path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 00e4d77 — dropped the module-lifetime cache; loadCodingAgents() now only de-dupes concurrent in-flight calls, so every mount re-checks PATH for real instead of sticking with whatever was true the first time the tab was opened.

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.

Agreed. Installed-CLI detection is environment state, not a persisted setting, so a module-lifetime cache goes stale when the user installs an agent after opening Settings. Revalidate on panel open (drop the module-level memo, or expose a refresh that re-calls /api/settings/coding-agents when the API tab mounts) so a freshly installed binary is picked up without a full page reload.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Revalidate on panel open (drop the module-level memo...)

ErenAta16 added 2 commits July 7, 2026 16:40
- Clear detectedAgents (and skip the network call entirely) when the panel
  leaves a loopback base, instead of leaving a previous loopback detection
  result marked 'installed' for a command that now targets a LAN/tunnel/
  remote host.
- Add a separate, network-free correction effect keyed on the live
  activeGgufVariant: if codex was auto-picked while a GGUF model was loaded
  and the user then switches to a transformers-backed model while this panel
  stays mounted, steer away from codex instead of leaving a command that
  unsloth_cli's _require_gguf_for_codex will now reject. Never touches a
  manual pick.
- Drop coding-agents.ts's module-lifetime cache. Installed-CLI detection is
  environment state, not a persisted setting, so a stale positive/negative
  from before the user installed something (or reopened the tab) is worse
  than one extra cheap local API call per mount; keep only the in-flight
  de-dupe for concurrent callers.

Verified the correction-effect logic (gguf->non-gguf swap with/without a
fallback, still-gguf no-op, manual pick never overridden) with a standalone
port of the effect.

@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: 00e4d77423

ℹ️ 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 +555 to +557
if (agent !== "codex" || activeGgufVariant) return;
const fallback = detectedAgents.find((id) => id !== "codex");
if (fallback) setAgent(fallback);

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 Re-select Codex when a GGUF becomes active

When detection resolves while a transformers-backed model is loaded and only codex is detected, the earlier auto-pick correctly leaves the selection on the hardcoded claude fallback. If the user then loads a GGUF while this panel remains mounted, this effect returns as soon as activeGgufVariant is truthy and the detection effect does not rerun, so the copied command stays unsloth start claude even though Claude was not detected and Codex has become the compatible installed agent. Re-derive the preferred detected agent on both sides of the GGUF transition when the user has not manually picked an agent.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in d988f52 — merged the two effects into one: it now re-derives the preferred detected agent from scratch whenever detectedAgents or activeGgufVariant changes, in either direction, instead of only reacting to the codex-specific downgrade. So loading a GGUF model after a non-GGUF-gated fallback already picked something else now re-steers back to codex too. Never overrides a manual pick. Thanks for catching the asymmetry.

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.

Good catch on the mirror case: once activeGgufVariant is truthy the effect returns before re-deriving, so a claude fallback chosen while non-GGUF stays put after a GGUF loads even though codex is now the compatible detected agent. Re-derive the preferred detected agent on both sides of the GGUF transition (when the user has not manually picked) rather than short-circuiting on the GGUF branch, so the selection tracks the model type in both directions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's exactly what d988f52 already does — see lines 545-551 of usage-examples.tsx. There's no early-return on activeGgufVariant anymore; the effect only bails on detectedAgents.length === 0 or a manual pick, then re-derives preferred from scratch every time either dependency changes, so it re-selects codex when a GGUF loads after a non-GGUF fallback just as it steps away from codex when the model stops being GGUF. Happy to walk through it further if you're seeing a case where it doesn't hold.

The correction effect only steered away from codex when the model stopped
being GGUF; it never steered back toward codex if the model became GGUF
*after* a non-GGUF-gated fallback had already picked something else (e.g.
codex is the only detected CLI, a transformers model is loaded so the
selection correctly falls back to the claude default, then the user loads a
GGUF model while the panel stays mounted -- codex never gets reconsidered).

Consolidate into one effect that re-derives the preferred detected agent
from scratch whenever detectedAgents or activeGgufVariant changes, in either
direction, instead of only reacting to the codex-specific downgrade case.
The fetch effect now only populates detectedAgents/availableAgents; this
effect is the single source of truth for what gets auto-picked from that
list. Never overrides a manual choice.

Verified both transition directions plus the manual-pick-survives and
initial-detection cases with a standalone port of the derivation logic.
@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: d988f52a00

ℹ️ 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 +549 to +550
const preferred = detectedAgents.find((a) => a !== "codex" || isGguf);
if (preferred) setAgent(preferred);

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 Reset auto-picked Codex when GGUF support disappears

When Codex was auto-selected while a GGUF model was active and the user later switches to a non-GGUF model (or Codex is the only detected agent), preferred becomes undefined and this effect leaves the existing agent as codex. The copied command then remains unsloth start codex, but the CLI rejects Codex for non-GGUF models in _require_gguf_for_codex, so the panel can keep offering a command that is known to fail instead of falling back to a non-Codex agent.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in dca2106 — when no compatible agent remains and the current selection is the now-incompatible codex, it now resets to DEFAULT_AGENT instead of leaving codex selected. Good catch, this was a real gap in the "leave it untouched" fallback.

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.

Right, the mirror of the earlier fix: when GGUF support disappears, an auto-picked codex should reset (to the claude default or another compatible detected agent) rather than stay selected. Re-derive the preferred agent when activeGgufVariant goes falsy too, as long as the user has not manually picked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is already what dca2106 does — the derivation effect falls back to DEFAULT_AGENT when activeGgufVariant goes falsy and no other detected agent is compatible, as long as the user hasn't manually picked. See lines 545-560 of usage-examples.tsx if you want to double check.

Comment on lines +516 to +518
if (!isLoopbackBase) {
setDetectedAgents([]);
return;

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 Clear auto-picked agents when leaving loopback

When the panel first renders against a loopback base, the fetch below can auto-select an agent from the backend's PATH; if the Cloudflare URL then arrives or the user flips Secure HTTPS so isLoopbackBase becomes false, this branch only clears the green-dot detections and leaves that backend-derived agent selected. In SSH-tunnel or remote-browser setups this can leave the copied tunnel/remote command pointing at a CLI that exists on the Studio server rather than on the machine where the user runs the command, despite this branch explicitly saying those detections must not drive the default for non-loopback bases.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in dca2106 — leaving a loopback base now also resets the auto-picked agent back to DEFAULT_AGENT (not just clearing the detected-badges), unless the user picked one by hand. Thanks for catching that the previous fix only cleared the display, not the selection itself.

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.

Agreed. Leaving a loopback base for a tunnel/LAN base should also clear any agent that was auto-picked from the prior loopback detection (reset to the default), not just stop marking new detections, so a remote base never keeps steering the copied command from stale local detection.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also already in dca2106 — leaving a loopback base resets the auto-picked agent to DEFAULT_AGENT (not just clearing the detected badges), unless the user picked one by hand. Happy to walk through the diff if something's not matching what you're seeing.

ErenAta16 added 3 commits July 7, 2026 17:16
Two more real gaps from the latest Codex pass on d988f52:

- The unified derivation effect only handled the case where a *different*
  detected agent could take over. If codex was the only detected agent and
  auto-picked while a GGUF model was loaded, then the model stopped being
  GGUF, 'preferred' came back undefined and the effect silently left the
  selection on codex -- exactly the command unsloth_cli's
  _require_gguf_for_codex now rejects. Fall back to DEFAULT_AGENT in that
  case instead of leaving it untouched.
- Leaving a loopback base cleared detectedAgents (so the 'installed' badges
  correctly disappear) but left whatever agent had been auto-picked from
  that now-stale, server-side-only detection still selected. Reset to
  DEFAULT_AGENT there too, unless the user picked by hand.

Introduces a shared DEFAULT_AGENT constant instead of repeating the "claude"
literal at each reset site. Verified all five cases (both new resets, both
manual-pick-survives variants, and the existing multi-detected-agent
fallback still preferring another compatible agent over resetting) with a
standalone port of the effects.

@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: 5d3f848cc0

ℹ️ 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".

useEffect(() => {
if (agentPickedByUserRef.current) return;
if (detectedAgents.length === 0) return;
const isGguf = Boolean(activeGgufVariant);

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 Use GGUF status instead of the variant

When the loaded model is a direct/local .gguf file, activeGgufVariant can be null even though /api/inference/status reports is_gguf: true because the status variant is only the HF quant variant. In that case this marks the model as non-GGUF, so a Codex-only install is not auto-selected (or an auto-picked Codex can be reset) even though unsloth start codex would pass its GGUF preflight for the loaded model; derive this from the actual loaded GGUF state, such as the store's GGUF context/status, rather than the variant string alone.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 6f8bd72. activeGgufVariant only covers an HF-repo quant pick — a direct local .gguf file never has a "variant" to report even though /api/inference/status correctly reports is_gguf: true for it. Combined it with activeNativePathToken (drag-drop/picked-file case) and ggufContextLength (only ever populated when the backend last reported is_gguf: true, see applyActiveModelStatusToStore), matching the same is_gguf-equivalent check hasGgufSource already applies to a staged pick elsewhere in this codebase.

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.

Good catch. A direct/local .gguf load leaves activeGgufVariant null even though the model is GGUF, so gating on the variant string misclassifies it. Derive GGUF-ness from the actual loaded GGUF state (the store's is_gguf / ggufContextLength status) rather than the variant alone, so a native .gguf still counts as GGUF for the codex auto-default.

…tring

activeGgufVariant only covers an HF-repo GGUF pick (a specific quant
variant string). A direct local .gguf file -- custom folder, LM
Studio, or drag-drop -- is just as much a GGUF the codex preflight
(unsloth_cli's _require_gguf_for_codex) would accept, but it never has
a "variant" to report, so it read as non-GGUF here even though
/api/inference/status correctly reports is_gguf: true for it. That
mismatch could leave a Codex-only install not auto-selected, or reset
an auto-picked Codex, for a model that actually supports it.

Combined activeGgufVariant with activeNativePathToken (covers the
drag-drop/picked-file case) and ggufContextLength (only ever populated
when the backend last reported is_gguf: true for the active model, see
applyActiveModelStatusToStore) so all three paths a model can be GGUF
through are covered, matching the same is_gguf-or-equivalent check
hasGgufSource already applies to a staged pick elsewhere in this
codebase.

@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: 6bd08813e3

ℹ️ 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".

if (agentPickedByUserRef.current) return;
if (detectedAgents.length === 0) return;
const isGguf =
activeGgufVariant != null || activeNativePathToken != null || ggufContextLength != null;

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 Ignore stale native path token when gating Codex

When a direct/native GGUF was loaded and the backend later switches to a transformers model outside the UI load path (for example via another unsloth start ... --model call), refresh() adopts the new /api/inference/status with setCheckpoint(...)/applyActiveModelStatusToStore(...), but that status path never clears activeNativePathToken. This new isGguf OR therefore remains true even after ggufContextLength is reset to null, so a Codex-only detection can auto-select unsloth start codex for a non-GGUF model that the Codex preflight rejects.

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.

Right, this is a stale-state bug: switching from a native GGUF to a transformers model outside the UI load path never clears activeNativePathToken, so the isGguf OR stays true after ggufContextLength resets to null. Clear the native-path token in the status-refresh path (applyActiveModelStatusToStore / setCheckpoint) when the new status is not GGUF, so isGguf tracks the actual loaded model.

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.

Concrete pointer for landing this: the stale token survives because applyActiveModelStatusToStore (studio/frontend/src/features/chat/lib/apply-inference-status-to-store.ts) resets ggufContextLength to null for a non-GGUF status but never clears activeNativePathToken. Clearing it in that same setState, gated the same way the gguf fields already are, fixes the isGguf OR:

ggufContextLength: currentGgufContextLength,
ggufMaxContextLength,
ggufNativeContextLength,
...(status.is_gguf ? {} : { activeNativePathToken: null }),

That leaves the token untouched on a real GGUF load (the load path owns it) and drops it whenever the refreshed status is non-GGUF, so a Codex-only detection no longer auto-selects for a transformers model.

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.

Pushed the fix in e1d6652: applyActiveModelStatusToStore now drops activeNativePathToken whenever the refreshed status is non-GGUF (a real GGUF load reports is_gguf: true, so its token is preserved). Verified the frontend still typechecks (tsc -b, clean). Confirmed setCheckpoint already nulls activeGgufVariant on a non-GGUF status, so with the token cleared the isGguf OR now correctly goes false after switching to a transformers model.

When a native (drag-dropped or picked) GGUF was loaded and the backend later
switches to a transformers model outside the UI load path, refresh() adopts the
new /api/inference/status via setCheckpoint and applyActiveModelStatusToStore.
Those reset activeGgufVariant and ggufContextLength but never clear
activeNativePathToken, so the isGguf OR stays true after the switch and a
Codex-only detection auto-selects unsloth start codex for a non-GGUF model its
preflight rejects.

Drop activeNativePathToken in applyActiveModelStatusToStore whenever the status
is non-GGUF. A real GGUF load reports is_gguf: true, so its token is preserved
(the load path owns it); only a non-GGUF status clears it.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 6830ba689c

ℹ️ 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".

@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: 76bfef18b8

ℹ️ 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".

const origin = typeof window !== "undefined" ? window.location.origin : "";
const base =
useTunnel && cloudflareUrl ? cloudflareUrl : (serverUrl ?? origin);
const isLoopbackBase = resolveIsLoopbackBase(base);

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 Avoid trusting loopback URLs as same-host proof

When Studio is reached through an SSH/local port forward such as http://127.0.0.1:8888, this check returns true even though /api/settings/coding-agents runs on the remote backend host. The fetch below can then mark and auto-pick CLIs from the remote PATH, while the copied loopback command is also valid for a user to paste locally into the tunnel; if that CLI is not installed locally, the default command cannot launch. Fresh evidence: the current guard trusts only the displayed URL hostname, so forwarded loopback URLs still take the server-side detection path.

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 observation. The panel already gates server-side detection on resolveIsLoopbackBase, but you are right that a loopback hostname is necessary, not sufficient: an SSH/local port-forward makes http://127.0.0.1:8888 reach a remote backend, and the browser cannot distinguish a forwarded loopback from a genuinely local one (no client-side signal separates them). So auto-picking a server-detected CLI over a tunnel can surface a CLI that is not installed locally. Since the distinction is client-side-indistinguishable, the loopback gate is the reasonable best-effort for the common local case; a stricter stance would be a UX choice (e.g. detect but do not auto-select, or annotate the copied command as 'if run on the Studio host'). Flagging for @ErenAta16 as a design call on the detection feature.

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.

Resolved on 6a897c1: canUseLocalAgentDetection now requires isTauri (the desktop app, where the UI and backend are the same locally bundled machine, so no SSH/port-forward indirection is possible) in addition to a loopback host. That makes desktop-app + loopback a reliable same-host signal, and a browser loopback (which could be a forward) no longer takes the server-side detection path. Verified the frontend typechecks. Re-triggering review.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 6a897c123c

ℹ️ 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".

@danielhanchen
danielhanchen merged commit e86b787 into unslothai:main Jul 8, 2026
1 check passed
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