Skip to content

AI chat model overlay: download progress, and keep the overlay across tab switches - #3857

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3841-model-overlay-progress
Oct 20, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3841-model-overlay-progress

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

What changed

  • model-store.svelte.ts: new ensureReady(modelId) runs ensure_model_ready and publishes preparations[modelId] with the phase (preparing, downloading with bytes done/total, verifying, loading). Phases come from the existing model://status and model://download-progress events (Tauri) or the dev-proxy SSE modelLoadProgress events (browser), which ensure_model_ready already emits, so no backend change was needed. Concurrent callers share one run. cancelPreparation calls the existing cancel-download command and the run then fails with "Download cancelled". Also exports describePreparation (label text) and formatDownloadSize.
  • ai-chat-native-node-viewer.svelte: isEnsuringModel and the phase were component-local $state, so a remounted viewer lost the overlay. The overlay is now derived from modelStore.preparations[model]: "Downloading … 42% (1.2 of 4.5 GB)", then "Verifying model integrity…", then "Loading model…". A cached model emits no download events and goes straight to verifying/loading. A Cancel button shows while downloading. A failed or cancelled run clears the overlay and the existing send-error path states why; the chat stays usable. The viewer's own model-status listeners were removed (the store owns them).

Tests

  • src/tests/stores/model-store-preparation.test.ts (10): phase transitions, cached model skips download, other-model events ignored, shared run, failure clears state, cancel reports cancelled, label text.
  • src/tests/components/ai-chat-model-overlay.test.ts (8): label per phase, live phase updates, overlay survives unmount and remount at the current phase, cancel only while downloading.
  • All with mocked store state and mocked Tauri commands/events; no model was downloaded or loaded.

Ran: the new files plus model-store.test.ts, ai-chat-native-viewer-messages.test.ts, ai-chat-viewer-lifecycle.test.ts; bun run test:changed (frontend + browser, passed); desktop-app quality:fix (eslint, design tokens, svelte-check: 0 errors).

Closes #3841

🤖 Generated with Claude Code

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review Type: Initial Review

Verdict: APPROVE WITH NITS

Checked out the head in a throwaway worktree. model-store-preparation.test.ts and ai-chat-model-overlay.test.ts pass (18/18) and eslint is clean on the touched files. Neither test downloads or loads a model: tauri-commands and @tauri-apps/api/event are mocked, and the overlay test sets store state directly. The only real call is fetch, which is stubbed to reject.

Requirements (#3841)

  • Download progress with size and percentage: met (describePreparation).
  • Downloading, verifying and loading, each labelled: met.
  • Cached model skips the download phase: met (a test covers it).
  • Tab switch keeps the overlay at the current phase: met. State now lives in modelStore.preparations, and the remount test covers it.
  • Failed or cancelled download leaves the chat usable and says why: met. The catch in sendMessage sets sendError, and the overlay clears in finally.
  • Tests per phase label and tab switch: met.

Checks you asked for

  • Stuck overlay on failure or cancel: no. runEnsureReady's finally always removes preparations[modelId], and the failure and cancel paths are tested.
  • Concurrent callers: the second caller gets the same promise from inFlightEnsure, and a test covers it.
  • Store entry cleanup: preparations and inFlightEnsure are both cleaned in .finally(). No leak in normal operation.
  • Listeners: unsubscribed in finally (see finding 2 for one gap). The viewer no longer owns any model listeners, so nothing is left to unsubscribe on unmount.
  • Formatting: total <= 0 shows no percent; percent is capped at 100 and floored (99.9% shows 99%); the unit follows the total (B/KB/MB/GB). Zero downloaded of a known total shows "0.0 of 4.5 GB". Fine.
  • Browser mode: runEnsureReady subscribes via browserSyncService.onModelLoadProgress, reads bytesDownloaded and bytesTotal from the SSE event type, and cancel goes through the proxy DELETE. Consistent. There is no test for the browser path (non-blocking).

Findings

  1. Non-blocking: Cancel is per model and global, not per chat.

    • Files: ai-chat-native-node-viewer.svelte:515-525 (button), model-store.svelte.ts:441-451; daemon packages/agent/src/local_agent/model_manager.rs:378.
    • The overlay is derived from preparations[model], so a second chat that shares the model (or just shows it in its dropdown) also gets the overlay and a Cancel button. That button cancels the download that the first chat's Send started. The daemon cancels by model id, so a Settings-initiated download of the same model is cancelled too.
    • Result: chat A shows "Download cancelled" although the user pressed Cancel in chat B. This is acceptable for a shared download, but it is a surprise. Consider showing Cancel only in the viewer that started the run, or labelling the overlay in other viewers as read-only.
  2. Non-blocking: a listener can leak if the second listen throws.

    • File: model-store.svelte.ts:469-480.
    • unlisteners.push(await listen(...status), await listen(...progress)) evaluates both awaits before push runs. If the second listen rejects, the first unlisten function is never pushed and never called. Pushing each one as it resolves fixes it.
  3. Non-blocking: inFlightEnsure and preparations cleanup is not identity-checked after reset().

    • Files: model-store.svelte.ts:434-436, 501-502, 619-621.
    • After reset() clears both, an old in-flight run's finally still deletes the entry by key. If a new run for the same model started in between, it removes the new run's map entry and its preparation. This is test and teardown territory only, but comparing the entry to run before deleting makes it safe.
  4. Non-blocking: a failure after Cancel is reported as "Download cancelled".

    • File: model-store.svelte.ts:494-498.
    • If cancelRequested is true but the download had already finished and verify or load then failed, the real error is replaced by Download cancelled. Only convert to the cancelled error when the failure happened during the downloading phase.
  5. Non-blocking: the unusable-model path while the overlay is up.

    • File: ai-chat-native-node-viewer.svelte:90-100.
    • The overlay follows the node's current model. If the user changes the dropdown during preparation, the overlay for the old model disappears and the old run continues in the background. This is harmless but worth a note.
  6. Nit: coverage gaps.

    • There are no tests for: the browser path; unsubscribe on failure (the test only asserts state is cleared); the cancel IPC failing (it resets cancelRequested, untested); and the case in finding 4.
  7. Nit: the cancel button has no accessible name beyond "Cancel" and no aria-busy; the disabled state after click gives no "Cancelling…" text. Minor UX.

No blocking issues.

mstomar125 and others added 2 commits October 20, 2026 13:15
…del store

ModelStore.ensureReady runs ensure-model-ready and publishes the phase
(preparing, downloading with bytes, verifying, loading) in
preparations[modelId]; concurrent callers share one run, and a user
cancel surfaces as a cancelled error. The chat viewer derives its
overlay from that state instead of component-local flags, so the overlay
is still shown at the current phase after the tab is remounted, and
offers Cancel while downloading.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Cancel is offered only to the chat that started the run (not for a
download already running elsewhere). Each event unlisten is recorded as
soon as its listen resolves, a superseded run no longer clears a newer
run's state after reset, and a verify/load failure after the download
finished is no longer reported as a cancel.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3841-model-overlay-progress branch from 0a66cdb to 75b1742 Compare October 20, 2026 11:15
@mstomar125
mstomar125 merged commit 23ff3c0 into main Oct 20, 2026
@mstomar125
mstomar125 deleted the issue-3841-model-overlay-progress branch October 20, 2026 11:15
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.

AI chat model overlay: show download progress, and keep the overlay when the tab is switched away and back

1 participant