Skip to content

Fix AI chat viewer and model manager bugs found during Gemma 4 verification - #1286

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1285-ai-chat-model-bugs
May 31, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1285-ai-chat-model-bugs

Conversation

@malibio

@malibio malibio commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Closes #1285

…meout (#1285)

- Hydration setNode now uses type:'viewer' source so the skip-while-editing
  guard can't block it when the node has pending writes (fixes viewer stuck
  on placeholder after provider selection)
- chat_model_download emits model://download-ready Tauri event on completion;
  model picker listens and calls refresh() immediately (fixes download status
  stuck on "downloading")
- Daemon startup timeout extended from 5s to 30s to accommodate cold-start
  embedding model load (6-8s on first launch)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

This PR fixes bugs #3–6 from issue #1285 with targeted, well-scoped changes. All six acceptance criteria are addressed (items 1–2 were already merged). The overall approach is sound. I have one improvement-level finding and two nits.


Findings

Suggested Improvements

ai-chat-model-picker.svelte — Double refresh() on successful download

The download() function already calls await refresh() after await chatModelDownload(modelId) resolves (line 124). The MODEL_DOWNLOAD_READY event listener also calls refresh() (line 106). Because chat_model_download is a streaming Tauri command that only resolves after the Rust command loop exits — which happens after the "ready" event is emitted and forwarded to the frontend — the event-triggered refresh() will fire and complete first, then the await chatModelDownload resolves and fires a second refresh(). The end result is two sequential chatModelList() + getSystemRamGb() calls in rapid succession.

This is a minor redundancy, not a correctness bug — the UI settles correctly. But it does mean two network round-trips on every successful download. The recommended fix is to remove the await refresh() from inside download(), since the event listener now handles that responsibility reliably:

async function download(modelId: string) {
  error = null;
  downloads = { ...downloads, [modelId]: { downloaded: 0, total: 0 } };
  try {
    await chatModelDownload(modelId);
    // Refresh is handled by the MODEL_DOWNLOAD_READY event listener.
  } catch (e) {
    log.error('Download failed', e);
    error = e instanceof Error ? e.message : String(e);
    // On error, the ready event won't fire, so refresh manually.
    await refresh();
  } finally {
    const next = { ...downloads };
    delete next[modelId];
    downloads = next;
  }
}

daemon_setup.rs — Hard-coded 30s timeout without user-visible feedback

The fix extends the blocking startup wait from 5s to 30s. This is correct for the cold-start scenario, but the UX implication is that the Tauri app will appear frozen for up to 30 seconds with no indication of progress if the daemon is slow. The existing poll loop at 250ms intervals provides no progress channel to the frontend. This does not block merge — the issue is pre-existing and the fix is clearly better than a spurious "connection failed" error — but a follow-up issue to emit a "daemon starting..." status event on each failed poll would be a meaningful improvement.


Nitpicks

Nit: chat_models.rs — Inline ReadyEvent struct duplicates the ProgressEvent pattern

Both ReadyEvent and ProgressEvent are defined inline inside match arms. The ReadyEvent payload is minimal (just model_id: String), so this is fine. But they follow slightly inconsistent placement: ProgressEvent is defined where it is used (inside the "downloading" arm), and ReadyEvent mirrors that. If this file grows more event arms in the future, hoisting the structs to module level would improve readability. Non-blocking for this PR.

Nit: ai-chat-node-viewer.svelte hydration comment

The comment at the hydration fallback block says "the root cause class behind the original 'picker does nothing'" — the word "class" reads oddly here; "root cause of the original..." would be clearer.


Acceptance Criteria Coverage

Criterion Status
LocalAgentService registered (bug #1) Previously merged
Dev proxy flattenProperties (bug #2) Previously merged
Viewer renders AiChatModelPicker after provider selection (bug #3) type: 'viewer' source bypasses skip-while-editing guard correctly
Download status transitions to "ready" (bug #4) Rust emits model://download-ready, picker calls refresh()
No "Error" flash on valid download trigger (bug #5) Addressed via the ready event clearing the downloads map before refresh
Daemon startup timeout extended for cold start (bug #6) 5s -> 30s with explanatory comment

Net assessment: approve. The double-refresh is worth noting but is not a regression. The core correctness and architecture are solid. The event constant is properly mirrored in both Rust (agent_events.rs) and TypeScript (agent-types.ts) with matching string values, and listener teardown in onDestroy is correct.

The MODEL_DOWNLOAD_READY event listener already calls refresh() on the
success path; awaiting chatModelDownload() also called refresh() after
it resolved (which is after the ready event fires), causing two
sequential list+RAM fetches. Now only the event listener owns the
success-path refresh; the catch block handles error-path refresh.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@malibio
malibio merged commit 740f037 into main May 31, 2026
@malibio
malibio deleted the worktree-issue-1285-ai-chat-model-bugs branch May 31, 2026 20:56
malibio added a commit that referenced this pull request Jun 22, 2026
…cation (#1286)

* Fix AI chat viewer reactivity, download status, and daemon startup timeout (#1285)

- Hydration setNode now uses type:'viewer' source so the skip-while-editing
  guard can't block it when the node has pending writes (fixes viewer stuck
  on placeholder after provider selection)
- chat_model_download emits model://download-ready Tauri event on completion;
  model picker listens and calls refresh() immediately (fixes download status
  stuck on "downloading")
- Daemon startup timeout extended from 5s to 30s to accommodate cold-start
  embedding model load (6-8s on first launch)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

* Address review: remove duplicate refresh() on successful download

The MODEL_DOWNLOAD_READY event listener already calls refresh() on the
success path; awaiting chatModelDownload() also called refresh() after
it resolved (which is after the ready event fires), causing two
sequential list+RAM fetches. Now only the event listener owns the
success-path refresh; the catch block handles error-path refresh.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

---------

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
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.

Fix AI chat viewer and model manager bugs found during Gemma 4 verification

1 participant