Skip to content

Refresh the cached model list when the host or API key changes - #102

Merged
dkotter merged 3 commits into
Fueled:developfrom
eastagiletracker:agile-board/refresh-model-list
Oct 28, 2026
Merged

dkotter merged 3 commits into
Fueled:developfrom
eastagiletracker:agile-board/refresh-model-list

Conversation

@eastagiletracker

@eastagiletracker eastagiletracker commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

This PR proposes refreshing the cached Ollama model list when the host or API key changes, plus a Refresh models button on the settings screen (Fixes #82). We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/772. You can sign in with your GitHub ID to claim ownership of the project.

What was wrong. listModelMetadata() goes through the client SDK's cached() helper, which stores the model list for 24 hours under a key built only from the directory class name. Nothing in the plugin ever called invalidateCaches(), so on a site with a persistent object cache, saving a new Host URL or a new API key on Settings > Connectors kept serving the old list. Deactivating or reinstalling the plugin does not clear the object cache either, which matches what the reporter tried. The empty-list hint ("pull a model and reload this page") had the same problem, since a reload serves the cached list again.

What changed. OllamaSettings::init() now hooks add_option_, update_option_ and delete_option_ for both the plugin's own settings option (Host URL) and the option core stores the Ollama API key in (OllamaSettings::API_KEY_OPTION_NAME) and calls a new invalidate_model_cache(). That method calls invalidateCaches() on the provider's model metadata directory, which also clears the in-memory /api/tags result added in #100. For the "maybe a button?" part of the issue, the AJAX handler accepts refresh=1, which drops the cache before listing, and the settings screen gets a Refresh models button that uses it. loadModels() now rebuilds its status element on each run so it can be called more than once, and the button is disabled while a request is in flight. Nothing changes for callers that don't pass refresh, and unrelated option saves leave the cache alone (there's a test for that).

Reproduction at develop HEAD (2223d19). Running the real OllamaProvider against a mock transporter in the WP test suite, where the object cache lasts for the whole process like a persistent cache does:

before key change: llama3.1,mistral,qwen3
after key+host change: llama3.1,mistral,qwen3
requests to /api/tags: 1

After update_option() on the Ollama API key option and on the plugin's Host URL setting, the old list is still returned and Ollama is never asked again.

Verification. The new tests/Integration/Settings/OllamaSettingsModelCacheTest.php has 10 tests covering key add/update/delete, host change, the AJAX handler with and without refresh=1, an unrelated option save, and the case where the provider isn't registered. With the OllamaSettings change reverted, 7 of them fail (5 assertion failures showing the stale list, and 2 on the missing method), while the three "stays cached" controls pass. With the change, the full PHPUnit suite goes from 145 to 155 tests, all passing, with the same 12 skipped. PHPCS, PHPStan, tsc --noEmit, wp-scripts lint-js and wp-scripts build are clean before and after. I checked the button in headless Chrome against the built settings.js, with apiFetch stubbed: it showed 3 models on the first load, and after the click it requested â€Ķ&refresh=1, showed 1 model and re-enabled itself.

How this was managed

This work was tracked as a story, https://eastagiletracker.com/projects/772/stories/982594, on a board imported from this repo's issues and pull requests (84 stories) at https://eastagiletracker.com/projects/772.

If you'd rather not receive contributions like this, reply no-more-prs on this pull request and we won't open any further ones on your repositories.


Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com

Open WordPress Playground Preview

â€Ķdd a Refresh models button

The model list is cached per provider for a day, so on sites with a persistent object cache a new host or API key kept showing the old models. Drop the cache when either setting is added, updated or deleted, and let the settings screen ask for a fresh list.
@jeffpaul jeffpaul added this to the 1.4.0 milestone Sep 30, 2026
@jeffpaul
jeffpaul requested a review from dkotter September 30, 2026 15:37
@jeffpaul jeffpaul modified the milestones: 1.4.0, 1.3.0 Oct 7, 2026
@jeffpaul

Copy link
Copy Markdown
Collaborator

Seems reasonable if this isn't how things work, especially if its limiting what models the provider could select from when being used for some AI tasks on a WP site.

@dkotter
dkotter merged commit 0a79242 into Fueled:develop Oct 28, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refresh list of models

3 participants