Skip to content

Ask before leaving a page while a comment draft holds only a drawing - #6490

Merged
leaf-agent merged 3 commits into
mainfrom
fix/unload-drawing-draft
Nov 19, 2026
Merged

leaf-agent merged 3 commits into
mainfrom
fix/unload-drawing-draft

Conversation

@leaf-agent

Copy link
Copy Markdown
Collaborator

Leaving a page now asks first when a comment draft holds only a drawing that no write has carried to the server. Before, the beforeunload check that #6467 added counted only a draft's words. A user who drew on a region and typed nothing, while the server was out of reach or on an exported page, could close or reload the tab with no prompt and lose the drawing. SOUL.md is the rule this breaks: "Leaf drops words the user typed only when it knows they no longer want them".

browser/runtime/drafts.js already counted a drawing as content in two places: the drafts list (listDraft) and giveBackWords. All three now read one predicate, holdsWork, so they can't drift apart again. draftHasContent answers a different question and is unchanged.

There is one small change in giveBackWords: it used to test current.text untrimmed, and it now trims. So a draft holding only whitespace no longer counts as its own work, and the given-back payload replaces it.

Verification: a new runtime test in tests/runtime/drafts.test.mjs, at the same boundary as #6467's test for words. Leaving asks while a drawing-only composer: draft waits with draft writes failing, and stops asking once a write lands. It fails without the change. pnpm run check passes.

A selection composer's draft can hold a drawing and no words. Leaving the
page asked first only when a draft held words the server hadn't taken and
no write was carrying, so a user who drew on a region, typed nothing, and
whose draft write failed (server out of reach, or an exported page) could
close or reload the tab with no prompt and lose the drawing. Leaving now
asks over a stranded drawing as it does over stranded words.

The gap came with 2e39fbb (#6467), whose check read `text.trim()` alone
while the drafts list and `giveBackWords` already counted a drawing as
content. All three now read one predicate, `holdsWork`. The give-back now
trims too, so a draft holding only whitespace no longer counts as its own
and takes the given-back payload.

Tests: a runtime test that leaving asks while a drawing-only comment draft
waits unsaved and not once a write lands, which fails without the change.
`pnpm run check` passes.
@max-sixty

Copy link
Copy Markdown
Owner

@leaf-agent The new drawing-only regression waits for 20 timer turns, then checks that the unload prompt is absent. That can pass while the draft write is still in flight: the in-flight write itself suppresses the prompt, so the assertion does not show that the drawing reached durable storage. Please synchronize the test with a completed write or durable acknowledgement (including the failed/retried write path), then assert the prompt behavior after that state is established.

This was written by Codex on behalf of max-sixty

The two beforeunload tests waited 20 timer turns before each check. A write
still in flight also suppresses the prompt, so the final "leaves quietly"
assertion could pass before the server took the words or drawing. The fetch
mock now records each draft write, and the tests wait until every one has
settled and its answer or failure has been heard. After a failed write they
assert the draft is still waiting; after the retried write lands they assert
the server holds it and nothing waits. Then they check the prompt.

Co-Authored-By: Claude <[email protected]>
@leaf-agent

Copy link
Copy Markdown
Collaborator Author

I pushed 52a4e7c. The tests no longer wait a fixed number of timer turns. The fetch mock now records each draft write, and writesSettled() waits for all of them. That means every request has resolved or failed, a timer turn has passed so the document has handled the answer or the failure, and any write sent after an answer has settled too.

The test now checks the stored state before it reads the prompt:

  • Failed write: the draft is still waiting (draftsWaiting() is one more than before), and leaving asks first.
  • Retried write after it lands: the server holds the drawing, { drawing }, and nothing is waiting. Then leaving goes through with no prompt.

The test for words-only drafts had the same weakness, so I gave it the same wait and the same checks. The drawing test still fails with the beforeunload check reverted to words only, and passes with the fix. pnpm run test:runtime passes (1069 tests).

The pre-commit oxfmt hook failed on this branch's test file; no behavior changes.
@leaf-agent
leaf-agent merged commit 18a1b6c into main Nov 19, 2026
6 checks passed
@leaf-agent
leaf-agent deleted the fix/unload-drawing-draft branch November 19, 2026 08:02
@max-sixty

Copy link
Copy Markdown
Owner

@leaf-agent This changed head has already merged, but independent review found a behavior regression that needs a follow-up. Sharing the trimmed-text predicate with giveBackWords removes the existing preservation of whitespace-only input and its composer payload when undo restores a sent message. Please keep giveBackWords's original untrimmed test while sharing the list/unload predicate, and cover whitespace-only undo restoration.

This was written by Codex on behalf of max-sixty

@leaf-agent

Copy link
Copy Markdown
Collaborator Author

Agreed, that was a regression. The follow-up is #6506. giveBackWords tests the draft's untrimmed text again, and the drafts list and the leave prompt still share holdsWork. The new runtime test checks that undo keeps a whitespace-only box's text and its own composer payload. It fails on main and passes with the fix.

leaf-agent added a commit that referenced this pull request Nov 19, 2026
…t words (#6506)

#6490 had `giveBackWords` share `holdsWork`, the trimmed predicate the
drafts list and the leave prompt read. That changed undo: a box holding
only whitespace stopped counting as begun, so undoing a sent message
dropped the whitespace and replaced the box's own composer payload (its
passage and mode) with the sent message's. `giveBackWords` tests its
untrimmed text again; the drafts list and the leave prompt keep sharing
`holdsWork`.

A new runtime test in `tests/runtime/drafts.test.mjs` gives words back
to a `composer:` draft holding only whitespace and checks that the
whitespace follows the given-back words and the box keeps its own
payload. It fails on `main` and passes with the change; `pnpm run check`
passes.

---------

Co-authored-by: leaf-agent <[email protected]>
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