fix: address PR #4639 review feedback - seed currentContent and fix auto-save scheduling#4834
Conversation
There was a problem hiding this comment.
🟡 Duplicate scheduleAutoSave() call — original not removed after "move"
The PR description states scheduleAutoSave() was moved before the guard let coordinator check, but the original call at line 94 was left in place. When the coordinator IS available (the normal path), scheduleAutoSave() is called twice in the same synchronous execution: once at line 83 and again at line 94.
Root Cause and Impact
The second call at line 94 immediately cancels the autoSaveTask created by the first call at line 83 and schedules a brand new one. While this is functionally equivalent to calling it once (due to the cancel-and-reschedule pattern in scheduleAutoSave()), it is clearly unintentional leftover code from an incomplete move.
During rapid streaming updates, each updateDocument call resets the debounce timer twice instead of once per invocation. The practical impact is negligible since both calls happen synchronously, but the redundant call should be removed to match the stated intent of the fix.
(Refers to line 94)
Was this helpful? React with 👍 or 👎 to provide feedback.
…ore guard Addresses review feedback on #4639: - createDocument now sets self.currentContent = initialContent so subsequent append-mode updateDocument calls do not lose the loaded content - scheduleAutoSave() is now called before the guard let coordinator check so the document is persisted even when the WebView coordinator is not yet ready Co-Authored-By: Claude <noreply@anthropic.com>
… state (LUM-1272) (#28681) * fix(macos): flush pending autosave before clearing state in closeDocument() (LUM-1272) - closeDocument() now calls save() before cancelling the autoSave task and clearing state, preventing silent data loss when the user closes within the 2-second debounce window. - save() captures title, wordCount, and documentClient as locals before the Task to prevent reading stale/cleared values from self after close. - save() uses [weak self] and a surfaceId scope guard so stale save responses from a previous document cannot clobber a newly-opened document's state. - createDocument() and closeDocument() reset isSaving/lastSaveError for clean state at document boundaries. - Remove redundant scheduleAutoSave() call in updateDocument() (became dead after PR #4834 moved the call before the coordinator guard). - Add deinit to cancel autoSaveTask per @observable task lifecycle guidance. Apple refs checked (2026-04-28): - WWDC21 Protect mutable state with Swift actors - swift#79551 @observable deinit actor isolation Co-Authored-By: ashlee@vellum.ai <ashlee@vellum.ai> * fix: flush active document in createDocument() before overwriting state Callers like handleDocumentEditorShow and handleDocumentLoadResponse call createDocument() directly without closeDocument(). If a document has unsaved edits, the new document would silently overwrite them. Guard at the data layer so all callers get the flush automatically. Co-Authored-By: ashlee@vellum.ai <ashlee@vellum.ai> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Summary
Addresses review feedback on #4639 (feat: persist document widget in chat after app reload).
Fix 1: Seed
currentContentincreateDocumentcreateDocumentnow setsself.currentContent = initialContentbefore marking the document active. Previously, when a document was opened viadocument_load_response(with existing content) and a subsequentappend-mode streaming update arrived,currentContentwasnil, causing the buffer to drop the original text and lose data on reload.Fix 2: Schedule auto-save before the coordinator guard
Moved
scheduleAutoSave()to before theguard let coordinator = editorCoordinator else { return }block inupdateDocument. Previously, if all streaming updates completed before the WebView coordinator finished loading,scheduleAutoSave()was never called and the document was never persisted. The auto-save now fires regardless of coordinator readiness.Files Modified
clients/macos/vellum-assistant/Features/MainWindow/DocumentManager.swiftNotes
Fix 3 from the review (use
selection = .panel(.documentEditor)instead oftogglePanel) was already applied in commitd3f80158("fix: prevent document editor panel closing on second show") and is not included here.🤖 Generated with Claude Code