pgadmin4 icon indicating copy to clipboard operation
pgadmin4 copied to clipboard

Configuring an AI provider doesn't enable AI features until pgAdmin is restarted

Open dpage opened this issue 1 month ago • 2 comments

Describe the bug

After configuring an AI provider in Preferences, the AI features (the Query Tool's AI Assistant tab and the AI Reports menus) stay disabled until pgAdmin is restarted or the page is reloaded.

To Reproduce

  1. Start pgAdmin 9.19 with LLM_ENABLED = True and no provider configured.
  2. In Preferences > AI, configure a provider and save.
  3. Open a Query Tool, or right-click a server/database/schema: no AI Assistant tab, and the AI Reports menus remain disabled.
  4. Restart pgAdmin: everything is now enabled.

Expected behavior

AI features become available as soon as the provider preferences are saved (and are disabled again if the provider is removed).

Cause

The enabled state is only ever read once, at page load:

  • pgAdmin.llm_enabled is rendered into the page by the Jinja template at web/pgadmin/browser/templates/browser/js/utils.js:76 (from is_llm_enabled() in browser/__init__.py), and the Query Tool's default layout reads it in QueryToolComponent.jsx:261.
  • AITools.checkLLMStatus() in web/pgadmin/llm/static/js/ai_tools.js calls llm.status once from init() and caches llmEnabled, which the menu enable callbacks then use.

Neither is refreshed when the ai preferences change. A fix would be to re-run the status check (and update pgAdmin.llm_enabled) from a preference-change listener.

Desktop

  • pgAdmin version: 9.19 (release candidate builds)

dpage avatar Oct 27 '26 10:10 dpage

Hi Dave, could I take this issue if it is still available?

I traced the preference-save path at 062099a: PreferencesComponent refreshes preferencesStore, and the store broadcasts updates, but AITools.init() only performs its status request once. An isolated probe of the current ai_tools.js (JSX transpiled, status responses and menu rendering mocked) showed:

  • Initial provider missing: llmEnabled=false, one status request.
  • Provider configured, then init() called again: still false, still one request.
  • Explicit checkLLMStatus(): true, two requests.
  • Provider removed, then init() again: still true, still two requests.

This is module-level evidence, not a full UI reproduction. I'd first reproduce the preferences flow locally, then refresh the shared status when AI preferences change and test both enable and disable transitions, failed status requests, and repeated saves without duplicate menus or listeners. I would keep provider integrations and the separate layout-restoration issue #10689 out of scope.

Should already-open Query Tool tabs gain/lose the Assistant tab immediately too, or should the first change cover the report menus and newly opened Query Tools? If that scope fits, please assign #10688 to me or confirm I may take it. I haven't started the implementation.

Shubham-Padkonde avatar Oct 28 '26 16:10 Shubham-Padkonde

Yes, please go ahead. Thank you!

dpage avatar Nov 05 '26 11:11 dpage