Skip to content

fix(composer): keep saved drafts and their attachments safe across failed writes - #84

Merged
Tarquinen merged 1 commit into
devfrom
port-drafts
Nov 15, 2026
Merged

Tarquinen merged 1 commit into
devfrom
port-drafts

Conversation

@Tarquinen

@Tarquinen Tarquinen commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

A failed attachment write no longer loses the attachment: the saved draft only points at attachments once they're on disk, and old ones are deleted only after the new draft is saved. Each attachment is also written once instead of on every keystroke, and delivered sends let go of their bytes after two minutes.

iOS: 070c2401, 771e0573 (not ported: treating an unreadable state file as an error, since the app isn't Direct Boot aware).

Checked on the emulator (session-lab), same steps on dev and this branch:

  • Typing with a photo attached: on dev the 97 KB photo file was rewritten on every keystroke save; here only composer-state.json changes.
  • Failed write (ComposerAttachments/ made read-only, photo added, app killed): on dev the log shows Couldn’t write composer attachment (85628 bytes): AccessDeniedException, yet the saved draft pointed at the missing file and the relaunch dropped the photo. Here the last good draft stays on disk, and the next save after the folder is writable again writes the photo and the draft.
  • Sent photos: a throwaway test on dev (8 delivered 500 KB sends, an hour later) found 4,000,000 bytes still held by PromptOutbox; here 0.

Verified: ported ComposerAttachmentPersistenceTests (8 of 9 iOS cases); scripts/check.sh :feature:composer passes.

Port of iOS 771e0573 and 070c2401 (opencode-ios #297, #306).

- Each attachment blob is written once instead of on every draft edit,
  and the blob directory is cleaned only when the referenced set changes
  (and once after launch), not scanned on every flush.
- The state file is written only after every blob it names was written,
  and old blobs are removed only after the state without them lands.
  Before, a failed blob write still saved a state pointing at the missing
  blob, so a relaunch dropped that attachment.
- Flushes run one at a time and an older generation no longer cancels a
  newer flush.
- The attachment cache keeps only referenced bytes; delivered outbox sends
  expire after two minutes and let go of their bytes.

Not ported: treating an unreadable state file as an error (070c2401). The
app isn't Direct Boot aware, so the iOS before-first-unlock read can't happen.

Verified: ported ComposerAttachmentPersistenceTests (8 of the 9 iOS cases),
VM `check :feature:composer`. On the emulator, dev rewrote every blob on
each keystroke and, with the blob directory made read-only, saved a state
pointing at a missing photo that a relaunch dropped; this branch leaves
blob mtimes alone while typing, keeps the last good state on a failed
write and writes both on the next save.
@Tarquinen
Tarquinen merged commit ca96025 into dev Nov 15, 2026
1 check passed
@Tarquinen Tarquinen mentioned this pull request Nov 16, 2026

This branch was previously deployed

1 inactive deployment
release — d9dd8ca6 Deployed Nov 15, 2026 by Tarquinen via check #296
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