Skip to content

fix(objectql): listDrafts surfaces env-wide drafts under a non-null org (orphaned-draft fix)#1852

Merged
xuyushun441-sys merged 1 commit into
mainfrom
fix/list-drafts-include-env-wide
Jun 14, 2026
Merged

fix(objectql): listDrafts surfaces env-wide drafts under a non-null org (orphaned-draft fix)#1852
xuyushun441-sys merged 1 commit into
mainfrom
fix/list-drafts-include-env-wide

Conversation

@xuyushun441-sys

Copy link
Copy Markdown
Contributor

Problem

GET /meta/_drafts — the pending-changes list that drives the Publish CTA — calls SysMetadataRepository.listDrafts, which queried:

{ organization_id: this.organizationId, state: 'draft' }

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:

  • ✅ showed in ?preview=draft (getMetaItems overlays env-wide rows)
  • ✅ would be promoted by publish-drafts
  • ❌ but never appeared in the pending-changes list → the Publish CTA never showed → the user couldn't publish their AI-made change ("orphaned draft").

(In single-env org=null the 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 how getMetaItems/preview already overlays env-wide drafts.

Verification

  • 2 regression tests: a non-null-org repo surfaces env-wide drafts; mixed org-scoped + env-wide returned while other orgs' drafts stay excluded. listDrafts suite green (6); mock engine extended to evaluate $or.
  • On the objectos-ee rig (single-env, org=null — the no-op path) the full loop is clean: draft → _drafts lists it → publish-drafts materializes the field immediately.

🤖 Generated with Claude Code

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>
@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
spec Building Building Preview, Comment Jun 14, 2026 3:55pm

Request Review

@github-actions github-actions Bot added the tests label Jun 14, 2026
@xuyushun441-sys
xuyushun441-sys merged commit 42c5469 into main Jun 14, 2026
7 of 8 checks passed
@xuyushun441-sys
xuyushun441-sys deleted the fix/list-drafts-include-env-wide branch June 14, 2026 15:55
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants