pi-web icon indicating copy to clipboard operation
pi-web copied to clipboard

Model dialog doesn't clean up `enabledModels` in settings.json when a connector/models are removed → persistent 'No models match pattern' warnings

Open mufflegyro opened this issue 3 months ago • 3 comments

Summary

Removing a connector (or its models) in the pi-web model dialog does not clean up the stale entries in the global enabledModels setting (~/.pi/agent/settings.json). After the connector is gone, pi-web keeps showing Warning: No models match pattern "..." (rendered as a Model scope warning banner) for every subsequent session, and the only workaround is manually editing settings.json.

Environment

  • pi-web: 0.8.9 (@agegr/pi-web)
  • pi-coding-agent: 0.84.2
  • macOS

Repro steps

  1. Have a connector configured whose models are part of the enabled scope. This persists entries like these into ~/.pi/agent/settings.json:

    "enabledModels": [
      "vercel-ai-gateway/poolside/laguna-s-2.1-free",
      "vercel-ai-gateway/alibaba/qwen3.7-flash"
    ]
    
  2. In pi-web's model dialog, remove the connector (it disappears from models.json and the catalog).

  3. Reload / open a session. The UI now shows:

    Model scope warning
    No models match pattern "vercel-ai-gateway/poolside/laguna-s-2.1-free"
    No models match pattern "vercel-ai-gateway/alibaba/qwen3.7-flash"
    
  4. ~/.pi/agent/settings.json still contains the two stale enabledModels entries — the dialog never prunes them.

Root cause

  • The model dialog's write path (PUT /api/models-config) only writes ~/.pi/agent/models.json (provider/model config). It sanitizes empty model IDs and normalizes cost, but it never touches settings.json.
  • pi-web never calls setEnabledModels — grep of the entire build (server + frontend) shows zero occurrences. The only writer of enabledModels is the pi CLI /models selector (interactive-mode.js → settingsManager.setEnabledModels(...)), and even that selector deliberately re-injects no-match patterns back into the enabled list (ids.push(diagnostic.pattern)), so it doesn't prune them either.
  • GET /api/models reads settingsManager.getEnabledModels() and feeds the patterns into resolveModelScopeWithDiagnostics(). Every pattern with no catalog match becomes a no-match diagnostic, which is returned as modelScopeWarnings and rendered as the warning banner.

So: removing a connector in pi-web removes the models from models.json, but the stale enabledModels patterns in settings.json are never pruned, and scope resolution keeps reporting them on every load.

Expected behavior

Removing a connector/models in the model dialog should also prune the corresponding enabledModels entries from settings.json (e.g. by calling settingsManager.setEnabledModels(...) with the filtered list), so no stale-pattern warnings appear afterwards.

Suggested fix (any of these)

  1. Prune on connector removal: when PUT /api/models-config saves the provider list, intersect the existing enabledModels with the new model set and persist the pruned list.
  2. Prune in scope resolution: in GET /api/models, drop no-match patterns instead of surfacing them as warnings — or filter them out of the enabled set before persisting.
  3. CLI parity: make the /models selector stop re-adding no-match patterns, or surface an explicit "remove stale entries" action.

Notes

  • Workaround for users today: remove stale entries from enabledModels in ~/.pi/agent/settings.json.
  • The same stale-entry problem can be triggered from the CLI (connector removed elsewhere), so a fix in scope resolution (#2) would cover both entry points.

mufflegyro avatar Aug 20 '26 10:08 mufflegyro

enabledModels is a pi global setting and is not managed by pi-web. I don't think saving models.json should implicitly modify it; stale entries should remain a warning or be cleaned up explicitly by pi itself.

agegr avatar Aug 25 '26 13:08 agegr

Ok up to you as the maintainer, but I still don't understand the logic of surfacing controls to add and remove providers and models in pi-web and then not cleaning them up when removing them through the same interface. That seems untidy.

mufflegyro avatar Aug 25 '26 14:08 mufflegyro

Ok up to you as the maintainer, but I still don't understand the logic of surfacing controls to add and remove providers and models in pi-web and then not cleaning them up when removing them through the same interface. That seems untidy.

pi-web has always treated enabledModels as read-only: any changes to it originate outside pi-web, so pi-web should not remove or otherwise modify its entries.

agegr avatar Aug 25 '26 16:08 agegr