Skip to content

feat(6.33): auto-refresh ollama models on boot + manual "Refresh" button#38

Merged
fstamatelopoulos merged 2 commits intomainfrom
iteration-6/ollama-model-refresh-6.33
May 9, 2026
Merged

feat(6.33): auto-refresh ollama models on boot + manual "Refresh" button#38
fstamatelopoulos merged 2 commits intomainfrom
iteration-6/ollama-model-refresh-6.33

Conversation

@fstamatelopoulos
Copy link
Copy Markdown
Owner

Summary

Closes a UX gap surfaced during dogfood: the user pulled a new ollama model, restarted the cfcf server, and the model didn't appear in the role-picker dropdowns. Root cause: listOllamaModels() was only called at cfcf init (interactive setup) and cfcf doctor (read-only display) — neither the server nor the web UI ever re-detected.

Adds three pieces (boot-time refresh + manual button + helper) and fixes a related model-picker UX bug for ollama-routed adapters that surfaced while implementing the button.

What's new

  1. refreshOllamaModelsInConfig() core helper — detects ollama, lists models, persists to availableOllamaModels if the live list differs (order-insensitive comparison since ollama list reorders by mtime). Best-effort, never throws.
  2. Boot-time auto-refresh in cfcf server start — runs after the orphan reaper. Single log line on change, silent otherwise. Solves the "stop + start to pick up the new model" expectation.
  3. POST /api/agents/refresh-ollama-models + "Refresh ollama models" button in both web Settings and workspace Config Agent-roles sections. Solves the "I just pulled a model and don't want to bounce the server" path. Button shows in-flight state + result message ("✓ N models detected — list updated" / "list already current" / hint when ollama isn't installed) and triggers a re-fetch of /api/agents/models so the *-ollama dropdowns update without a page reload.

Test plan

  • bun run typecheck — clean
  • bun test packages/core packages/cli — 778/778 pass (4 new unit + 2 new endpoint)
  • cd packages/web && bun run build — clean
  • Manual: ollama pull <new-model> → restart cfcf server → confirm log line [server] Refreshed availableOllamaModels (N models detected) → open web Settings → new model appears in claude-code-ollama / opencode-ollama dropdowns
  • Manual: ollama pull <another-new-model> → click "Refresh ollama models" in Settings → confirm status message + new model appears in dropdowns without server restart
  • Manual: same flow on workspace Config tab

fstamatelopoulos and others added 2 commits May 8, 2026 17:24
`availableOllamaModels` was previously captured ONCE at `cfcf init` and
never re-detected by the server or web UI. Newly-pulled ollama models
were invisible to the role-picker dropdowns until the user re-ran
`cfcf init --force`.

Three pieces:

1. New `refreshOllamaModelsInConfig()` helper in `@cfcf/core`. Detects
   ollama, lists models, compares against saved (order-insensitive
   since `ollama list` reorders by mtime), persists if different.
   Best-effort: never throws; missing-ollama is reported via the
   `error` field, not a thrown exception.

2. Boot-time auto-refresh in `start.ts`, runs after the orphan reaper.
   Single log line if the list changed; silent otherwise. Failures
   log + continue, never block boot. Solves "I pulled a model + did
   `cfcf server stop && cfcf server start` but the dropdown is stale".

3. `POST /api/agents/refresh-ollama-models` endpoint + a "Refresh
   ollama models" button in the Agent roles section of both web
   Settings (`ServerInfo.tsx`) and workspace Config (`ConfigDisplay.tsx`).
   Solves "I pulled a model and don't want to bounce the server".
   Button shows in-flight + result message ("✓ N models detected —
   list updated" / "list already current" / error hint when ollama
   isn't installed). Bumps a `modelsRev` counter to trigger a
   re-fetch of `/api/agents/models` so dropdowns pick up the change.

Tests: 4 new unit tests in `ollama-detection.test.ts` (response
shape, no-config-no-write, list-equality persistence guard, ordering
insensitivity); 2 new endpoint tests in `agent-models.test.ts`
(documented shape, no-500-on-missing-ollama defence-in-depth).

Pre-existing `app.test.ts` config-merge failure on main is NOT
caused by this work (verified earlier via `git stash`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
… ollama-routed adapters

The "(adapter default)" empty-value option in the model picker means
"let the CLI pick" — works for `claude-code` (claude has its own
default) and `codex` (codex picks gpt-5-codex), but is broken for
`claude-code-ollama` / `opencode-ollama`: `ollama launch <agent>`
requires an explicit `--model <name>` to know which local model to
hand off, and our adapters skip the flag entirely when `model` is
falsy. Saving `model=""` for an ollama-routed adapter produces a
silent misconfiguration at spawn time.

Hide the "(adapter default)" option in `AgentModelSelect` for the
two ollama-routed adapters via a small `OLLAMA_ROUTED_ADAPTERS` set
(hardcoded in the web tree per the existing convention — web is
Vite-built and doesn't import @cfcf/core directly; same pattern as
HarnessPolicyWarning).

For the empty-list case (no ollama models pulled yet, or the boot
refresh hasn't run), surface a disabled placeholder option:
`(no ollama models — pull one or click Refresh)`. The dropdown isn't
visually empty + the user gets a hint about the Refresh button or
`ollama pull`.

Behavior unchanged for seed-sourced adapters.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fstamatelopoulos fstamatelopoulos merged commit da66e22 into main May 9, 2026
2 checks passed
@fstamatelopoulos fstamatelopoulos deleted the iteration-6/ollama-model-refresh-6.33 branch May 9, 2026 00:37
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.

1 participant