Skip to content

🏗️ feat(prompts): add source identity to prompt groups - #16891

Open
AtefBellaaj wants to merge 1 commit into
atef/ai-2271-langfuse-prompt-testfrom
atef/ai-2272-add-source-identity-to-promptgroup
Open

AtefBellaaj wants to merge 1 commit into
atef/ai-2271-langfuse-prompt-testfrom
atef/ai-2272-add-source-identity-to-promptgroup

Conversation

@AtefBellaaj

@AtefBellaaj AtefBellaaj commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A PromptGroup has no record of where it came from, so later work that routes prompt operations by source, or that syncs prompts from an external catalog such as Langfuse, has nothing to key on. This PR adds the source fields to PromptGroup and stops a client from setting them. Existing native prompts keep working without a migration.

Stacked on #16854 (atef/ai-2271-langfuse-prompt-test). No UI change.

How it works

The schema stores flat, typed scalar fields rather than a subdocument or a Mixed blob, so each one maps to one column on FerretDB/PostgreSQL. source defaults to native, and toPromptGroupRecord maps a stored group without source to native, which is the only place the default applies.

 productionId: {
   type: Schema.Types.ObjectId,
   ref: 'Prompt',
-  required: true,
+  required: function (this: IPromptGroupDocument) {
+    return (this.source ?? 'native') === 'native';
+  },
 },
+source: { type: String, enum: ['native', 'langfuse'], default: 'native' },
+sourcePromptName: {
+  type: String,
+  required: function (this: IPromptGroupDocument) {
+    return this.source === 'langfuse';
+  },
+},
+// sourceProjectId and sourceDestination: same shape
...
+promptGroupSchema.index(
+  { tenantId: 1, sourceDestination: 1, sourceProjectId: 1, sourcePromptName: 1 },
+  { unique: true, partialFilterExpression: { sourcePromptName: { $exists: true } } },
+);

Write paths:

  • Create: createPromptGroup in packages/api/src/prompts/service.ts removes source, sourcePromptName, sourceProjectId and sourceDestination from the client group, so a client create always produces a native group. The native create upsert filter also has source: { $ne: 'langfuse' }, because productionId: null alone also matches a group with no productionId.
  • Update: updatePromptGroupSchema is .strict() and already rejects these keys. A test covers this.
  • Reads: getAllPromptGroups, getPromptGroups and getListPromptGroupsByAccess select the four fields. PromptGroupRecord and TPromptGroup declare source as required.

Type of change

  • Feature

Testing

Tested environments/configuration: mongodb-memory-server (Jest).

Automated tests:

  • packages/data-schemas: npx jest src/methods/prompt (57 pass). These tests cover native groups rejected without productionId, langfuse groups saved without it, langfuse groups rejected without identity fields, duplicate identity rejected in one tenant and accepted across tenants, duplicate native names accepted, the source fields in all three list methods, and a native create that does not merge into a langfuse group with the same name.
  • packages/api: npx jest src/prompts (125 pass), including the new records.spec.ts (missing source maps to native), the create guard (raw stored document is native, without identity fields) and the strict update schema.
  • api: npx jest server/routes/prompts.test.js (55 pass).
  • npx tsc --noEmit passes in packages/data-schemas, packages/api, packages/data-provider and client. Prettier, eslint and sort-imports pass on the changed files.

Screenshots / recordings

No user-facing change.

Risk / compatibility

  • Additive schema change. Existing groups have no source; they validate as native (productionId stays required for them) and read as native. No data migration.
  • The unique partial index covers only documents with sourcePromptName. No existing document has it, so the autoIndex build at startup is empty and cannot fail on duplicates. It uses the same $exists partial filter form as existing indexes, so it works on FerretDB and DocumentDB. No new aggregate stages or Mongo-only operators.
  • Rollback is safe: earlier versions ignore the new fields, and the empty index is harmless.
  • Rollout order: a later change that writes non-native groups must deploy only after every pod runs this schema, because the earlier native create upsert does not exclude them.
  • The create guard removes only the four source fields. Other keys in the client group reach the upsert as before.

