Skip to content

FIX: Do not restore completed sends as unsent drafts - #3888

Open
Vishal Punjabi (vshalpnjabi) wants to merge 6 commits into
microsoft:mainfrom
vshalpnjabi:cursor/fix-completed-send-draft-restore-37d2
Open

Vishal Punjabi (vshalpnjabi) wants to merge 6 commits into
microsoft:mainfrom
vshalpnjabi:cursor/fix-completed-send-draft-restore-37d2

Conversation

@vshalpnjabi

@vshalpnjabi Vishal Punjabi (vshalpnjabi) commented Nov 3, 2026 •

Copy link
Copy Markdown

Description

Fixes #3737.

If a send was accepted and you left Chat before it finished (for example by going to Datasets), the composer came back on return with the same prompt and Send enabled, even though the prompt was already in saved history.

Now, when Chat unmounts during an accepted send, the draft handoff snapshot also stores that send's submission ID, as long as the composer hasn't changed since the send. The ID is carried across later visits until the prompt shows up in history or the draft is edited. On return, if the snapshot has an accepted submission ID and saved history already has a user message with that prompt, the composer is cleared instead of restored. The system prompt, objective, temperature, scorer and converter pipelines are kept; text, attachments and converter working state are cleared, the same as after a normal completed send. Drafts without an accepted send, and drafts edited after the send (including added attachments or edited converter output), are restored as before. Nothing is resent automatically.

The match is on prompt text, so if the same text was sent earlier in the conversation, it also counts as saved.

This doesn't touch #3734 (carrying a draft across conversation switches).

Tests and Documentation

  • New ChatWindow tests: (1) the issue's flow: unmount Chat during the send, remount after history has the prompt and reply; (2) an attachment added after a failed status read is kept; (3) the converter pipeline is kept; (4) leaving and returning twice while the send is in flight doesn't restore the prompt. Each fails without the fix and passes with it.
  • New unit test for historyContainsAcceptedDraft in useChatDraftHandoff.test.tsx.
  • npm run lint, npx tsc --noEmit and npm run build pass.
  • Full npm run test:coverage: 4123 of 4145 passed. The 22 failures were timeouts in 12 suites while the machine was overloaded. Re-run on their own, those 12 suites passed (516/516).
  • Playwright mock project, chat.spec.ts and routing.spec.ts: 33 passed. I didn't run the seeded or backend specs.

No docs changes needed.

Copilot AI balanced review requested due to automatic review settings November 3, 2026 16:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Pending-send reconciliation and navigation can erase unsent draft edits, lose converter configuration, and restore an accepted prompt as resendable.

3 open issues
What changed in this PR

This PR addresses #3737 by reconciling preserved Chat drafts with saved history, preventing completed sends from reappearing as unsent prompts. Conversation-switch draft isolation (#3734) remains out of scope.

Changes:

  • Records accepted submission IDs in draft handoff snapshots.
  • Clears restored prompt content when its text matches saved user history.
  • Adds utility and ChatWindow regression tests for navigation during a send.
File Description
frontend/​src/​utils/​chatDraft.ts Adds accepted-draft history matching.
frontend/​src/​types/​index.ts Adds the optional accepted submission ID to drafts.
frontend/​src/​hooks/​useChatDraftHandoff.test.tsx Tests accepted-draft matching conditions.
frontend/​src/​components/​Chat/​ChatWindow.tsx Records accepted sends and reconciles restored drafts.
frontend/​src/​components/​Chat/​ChatWindow.test.tsx Tests leaving Chat during a send and returning after completion.

Review effort: Balanced

@vshalpnjabi

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Track accepted submission IDs on the draft handoff snapshot and
reconcile them with saved history on return so a send that finished
while the user was on Datasets is not restored as unsent.
…leted send

Carry the accepted submission only while the composer is unchanged since the
send, including across repeated visits before the prompt reaches history.
Clearing a completed send now keeps the converter pipelines, as a normal
completion does.
@cursor
cursor Bot force-pushed the cursor/fix-completed-send-draft-restore-37d2 branch from f8b7992 to 2db9a8d Compare November 6, 2026 08:43
@vshalpnjabi

Copy link
Copy Markdown
Author

Roman Lutz (@romanlutz) Conflicts with main are resolved and the branch is up to date. Copilot’s three notes were addressed in f8b7992 with replies on each thread. Ready for a look when you have a minute — thanks!

This branch has not been deployed

No deployments
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.

A send that completes while away from Chat is restored as an unsent, resendable draft

2 participants