fix(editor): don't wipe in-flight uploads on external content sync#4196
Merged
Conversation
When a brand-new chat's first file upload triggers lazy session creation, `setActiveSession(null → uuid)` flips ChatInput's draft key mid-upload, which changes `defaultValue` to the new (empty) session draft. ContentEditor's "sync external defaultValue" effect then ran `setContent` over a document that still held the `uploading` image/fileCard node, wiping it — so the upload's finalize could no longer find the node. The file vanished and the draft was left with an empty `!file[name]()`. The editor was never remounted (instance stays alive); the node was removed by the content-sync effect. An uploading node is local state an external sync must not overwrite, exactly like the existing dirty/focused guards. Add a guard that bails the sync while any `uploading` node is present. Pure frontend; affects only the first upload in a new chat (subsequent uploads hit an existing session, so no draft-key flip). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
The content-sync effect now reads `editor.state.doc.descendants` on every run to detect uploading nodes; the mocked editor didn't implement it, crashing all ContentEditor tests. Add `descendants` (driven by `editorState.uploadingNodes`) to the mock and a regression test asserting an external `defaultValue` change does not setContent while an upload is in flight, and resumes once it settles. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The first file upload in a brand-new chat lazily creates the session, flipping ChatInput's draft key from `__new__:agent` to the session id mid-upload. The in-progress (empty-href) file-card markdown the editor had already written into the `__new__:agent` draft was neither migrated nor cleared, so it stayed stranded under that key — and resurfaced as a stale `!file[name]()` the next time a new chat opened for the same agent (the send only cleared the session-keyed draft). Migrate the `__new__:agent` draft onto the new session id the moment the session is created (upload path only — text send already clears the pre-flip key via `keyAtSend`). Add a shared `newSessionDraftKey` helper so ChatInput and ensureSession agree on the slot name, and a `migrateInputDraft` store action. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
pawelhajduk
pushed a commit
to pawelhajduk/multica
that referenced
this pull request
Jun 16, 2026
…ultica-ai#4196) * fix(editor): don't wipe in-flight uploads on external content sync When a brand-new chat's first file upload triggers lazy session creation, `setActiveSession(null → uuid)` flips ChatInput's draft key mid-upload, which changes `defaultValue` to the new (empty) session draft. ContentEditor's "sync external defaultValue" effect then ran `setContent` over a document that still held the `uploading` image/fileCard node, wiping it — so the upload's finalize could no longer find the node. The file vanished and the draft was left with an empty `!file[name]()`. The editor was never remounted (instance stays alive); the node was removed by the content-sync effect. An uploading node is local state an external sync must not overwrite, exactly like the existing dirty/focused guards. Add a guard that bails the sync while any `uploading` node is present. Pure frontend; affects only the first upload in a new chat (subsequent uploads hit an existing session, so no draft-key flip). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test(editor): cover the in-flight-upload content-sync guard The content-sync effect now reads `editor.state.doc.descendants` on every run to detect uploading nodes; the mocked editor didn't implement it, crashing all ContentEditor tests. Add `descendants` (driven by `editorState.uploadingNodes`) to the mock and a regression test asserting an external `defaultValue` change does not setContent while an upload is in flight, and resumes once it settles. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(chat): migrate new-chat draft onto the session id on lazy create The first file upload in a brand-new chat lazily creates the session, flipping ChatInput's draft key from `__new__:agent` to the session id mid-upload. The in-progress (empty-href) file-card markdown the editor had already written into the `__new__:agent` draft was neither migrated nor cleared, so it stayed stranded under that key — and resurfaced as a stale `!file[name]()` the next time a new chat opened for the same agent (the send only cleared the session-keyed draft). Migrate the `__new__:agent` draft onto the new session id the moment the session is created (upload path only — text send already clears the pre-flip key via `keyAtSend`). Add a shared `newSessionDraftKey` helper so ChatInput and ensureSession agree on the slot name, and a `migrateInputDraft` store action. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
furtherref
added a commit
to furtherref/multica
that referenced
this pull request
Jun 16, 2026
Syncs 16 upstream commits (v0.3.22..v0.3.23). Highlights: issue date filter (multica-ai#4129), client failure telemetry — JS errors + freeze/crash breadcrumbs to PostHog (multica-ai#4187), issue status/priority validation returning 400 (multica-ai#4156), bare issue-key expansion disabled in comments (MUL-3310), Lark WebSocket proxy support (MUL-3320), a runtime delete CLI command (MUL-3321), agent prompt switched to --content-file to avoid heredoc flag swallowing (MUL-3316), CLI callback params preserved across Google OAuth redirect (MUL-3313), and an in-flight upload fix on external content sync (multica-ai#4196). Upstream's chat-upload gate (MUL-3312) was added and reverted within the range, so it lands as a no-op. Conflicts resolved (4 paths, one decision): The fork carries CanonicalizeMentions (server-side mention label/UUID canonicalization, fork PR #65) layered on top of the upstream mention expansion code. Upstream's MUL-3310 (multica-ai#4190) deliberately disabled bare issue-key expansion in comments and deleted expand.go / expand_test.go. Resolution: follow upstream — drop ExpandIssueIdentifiers and stop auto-linking bare MUL-123 text — while keeping CanonicalizeMentions. - server/internal/handler/comment.go, server/internal/service/task.go: kept the CanonicalizeMentions pass before persistence (re-added the mention import the auto-merge dropped); removed the ExpandIssueIdentifiers calls. PreviewCommentTriggers already auto-merged to upstream's no-expansion form. - server/internal/mention/expand.go, expand_test.go: accepted upstream's deletion. CanonicalizeMentions still needs findSkipRegions / inSkipRegion / skipRegion (and uuidToString, used by canonicalize_test.go), so those helpers were moved into a new server/internal/mention/skip_regions.go rather than lost with the file. - server/internal/mention/canonicalize.go, canonicalize_test.go: dropped the comment's reference to sharing findSkipRegions with ExpandIssueIdentifiers; recovered the makeUUID test helper (previously defined in expand_test.go) into canonicalize_test.go. Follow-on fix: - update-notification.test.tsx: added the new DesktopAPI.getLastFreeze method (freeze-breadcrumb telemetry) to the fork test's inline mock. Verified locally: pnpm typecheck (6/6), full TS suites (8/8), go build/vet, mention + handler (comment write-path + issue validation) + execenv + lark + cmd Go tests against a real DB, reserved-slugs no drift, gofmt clean, lint 0 errors. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Switching agent in chat and then uploading a file (the first upload in the new chat) made the file vanish — leaving an empty
!file[name]()in the draft. Waiting longer before uploading did not help; only a second upload (or uploading into a chat that already has a session) worked.This is a distinct bug from #4192 (MUL-3312), which gated uploads on
activeAgent— that closed the no-agent window, not this one.Root cause (confirmed by instrumented logs)
Not a remount — the editor instance stayed alive (
editorIsDestroyed: false). The node was deleted from the document by the content-sync effect:activeSessionId = null).uploadingfileCard, then its handler lazily creates a session and callssetActiveSession(null → uuid)— mid-upload.draftKey(__new__:agent→ sessionId). The new key has an empty draft, sodefaultValuebecomes"".ContentEditor's "sync externaldefaultValue" effect runssetContent(""), wiping the document including the still-uploading node.finalizeFileCardcan't find the node → the real href is never written → empty!file[name]().editorKeyalready deliberately excludesactiveSessionIdto avoid a remount on this same flip — but the flip still leaked throughdraftKey → defaultValue → setContent.Fix
Add a guard at the top of the content-sync effect: if the editor holds any
uploadingnode, bail out and don'tsetContent. An in-flight upload is local state an external sync must not overwrite — same principle as the existing dirty/focused guards.Pure frontend. Only affects the first upload in a new chat (later uploads hit an existing session, so no draft-key flip).
Test plan
🤖 Generated with Claude Code