Skip to content

fix(drafts): apply draft list edits on the server so a stale tab can't write its old list back - #8667

Open
thalesvf wants to merge 1 commit into
mainfrom
fix/releases-server-edits
Open

thalesvf wants to merge 1 commit into
mainfrom
fix/releases-server-edits

Conversation

@thalesvf

@thalesvf thalesvf commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What is this contribution about?

Closes #8569.

A project's draft list (metadata.releases) was written whole by whichever tab acted last. useReleases().write read the list from the tab's cache, applied the edit and sent the full array, and COLLECTION_VIRTUAL_MCP_UPDATE replaced releases as sent. A tab opened before another change wrote its old list back: discarded drafts returned (on deleted branches) and drafts other people created in the meantime disappeared from the list.

  • VIRTUAL_MCP_RELEASE_EDIT applies one edit (add, add-pull-request, rename, remove, mark-sandbox) to the stored list. VirtualMCPStorage.editReleases reads the row FOR UPDATE, applies the edit and writes only the releases key, so concurrent edits from other tabs or people compose. It checks RELEASES_MAX against the stored list and fails closed on malformed stored metadata instead of overwriting it. Access matches COLLECTION_VIRTUAL_MCP_UPDATE: same agents:manage permission, organization and project-scope checks.
  • A whole-metadata update keeps the stored releases. VirtualMCPStorage.update now keeps the row's current list in the same statement. That also closes the other paths that sent an old copy: settings forms that resend the full metadata, VIRTUAL_MCP_PINNED_VIEWS_UPDATE, and the read at the top of the update tool.
  • Shared reducers: the edit reducers move to @decocms/shared/release-edits. The web applies the same edit to its cache optimistically, then takes the list the server returns.

Behavior change: releases sent through COLLECTION_VIRTUAL_MCP_UPDATE is now ignored; the field's description points to the new tool.

Not in this PR: pushing the list to other open tabs (they still show their old copy until the next refetch, but can no longer write it back), and cleaning up entries that already point at deleted branches.

How did you verify your code works?

  • apps/api/src/storage/virtual-patch-metadata.integration.test.ts against Postgres 16 (after bun run --cwd=apps/api migrate): two new tests. Concurrent editReleases calls (remove + add) both land, and a whole-metadata update with a stale list, and with metadata: null, keeps the stored list. Both fail without the storage change. virtual.integration.test.ts and studio-pack.integration.test.ts also pass.
  • release-edits.test.ts (17 tests) now imports the reducers from @decocms/shared/release-edits.
  • tsc --noEmit passes in apps/api, apps/web and packages/shared; bun run fmt, lint and knip are clean. tool-io.ts was regenerated with generate:tool-contracts.
  • Unit tests of the touched areas (apps/api/src/storage, apps/api/src/tools/virtual, apps/web/src/components/thread/repository, packages/shared/src) pass: 1552 pass, 0 fail, the same as main. The full bun run test hung locally on ENFILE (the machine ran out of open files), so CI runs the whole suite.

Screenshots/Demonstration

No visual change.

How to Test

  1. Open a project's Site Editor in tab A.
  2. In tab B, discard a draft.
  3. In tab A, without reloading, create a new draft.
  4. Reload: the discarded draft stays gone and the new draft is listed.

Migration Notes

None. No schema change.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes (releases sent through COLLECTION_VIRTUAL_MCP_UPDATE is now ignored)

🤖 Generated with Claude Code


Summary by cubic

Fixes draft list edits racing across tabs: a stale tab could write its old metadata.releases array back, resurrecting discarded drafts and hiding drafts other tabs created. Edits are now applied to the stored list on the server, and whole-metadata writes keep the stored list.

  • New VIRTUAL_MCP_RELEASE_EDIT tool applies one edit (add, add pull request, rename, remove, mark-sandbox) to the stored list under a row lock, so concurrent edits from other tabs or people compose.
  • The edit reducers moved to @decocms/shared/release-edits; the web applies the same edit to its cache optimistically, then takes the list the server returns.
  • Behavior change: releases sent via COLLECTION_VIRTUAL_MCP_UPDATE is now ignored; the field's description points to the new tool.

Not in this PR: pushing the list to other open tabs (they still show their old copy until the next refetch, but can no longer write it back), and cleaning up entries that already point at deleted branches.

Written for commit 8204c3b. Summary will update on new commits.

View guided diff Turn on auto-fix

…t write its old list back

`useReleases().write` sent the whole `metadata.releases` array from the tab's
cache, and the update tool replaced it as sent. A tab opened before another
change wrote its old list back: discarded drafts returned and drafts created
meanwhile disappeared.

- VIRTUAL_MCP_RELEASE_EDIT applies one edit (add, add pull request, rename,
  remove, mark sandbox) to the stored list under a row lock and writes only
  that key, so concurrent edits compose.
- A whole-metadata update keeps the stored `releases`; the list changes only
  through the new tool.
- The edit reducers move to `@decocms/shared/release-edits`; the web applies
  the same edit optimistically and then takes the server's list.

Closes #8569

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the claude PR authored by a coding agent label Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude PR authored by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Draft list: a stale tab writes its old metadata.releases back

1 participant