Skip to content

Fix empty composer cancellation and remote draft lifecycle - #38

Merged
mrinc merged 2 commits into
masterfrom
fix/draft-lifecycle
Oct 16, 2026
Merged

mrinc merged 2 commits into
masterfrom
fix/draft-lifecycle

Conversation

@bcbetterninja

@bcbetterninja bcbetterninja commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Opening and closing an untouched new message or reply currently saves generated signatures/quotes as a draft. Reopening a saved draft also advances its local revision, and synchronized drafts that leave Outlook's Drafts folder remain stuck as “Missing on server” when their old IDs stop resolving.

This change gives the composer an explicit default-content baseline, cancels default-only composers, and uses durable deletion plus a fresh identity when cleared content is typed again. Unchanged saves preserve the local revision. Closing remains open on a failed save/delete, and new edits in an editor whose synchronized copy was removed are recovered under a new identity; queued messages cannot be duplicated through that path.

Reconciliation uses a complete, validated Drafts snapshot and identity matching to transactionally remove an absent, unchanged synchronized mirror, including legacy mappings. Unidentified server entries defer cleanup and duplicate imports until identity capture recovers, and unsupported attachments protect ambiguous legacy copies. Real unsynced edits are preserved. This does not mark any outbox send accepted; uncertain sends still require positive delivery evidence.

Validation:

  • All 639 tests passed in the full local regression suite.
  • Real Linux WebView keyboard/capture checks passed, extended to close untouched new messages and replies with signatures.
  • Regressions for legacy IDs, restart recovery, redundant saves, genuine edits, queued-message protection, concurrent edits and failed later listing pages.

The live app tunnel returned HTTP 502 during investigation, so the remaining production drafts have not been manually modified.

Summary by CodeRabbit

  • New Features
    • Drafts removed from the mail server are cleared from the local Drafts list when it is safe to do so.
    • Changes made after a draft is removed are saved as a new draft.
  • Bug Fixes
    • Unsynced edits are preserved, and uncertain or incomplete server listings no longer trigger premature draft removal or duplicate imports.
    • Untouched reply or forward defaults no longer trigger unnecessary saves or deletions.
    • Sending saves the draft before dispatch. If saving fails, the compose window stays open so you can retry.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T01:47:36.068993Z 4ae2853 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.

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 8e55ed74-0ab1-479a-bc10-95b7191c44cc
📥 Commits

Reviewing files that changed from the base of the PR and between e94c1a7 and 4ae2853.

📒 Files selected for processing: 4
  • docs/draft-lifecycle.md
  • src/BetterMail.Core/DraftSynchronizationService.cs
  • tests/BetterMail.Tests/DraftSentRecoveryTests.cs
  • tests/BetterMail.Tests/DraftSynchronizationServiceTests.cs

Included review availability: This review used your included allowance. 3 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Walkthrough

Composer persistence now distinguishes authored changes from generated defaults. Sending forces a draft save, and closing waits for a successful flush. Synchronization removes eligible unchanged local drafts absent from the remote listing while retaining unsynced changes and deferring decisions when listing or identity data is incomplete.

Changes

Draft Lifecycle

Layer / File(s) Summary
Composer content and defaults
src/BetterMail.App/ComposeWindowViewModel.cs, src/BetterMail.App/MailContentRenderer.cs, tests/BetterMail.Tests/ComposeWindowViewModelTests.cs
The composer tracks response defaults and automatic signatures. Normalised content comparison excludes generated defaults and managed signatures. Tests cover untouched defaults and authored changes.
Draft persistence and composer closure
src/BetterMail.App/ComposeRequest.cs, src/BetterMail.App/ComposeWindow.axaml.cs, src/BetterMail.App/ComposeWindowViewModel.cs, src/BetterMail.App/MainWindowViewModel.cs, src/BetterMail.Core/EncryptedMailStore.cs, tests/BetterMail.Tests/ComposeWindowViewModelTests.cs, tools/BetterMail.UiPreview/Program.ComposeInput.cs, docs/draft-lifecycle.md
Saves skip unchanged state. Clearing a saved draft deletes it, and later edits use a new draft ID. Failed flushes leave the window open. Sending forces a save before dispatch.
Remote draft reconciliation
src/BetterMail.Core/DraftSynchronizationService.cs, src/BetterMail.Core/ProviderContracts.cs, src/BetterMail.Core/EncryptedMailStore.Actions.cs, tests/BetterMail.Tests/DraftSentRecoveryTests.cs, tests/BetterMail.Tests/DraftSynchronizationServiceTests.cs, tests/BetterMail.Tests/EncryptedMailStoreTests.cs, docs/draft-lifecycle.md
Synchronization removes an unchanged local copy when it is absent from the remote listing. Unsynced changes remain local, and incomplete listings or identities defer removal or import decisions. Removal uses a synchronized-draft action rather than a send-acceptance check.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant DraftSynchronizationService
  participant DraftsAPI
  participant EncryptedMailStore
  DraftSynchronizationService->>DraftsAPI: Request the Drafts listing
  DraftsAPI-->>DraftSynchronizationService: Return listing pages
  DraftSynchronizationService->>DraftSynchronizationService: Match remote and local draft identities
  DraftSynchronizationService->>EncryptedMailStore: Remove unchanged synchronized draft
  EncryptedMailStore-->>DraftSynchronizationService: Return removal result
Loading

Suggested reviewers: mrinc

Merge Risk: ⚪ Minimal · up to 4ae28

The change defers draft removal when listings or identities are incomplete, and it keeps local edits that have not been synced. No merge-blocking issue was identified in the supplied context.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 3.51% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 57 functions across 14 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarises the main changes: handling empty composer cancellation and managing the remote draft lifecycle.
Full details: Docstring Coverage

Explanation

Docstring coverage is 3.51% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 57 functions across 14 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the drafts at dawn,
It saves the words, then carries on.
A signature stays in its place,
While edits find a fresh draft space.
Remote lists arrive, and gaps are known,
The bunny keeps unsynced words at home.

Comment @coderabbitai help to get the list of available commands.

@bcbetterninja

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review the full draft lifecycle correction, especially generated-default cancellation, preserving local revisions on no-op saves, complete-snapshot removal of unchanged synchronized drafts, and recovering new work from an open composer after removal without duplicating queued messages. All 635 tests and the real Linux editor close/input checks passed locally. Draft disappearance never marks an outbox send successful.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e94c1a75b3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/BetterMail.Core/DraftSynchronizationService.cs
@bcbetterninja

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review current head 4ae2853. The identity-incomplete snapshot finding is addressed: unidentified unclaimed server drafts defer cleanup and duplicate imports, including queued mappings; ambiguous unsupported server drafts also protect legacy local content. All 639 local tests pass, including recovery on the next successful identity capture. CodeRabbit's initial review and all initial platform/CodeQL checks passed.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 4ae2853ced

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@mrinc
mrinc merged commit 184f484 into master Oct 16, 2026
9 checks passed
@mrinc
mrinc deleted the fix/draft-lifecycle branch October 16, 2026 01:50
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.

2 participants