Checklist

  • I reviewed my own changes
  • Relevant tests have been added or updated
  • Existing relevant tests pass
  • The change does not introduce new warnings or errors
  • User-facing or complex behavior is documented where necessary
  • Required dependency changes have been merged/published
  • Required documentation PR: N/A

🤖 Generated with Claude Code

@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review head edecafb7badacb1dae24a8d5e3615efa76b32ce2.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T16:33:43.173677Z 8649d12 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: edecafb7ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1129 to +1132
source: TPromptGroupSource;
sourcePromptName?: string;
sourceProjectId?: string;
sourceDestination?: string;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude immutable source fields from the update payload

When a typed client calls updatePromptGroup, TUpdatePromptGroupPayload = Partial<TPromptGroup> now permits all four provenance fields added here, but packages/api/src/prompts/schemas.ts uses a strict update schema that rejects each of them. Thus the public client contract accepts requests that invariably receive an invalid-request response; omit these immutable fields from the update payload type or define the payload from the fields the endpoint actually accepts.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b0dc9fb. TUpdatePromptGroupPayload is now Partial<Omit<TPromptGroup, 'source' | 'sourcePromptName' | 'sourceProjectId' | 'sourceDestination'>>, so the typed client contract matches the strict update schema. tsc --noEmit is clean in data-provider, api and client; the only caller (PromptForm.tsx) already passes specific fields. packages/api src/prompts: 125 tests pass.

@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch from edecafb to b0dc9fb Compare October 8, 2026 15:37
@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review head b0dc9fbb9ccd8b9824328af7c6a76107d0259b27.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: b0dc9fbb9c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@AtefBellaaj AtefBellaaj changed the title feat(prompts): add source identity to prompt groups 🏗️ feat(prompts): add source identity to prompt groups Oct 8, 2026
@AtefBellaaj
AtefBellaaj added this pull request to stack #16896 October 8, 2026 16:19
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch from b0dc9fb to 8649d12 Compare October 8, 2026 16:20
@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review head 8649d12ec7e96756e234d6618cf33ff88c732d49 (rebased onto the updated base; same change as b0dc9fbb9).

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 8649d12ec7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@AtefBellaaj
AtefBellaaj marked this pull request as ready for review October 8, 2026 16:59
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch from 8649d12 to 3c2a54d Compare October 8, 2026 16:59
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch 2 times, most recently from 137b801 to 7f587fd Compare October 9, 2026 10:06
@codegraph-librechat codegraph-librechat Bot added 🗺️ Mongoose Models codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🗺️ DB Models codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) labels Oct 9, 2026
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch 2 times, most recently from 3e96977 to 00f8d83 Compare October 13, 2026 09:08
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch 2 times, most recently from be6a058 to 42af5a6 Compare October 14, 2026 07:00
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch from 42af5a6 to c1e1748 Compare October 14, 2026 12:15
@AtefBellaaj
AtefBellaaj removed this pull request from stack #16896 October 14, 2026 12:53
@AtefBellaaj
AtefBellaaj added this pull request to stack #17090 October 14, 2026 12:55
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch from c1e1748 to 8a7fe3e Compare October 14, 2026 12:55
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch from 8a7fe3e to fecabe8 Compare October 14, 2026 13:41
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch 2 times, most recently from 504bd04 to 1546660 Compare October 15, 2026 08:22
Add source, sourcePromptName, sourceProjectId and sourceDestination to
PromptGroup. productionId is required only for native groups. A unique
partial index on the source identity covers only groups that have
sourcePromptName, so native groups need no migration.

The create path drops client-supplied source fields, and the native
create upsert does not match langfuse groups. Records map a missing
source to native.
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2272-add-source-identity-to-promptgroup branch from 1546660 to 1019558 Compare October 15, 2026 10:49
@codegraph-librechat codegraph-librechat Bot added the 🗺️ DB Models & Ops codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) label Oct 15, 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

🗺️ DB Models & Ops codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🗺️ DB Models codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) 🗺️ Mongoose Models codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant