ai: cache the models manifest, skip it offline, show a loading state

The Manage tab fetched the CDN manifest and its signature on every
catalog request with a 30s timeout each, and the tab polls every 30s.
On a black-holed or offline network every poll paid up to 60s before
falling back to the bundled list, the frontend's 60s limit threw the
response away, and the tab showed a blank page the whole time.

get_models_catalog now skips the CDN while the have_internet flag is
explicitly clear, reuses the last attempt (success or failure) for an
hour, and uses a 5s timeout for the 2KB manifest. A skipped attempt is
not cached so the CDN is tried as soon as internet comes up. The cache
is per process and is cleared between tests by an autouse fixture.

The Manage tab shows "Loading the model catalog" while the first
response is pending, and on failure shows the error with a Retry
button and a note that the API may still be starting, instead of
rendering nothing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Roland 2026-09-24 18:28:11 -06:00
parent 5b1b0559b5
commit 861e183bd2
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
5 changed files with 136 additions and 9 deletions

View file

@ -15,3 +15,12 @@ def test_ai_config(test_directory, async_client):
with ai_config_context() as config:
config.initialize(api_app.shared_ctx.ai_config)
yield config_path
@pytest.fixture(autouse=True)
def _clear_models_catalog_cache():
"""Each test starts with an empty manifest cache."""
from modules.ai import catalog
catalog.clear_models_catalog_cache()
yield
catalog.clear_models_catalog_cache()