Skip to content

feat(prompts): make external prompt groups read-only - #17008

Open
AtefBellaaj wants to merge 1 commit into
atef/ai-2275-route-prompts-by-source-and-add-a-read-only-langfuse-adapterfrom
atef/ai-2276-make-external-prompt-groups-read-only
Open

AtefBellaaj wants to merge 1 commit into
atef/ai-2275-route-prompts-by-source-and-add-a-read-only-langfuse-adapterfrom
atef/ai-2276-make-external-prompt-groups-read-only

Conversation

@AtefBellaaj

@AtefBellaaj AtefBellaaj commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Pull Request

Summary

Prompt groups with a non-native source (Langfuse, from #16909) are owned by the external system and are recreated by a later sync, but today PATCH /api/prompts/groups/:groupId and DELETE /api/prompts/groups/:groupId still change them, promote and revision delete are blocked only because these groups have no local Prompt rows, and the UI shows Edit and Delete for them.

This PR makes every mutation of an external group fail with a new read_only service error, which the handlers map to 403 { code: 'read_only', error: 'Externally managed prompts are read-only' }. The guard reads the stored group (the middleware-loaded record when its id matches, otherwise the database), so the MANAGE_PROMPTS ACL bypass is covered too. Sharing, POST /groups/:groupId/use and GET /groups/:groupId/resolve are unchanged.

In the client, the list menu hides Edit and Delete for external groups and shows a source badge, and the detail page renders a read-only view with a "Managed in Langfuse" notice and keeps Share. The group update and group delete error toasts map read_only to localized copy. Prompt text display for external groups is not part of this PR.

Depends on #16909 (this PR is based on its branch).

How it works

Every write path checks the stored group before validation, writes, revision reads or cache clears:

savePrompt            readGroup(groupId, loadedGroup)      -> read_only
updatePromptGroup     readGroup(groupId, loadedGroup)      -> read_only
deletePromptGroup     readGroup(groupId, loadedGroup)      -> read_only   (revision ids for cache invalidation are read after the guard)
makePromptProduction  readPrompt -> readGroup(revision.groupId) -> read_only
deletePrompt          readPrompt -> readGroup(revision.groupId) -> read_only
sendRejection         read_only -> 403 { code: 'read_only', error: 'Externally managed prompts are read-only' }

service.deletePromptGroup now returns the service's { ok } | error result; DELETE /groups/:groupId still responds { message } on success.

Type of change

  • Feature

Testing

  1. Start LibreChat and set a group to Langfuse in mongosh: db.promptgroups.updateOne({_id}, {$set: {source: 'langfuse', sourcePromptName: 'x', sourceProjectId: 'p', sourceDestination: 'env'}, $unset: {productionId: ''}}).
  2. Confirm the list menu has no Edit or Delete, the detail page is read-only with the notice, and Share works.
  3. Confirm PATCH and DELETE on the group return 403.

Tested environments/configuration:

  • Database: mongodb-memory-server (automated tests). The manual steps above have not been run yet.

Automated tests:

  • cd packages/api && npx jest src/prompts: 198 passed. Added read_only cases for all five mutations (loaded group, no loaded group, mismatched loaded group), a native deletePrompt success, and 403 / no cache clear in handlers.spec.ts.
  • cd api && npx jest server/routes/prompts.test.js: 76 passed. 403 with the database unchanged for PATCH group, DELETE group, POST revision, PATCH production and DELETE revision, as owner and as admin; /use still increments numberOfGenerations; the owner can still share through /api/permissions; a stored group without source stays editable.
  • cd client && npx jest components/Prompts hooks/Prompts utils/__tests__/prompts utils/__tests__/promptGroups: 83 passed. New specs for usePromptGroupPermissions, isExternalPromptGroup, disabled on PromptName and CategorySelector, ChatGroupItem and the PromptForm read-only view.
  • npx tsc --noEmit in packages/api and client, and node scripts/static-checks.mts --full on the changed files: pass.

Screenshots / recordings

Not captured yet. The change adds a read-only detail view, a list badge, and removes Edit/Delete from the list menu for external groups; screenshots from a local run will be added before this leaves draft.

Risk / compatibility

Additive guards only. Native groups behave the same, and there is no schema, index or migration change. Older clients receive the 403 through their existing error handling. No external groups exist before sync, so nothing changes for current users. Rollback is a revert.

Checklist

🤖 Generated with Claude Code

@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: 79cf62c

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 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-12T15:35:49.306908Z ad4818a 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: 79cf62c1d0

ℹ️ 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 thread client/src/utils/promptGroups.ts Outdated
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch from 79cf62c to ed6ba90 Compare October 12, 2026 07:30
@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: ed6ba90

@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: ed6ba90572

ℹ️ 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 thread packages/api/src/prompts/handlers.ts Outdated
@AtefBellaaj
AtefBellaaj added this pull request to stack #16896 October 12, 2026 07:48
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch from ed6ba90 to 58a613e Compare October 12, 2026 07:59
@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: 58a613e

@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: 58a613e45b

ℹ️ 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 thread client/src/utils/prompts.ts
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch from 58a613e to 94ecb40 Compare October 12, 2026 09:56
@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: 94ecb40

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 94ecb40d44

ℹ️ 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".

@codegraph-librechat codegraph-librechat Bot added the 🗺️ Prompt Library codegraph: the taxonomy area this belongs to (classifier, confidence ≥ 0.9) label Oct 12, 2026
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch from 94ecb40 to 06461ac Compare October 12, 2026 12:25
@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: 06461ac

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 06461acb73

ℹ️ 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 force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch from 06461ac to ad4818a Compare October 12, 2026 15:26
@AtefBellaaj

Copy link
Copy Markdown
Collaborator Author

@codex review

Head: ad4818a

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: ad4818ae51

ℹ️ 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 13, 2026 09:08
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch from ad4818a to fad646f Compare October 13, 2026 09:08
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch 2 times, most recently from a78bde9 to 0990874 Compare October 14, 2026 07:00
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch from 0990874 to 3aa58a6 Compare October 14, 2026 12:16
@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-2276-make-external-prompt-groups-read-only branch from 3aa58a6 to 1e40e77 Compare October 14, 2026 12:55
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch 3 times, most recently from 1e40e77 to e7ba6fe Compare October 14, 2026 13:43
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch 2 times, most recently from 6b7bbc9 to dbba52d Compare October 15, 2026 08:22
Reject edits, deletes, new revisions, promotion and revision deletes on
prompt groups whose source is not native with a read_only service error,
mapped to 403 "Externally managed prompts are read-only". The guard reads
the stored group, so the MANAGE_PROMPTS bypass is covered. Sharing,
usage counts and resolution are unchanged.

The client hides Edit and Delete for external groups, shows a read-only
detail view with a Langfuse notice and keeps Share.
@AtefBellaaj
AtefBellaaj force-pushed the atef/ai-2276-make-external-prompt-groups-read-only branch from dbba52d to 61eecd1 Compare October 15, 2026 11:05

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

🗺️ Prompt Library 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