Repository navigation
[backport cloud/1.48] fix: isolate and preserve workflow drafts on workspace switch - #14302
Merged
Merged
Conversation
## Summary Follow-up to #14266: flushes the source workspace's pending draft, clears transient restore pointers, and blocks later persistence writes before a successful workspace switch changes auth context and reloads. Denys' [cross-check on the #14266 test environment](https://comfy-organization.slack.com/archives/C0932CGKT5K/p1785351064538329?thread_ts=1785169746.169899&cid=C0932CGKT5K) confirmed that the successful-switch path still reproduced the Cloud 1.48 QA report. ## Root cause #14266 fixed failed token exchange and logout, but a successful switch still cleared the current workspace context before reload without first draining and stopping workflow persistence or removing transitional restore state. A save queued inside the 512 ms debounce window could be lost or resolve against the destination identity, while unscoped legacy and per-tab session pointers survived the reload. Workspace A tabs and dirty content could then restore in Workspace B. The transition sequence was introduced with workspace switching in #8194 on 2026-01-21. The user-visible tabs/unsaved-edit leak became possible when draft and tab-state persistence shipped in #8519 on 2026-02-19; #8520 added workspace scoping two days later but did not add a transition write barrier. The earlier #14266 browser fixture seeded already-scoped V2 state, which naturally stayed isolated and therefore missed this transition path. ## Reproduction 1. Open Workspace A and leave one or more workflow tabs with unsaved edits. 2. Switch successfully to Workspace B (the team-to-personal path is deterministic because the cleared context resolves to `personal`). 3. After reload, observe Workspace A's tabs and dirty content in Workspace B. ## Changes - Flush pending workflow persistence while the source workspace is still active, then block later writes before changing workspace auth context. - Treat the terminal write barrier as unavailable storage so delayed saves cannot enter quota eviction and delete preserved drafts. - Remove only unscoped legacy and per-tab session restore pointers during workspace-changing reloads. - Preserve workspace-scoped V1/V2 draft payloads and indexes, so returning to Workspace A can restore Workspace A's own work. - Clear transitional restore state when initialization falls back from a deleted or revoked session workspace. - Reuse the same targeted key-removal primitive for full logout cleanup. ## Review Focus Confirm the transition ordering is flush source draft → block writes → clear transient pointers → clear auth context → reload, and that scoped draft keys are preserved. ## Screenshots ### AS IS Workspace B is active, but Workspace A's private Markdown Note and dirty workflow remain visible.   Also see [Denys' independent reproduction recording](https://comfy-organization.slack.com/archives/C0932CGKT5K/p1785351064538329?thread_ts=1785169746.169899&cid=C0932CGKT5K). ### TO BE After the same successful switch, Workspace B initializes without Workspace A's private note or workflow state. The default destination workflow may still be dirty in this mocked environment; the isolation assertion is that the source-only `Workspace A only` note and restore pointers are absent.   Verified at final head `4c102a62c` on the [#14290 test deployment](https://fe-pr-14290.testenvs.comfy.org/) in both Team → Personal and Personal → Team directions. In both directions, source-only workflow content, the dirty source tab, unscoped workflow data, and per-tab active/open restore pointers were absent after the switch. ## Verification - Deterministic red → green regression proof using the exact same checked-in behavioral test: - Before the flush fix (`bfb4e8a69`): **fails** — a Workspace A edit queued inside the 512 ms debounce window has no A-scoped payload after transition (`sourcePayload` is `null`). - After the flush fix (`4c102a62c`): **passes** — Workspace A's final edit is stored under A, a post-barrier write cannot create a Workspace B payload, and per-tab active/open restore pointers are removed. - Earlier transition-order regression proof: - #14266 (`9ef6fe55f`): **fails** — `clearWorkflowRestoreState({ blockWrites: true })` received 0 calls during a valid workspace switch. - #14290: **passes** — the workspace transition boundary runs exactly once before auth context is cleared and before reload. - `pnpm test:unit src/platform/workflow/persistence/composables/useWorkflowPersistenceV2.test.ts src/platform/workflow/persistence/base/storageIO.test.ts src/platform/workspace/stores/teamWorkspaceStore.test.ts` — 121 passed - `pnpm typecheck` - `pnpm exec eslint src/platform/workflow/persistence/base/storageIO.ts src/platform/workflow/persistence/composables/useWorkflowPersistenceV2.ts src/platform/workflow/persistence/composables/useWorkflowPersistenceV2.test.ts src/platform/workspace/stores/teamWorkspaceStore.ts src/platform/workspace/stores/teamWorkspaceStore.test.ts` - `pnpm exec oxfmt --check ...` - `pnpm knip` (pre-push hook) - `git diff --check` The deployment fixture separately verifies the browser-visible outcome using mocked Cloud workspace APIs. The checked-in unit regression is the CI gate for transition ordering and scoped-draft preservation; the screenshots and GIFs document the end-to-end user behavior. --------- Co-authored-by: dante01yoon <6510430+dante01yoon@users.noreply.github.com> Co-authored-by: Amp <amp@ampcode.com>
comfy-pr-bot
enabled auto-merge (squash)
July 29, 2026 23:13
📄 Knowledge reviewDosu skipped reviewing this PR because your organization has used its |
Contributor
🎭 Playwright: ✅ 1736 passed, 0 failed · 2 flaky📊 Browser Reports
🎨 Storybook: ✅ Built — View Storybook |
dante01yoon
approved these changes
Jul 29, 2026
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## cloud/1.48 #14302 +/- ##
=============================================
Coverage ? 79.21%
=============================================
Files ? 1744
Lines ? 98890
Branches ? 31663
=============================================
Hits ? 78331
Misses ? 20158
Partials ? 401
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Backport of #14290 to
cloud/1.48Automatically created by backport workflow.