Skip to content

[backport cloud/1.48] fix: isolate and preserve workflow drafts on workspace switch - #14302

Merged
comfy-pr-bot merged 1 commit into
cloud/1.48from
backport-14290-to-cloud-1.48
Jul 29, 2026
Merged

comfy-pr-bot merged 1 commit into
cloud/1.48from
backport-14290-to-cloud-1.48

Conversation

@comfy-pr-bot

Copy link
Copy Markdown
Member

Backport of #14290 to cloud/1.48

Automatically created by backport workflow.

## 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.

![AS IS — Workspace A private content visible in Workspace
B](https://ampcode.com/user-content/artifacts/5de321d78b00b1b147cbd0bdae37d8f4957ed65dba9e542d5da1c49d842bb441-file.png)

![AS IS
reproduction](https://ampcode.com/user-content/artifacts/6b84ba3dd1a98b1dbcae0df5ec7579d7501fe748b04fd391bd3f12d401ec6468-file.gif)

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.

![TO BE — Workspace B has no Workspace A private
content](https://ampcode.com/user-content/artifacts/f5a4c0b0ddca66b9a5eb72dac19f296d1d65e341f58277890d376b2788b90693-file.png)

![TO BE
verification](https://ampcode.com/user-content/artifacts/a6cef058cfd29cbeec913fd3369adc3373ab730f861a37854d44bf4acb96f97a-file.gif)

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 comfy-pr-bot added the backport Backporting a PR onto a release candidate label Jul 29, 2026
@comfy-pr-bot
comfy-pr-bot enabled auto-merge (squash) July 29, 2026 23:13
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 29, 2026
@dosubot

dosubot Bot commented Jul 29, 2026

Copy link
Copy Markdown

📄 Knowledge review

Dosu skipped reviewing this PR because your organization has used its 200 included credits for the month. Your usage will reset on 2026-08-01. To have Dosu review this PR before then, ask your organization admin to upgrade to a pro account.


Leave Feedback Ask Dosu about ComfyUI_frontend Add Dosu to your team

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright: ✅ 1736 passed, 0 failed · 2 flaky

📊 Browser Reports
  • chromium: View Report (✅ 1715 / ❌ 0 / ⚠️ 2 / ⏭️ 5)
  • chromium-2x: View Report (✅ 2 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • chromium-0.5x: View Report (✅ 1 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • mobile-chrome: View Report (✅ 18 / ❌ 0 / ⚠️ 0 / ⏭️ 0)

🎨 Storybook: ✅ Built — View Storybook

Details

⏰ Completed at: 07/29/2026, 11:14:50 PM UTC

Links

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...rc/platform/workflow/persistence/base/storageIO.ts 94.28% 2 Missing ⚠️
@@              Coverage Diff              @@
##             cloud/1.48   #14302   +/-   ##
=============================================
  Coverage              ?   79.21%           
=============================================
  Files                 ?     1744           
  Lines                 ?    98890           
  Branches              ?    31663           
=============================================
  Hits                  ?    78331           
  Misses                ?    20158           
  Partials              ?      401           
Flag Coverage Δ
unit 68.90% <95.45%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ersistence/composables/useWorkflowPersistenceV2.ts 92.81% <100.00%> (ø)
...rc/platform/workspace/stores/teamWorkspaceStore.ts 66.72% <100.00%> (ø)
...rc/platform/workflow/persistence/base/storageIO.ts 92.07% <94.28%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@comfy-pr-bot
comfy-pr-bot merged commit d8863a9 into cloud/1.48 Jul 29, 2026
74 checks passed
@comfy-pr-bot
comfy-pr-bot deleted the backport-14290-to-cloud-1.48 branch July 29, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Backporting a PR onto a release candidate size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants