Repository navigation
studio: return a clean model id from the OpenAI API instead of the local .gguf path - #6518
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to clean up model identifiers exposed via the OpenAI-compatible API, preventing local filesystem paths (such as absolute .gguf paths) from leaking to clients. It adds a new utility module model_ids.py to parse and clean model IDs, integrates it across the inference routes and llama-server command arguments, and includes comprehensive tests. The feedback suggests utilizing the newly introduced model_id_matches helper function in the model retrieval route to ensure consistent backward compatibility matching.
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.
| from core.inference.model_ids import public_model_id | ||
|
|
||
| objects = _openai_model_objects() | ||
| for model in objects: | ||
| if model["id"] == model_id: | ||
| return model | ||
| # Backward compatibility: a client may still send the legacy raw identifier | ||
| # (e.g. an absolute .gguf path cached from an older /v1/models). Resolve it to | ||
| # the clean object so it keeps working, without ever echoing the path back. | ||
| llama_backend = get_llama_cpp_backend() | ||
| backend = get_inference_backend() | ||
| for raw in ( | ||
| llama_backend.model_identifier if llama_backend.is_loaded else None, | ||
| backend.active_model_name or None, | ||
| ): | ||
| if raw and model_id == raw: | ||
| clean = public_model_id(raw) | ||
| for model in objects: | ||
| if model["id"] == clean: | ||
| return model |
There was a problem hiding this comment.
The newly introduced model_id_matches helper function from core.inference.model_ids is specifically designed to handle backward compatibility matching between requested model IDs and internal identifiers. We should reuse it here instead of manually checking model_id == raw to ensure consistency and robustness.
| from core.inference.model_ids import public_model_id | |
| objects = _openai_model_objects() | |
| for model in objects: | |
| if model["id"] == model_id: | |
| return model | |
| # Backward compatibility: a client may still send the legacy raw identifier | |
| # (e.g. an absolute .gguf path cached from an older /v1/models). Resolve it to | |
| # the clean object so it keeps working, without ever echoing the path back. | |
| llama_backend = get_llama_cpp_backend() | |
| backend = get_inference_backend() | |
| for raw in ( | |
| llama_backend.model_identifier if llama_backend.is_loaded else None, | |
| backend.active_model_name or None, | |
| ): | |
| if raw and model_id == raw: | |
| clean = public_model_id(raw) | |
| for model in objects: | |
| if model["id"] == clean: | |
| return model | |
| from core.inference.model_ids import model_id_matches, public_model_id | |
| objects = _openai_model_objects() | |
| for model in objects: | |
| if model["id"] == model_id: | |
| return model | |
| # Backward compatibility: a client may still send the legacy raw identifier | |
| # (e.g. an absolute .gguf path cached from an older /v1/models). Resolve it to | |
| # the clean object so it keeps working, without ever echoing the path back. | |
| llama_backend = get_llama_cpp_backend() | |
| backend = get_inference_backend() | |
| for raw in ( | |
| llama_backend.model_identifier if llama_backend.is_loaded else None, | |
| backend.active_model_name or None, | |
| ): | |
| if raw and model_id_matches(model_id, raw): | |
| clean = public_model_id(raw) | |
| for model in objects: | |
| if model["id"] == clean: | |
| return model |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6cc877401d
ℹ️ 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".
| return True | ||
| if len(identifier) >= 2 and identifier[1] == ":": # Windows drive, e.g. C:\ | ||
| return True | ||
| if identifier.count("/") >= 2 or "\\" in identifier: |
There was a problem hiding this comment.
Handle one-level relative GGUF directories as paths
When a local GGUF is loaded via an accepted one-level relative directory such as ./model or ~/model, ModelConfig.from_identifier can keep that string as model_identifier, but _looks_like_path() returns false here because there is only one / and no .gguf suffix. Then /v1/models and the --alias added in this change expose ./model/~/model instead of a clean basename, so the path-leak fix is bypassed for local loads through those path forms. Please recognize ./~ prefixes, or derive the public id from the resolved GGUF path.
Useful? React with 👍 / 👎.
| _alias = public_model_id(self._model_identifier or model_path) | ||
| if _alias: | ||
| cmd.extend(["--alias", _alias]) |
There was a problem hiding this comment.
Prevent extra args from overriding the managed alias
This alias is supposed to keep llama-server pass-through responses aligned with GET /v1/models, but llama_extra_args are appended after Studio's flags (llama_cpp.py lines 5629-5633) and validate_extra_args still permits --alias/-a. In any load carrying that extra arg, llama.cpp's last-wins parsing can make /v1/chat/completions or /v1/completions return a different id—or the old absolute path—while /v1/models returns public_model_id(...). Treat the alias flag as Studio-managed, or strip it when emitting this clean alias.
Useful? React with 👍 / 👎.
| model_info = backend.models.get(backend.active_model_name, {}) | ||
| entry = { | ||
| "id": backend.active_model_name, | ||
| "id": public_model_id(backend.active_model_name), |
There was a problem hiding this comment.
Keep non-GGUF response ids consistent with models
For a local non-GGUF/LoRA load where backend.active_model_name is a filesystem path, this line now advertises only the basename in /v1/models, but the non-GGUF chat path still builds responses with model_name = backend.active_model_name (line 4537). Clients that discover the model from /v1/models will see a different model echoed by /v1/chat/completions, and the response still leaks the full local path for the same load that the listing now hides.
Useful? React with 👍 / 👎.
| from core.inference.model_ids import public_model_id | ||
|
|
||
| # Echo a clean public id in the response, never the absolute .gguf path. | ||
| model_name = public_model_id(llama_backend.model_identifier) or payload.model |
There was a problem hiding this comment.
Pass clean GGUF audio model id into response
For GGUF audio chat completions, this clean model_name is only passed to the monitor wrapper; _monitored_generate_audio() calls generate_audio(payload, request), and generate_audio recomputes model_name = llama_backend.model_identifier before serializing the JSON response. A local TTS GGUF therefore still returns the absolute .gguf path in /v1/chat/completions even though /v1/models now advertises the clean id.
Useful? React with 👍 / 👎.
6cc8774 to
1e526a4
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e526a450d
ℹ️ 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 identifier.count("/") >= 2 or "\\" in identifier: | ||
| return True | ||
| return False |
There was a problem hiding this comment.
Sanitize existing relative GGUF directories
Fresh case not covered by the earlier .//~ path handling: utils/paths/path_utils.py treats an existing relative path such as outputs/foo as local, and ModelConfig.from_identifier preserves that raw identifier for a detected GGUF directory. _looks_like_path() returns false for this one-slash relative path unless it has a ./ prefix or .gguf suffix, so /v1/models and --alias still expose outputs/foo instead of the clean basename. Consider using the resolved GGUF file path or checking existing relative paths before classifying org/model repo ids.
Useful? React with 👍 / 👎.
…cal .gguf path
GET /v1/models reported the loaded model's internal identifier verbatim, which
for a direct local load is the absolute .gguf path. That leaks the host
filesystem layout and is awkward for clients to round-trip as a model id.
Add core.inference.model_ids.public_model_id: a local GGUF path collapses to its
clean file stem (Qwen3-30B-A3B-Q4_K_M), while Hugging Face repo ids (org/model)
and already-clean names pass through unchanged. Use it for the id in
_openai_model_objects (both backends), have GET /v1/models/{id} still accept a
legacy raw identifier for backward compatibility while returning the clean
object, and pass --alias to llama-server so its own /v1/models and the model
field of its proxied responses are clean as well.
Sanitize every other surface that echoed the identifier back to the client, so
the path cannot leak through a different endpoint: the non-GGUF chat completion
reply, GGUF and non-GGUF audio replies, /v1/messages (Anthropic-compatible), and
all status/echo envelopes streamed from /v1/responses. A raw .gguf path sent by
a client as the request model is likewise collapsed before it is echoed.
Deny a user-supplied --alias/-a in llama-server passthrough args: Studio appends
its sanitized alias and llama.cpp's last-wins parsing would otherwise let a
caller reintroduce the path leak.
Treat relative and home paths (./model, ../model, ~/model and their Windows
forms) as local paths in public_model_id so they are sanitized rather than
returned verbatim.
1e526a4 to
18dcdf9
Compare
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ae673d90f
ℹ️ 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".
| return True | ||
| if len(identifier) >= 2 and identifier[1] == ":": # Windows drive, e.g. C:\ | ||
| return True | ||
| if identifier.count("/") >= 2 or "\\" in identifier: |
There was a problem hiding this comment.
Sanitize one-slash local directory loads
When a local GGUF is selected via an existing relative directory such as models/Qwen, ModelConfig.from_identifier treats it as a local path and loads the GGUF inside that directory, but this predicate returns False because the identifier has exactly one slash and no .gguf suffix. The new callers then publish models/Qwen as both /v1/models id and llama-server --alias, so the OpenAI API still exposes the server-side relative path for this supported load shape. Please distinguish existing local relative paths (or derive the id from the resolved GGUF/display name) before preserving org/model repo ids.
Useful? React with 👍 / 👎.
|
@codex review |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8fc5d9e1c0
ℹ️ 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 identifier.count("/") >= 2 or "\\" in identifier: | ||
| return True |
There was a problem hiding this comment.
Treat relative GGUF directories as paths
When a local GGUF is loaded from an existing relative directory such as models/foo, ModelConfig.from_identifier() keeps that original identifier while resolving the actual .gguf separately. This heuristic returns false for a one-slash directory without a .gguf suffix, so /v1/models, chat responses, and the new --alias can still expose models/foo instead of a clean basename, leaving the path leak unfixed for that supported load form.
Useful? React with 👍 / 👎.
| if identifier.lower().endswith(_GGUF_SUFFIX): | ||
| return True |
There was a problem hiding this comment.
Preserve repo ids whose names end in .gguf
For a remote Hugging Face GGUF repo whose id itself ends with .gguf (for example org/model.gguf), this check treats the repo id as a local file path and publishes just model, even though the helper's contract says HF repo ids should round-trip unchanged. That changes /v1/models and the llama-server --alias away from the actual loaded repo id for those valid one-slash identifiers.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d13b6fa7c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Verified the sanitizer across path forms. Local Merging now. |
Problem
For a local GGUF, the OpenAI-compatible API used the absolute
.gguffile path as the model id, leaking the server filesystem layout in/v1/models,/v1/models/{id}, and themodelfield of chat/completions responses.Change
core/inference/model_ids.pywithpublic_model_id()(local GGUF path to file stem, HF repo id unchanged) andmodel_id_matches().--alias <clean id>so upstream pass-throughmodelfields are already clean.modelfield.Validation
test_model_ids.pyandtest_openai_models_path_leak.py./v1/modelsand chat/completions returnQwen3-30B-A3B-Q4_K_Mwith no path anywhere, and the legacy path still resolves.