fix(objectql): listDrafts surfaces env-wide drafts under a non-null org (orphaned-draft fix)#1852
Merged
Merged
Conversation
The pending-changes list (`GET /meta/_drafts`, the Publish CTA's source)
queried `organization_id = this.organizationId AND state = 'draft'`. AI-
authored metadata is written ENV-WIDE (`organization_id IS NULL`), so under
a non-null active org (every multi-tenant / cloud request) the strict
equality dropped those drafts: the change showed in `?preview=draft` and
`publish-drafts` would promote it, but the pending-changes list returned
nothing — so the Publish CTA never appeared and the user couldn't publish
their AI-made change ("orphaned draft").
Surface both org-scoped and env-wide drafts: when the active org is
non-null, match `organization_id = org OR organization_id IS NULL`; when
null (single-env), keep the env-wide query. This mirrors how
`getMetaItems`/preview already overlays env-wide drafts.
Tests: non-null-org surfaces env-wide drafts; mixed org-scoped + env-wide
returned while other orgs' drafts excluded. Suite green (6). Mock engine
extended to evaluate `$or`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
os-zhuang
added a commit
that referenced
this pull request
Jul 18, 2026
…scope (#3115) (#3156) * fix(metadata): publish/discard package drafts in the draft's own org scope (#3115) Studio "Save Draft" goes through REST `PUT /meta/:type/:name?mode=draft`, which never threads the session's `activeOrganizationId` into `saveMetaItem` — so the draft row is written env-wide (`organization_id = NULL`). "Publish" goes through `POST /packages/:id/publish-drafts`, which DOES resolve the active org (non-null once a default org is stamped on the session). PR #1852 taught `listDrafts` to surface those env-wide drafts to a non-null active org via `$or [{org}, {org IS NULL}]` — so the Publish CTA appears — but the publish path (`promoteDraft`) still looked the draft up with a STRICT `organization_id = <org>` equality and 404'd (`[no_draft] No pending draft exists …`) on the env-wide row it could never match. `discardPackageDrafts` had the identical latent gap (delete under the request org silently no-ops on env-wide rows). Fix: `listDrafts` now projects each draft's own `organizationId`, and `publishPackageDrafts` / `discardPackageDrafts` promote / delete each draft in THAT scope (env-wide stays env-wide, per-org stays per-org) — so the pending-changes list and the publish/discard paths agree. Seed-body capture and the ADR-0067 revert-plan pre-state read are scoped the same way. Regression tests reproduce the exact `no_draft` error (env-wide draft + non-null publish org) and assert publish now succeeds env-wide, plus a no-regression case for a genuinely org-scoped draft. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * chore(changeset): metadata-protocol patch for publish-drafts org-scope fix (#3115) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Jack Zhuang <277994282+os-zhuang@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
GET /meta/_drafts— the pending-changes list that drives the Publish CTA — callsSysMetadataRepository.listDrafts, which queried:AI-authored metadata is written env-wide (
organization_id IS NULL). Under a non-null active org (every multi-tenant / cloud request) the strict equality dropped those drafts. So an AI-added field/view:?preview=draft(getMetaItems overlays env-wide rows)publish-drafts(In single-env
org=nullthe old query already matched env-wide rows, so this only bit the multi-tenant/cloud path.)Fix
Surface both org-scoped and env-wide drafts — when the active org is non-null, match
organization_id = org OR organization_id IS NULL; when null, keep the env-wide query. Mirrors howgetMetaItems/preview already overlays env-wide drafts.Verification
listDraftssuite green (6); mock engine extended to evaluate$or._draftslists it →publish-draftsmaterializes the field immediately.🤖 Generated with Claude Code