fix(drafts): adopt legacy state atomically and preserve clear ownership

Draft
TE
6d ago
+796-35

Legacy draft adoption could leave partial attachments or resurrect an intentional clear after a copy or publication failure. Keep draft state under its stable logical-channel root, adopt only exact supported legacy identities, and preserve every current destination draft, including empty clear values.

Migration stages the current root and each artifact, retains per-artifact completion markers and current ownership, and publishes through one Darwin renamex_np exchange/exclusive rename. Failed publication leaves canonical data intact. Attachment writers persist independent per-chat ownership before moving files, clearing, error cleanup or pruning; those markers survive outside deleted chat folders and prevent both preexisting and newly created chats from reappearing on a retry. Wake consumption/save records ownership before mutation. Unsent drafts retain empty-key and moved-from tombstones; ordered saves use the injected app BackgroundWork.files owner with a shutdown hold, and seed/hasDraft ignore empty tombstones. Once quit is irrevocably committed and all session-end/retry steps finish, the unsent store fences new producers and awaits its ordered files lane before browser shutdown. Cancelled quits remain writable, and the shared background owner remains open for the final Home flush.

The startup barrier completes adoption before draft readers or wake restoration. Regressions retain sibling/leaf copy failures, failed publication with missing/empty/current roots, current and late-created chat clears, ownership-write failure, unrelated malformed artifacts, consumed wake state, unsent clears/moves, shutdown/relaunch, a blocked files lane for Keep and End with text/empty clears, late callbacks during finalization, cancelled-quit writability, channel isolation and backward-compatible draft schemas. Native test sources are authored; runtime behavior remains unverified while native execution is on HOLD.

Exact head: 87d8459a652168f33482c2012f9203e20156df2a. Actual feat-cmux-next merge base: 9445568053d73aaed41afefe1e7afa0dd9246aee. Foundation diff: 14 files, 796 insertions and 35 deletions (831 total). This is slightly above the initial approximately 800-line budget because the quit durability repair retains 71 native regression-source lines for blocked-save, late-callback and cancelled-quit behavior. Those regressions are in distinct source commit 30bd9c9ea1d; the quit wiring is commit 87d8459a652. The off-main unsent owner remains isolated in commit 6b3634097d3.

Dependent text/hydration draft #26842 is frozen at b37323992f8e3e5e21627e49408761b4ffca4e64, still based on the previous foundation head 30d5897, pending one rebase onto this repaired head. Its relative diff is 335 lines. It contains daemon/native text recovery, provider wiring, and the first-session web handshake repair. NewTab/Quick stack on that text lane; queue uses this foundation's markCurrent API.

Validation: exact-head prepush gate against the merge base reports no new violations; diff check is clean. The foundation has no web source diff; the unchanged web tree passed the full web check. The dependent text route passed its exact-head web-lint wrapper and 36 focused composer tests/67 assertions. Native compilation and tests remain UNEXECUTED/HOLD under #26809/HQ4779. Fresh whole-diff exact-head review and native verification remain required; the composer P0 root session owns the final primary review, required-check reconciliation and guarded landing.

Agent session: agent session