Repository navigation
serve: one model by name (GET /v1/models/{model}), Ollama's /api/tags and /api/show, and a 404 that names the request - #994
Conversation
There was a problem hiding this comment.
Verdict: MUST_FIX: model lookup confuses URL encoding with literal model names.
Must fix
1. Decode model names at the URL boundary
Kind A: crates/serve/src/models.rs:60 checks raw text first. With chat ID m/a and side-model ID m%2Fa, GET /v1/models/m%2Fa returns the side model instead of the URL-encoded chat model. The new assertion at line 126 pins this error.
crates/serve/src/api.rs:2406 passes JSON names through the same decoder: serving only mock, POST /api/show with {"model":"%6dock"} returns 200 instead of the promised unknown-model 404.
Cost: separating these representations now avoids changing published lookup behavior later.
Fix: decode once in named; keep lookup exact. Replace their definitions and update their comments accordingly. Point the decoder's doc link at named:
pub(crate) fn named(path: &str) -> Option<Result<String, String>> {
crate::http::below(path, "models").map(|id| {
crate::http::percent_decode(&id.replace('+', "%2B"))
.map_err(|_| format!("invalid percent-encoded model name: {id:?}"))
})
}pub(crate) fn lookup(listing: &Value, id: &str) -> Result<Value, String> {
let data = listing["data"].as_array().map_or(&[][..], Vec::as_slice);
data.iter()
.find(|m| m["id"] == id)
.cloned()
.ok_or_else(|| {
let served: Vec<&str> = data.iter().filter_map(|m| m["id"].as_str()).collect();
format!(
"model {id:?} not found: this server serves {}",
served.join(", ")
)
})
}Replace the named-model arm in api::route:
("GET", p) if let Some(id) = crate::models::named(p) => {
id.map_err(invalid).and_then(|id| {
crate::models::lookup(&models(state), &id).map_err(not_found)
})
}Replace that arm in decide::reply:
("GET", p) if let Some(id) = crate::models::named(p) => {
match id {
Ok(id) => match crate::models::lookup(&s.fixed.models, &id) {
Ok(entry) => Reply::json(200, &entry),
Err(message) => Reply::error(404, "not_found_error", &message),
},
Err(message) => Reply::error(400, "invalid_request_error", &message),
}
}Update named expectations to Some(Ok(String)); unwrap it before looking up encoded paths. For the existing two-ID fixture, replace its collision assertion with:
let id = named("/v1/models/m%2Fa").unwrap().unwrap();
assert_eq!(lookup(&v, &id).unwrap(), v["data"][0]);
let id = named("/v1/models/m%252Fa").unwrap().unwrap();
assert_eq!(lookup(&v, &id).unwrap(), v["data"][1]);
assert_eq!(lookup(&v, "m%2Fa").unwrap(), v["data"][1]);Extend the existing discovery test to require 404 for JSON {"model":"%6dock"}.
Checked
Duplicates: 17 new items checked; no duplicate owner found. The dryer pair, invalid/not_found, represents different HTTP errors.
Complexity: api::route rose 29 → 31 through new dispatch branches; lookup remains owned by models.
Silent failure: 3 lookup fallback/drop sites followed. Listing shape and ID types come from listing; decoding errors are discarded by the defect above.
Tests, static mutation analysis: disabling decoded matching at models.rs:63 fails the model-lookup assertions; dropping fields/capabilities at api.rs:2412–2425 fails the show test; dropping discovery arms at api.rs:1641–1645 or decide.rs:560–565 fails the two discovery tests; dropping request text at decide.rs:592 fails the decision-route test. The collision assertion currently requires the wrong result.
Gates: no thresholds or pins moved.
Escape catalog: no C1–C4 patterns matched. Authentication precedes dispatch; stored-response prefix behavior is preserved. No inference hot path changed.
Notes
Rust tests were not run; mutation results are source analysis.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
471a5a4 to
b0a49cf
Compare
There was a problem hiding this comment.
Since the last review: the earlier URL/JSON model-name finding is fixed. models.rs:49 decodes URL names once; lookup matches JSON names literally.
Verdict: CLEAN: the revised lookup resolves the earlier failure, and no new must-fix finding survives.
Checked
Duplicates: 0 new definitions in the interdiff; changed lookup reuses the existing decoder. The dryer pair, invalid/not_found, represents different HTTP errors.
Complexity: crapper flagged decide::reply (9 → 14) and api::route (29 → 31). Existing dispatch functions gained route/error branches; model matching remains in the common owner.
Silent failure: 2 decoder-error paths followed; both return 400. Unknown literal model names return 404.
Tests (static mutation analysis): removing or repeating decoding at models.rs:51 breaks the model collision assertions; dropping literal-plus preservation breaks the plus assertions. Adding decoding at models.rs:60 breaks the literal-lookup and discovery assertions. Returning 404 for decoding errors at api.rs:1643 or decide.rs:566 breaks the two route tests.
Gates: no thresholds, pins or test cases removed or relaxed.
Escape catalog: no C1–C4 patterns matched.
Adversarial checks: encoded-name collisions, malformed escapes and invalid UTF-8 are handled; double-encoded names and literal plus signs preserve identity. No inference hot path changed.
Notes
Rust tests were not run. Mutation results are source analysis.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
… and /api/show, and a 404 that names the request
GET /v1/models/{model} (and /models/{model}) answers the listing's entry of that name, taken as sent or percent-decoded, on the generative and decision servers alike; a name the server does not serve is a 404 not_found_error naming the ones it does. GET /api/tags answers the /v1/models list, whose models array is Ollama's shape, as llama-server served it. POST /api/show answers the chat model's template, the file's format, architecture and quant, the served context as <arch>.context_length and its capabilities (completion, tools when the template's markup is one the server parses, vision with an image encoder); the embedding model answers embedding.
A route the server does not have was answered with the SystemOne route alone; its 404 now starts with the method and path the request named, then the route that note gave.
b0a49cf to
4fc7275
Compare
There was a problem hiding this comment.
Verdict: CLEAN: carried from b0a49cfa, not re-reviewed.
The approval of b0a49cfa stands for 4fc72752. This pull request's 1 commit are the same patches in the same order: git patch-id --verbatim (the changed lines, the lines around them and whitespace) and the subject are equal for every commit. That review ran under the reviewer instructions, tools and slag ledger that review this head, and it approved.
The base moved, and changed none of the files this pull request changes.
A carry covers each patch's own lines and the lines around them. What the base changed elsewhere is covered by CI on this head and by the landing gates.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
모델 이름 하나를 조회하는 API와 Ollama 클라이언트용
/api/tags,/api/show를 더하고, 없는 경로의 404가 요청한 method와 path를 말하게 했습니다.What and why
Clients that talk to the server by model name need to ask for one model, and Ollama clients read
/api/tagsand/api/showto learn what is served. This addsGET /v1/models/{model}(and/models/{model}), which returns that model's/v1/modelsentry or a 404 that names the model being served.GET /api/tagsreturns the/v1/modelslisting.POST /api/showtakes{"model": NAME}and returns the template, the file's format, architecture and quantization, the served context length, and the capabilities (completion, plustoolsandvisionwhen the server supports them). A side embedding model reportsembeddingonly. The decision server answers/api/tagsand the lookup, not/api/show. A request to an unknown path now gets a 404 that starts withFile Not Found: <METHOD> <path>before the existing SystemOne hint. The new routes need the API key like/v1/models. Ollama's generation endpoints are not added.Release notes: Added:
GET /v1/models/{model},/api/tagsand/api/showon the server, and a 404 that names the requested method and path.Code shape
crates/serve/src/models.rsgained the lookup (named,lookup) and both servers call it.Request::not_found()inhttp.rsis the one 404 head for both servers and the stored responses.modelin/api/showis a 400.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up.Duplication found or removed (
path:line), or "none": none.What I ran
Tests on the head:
cargo test -p bloomery-serve --libgavetest result: ok. 431 passed; 0 failed, includingmodels::tests::one_model_is_looked_up_by_its_id,api::tests::show_names_the_files_facts_and_capabilities,api::embeddings::tests::discovery_names_the_seated_models,decide::tests::the_routes_are_the_deciders_and_no_otheranddecide::tests::not_supported_is_501_and_the_models_are_listed. The whole serve suite including the--test serve -- --include-ignoredintegration tests passed withtest result: ok. 111 passed; 0 failed.The new
discovery_names_the_seated_modelsfails on base (left: 404,right: 200at/api/tags) and passes with the change.Real binary on one NVIDIA GB10 (driver 595.84, CUDA 13.3,
sm_121a),bloomery-serve 0.3.11built with release features, serving the existing Qwen3.8 FP4-Local folder:The run checked that
/api/showreturnsgeneral.architecture, that<arch>.context_lengthequalsmax_model_len(2048), thatdetails.familyequals the architecture, thatcapabilitiescontainscompletion, and thattemplateis not empty.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.