Repository navigation
fix(composer): keep saved drafts and their attachments safe across failed writes - #84
Merged
Merged
Conversation
Tarquinen
force-pushed
the
port-drafts
branch
from
November 15, 2026 06:34
5a4d4a5 to
b731a84
Compare
Tarquinen
force-pushed
the
port-drafts
branch
from
November 15, 2026 23:26
b731a84 to
4859010
Compare
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
force-pushed
the
port-drafts
branch
from
November 15, 2026 23:42
4859010 to
d9dd8ca
Compare
Merged
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
devand this branch:devthe 97 KB photo file was rewritten on every keystroke save; here onlycomposer-state.jsonchanges.ComposerAttachments/made read-only, photo added, app killed): ondevthe log showsCouldn’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.dev(8 delivered 500 KB sends, an hour later) found 4,000,000 bytes still held byPromptOutbox; here 0.Verified: ported
ComposerAttachmentPersistenceTests(8 of 9 iOS cases);scripts/check.sh :feature:composerpasses.