Skip to content

✍️ fix: Keep an Unsent Draft in the Composer When a Run It Did Not Send Starts - #18472

Draft
danny-avila wants to merge 1 commit into
devfrom
danny-avila/draft-survives-foreign-run
Draft

danny-avila wants to merge 1 commit into
devfrom
danny-avila/draft-survives-foreign-run

Conversation

@danny-avila

Copy link
Copy Markdown
Collaborator

Summary

Words written in the composer and not sent are lost when a run starts that the composer did not send. Type a draft, then click Regenerate on the last reply: the composer empties at once, and when the rerun ends the draft is gone for good. The same happens when a run started somewhere else reaches the conversation on screen (a second tab sending in it, for one): the tab holding the draft empties its composer as it attaches.

The composer saves its text under the conversation while idle and under a pending key while a run is under way. When a run starts, useAutoSave writes the field to the conversation's record and then restores the pending record over the field. For a send that is right: the send has already emptied the field. For any other run the field still holds the reader's words, the pending record is empty, and the restore blanks them. The end of the run then clears the conversation's record, which by then is their only copy. Staged files were already carried across this switch; text was not.

With this change, words still in the composer when a run starts stay there, as staged files do. They are saved under the pending key for the run's duration and become the conversation's draft again when it ends. A composer drawn for the first time with words already in it, and no record to restore, keeps them too; that is what lets a composer mounted by something other than the route start from text it was handed.

How it works

-    const sameComposerPhase =
-      filesRef.current.size > 0 &&
-      currentDraft?.conversationId === (_conversationId ?? Constants.NEW_CONVO) &&
-      ((currentConversationId === conversationDraftId && conversationId === pendingDraftId) ||
-        (currentConversationId === pendingDraftId && conversationId === conversationDraftId));
+    const startsRun =
+      currentConversationId === conversationDraftId && conversationId === pendingDraftId;
+    const endsRun =
+      currentConversationId === pendingDraftId && conversationId === conversationDraftId;
+    const keepsWords = startsRun && (textAreaRef?.current?.value ?? '') !== '';
+    const sameComposerPhase =
+      currentDraft?.conversationId === (_conversationId ?? Constants.NEW_CONVO) &&
+      (keepsWords || (filesRef.current.size > 0 && (startsRun || endsRun)));

sameComposerPhase is the existing branch that saves the live composer under the new key instead of restoring that key's record over it. It now also holds at the start of a run when the field has text. The end of a run is left as it was: the pending record is moved to the conversation and restored, which is the path the tests for typing as a run finishes cover.

A send is unaffected because submitMessage resets the form in the same event that starts the run, so the field is empty by the time this effect sees the switch.

Type of change

  • Bug fix

Testing

Reproduced in a real browser on the mock e2e lane, one tab: send a message, type a draft I have not sent, click Regenerate. Before the change the composer read "" half a second later, the text sat under the conversation's draft key for the length of the run, and after the run both the field and storage were empty. After the change the field keeps the words through the run and after it, and a reload restores them as the conversation's draft.

The two-tab case (a draft in one tab, a slow reply started in the same conversation from another) was reproduced before the change and not re-run after it; it goes through the same switch.

The new unit tests fail with the change removed (2 of 63), and the new scenario fails against a build without it (Expected: "still writing this one", Received: "").

Tested environments/configuration:

  • Chromium via Playwright, mock e2e lane (in-memory MongoDB, fake model), desktop 1440×900. Save Drafts on (the default).

Automated tests:

  • client: new cases in src/hooks/Input/useAutoSave.spec.ts (a draft held when a run starts stays, is kept under the pending key, and is the conversation's draft when the run ends; an empty composer still restores the pending record; a composer drawn with words and no record keeps them). npx jest src/hooks/Input src/components/Chat/Input: 52 suites, 1200 tests pass.
  • New scenario @scenario:composer-draft-survives-a-regenerate in e2e/specs/mock/scenarios/composer-draft-survives-run.spec.ts.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: 348a33f

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T22:19:10.123374Z 348a33f Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 348a33fdcd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant