* refactor(cookbook): move endpoint registration out of the routes closure
_auto_register_llm_endpoint and _auto_register_image_endpoint use no
closure state and model_serve is their only caller, so they can live in a
plain module and be imported and tested directly. Bodies are unchanged
apart from indentation.
Tests now import the helpers instead of reading them from the route's
closure. That lookup also failed if the route stopped referencing a
helper, so add a test that pins which helper model_serve calls.
Part of #4071
* fix(cookbook): bound the OLLAMA_HOST port scan
The pattern rescanned the rest of the token from every OLLAMA_HOST=
occurrence, so a long serve command with repeated assignments took
quadratic time. model_serve runs this on the event loop, and a 192 KB
command stalled the whole app for about 9s.
Cap the host at 253 characters, the longest DNS name, so every valid host
still matches.
Part of #4071
* feat(admin): rename model endpoints inline
* fix(cookbook): keep renamed endpoint names on relaunch
Relaunching a model at an existing endpoint URL reset the endpoint name
to the launched repo's short name, undoing a rename made in Added Models.
Only replace the name when it is still a name the Cookbook generates for
one of the endpoint's pinned models, so endpoints that were never renamed
still follow the newly served model.
---------
Co-authored-by: Alexandre Teixeira <general@alexandreteixeira.dev>
* fix(cookbook): match stale endpoints by launched model, not display name
After registering an LLM endpoint, the Cookbook deleted every other local-*
endpoint with the same display name at a different URL. The display name is
the repo short name, which repos from different orgs share (for example
meta-llama/Llama-3.1-8B-Instruct and unsloth/Llama-3.1-8B-Instruct), so
launching one deleted the endpoint of the other while its server was running.
Match stale endpoints by the full model id they were last launched for,
which is the last entry of their pinned_models. Reusing an endpoint now
moves the launched model to the end of its pins so that entry stays current.
* fix(cookbook): guard endpoint cleanup by serve ownership
Preserve independently launched models instead of sweeping endpoints by display name or mutable model pins.
Bind Cookbook endpoint registrations to their serve sessions and prevent stale watchdogs or scheduled stops from deleting newer registrations.
Reuse the existing endpoint deletion contract to preserve settings, preferences, session cleanup, and cache invalidation.
Cover LLM and image endpoint lifecycle regressions.
---------
Co-authored-by: Alexandre Teixeira <general@alexandreteixeira.dev>