Skip to content

fix(editor): don't wipe in-flight uploads on external content sync#4196

Merged
NevilleQingNY merged 3 commits into
mainfrom
fix/chat-upload-wiped-by-session-create
Jun 16, 2026
Merged

fix(editor): don't wipe in-flight uploads on external content sync#4196
NevilleQingNY merged 3 commits into
mainfrom
fix/chat-upload-wiped-by-session-create

Conversation

@NevilleQingNY

Copy link
Copy Markdown
Collaborator

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:

  1. After switching agent the chat has no session (activeSessionId = null).
  2. The first upload inserts an uploading fileCard, then its handler lazily creates a session and calls setActiveSession(null → uuid) — mid-upload.
  3. That flip changes ChatInput's draftKey (__new__:agent → sessionId). The new key has an empty draft, so defaultValue becomes "".
  4. ContentEditor's "sync external defaultValue" effect runs setContent(""), wiping the document including the still-uploading node.
  5. The upload finishes but finalizeFileCard can't find the node → the real href is never written → empty !file[name]().

editorKey already deliberately excludes activeSessionId to avoid a remount on this same flip — but the flip still leaked through draftKey → defaultValue → setContent.

Fix

Add a guard at the top of the content-sync effect: if the editor holds any uploading node, bail out and don't setContent. 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

  • New chat → switch agent → upload a file immediately: file stays and finalizes with a real link.
  • Existing chat upload still works.
  • WS-driven description sync into the issue editor still updates content when no upload is in flight.

🤖 Generated with Claude Code

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>
@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
multica-docs Ready Ready Preview, Comment Jun 16, 2026 9:51am

Request Review

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>
@NevilleQingNY NevilleQingNY merged commit f46b929 into main Jun 16, 2026
6 checks passed
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>
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.

1 participant