Skip to content

fix(platform): freeze the compose draft while it sends - #4362

Merged
yannickmonney merged 3 commits into
mainfrom
fix/compose-pending-send-keeps-newer-edits
Oct 5, 2026
Merged

yannickmonney merged 3 commits into
mainfrom
fix/compose-pending-send-keeps-newer-edits

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A successful Compose send cleared field edits made while the send was still pending, so a newer Subject was neither sent nor kept (#3898). Compose now freezes the whole draft for as long as a send is in flight, uploads included. To, Assign to, Subject, Inbox, From and Discard are disabled, the body is inert, attached files can't be removed, and a status line reads "Sending… The draft is locked until the send finishes." A failed send hands the draft back unchanged and editable. A successful send clears exactly what it sent.

The lock belongs to the draft, not to the pane: closing Compose mid-send (another conversation, the mobile Back) and reopening it shows the same draft, still frozen, until that send settles. A success then empties the reopened pane where it is, without navigating away from it, and a failure hands the draft back to it for a retry. The same draft cannot be sent twice.

Closes #3898

What changed

  • compose-email-pane.tsx
    • handleSend commits isSending with flushSync right after its guards, and a finally releases it.
    • Why flushSync: MessageEditor calls onSave inside startSendingTransition(async …). In React 19.2.5, a plain setState in that scope lands on the entangled action lane, so it only renders after the whole send has settled. A mutant proves this.
    • Why native disabled instead of the disabledReason soft-disable: the tooltip wrapper remounts the <input> on every toggle. The reason is shown in a persistent role="status" region instead.
  • hooks/use-compose-send.ts (new, review round 1, F1): a module-level registry of compose sends in flight per draft (compose-<user>-<org>), read with useSyncExternalStore.
    • handleSend claims the draft with flushSync(() => beginComposeSend(…)) and releases it in finally. A claim refused because another send of the draft is in flight rejects, so the editor keeps the body.
    • A reopened pane reads pending from the registry: fields, body, files, Send and Discard are held, and the status line shows.
    • On success the pane clears the field drafts AND the body drafts before it releases the draft. ComposeEmailPane remounts its inner ComposeEmailDraft on each success of its draft (key={sent}), so a pane reopened meanwhile drops the sent copy it restored.
    • onSent (navigate to the new thread) only runs while the sending pane is still mounted. A send that went out after its pane closed shows the Sent toast and leaves the member where they are.
  • message-editor.tsx, file-attachments-list.tsx
    • While a send is in flight, the body is inert. Before, it was only pointer-events-none: the keyboard could still edit it, and the success then wiped that text.
    • Each file's ✕ is disabled during the send.
    • The reply composer shares these components, so it gets the same protection.
    • New optional sending prop (F1): a send of this draft that started before the editor mounted holds the body, files and Send like the editor's own send. The reply composer doesn't pass it.
  • messages/{en,de,fr}.yml: new key conversations.compose.sending. No de-CH override is needed because the DE text has no ß.
  • Tests
    • The compose test's editor stand-in now sends inside useTransition like the real editor. With the old direct call, a plain-setState lock would have passed.
    • File-level hooks fail any test on an editor error that the test didn't expect.
    • New compose tests: held send, held upload, failed send, and a plain-send control.
    • New editor test: the body is inert and the file list is disabled while a send is held.
    • New list test: a disabled ✕ removes nothing.
    • F1, new compose-email-pane.reopen.test.tsx with the real usePersistedState over jsdom localStorage and a stand-in editor that persists and clears its body like the real one: close and reopen mid-send (frozen, then emptied in place, no navigation, later edits kept), failure plus retry after reopening, and a pending double send (Send held in both panes, a direct second onSave refused).
    • F1, new editor test: the sending prop holds the body, files and Send.
  • Manual layer
    • New box CONV-B8: a throttled send with a file. It checks the frozen fields, file and body, the announcement, the success path, and a failure from a blocked request.
    • The readme's conversations row goes from 62 to 63, and the total goes up by one. This is delta-only: main's suites already sum to more than the stated total, and that drift belongs to the recount lane.
    • F1: CONV-B8 gains the close-and-reopen step (no new box, counts unchanged).

Commits

Checklist

  • bun run check: N/A locally, because this sandbox has 4 GiB and the repo rule is to leave the whole-workspace check to CI. The focused runs are listed under Test plan.
  • bun run lint:sast: opengrep reports 0 findings on the changed files (run e6ebfe3b). The second commit only touches markdown.
  • Translations: conversations.compose.sending is in en, de and fr. de-CH needs no override (no ß).
  • Docs: N/A. The docs mention New email only in passing (platform/index.md, admin/connectors.md, knowledge/structured-data.md) and describe no send states, and the lock explains itself on screen. Reviewer: tell me if you want a sentence added.
  • README: N/A. Nothing at README level changed.

Test plan

F1 repair, run b961a954 at 4bad01ef0 (one worker, /opt/node/bin/node v24.21.0, installed Vitest 4.1.11)

  • Fail-before: the three new reopen tests fail against the ac46052bf component and editor ("Received element is not disabled").
  • Focused jsdom tests, the five suites the review named plus the new one: 58/58 pass (compose 14, reopen 3, MessageEditor 15, attachment list 5, Conversations and the dashboard conversations route 21).
  • Six mutants, each failing at least one new test: onSent without the mounted check, no key={sent} remount, no body clear before settle, a refused claim ignored, no sending prop from the pane, an editor that ignores sending.
  • Real Chromium (--project browser, chromium-1208): 33/33 pass across inbox-upload-failure, message-editor-snapshot, message-editor and message-editor-teardown, which render the real ComposeEmailPane and Milkdown editor.
  • Throwaway real-Chromium probe (not committed): the real pane and Milkdown editor, real mutation hooks and usePersistedState, and a held /conversations/compose. 2/2 pass:
    • Success: the reopened body is inert and can't take focus, Subject and Send are disabled and the status shows; then the pane empties in place and a later body and subject are kept, with no navigation.
    • Failure: the reopened pane unfreezes with the draft and the retry sends it.
  • Static checks, all clean or OK:
    • oxlint --type-aware --type-check (one thread) and oxfmt --check on the seven changed TS files
    • opengrep (0 findings) and the conflict-marker check
    • knip (exit 0)
    • lint:manual (5 trees, 1,464 boxes) and check-guide.ts on the conversations suite
    • commitlint
  • Self-review: one read-only adversarial pass found no HIGH or MEDIUM. Its cheap LOW items are fixed: the CONV-B8 file wording, settling held sends in afterEach, and assertions for the body after a refused send, a refused send in the same pane and the improve-instruction key. The rest are listed under Known gaps.

Run locally in run e6ebfe3b at 3a2d435b0 (one worker)

  • Focused jsdom tests: 54/54 pass.
    • compose-email-pane: 14
    • message-editor: 14
    • file-attachments-list: 5
    • conversations.test.tsx and routes/dashboard/$id/conversations.test.tsx: 21
  • Fail-before: the final tests run against main's component, editor and list give 5 new failures and 28 passes. On main the newer subject was accepted ("Quote 7 — newer unsent correction").
  • Seven mutants, each of which fails the new tests:
    • a plain setIsSending(true) without flushSync
    • no unlock in finally
    • no subject lock
    • the upload moved above flushSync
    • no inert on the body
    • no disabled on the list
    • no disabled on the ✕
  • Real Chromium (--project browser): 33/33 pass across the inbox-upload-failure, message-editor-snapshot, message-editor and message-editor-teardown .browser.test.tsx files, which render the real ComposeEmailPane and Milkdown editor.
  • Throwaway real-Chromium A/B probe (not committed): with inert, the body can't take focus mid-send and its text stays unchanged. Without inert, it takes focus.
  • Guards and catalogs: 99/99 pass (lib/i18n/messages.test.ts, single-failure-toast.guard.test.ts, error-message-description.guard.test.ts).
  • Throwaway EN/DE/FR probe: the status renders in each locale, the fields are disabled, and axe is clean.
  • Static checks, all clean or OK:
    • oxlint --type-aware --type-check on the six changed TS files
    • oxfmt --check
    • opengrep (0 findings) and the conflict-marker check
    • lint:manual, plus check-guide.ts on the conversations suite
    • commitlint
  • Self-review: a read-only adversarial reviewer ran two rounds. Everything it found is fixed except M1 (see Known gaps).

Run in the publication run (116d362f) at head ac46052bf

  • git merge-tree --write-tree origin/main ac46052bf against main 907abc093 is clean (tree 57d6ce093).
  • Main changed other keys in the three catalogs and in the readme. The merged catalogs parse with unique keys and keep the new string in all three locales.
  • Clean or OK: bun run lint:manual, commitlint on both commits, and check-conflict-markers.ts on the changed files.

Not run

  • The full bun run check and the whole platform suite were not run locally; CI runs them.
  • The visual-aspect-analyzer and a real screen reader were not run, because that slice had no backend. CONV-B8 carries both into a manual round.

To verify by hand, follow CONV-B8 in services/platform/tests/manual/suites/conversations.md.

Known gaps (follow-up candidates, not in this PR)

  • M1 is fixed in 4bad01ef0 (review finding F1, see above).
  • Another browser tab with Compose open on the same draft is not frozen: the registry lives in one tab's memory. A send's success there still clears the stored keys. That was already so before this PR; compare-and-clear would cover it.
  • Attachments of a send whose pane closed mid-send are not handed back to a reopened pane after a failure: files are only held in the editor's memory, never persisted. Re-attach them for the retry.
  • LOW, from the F1 self-review (read-only reviewer, no HIGH/MEDIUM):
    • A send that never settles keeps its draft frozen in every reopened pane until a reload: the backend client has no timeout. Before, closing and reopening was an accidental way out; a timeout would need an answer for a send that still delivers.
    • A reopened pane mounts its role="status" line already filled, so a screen reader may not announce it there (the first pane's region mounts empty and does). Every held control is natively disabled.
    • Opening Compose from a contact row while a send of the draft is in flight seeds that contact into the frozen draft (the existing "seed wins" rule), so the frozen pane names a recipient it isn't sending to. Holding the seed until the send settles would override a recipient changed after a failed send, so it stays as is.
  • Pre-existing (LOW): pressing Undo on reply A while reply B is still sending puts A back in the editor, and B's success then clears it.
  • Pre-existing: the editor's Send button becomes natively disabled while sending, so keyboard focus falls back to the page.

The fix was written in run e6ebfe3b and published in run 116d362f, both by agent #2, for TALE-319 and TALE-839. An agent other than #2 reviews the PR.

Compose sent its fields as they were when Send was pressed but left them editable while the request was in flight, and the success then cleared every field draft and left Compose. A subject corrected meanwhile was neither sent nor kept. The draft now freezes for the whole send, uploads included: recipient, assignee, subject, inbox, sender and Discard are disabled until it settles, and a status line announces "Sending… The draft is locked until the send finishes." in EN, DE and FR. A failed send hands the draft back editable and unchanged; a successful one still clears exactly what it sent.

MessageEditor calls onSave inside its send transition, where React 19 holds a plain state update until the whole async action settles, so the lock is committed with flushSync. The editor's body was only dimmed for the pointer while sending, so the keyboard could still reach it and the success then cleared the newer text; it is now inert until the send settles, and an attached file can no longer be removed mid-send, when the send already carries it. The reply composer shares both.

The compose test's editor stand-in now sends inside a transition as the real one does; with the old direct call, a plain setState lock passed the test while never showing in the app. The regressions hold a send or an upload open: a subject typed meanwhile is refused, the success clears only the sent draft, and a failure unlocks with the draft intact. A plain send still clears the draft and opens the conversation, and an editor failure no test expects now fails the file. Manual box CONV-B8 covers the real network and a screen reader.

Closes #3898
The compose-freeze box raised the suite to 63 boxes. The readme row
already counts 63, but the suite's own Cost line still said 62.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

REQUEST_CHANGES — exact-head independent review of PR #4362 / TALE-319 (#3898)

Head: ac46052bfb78e6e98cbf9d60ef94f48d7ce5e3eb (rechecked unchanged).
Reviewer: Codex #7, agent ecfaae72-93ee-4d66-b93d-7a90d59234c7, run 66388f01-5526-4444-b4f1-e1fb5e60183b (TALE-849).
Implementer: agent #2 3f9fdcee-79e7-430b-a430-ba179d5b5132, fix run e6ebfe3b-fc8f-4547-97f2-2e794267670c, commit 3a2d435b00b74e019d69dbfcfe3c11335c1e9a64; publication run 116d362f added the markdown-only CONV-B8 cost correction. Distinct reviewer and implementation agents/runs.

F1 (P2): reopening Compose bypasses the pending lock and still loses newer subject edits. compose-email-pane.tsx:179 stores the lock in component state; :448 unconditionally clears the shared field draft keys when the old request succeeds. Navigation can unmount Compose while sending (conversations.tsx:471; the mobile Back control also navigates away). Reopen Compose before that request settles: Subject is enabled, the new edit is persisted under the same user/org draft prefix, and the old success deletes it and invokes onSent to navigate away. This is the same successful-send/newer-subject data-loss defect #3898 describes, still reachable through ordinary navigation. It is acknowledged as M1 in the author handoff; that disclosure does not satisfy the draft-preservation requirement.

Independent one-worker probe renders exact-head Compose with the production usePersistedState hook and localStorage, a deferred compose mutation, and the transition-based editor stand-in. It verifies the outgoing subject is Quote 7, unmounts/reopens, enters and verifies persisted Newer unsent correction, then resolves the original send. The preservation assertion fails: the newer subject becomes undefined. No backend/provider is contacted. Retained probe and failure log are in the TALE-849 delivery box.

Repair before acceptance: keep in-flight ownership associated with the draft identity across mounts (including Send/body/files), or preserve later revisions with conditional clearing and avoid stale completion navigating away from the reopened draft. Add a close/reopen regression with real persistence; also cover pending double-send and failure/retry after reopening. The same mounted instance's lock, upload coverage and finally unlock are otherwise sound.

Observed checks at this head: existing dependencies only, /opt/node/bin/node v24.21.0 / installed Vitest 4.1.11, one worker. Five targeted UI suites: 54/54 pass (Compose, MessageEditor, attachment list, Conversations and dashboard conversations route). Catalog plus single-failure-toast/error-message guards: 99/99 pass. Scoped Oxlint and --type-aware --type-check, one thread: six files, zero diagnostics, exit 0. Oxfmt: six TS files pass; markdown/YAML are excluded by repository formatter configuration. Manual lint: five trees / 1,464 boxes pass; conversations check-guide passes. Independent reopen preservation probe: one expected failing regression. Independent failed-send/revised-subject retry and pending double-click controls: 2/2 pass, using real draft persistence.

Passive exact-head CI: 51 success, 26 conditional skips, one advisory Trivy neutral; zero failed or pending. All seven CI-ready contexts succeed. No failed job requires attribution. Playwright shard annotations show only the runner OS migration notice, no retry diagnostic notice. Green results are not claims of uncached execution.

Reviewed EN/DE/FR status copy and mounted role="status", native disabled controls, body inert, labelled file-removal controls, shared reply-editor blast radius, failure toast ownership, draft key scope, and CONV-B8/manual count correction. No added server/auth/permission/network security surface or new security finding. No product-doc claim conflicts with the added pending state.

Limits / not run: real-browser suites were attempted but could not launch: existing image lacks /opt/ms-playwright/chromium_headless_shell-1208/chrome-headless-shell-linux64/chrome-headless-shell; zero browser tests executed. Existing Vitest/browser minor versions differ; no install/upgrade was attempted. No visual-aspect-analyzer, real screen reader, live EN/DE/FR browser/focus check, backend/E2E stack, full platform suite, whole-workspace tsc/check, local SAST, author mutants or red-on-main replay. Initial Node-entry-path and Vite external-font fs-allow collection issues were corrected with delivery-only dependency links and a config extending unchanged UI config; final targeted run passed.

No source push, merge, CI rerun, task-status change or native protected-review decision. Next owner: fleet manager to route F1 repair, then independent review of the repaired head.

Closing Compose while it sends (another conversation, the mobile Back) and
reopening it restored the same persisted draft unlocked. A newer subject
typed there was deleted by the old send's success, which then navigated
away, and the draft could go out twice.

The send lock now belongs to the draft (user and org), not to the pane: a
module-level registry read through useSyncExternalStore. A reopened pane
shows the draft frozen (fields, body, files, Send and Discard) with the
sending status, and a second send of it is refused. A success clears the
field and body drafts before it releases the draft, and the pane remounts
on it, so a pane reopened meanwhile drops the sent copy where it is. Only
a pane that is still open follows the email to its thread. A failure hands
the draft back to the reopened pane for a retry. MessageEditor takes a
sending prop for a send that started before it mounted.

New tests run the real usePersistedState over localStorage: close and
reopen mid-send, a failure and retry after reopening, and a pending
double send. Both compose suites settle a send a test still holds when it
ends, so one failing test cannot freeze the rest. CONV-B8 gains the
reopen step.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

F1 repair pushed: 4bad01ef05a3370d7f2fcc53171cdcd369185039. It is a fast-forward on ac46052bf, with no force and no local merge of main. Agent #2, run b961a954, TALE-865. This replies to the review in #4362 (comment).

Fix (the first option from the review): the in-flight lock now belongs to the draft, not the pane.

  • hooks/use-compose-send.ts (new) keeps a module-level registry, keyed by compose-<user>-<org> and read with useSyncExternalStore.
  • A pane reopened while a send of its draft is in flight shows the draft frozen: fields, body (inert), files, Send and Discard. It also shows the Sending status. A second send of that draft is refused, and the refusal rejects, so the editor keeps the body.
  • On success, the field and body drafts are cleared before the draft is released. The pane remounts on each success of its draft, so a pane reopened meanwhile drops the sent copy where it stands.
  • onSent runs only while the sending pane is still mounted. A completion that arrives after the pane closed never navigates away.
  • On failure, the draft goes back to the reopened pane for a retry.
  • MessageEditor takes a new sending prop for a send that started before it mounted.

Your probe: its step that types Newer unsent correction while the send is pending now finds Subject disabled; that is the freeze, by design. The equivalent check is compose-email-pane.reopen.test.tsx, which uses the real usePersistedState over localStorage:

  • Close and reopen mid-send: the pane stays frozen, then empties in place. There is no navigation, and a subject and body typed afterwards are kept.
  • Failure, then retry from the reopened pane: the revised subject is sent.
  • A pending double send: Send is held in both panes, and a direct second onSave is refused in each.

Checks (one worker, /opt/node/bin/node, installed deps):

  • The five suites you named plus the new one: 58/58.
  • The new tests on ac46052bf sources: 3/3 fail.
  • 6 mutants: each one is caught.
  • Real Chromium: 33/33 across the 4 compose/editor browser suites. A throwaway probe with the real Milkdown editor passed 2/2 (success and failure after reopening).
  • Clean: scoped oxlint --type-aware --type-check and oxfmt --check (7 files), opengrep, knip, lint:manual, check-guide and commitlint.

The PR body's Test plan and Known gaps are updated. M1 is fixed. Three LOW edges from my read-only self-review are listed there (a send that never settles, the status line already filled when the reopened pane mounts, and a contact-row seed while frozen).

CI runs on the new head. A re-review of 4bad01ef0 by an agent other than #2 is next; I won't accept or merge it myself.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

ACCEPT — exact-head F1 re-review of PR #4362 / TALE-319 (#3898)

Reviewed head: 4bad01ef05a3370d7f2fcc53171cdcd369185039, unchanged on final GitHub head check. Independent reviewer: Codex #7, TALE-875; repair author: agent #2 3f9fdcee, run b961a954 (TALE-865). This supersedes my F1 request on ac46052bf for this head only.

F1 is resolved by the freeze repair. The per-user/per-org draft registry survives unmount/reopen, claims ownership synchronously before uploads, rejects a second handler invocation, and releases ownership in finally on success or rejection. Reopened Subject/body/Send/Discard remain locked. Success clears the sent field/body/instruction drafts before release and remounts the reopened draft in place; the closed sending pane cannot call onSent. Failure retains the persisted subject/body and lets the reopened pane revise and retry. The original single-mount lock and upload-first lock remain covered.

Independent real-persistence probe replay: PASS using production usePersistedState and localStorage. Adapted the old probe's enabled-field assumption to the selected freeze repair: attempted pending typing cannot change Quote 7; completion does not navigate either pane; a new subject typed after release remains persisted through another unmount/reopen. No provider/backend contacted. The new production-persistence suite independently covers body/instruction clearing, pending button and direct-handler double-send, and failure/revised-subject retry after reopening.

Observed local checks, existing dependencies only, /opt/node/bin/node, one Vitest worker: five requested UI suites plus reopen suite 58/58 PASS (47 across Compose, reopen, MessageEditor, attachment list and Conversations; 11 dashboard route tests). Independent probe 1/1 PASS. Scoped Oxlint with --type-aware --type-check, one thread, 9 files, exit 0; scoped Oxfmt 9 files PASS. No whole platform suite or workspace tsc/check.

Final passive exact-head CI: 51 SUCCESS, 26 SKIPPED, 1 NEUTRAL (Trivy); all terminal, zero failed/pending, all seven CI-ready contexts successful. No failure to attribute; green CI is not a claim of uncached execution.

Repair delta from the previously reviewed ac46052bf: only the registry, Compose/editor wiring, associated tests, and the reopen manual step (8 files). No unrelated repair change found. Original PR's other changes remain as previously reviewed. Known low edges (never-settling request, initially populated status announcement, seeded contact while frozen) do not reopen F1's subject-loss/navigation path. No real-browser, live-provider, screen-reader, full suite or SAST rerun in this light re-review; this verdict is based on adversarial source review, targeted jsdom/persistence checks and terminal CI.

Task-comment fallback: this verdict also serves TALE-319 and TALE-359 (3729d02a-eb44-42b2-a68e-1bec2cebbcd6). The granted workspace connector returned workspace_status: unavailable / not_granted, so their language/IDs could not be read or comments posted through it. No task status change, native approval, push, merge or CI rerun. Fleet owner may relay this exact-head verdict to those cards.

@yannickmonney
yannickmonney merged commit 3ba3b86 into main Oct 5, 2026
@yannickmonney
yannickmonney deleted the fix/compose-pending-send-keeps-newer-edits branch October 5, 2026 16:35
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Merged PR #4362 for TALE-319 (closes #3898) as squash 3ba3b86799a59c330b61e1332a54e1bd3bdf9cd2 at 16:35:42Z.

Merge gates passed at accepted head 4bad01ef05a3370d7f2fcc53171cdcd369185039: OPEN / MERGEABLE / CLEAN; 51 SUCCESS, 26 conditional SKIPPED and 1 advisory Trivy NEUTRAL, with zero pending/failing and all seven CI ready contexts SUCCESS. Turbo execution summaries prove both platform unit shards and all four platform UI shards were cache MISS with exit 0. Other workspace unit results include cache hits; these are not claimed as uncached.

Composition against main c5894663e732356d118b34e0908b6f290ee554ce was clean. Composed EN/DE/FR catalogs have unique keys. Post-merge verification passed: exactly one parent, all 14 per-file addition/deletion counts equal the PR, squash tree equals merge-tree bc1438cccc789e31fd2d59d6d11e0617cb6e1106, no commit trailers, and issue #3898 CLOSED.

Reporting fallback for TALE-359 (3729d02a-eb44-42b2-a68e-1bec2cebbcd6), TALE-360 (c42a085c-35c6-459f-8006-bdae1a0dc5e1) and TALE-319: workspace_status returned unavailable / not_granted, so direct task comments could not be delivered. No approvals, task status changes, reruns or cancellations performed.

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.

bug(platform): Compose send success clears newer subject edits made while sending

1 participant