Commit 704ec6f
committed
fix(router): support model aliases end to end
A worker registers under a canonical model ID and may declare aliases
next to it. Routing only ever matched the canonical ID, so a request that
named an alias found no workers and got a 404.
The registry now keeps an alias index next to the model index. It is
separate so aliases stay out of `/v1/models` and out of the statistics,
and `get_by_model` falls back to it. Every other per-model map — hash
rings, retry overrides, load balancing policies — stays keyed by the
canonical ID, so each request entry point resolves the alias exactly once
and passes the canonical ID from there on:
- the gRPC pipeline resolves in `RequestContext::new` and rewrites both
`input.model_id` and the request's own `model` field, so worker
selection, tokenizer lookup, parser selection and tool call ID format
all read the canonical ID without resolving anything themselves;
- both HTTP routers resolve at the top of their request path and rewrite
the `model` field of the body they forward. The backend was registered
under the canonical ID and has never heard of the alias.
One visible consequence: the response reports the canonical model ID, not
the alias the client sent, matching how the OpenAI API answers with the
model it actually ran.
`/v1/responses` gates on the client-supplied name before the pipeline
canonicalizes it, so it gets `WorkerRegistry::contains_model`, which
accepts both spellings. The `unknown` wildcard is not a registered name
and stays rejected.
Alias conflicts are resolved so that a name is either a canonical model
ID or an alias, never both:
- an alias naming a registered model is refused, and an alias already
recorded is dropped when a model later claims that name — otherwise the
name would start resolving to a different model once the real one's
last worker left;
- when two models declare the same alias the first registration wins, and
losing that worker hands the alias to a remaining model that declares
it rather than stranding it;
- the alias entry is held across that whole decision, so a concurrent
registration cannot be erased between the check and the delete.
Per-model retry overrides are keyed by the canonical ID and are read
before the pipeline canonicalizes, so `GrpcRouter::resolve_retry_config`
resolves the alias itself. Without it a request naming an alias silently
took the router default instead of the worker's override, on chat,
generate, messages and completion alike.
Tests cover the registry rules, both HTTP request paths end to end
against the body the worker actually received, the multipart form, the
rerank response, the gRPC pipeline, the Responses canonicalization, the
retry override under an alias, and the Responses gate.
Signed-off-by: Jun Liu <jun.c.liu@rakuten.com>1 parent 4cd2647 commit 704ec6f
14 files changed
Lines changed: 1550 additions & 134 deletions
File tree
- model_gateway
- src
- routers
- grpc
- common
- responses
- stages
- http
- worker
- tests
- common
- routing
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
102 | 107 | | |
103 | 108 | | |
104 | 109 | | |
105 | 110 | | |
106 | | - | |
107 | | - | |
108 | | - | |
| 111 | + | |
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
| |||
175 | 178 | | |
176 | 179 | | |
177 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
70 | 94 | | |
71 | 95 | | |
72 | 96 | | |
| |||
112 | 136 | | |
113 | 137 | | |
114 | 138 | | |
| 139 | + | |
115 | 140 | | |
116 | 141 | | |
117 | 142 | | |
| |||
448 | 473 | | |
449 | 474 | | |
450 | 475 | | |
451 | | - | |
452 | | - | |
453 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
454 | 489 | | |
455 | | - | |
| 490 | + | |
456 | 491 | | |
457 | 492 | | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
458 | 499 | | |
459 | 500 | | |
460 | | - | |
| 501 | + | |
461 | 502 | | |
462 | 503 | | |
463 | 504 | | |
| |||
467 | 508 | | |
468 | 509 | | |
469 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
470 | 521 | | |
471 | 522 | | |
472 | 523 | | |
473 | 524 | | |
474 | 525 | | |
475 | 526 | | |
476 | 527 | | |
477 | | - | |
478 | | - | |
479 | | - | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
484 | 532 | | |
485 | | - | |
486 | | - | |
| 533 | + | |
487 | 534 | | |
488 | 535 | | |
489 | 536 | | |
| |||
493 | 540 | | |
494 | 541 | | |
495 | 542 | | |
496 | | - | |
497 | | - | |
498 | | - | |
499 | | - | |
500 | | - | |
501 | | - | |
502 | | - | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
503 | 547 | | |
504 | | - | |
505 | | - | |
| 548 | + | |
506 | 549 | | |
507 | 550 | | |
508 | 551 | | |
| |||
512 | 555 | | |
513 | 556 | | |
514 | 557 | | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
522 | 562 | | |
523 | | - | |
524 | | - | |
| 563 | + | |
525 | 564 | | |
526 | 565 | | |
527 | 566 | | |
| |||
531 | 570 | | |
532 | 571 | | |
533 | 572 | | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
541 | 577 | | |
542 | | - | |
543 | | - | |
| 578 | + | |
544 | 579 | | |
545 | 580 | | |
546 | 581 | | |
| |||
550 | 585 | | |
551 | 586 | | |
552 | 587 | | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
560 | 592 | | |
561 | | - | |
562 | | - | |
| 593 | + | |
563 | 594 | | |
564 | 595 | | |
565 | 596 | | |
| |||
569 | 600 | | |
570 | 601 | | |
571 | 602 | | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
579 | 607 | | |
580 | | - | |
581 | | - | |
| 608 | + | |
582 | 609 | | |
583 | 610 | | |
584 | 611 | | |
| |||
0 commit comments