From 719f154b49c8d267ef9b9be58eef41d65433b724 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 24 Nov 2026 10:24:13 +0000 Subject: [PATCH] :bug: Clarify plugin save recovery warning Warn that recovery may discard unsaved edits instead of implying that reopening is the only recovery path. Update the API docs and test. AI-assisted-by: gpt-6.1-terra --- .serena/memories/frontend/plugin-save-events.md | 2 +- frontend/src/app/plugins/persist.cljs | 7 +++---- .../test/frontend_tests/plugins/wait_for_save_test.cljs | 2 +- plugins/CHANGELOG.md | 1 + plugins/libs/plugin-types/index.d.ts | 5 +++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.serena/memories/frontend/plugin-save-events.md b/.serena/memories/frontend/plugin-save-events.md index 3b1ed4db5d..a259e102a0 100644 --- a/.serena/memories/frontend/plugin-save-events.md +++ b/.serena/memories/frontend/plugin-save-events.md @@ -2,7 +2,7 @@ - Start at `app.plugins.persist` for `penpot.waitForSave` and `app.plugins.events` for `contentsave` and `contentrollback`. The runtime forwarder requires `content:read` for `waitForSave`; new event names must also be added to runtime `validEvents`, and a stale runtime build can reject them. - `waitForSave(timeout?)` observes the shared persistence queue, not only the plugin's commits. Its default timeout is 60 seconds. It waits briefly for incoming commits, capped by the timeout; if work is pending it forces persistence and races settlement against rollback start or completion. A rollback must reject even if the status later becomes `:saved`. See `mem:frontend/workspace-persistence`. -- An earlier `:error` rejects even when no work is pending: a slow retry produces `save-retrying`; terminal failures use the stored failure code (default `save-failed`). Other error codes include `save-timeout` and `rolled-back`. Timeout validation accepts a positive finite number up to `u/max-timeout`; rejection must be an `Error`, not a string. For queue halts and recovery conditions see `mem:frontend/workspace-persistence`. +- An earlier `:error` rejects even when no work is pending: a slow retry produces `save-retrying`; terminal failures use the stored failure code (default `save-failed`) and warn that recovery may discard unsaved changes. Other error codes include `save-timeout` and `rolled-back`. Timeout validation accepts a positive finite number up to `u/max-timeout`; rejection must be an `Error`, not a string. For queue halts and recovery conditions see `mem:frontend/workspace-persistence`. - `contentsave` is a debounced state watch for transitions to `:saved` and passes no value. It does not prove the buffer is empty. - `contentrollback` subscribes to `::dps/rolled-back`, not the state watch. It is not debounced and is delivered asynchronously after reverted or reloaded data is in state. Its `{fileIds, pageIds, shapeIds}` payload comes from page-shape redo changes in reverted commits. Remove the stream subscription when the listener is removed. - MCP forwards rollback notices with task responses and retains unsent notices in per-file plugin local storage when available. Delivery is not an end-to-end acknowledgment; for its storage permissions, handoff and failure limits see `mem:mcp/save-and-rollback`. diff --git a/frontend/src/app/plugins/persist.cljs b/frontend/src/app/plugins/persist.cljs index 0d3c81eb59..8e929f4f3b 100644 --- a/frontend/src/app/plugins/persist.cljs +++ b/frontend/src/app/plugins/persist.cljs @@ -46,9 +46,8 @@ err)) (def ^:private earlier-failure-message - (dm/str "Changes could not be saved: the file has a failed save that " - "stays until the file is reopened, so no change can be confirmed " - "as saved. Reopen the file to resume saving.")) + (dm/str "Changes could not be saved: a previous save failed. " + "Unsaved changes may be discarded during recovery.")) (def ^:private retrying-message (dm/str "Changes could not be saved yet: saves are failing and Penpot " @@ -95,7 +94,7 @@ or there is nothing to save after a short intake window. Rejects when `timeout` is invalid, the save fails (also a failure from - before the call: a terminal one stays until the file is reopened), + before the call while the error remains), changes are rolled back during the wait, or the deadline elapses. The Error `code` is `save-timeout`, `rolled-back`, `save-retrying` (an earlier failure Penpot keeps retrying), or the failure code diff --git a/frontend/test/frontend_tests/plugins/wait_for_save_test.cljs b/frontend/test/frontend_tests/plugins/wait_for_save_test.cljs index c9951aa657..6140e0bdeb 100644 --- a/frontend/test/frontend_tests/plugins/wait_for_save_test.cljs +++ b/frontend/test/frontend_tests/plugins/wait_for_save_test.cljs @@ -105,7 +105,7 @@ (let [outcome (await (await-outcome (persist/wait-for-save 2000)))] (t/is (contains? outcome :error) "terminal :error rejects waitForSave") - (t/is (re-find #"(?i)could not be saved.*reopen" + (t/is (re-find #"(?i)unsaved changes may be discarded during recovery" (or (some-> (:error outcome) .-message) ""))) (t/is (= "save-permission-denied" (error-code outcome)) "the stored failure code is kept"))))))))) diff --git a/plugins/CHANGELOG.md b/plugins/CHANGELOG.md index 550c2ee12f..81d7cf2edf 100644 --- a/plugins/CHANGELOG.md +++ b/plugins/CHANGELOG.md @@ -10,6 +10,7 @@ ### 🩹 Fixes +- **plugin-types:** Clarified that `waitForSave` rejects while a terminal save error remains and recovery may discard unsaved changes. - **plugins-runtime:** Methods that rejected an invalid value with a plain string (`connectLibrary`, file `restore`, `remove`, `pin`, `export`, `findVersions`, `saveVersion`) now reject with an `Error` carrying the same message. - **plugin-runtime:** `LibraryComponent.instance()`, `createShapeFromSvg()` and `createShapeFromSvgWithImages()` now create shapes at the page root instead of inside a board at the page origin. Closes #12086. - **plugin-types, plugin-runtime:** Dashboard property setters now update values after backend success and log failures without interrupting the workspace. File moves reject projects in other teams, backend rejections include their type and code, and `project.fileCount` stays at its listing snapshot. Duplicated projects include their file count and pinned state. diff --git a/plugins/libs/plugin-types/index.d.ts b/plugins/libs/plugin-types/index.d.ts index 05a2d3faee..c39f16c32d 100644 --- a/plugins/libs/plugin-types/index.d.ts +++ b/plugins/libs/plugin-types/index.d.ts @@ -1655,8 +1655,9 @@ export interface Context { * rejected with an Error on save failure, when changes are rolled back * during the wait, on timeout, or on an invalid timeout value. A save * that failed before the call also rejects: with `save-retrying` while - * Penpot keeps retrying it, otherwise with the failure code until the - * file is reopened. The Error `code` property tells the cases apart: + * Penpot keeps retrying it, otherwise with the failure code while the + * error remains. Recovery may discard unsaved changes. The Error `code` + * property tells the cases apart: * `save-timeout`, `rolled-back`, `save-retrying`, or the failure code * (`save-failed` unless the backend gave a more specific one). */