Skip to content

ui: keep agent mode, tools and models fresh when the server changes - #155

Draft
allozaur wants to merge 1 commit into
masterfrom
allozaur/fix/ui-capability-reactivity
Draft

allozaur wants to merge 1 commit into
masterfrom
allozaur/fix/ui-capability-reactivity

Conversation

@allozaur

Copy link
Copy Markdown
Owner

Empty draft: no code yet. The single commit is --allow-empty on purpose — this PR exists to hold the write-up below.

Problem

Llama Chat asks the server what it can do once, at page load, and never asks again. Everything the UI builds from that first answer — agent mode, the tools menu, the working folder, MCP, the model list — is then frozen for the life of the tab.

The flags llama-server was started with therefore only apply to tabs opened after the restart:

Change on the server What an already-open tab does
restart with --agent or --tools stays a plain chat: no tools menu, no working folder, no MCP, no agentic loop
restart with --ui-mcp-proxy agenticMode.enabled stays false, cors_proxy_enabled is stale
restart with --ui-agent browser tools and browser-side MCP never show up
restart with those flags removed keeps offering agent UI the server can no longer serve
restart on another model, or load / unload one in ROUTER mode stale n_ctx, modalities, build info, settings defaults

The only way to see the new state is a manual refresh.

How the UI learns this today

  • serverStore (ui/apps/chat/src/lib/stores/llama-server.svelte.ts) owns props from GET /props. It refetches only on 503 — the "model still loading" case, via scheduleRetry() — or when the user hits retry on the error splash / banner.
  • +layout.svelte:239-247 runs that fetch once, guarded by if (!serverStore.props).
  • toolsStore.fetchServerTools() (lib/stores/tools.svelte.ts:240) fills agenticMode.serverHasTools / serverToolsKnown. It is called lazily (use-tools-panel.svelte.ts:135, stores/agentic/index.svelte.ts:945) and never re-validated.
  • agenticMode (lib/stores/agentic-mode.svelte.ts:27) combines the two sources: serverHasTools || props.cors_proxy_enabled || props.ui_agent. Its settled getter tells a page the answer is final — and nothing ever invalidates it.
  • Server side these are process-lifetime constants: cors_proxy_enabled and ui_agent in /props (tools/server/server-context.cpp:5683, tools/server/server-models.cpp:2121), built-in tools in /tools.

Worth noting the asymmetry: per-model props do get re-validated — ModelPropsManager sits a TTL cache in front of /props?model=<id> (lib/stores/models/props.svelte.ts:48) — while the global /props and /tools have no TTL and no invalidation path at all. So model modalities go stale slowly, agent mode goes stale immediately.

Expected behavior

Restart llama-server with --agent with the tab already open: within a moment the tab shows the agent UI, no refresh. Same in reverse when the flags are dropped, and the same for the model list and the /props values settings sync reads.

Proposed direction

  1. One revalidation entry point. serverStore.revalidate() that refetches /props and /tools together, and resets agenticMode (serverHasTools, serverToolsKnown) first so no page can act on a mix of the old server and the new one. Reuse the existing background: true path so nothing flashes the loading splash.
  2. Cheap change detection. /props already returns build_info, and a restart changes it. Compare against the last seen value and revalidate on change — that is what makes "someone restarted with --agent" detectable without being told.
  3. When to look. On tab visibilitychange → visible (there is precedent: +layout.svelte:227 re-syncs running streams exactly there), on window online / focus, after a failing request starts succeeding again, plus a low-frequency poll as a fallback. Nothing while the tab is hidden.
  4. Patch the stores, do not reload the page. Only consumers reading agenticMode should re-render. A hard location.reload() would drop in-flight streams and unsent input — the 401 reload at +layout.svelte:204 is the pattern to avoid here.
  5. Server help (optional follow-up). A capability revision or ETag on /props and /tools would beat the build_info heuristic, and exposing the process start time would make a restart unambiguous.

Open questions

  • When agent mode disappears mid-conversation, should the UI say so? Quietly taking away a working folder or an MCP the user was relying on is a behavior change that probably deserves a toast rather than silence.
  • Fallback poll: what interval, and is /health a cheaper heartbeat than /props?
  • PWA: /props is in the precache list (lib/constants/pwa.constants.ts:133) — confirm revalidation never gets served from the service worker cache.

Plan

  • empty draft with the write-up
  • serverStore.revalidate() + agenticMode.reset(), /props and /tools in one pass
  • restart detection via build_info, wired to visibility / focus / online / error-recovery
  • fallback poll, skipped while hidden
  • notice when a capability the user was using goes away
  • unit tests: --agent appearing and disappearing across a revalidation; settled semantics after reset
  • e2e: start server without agent flags, reload page, restart with --agent, assert the tools menu appears without a refresh

Placeholder commit so the draft PR can exist with no code yet: the write-up
of the issue is in the PR body.

This branch has not been deployed

No deployments
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