Repository navigation
AI chat model overlay: download progress, and keep the overlay across tab switches - #3857
Conversation
mstomar125
left a comment
There was a problem hiding this comment.
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
catchinsendMessagesetssendError, and the overlay clears infinally. - Tests per phase label and tab switch: met.
Checks you asked for
- Stuck overlay on failure or cancel: no.
runEnsureReady'sfinallyalways removespreparations[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:
preparationsandinFlightEnsureare 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:
runEnsureReadysubscribes viabrowserSyncService.onModelLoadProgress, readsbytesDownloadedandbytesTotalfrom the SSE event type, and cancel goes through the proxyDELETE. Consistent. There is no test for the browser path (non-blocking).
Findings
-
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; daemonpackages/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.
- Files:
-
Non-blocking: a listener can leak if the second
listenthrows.- File:
model-store.svelte.ts:469-480. unlisteners.push(await listen(...status), await listen(...progress))evaluates both awaits beforepushruns. If the secondlistenrejects, the first unlisten function is never pushed and never called. Pushing each one as it resolves fixes it.
- File:
-
Non-blocking:
inFlightEnsureandpreparationscleanup is not identity-checked afterreset().- Files:
model-store.svelte.ts:434-436, 501-502, 619-621. - After
reset()clears both, an old in-flight run'sfinallystill 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 torunbefore deleting makes it safe.
- Files:
-
Non-blocking: a failure after Cancel is reported as "Download cancelled".
- File:
model-store.svelte.ts:494-498. - If
cancelRequestedis true but the download had already finished and verify or load then failed, the real error is replaced byDownload cancelled. Only convert to the cancelled error when the failure happened during the downloading phase.
- File:
-
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.
- File:
-
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.
- There are no tests for: the browser path; unsubscribe on failure (the test only asserts state is cleared); the cancel IPC failing (it resets
-
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.
…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]>
0a66cdb to
75b1742
Compare
What changed
model-store.svelte.ts: newensureReady(modelId)runsensure_model_readyand publishespreparations[modelId]with the phase (preparing,downloadingwith bytes done/total,verifying,loading). Phases come from the existingmodel://statusandmodel://download-progressevents (Tauri) or the dev-proxy SSEmodelLoadProgressevents (browser), whichensure_model_readyalready emits, so no backend change was needed. Concurrent callers share one run.cancelPreparationcalls the existing cancel-download command and the run then fails with "Download cancelled". Also exportsdescribePreparation(label text) andformatDownloadSize.ai-chat-native-node-viewer.svelte:isEnsuringModeland the phase were component-local$state, so a remounted viewer lost the overlay. The overlay is now derived frommodelStore.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.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-appquality:fix(eslint, design tokens, svelte-check: 0 errors).Closes #3841
🤖 Generated with Claude Code